(defvar command-list
'(("jpg jpeg png bmp" .
"gqview")
("pdf djvu ps" .
"evince")
("html htm" .
"firefox -new-tab")
("ogv mpg mpeg avi flv
VOB wmv mp4 mov mkv divx
ogm m4v asf rmvb" .
"mplayer -fs")
("doc odf odt rtf" .
"ooffice")))
(defun build-re (str)
(let ((re "\\.\\(")
(ext-list (split-string str)))
(dotimes (n (- (length ext-list) 1))
(setq re (concat re (nth n ext-list) "$\\|")))
(setq re (concat re (car (last ext-list)) "$\\)$"))
re))
(defun try-open-external (filename)
(let ((success nil))
;; ,
(dolist (command command-list)
(let ((cmd (cdr command))
;; ,
(re (build-re (car command))))
;; .
(when (string-match re filename)
;; ,
(shell-command-to-string (concat cmd
" "
(shell-quote-argument filename)
" &> /dev/null &"))
(setq success t))))
;; .
success))
(fset 'old-find-file-noselect (symbol-function 'find-file-noselect))
(defun find-file-noselect (filename &optional nowarn rawfile wildcards)
(if (try-open-external filename)
nil
;; .
(old-find-file-noselect filename nowarn rawfile wildcards)))
(defun my-org-find-file (file)
(when (not (try-open-external file))
(find-file-other-window file)))
(org-file-apps (quote ((".*" my-org-find-file file))))
Source: https://habr.com/ru/post/47524/