Created
June 1, 2016 11:40
-
-
Save kobapan/3fa4808790518b6b23273e764b36a46b to your computer and use it in GitHub Desktop.
【emacs】指定した拡張子のファイルをOSで関連づけられたプログラムで開く
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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