;; -*- coding: utf-8; lexical-binding: t; -*- ;; before 2022-08-19 (defun xah-open-in-external-app (&optional Fname) "Open the current file or dired marked files in external app. When called in emacs lisp, if Fname is given, open that. URL `http://xahlee.info/emacs/emacs/emacs_dired_open_file_in_ext_apps.html' Version: 2019-11-04 2021-07-21" (interactive) (let ($fileList $doIt ) (setq $fileList (if Fname (list Fname) (if (string-equal major-mode "dired-mode") (dired-get-marked-files) (list (buffer-file-name))))) (setq $doIt (if (<= (length $fileList) 5) t (y-or-n-p "Open more than 5 files? "))) (when $doIt (cond ((string-equal system-type "windows-nt") (mapc (lambda ($fpath) (shell-command (concat "PowerShell -Command \"Invoke-Item -LiteralPath\" " "'" (shell-quote-argument (expand-file-name $fpath )) "'"))) $fileList)) ((string-equal system-type "darwin") (mapc (lambda ($fpath) (shell-command (concat "open " (shell-quote-argument $fpath)))) $fileList)) ((string-equal system-type "gnu/linux") (mapc (lambda ($fpath) (let ((process-connection-type nil)) (start-process "" nil "xdg-open" $fpath))) $fileList)) ((string-equal system-type "berkeley-unix") (mapc (lambda ($fpath) (let ((process-connection-type nil)) (start-process "" nil "xdg-open" $fpath))) $fileList)))))) ;; after 2022-08-19 (defun xah-open-in-external-app (&optional Fname) "Open the current file or dired marked files in external app. When called in emacs lisp, if Fname is given, open that. URL `http://xahlee.info/emacs/emacs/emacs_dired_open_file_in_ext_apps.html' Version: 2019-11-04 2021-07-21 2022-08-19" (interactive) (let ($fileList $doIt ) (setq $fileList (if Fname (list Fname) (if (string-equal major-mode "dired-mode") (dired-get-marked-files) (list (buffer-file-name))))) (setq $doIt (if (<= (length $fileList) 5) t (y-or-n-p "Open more than 5 files? "))) (when $doIt (cond ((string-equal system-type "windows-nt") (mapc (lambda ($fpath) (shell-command (concat "PowerShell -Command \"Invoke-Item -LiteralPath\" " "'" (shell-quote-argument (expand-file-name $fpath )) "'"))) $fileList)) ((string-equal system-type "darwin") (mapc (lambda ($fpath) (shell-command (concat "open " (shell-quote-argument $fpath)))) $fileList)) ((string-equal system-type "gnu/linux") (mapc (lambda ($fpath) (call-process shell-file-name nil nil nil shell-command-switch (format "%s %s" "xdg-open" (shell-quote-argument $fpath)))) $fileList)) ((string-equal system-type "berkeley-unix") (mapc (lambda ($fpath) (let ((process-connection-type nil)) (start-process "" nil "xdg-open" $fpath))) $fileList))))))