Skip to content

Instantly share code, notes, and snippets.

@kobapan
Created June 1, 2016 11:40
Show Gist options
  • Save kobapan/3fa4808790518b6b23273e764b36a46b to your computer and use it in GitHub Desktop.
Save kobapan/3fa4808790518b6b23273e764b36a46b to your computer and use it in GitHub Desktop.
【emacs】指定した拡張子のファイルをOSで関連づけられたプログラムで開く
;; OS で直接開きたいファイルかどうかを判定する
(defun os-open-file-p (file)
(if (file-regular-p file)
(let ((ext (file-name-extension file))
;; OS で起動したいファイルの拡張子一覧
(os-open-file-suffixes '("doc" "docx"
"xls" "xlsx"
"ppt" "pptx"
"mdb" "mdbx"
"vsd" "vdx" "vsdx"
"mpp"
"pdf"
"odt" "ott"
"odg" "otg"
"odp" "otp"
"ods" "ots"
"odf"
"ttf" "otf" "eot" "woff"
"jpg" "jpeg" "gif" "png" "svg" "flv" "mp4")))
(if (and ext
(member (downcase ext) os-open-file-suffixes))
t))))
;; dired の f に xdg-open を当てる
(defadvice find-file (around ad-find-file-for-os-open-command activate)
(let ((file (ad-get-arg 0))(process-connection-type nil))
(cond ((os-open-file-p file)
(start-process "os-open-command" nil "xdg-open" file))
(t
ad-do-it))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment