emacs中dired如何能按照文件类型选择相应的软件打开

Vim、Emacs配置和使用
回复
happycock
帖子: 13
注册时间: 2007-08-05 4:03

emacs中dired如何能按照文件类型选择相应的软件打开

#1

帖子 happycock » 2009-02-23 18:33

希望在dired中在文件上回车后调用系统相应的软件打开文件,而不是用emacs自己以文本形式打开?不知道有没有解决方法?
happycock
帖子: 13
注册时间: 2007-08-05 4:03

Re: emacs中dired如何能按照文件类型选择相应的软件打开

#2

帖子 happycock » 2009-02-23 20:49

希望在dired中在文件上回车后调用系统相应的软件打开文件,而不是用emacs自己以文本形式打开?不知道有没有解决方法?
刚才自己diy了一个,参考的http://www.emacswiki.org/emacs/dired-open.el

自己又改了改,可以满足我的要求了。如果有人需要,把下面对应的程序改成自己想要的就行了,加到.emacs中

代码: 全选

;帮定到M-RET上
(add-hook 'dired-mode-hook
 (lambda ()
   (define-key dired-mode-map (kbd "M-RET") 'dired-open-file)
 )) 

(defun dired-open-file ()
  "Dired find file function.
Open file use another tool"
  (interactive)
  (dolist (file (dired-get-marked-files))
    (dired-open-file-internal file)))

(defun dired-open-file-internal (file)
  "Open diversified format FILE."
  (interactive "fFile: ")
  (let ((file-extension (file-name-extension file)))
    (if file-extension
        (cond ((string-match "\\(pdf\\|ps\\|dvi\\)$" file-extension)
	       (call-process-shell-command (format "kpdf %s" file) nil 0))               
	      ((string-match "\\(jpg\\|jpeg\\|gif\\|bmp\\|png\\)$" file-extension)
	       (call-process-shell-command (format "gwenview %s" file) nil 0))
	      ((string-match "\\(avi\\|rmvb\\|rm\\|mpeg\\|mpg\\|flv\\)$" file-extension)
	       (call-process-shell-command (format "kaffeine %s" file) nil 0))
	      ((string-match "\\(mp3\\)$" file-extension)
	       (call-process-shell-command (format "amarok %s" file) nil 0))
              (t (find-file file)))
      (find-file file))))
回复