2011-07-27 4 views

答えて

19

はい。 diredの中で、ファイルに対してシェルコマンドを実行する場合は、!を使用してください。

evinceの場合、&を使用するほうが賢明です。これはコマンドを非同期に実行するため、PDFを開いている間もemacsを使用できるようになります。

3

!を使用してファイルを開き、コマンドを指定することができます。

+4

このコマンドを非同期に実行する場合は、 '!'の代わりに '&'を使います。 – Thomas

14

それ以上の方法があります。私はOpenWithライブラリを提案します。あなたのケースのためのセットアップは、次のようになります。

(add-to-list 'load-path "/path/to/downloaded/openwith.el") 
(require 'openwith) 
(setq openwith-associations '(("\\.pdf\\'" "evince" (file)))) 
(openwith-mode t) 

それはdiredfind-fileの両方から動作するファイルハンドラを設定します。

+3

少なくともMac OSXでは、 'evince'を' open'に置き換えた後、デフォルトのソフトウェア(私の場合は 'Skim')を使います。 – Dror

+3

この場合、 '!'や '&'を使わずにシェルコマンドを実行する代わりにdiredのファイル名に 'RET'を打つだけです。また、openwith-associationsでsetqを使うことで、組み込みのすべての関連を失います。 .mp3、.jpg、...のアソシエーションを残しながら、pdfアソシエーションのみを変更するより良い方法がありますか? –

+0

はい、他のものを失うことなくpdfの関連付けを変更する簡単な方法があります:M-x customize-group RET open with RET – Jorge

8

これを試してください。あなたはdiredで単一のファイルにnohup [ウィキペディア]を使用してのEmacsを終了した後、生きプロセスを維持するので、ポイントを置くことができ

(defun dired-open-file() 
    "In dired, open the file named on this line." 
    (interactive) 
    (let* ((file (dired-get-filename nil t))) 
    (message "Opening %s..." file) 
    (call-process "gnome-open" nil 0 nil file) 
    (message "Opening %s done" file))) 
+3

これはうまくいきました。 KDEのような別のGUIで使用する場合、 'gnome-open'を' xdg-open'に置き換えます。 –

0

OSXボックスのdired-modeからの外部アプリケーションでは、ユーザが外部アプリケーションで開くファイルの行にカーソルがあるときにC-c oというキーボードショートカットを使用して開きます。 2番目のdiredバッファが/Applicationsフォルダに開かれ、Enterキーが外部アプリケーションを選択します。 [複数のファイルを選択することはこの回答の範囲外ですが、興味があった場合に備えて、dired-get-marked-filesの定義を含めました。 Finder.appやDock.app、Spotlightのようなものを使用する代わりに、外部アプリケーションを開くオプションも含まれています.DWDの/Applicationsフォルダから、RETキーを押すと、 。例えば、(start-process "pdf-with-skim" nil "open" "-a" "/Applications/Skim.app/Contents/MacOS/Skim" input-filename) - アプリケーションの外部またはパッケージアプリケーションフォルダに入る]

は、第二の方法は、条件を設定し、選択したファイルを開くには、特定の外部アプリケーションを起動するためにstart-process . . .を使用する(equal (file-name-extension input-filename) ".pdf"))のようなものを使用することです。これは、サブ選択肢(例えば、Adobe、Skim、Preview)で非常に精巧にすることができ、string-match機能やさまざまなファイル拡張子を使用することもできます。この第2のアプローチは、インストールされた特定のプログラムに基づいてユーザの個人的嗜好に向かっているが、第1のオプション(以下)は、インストールされた外部アプリケーションにアクセスするために使用できる。

(require 'dired) 

(defun dired-read-file-name (&optional directory) 
    (if directory 
     (dired directory) 
    (dired nil)) 
    (let (output-filename) 
     (recursive-edit) 
     output-filename)) 

;; Open with external application. 
(defvar open-with-variable nil) 
(define-key dired-mode-map (kbd "C-c o") (lambda() (interactive) 
    (setq open-with-variable t) 
    (let* (
     (lawlist-filename (dired-get-file-for-visit)) 
     (application (dired-read-file-name "/Applications"))) 
    (start-process "external" nil "open" "-a" application lawlist-filename) 
    (setq open-with-variable nil)))) 

;; select file or directory. 
(define-key dired-mode-map (kbd "<return>") (lambda() (interactive) 
    (let* (
    (input-filename 
     (if (or (re-search-backward "^*" nil t) 
      (re-search-forward "^*" nil t)) 
     (dired-get-marked-files) 
     (dired-get-file-for-visit))) 
    (dired-buffer-name (buffer-name))) 
    (cond 
    ;; open file 
    ((and (not (file-directory-p input-filename)) 
     (file-exists-p input-filename) 
     (not (equal input-filename (concat (file-name-directory input-filename) "."))) 
     (not open-with-variable)) 
     (kill-buffer dired-buffer-name) 
     (find-file input-filename)) 
    ;; open with external application 
    ((and (file-directory-p input-filename) 
     (not (equal input-filename (concat (file-name-directory input-filename) "."))) 
     open-with-variable 
     (equal (file-name-extension input-filename) "app")) 
     (setq output-filename input-filename) 
     (kill-buffer dired-buffer-name) 
     (throw 'exit nil)) 
    ;; Enter the directory; or, open an application 
    ((and (file-directory-p input-filename) 
     (not (equal input-filename (concat (file-name-directory input-filename) ".")))) 
     (if (equal (file-name-extension input-filename) "app") 
     (progn 
      (message "[o]pen %s" (file-name-nondirectory input-filename)) 
      (let* ((open-or-enter (read-char-exclusive))) 
      (cond 
       ((eq open-or-enter ?o) 
       (start-process "application" nil "open" "-a" input-filename) 
       (kill-buffer dired-buffer-name)) 
       (t 
       (dired-find-file) 
       (goto-char (point-min)) 
       (re-search-forward " \\.\\.$" nil t) 
       (kill-buffer dired-buffer-name))))) 
     (dired-find-file) 
     (goto-char (point-min)) 
     (re-search-forward " \\.\\.$" nil t) 
     (kill-buffer dired-buffer-name))))))) 
1

Windowsでは、私は使用しません! PDF/Word/Excelを開くための "explorer"コマンドを実行します。

+0

「スタート」もうまくいくはずだと思います。 –

関連する問題