Комментарии:
When in dired, just press ! top open a file in openoffice etc. You can also define external programs for file types.
ОтветитьIn Spacemacs theese two functions implement exactly what you want:
(defun spacemacs//open-in-external-app (file-path)
"Open `file-path' in external application."
(cond
((spacemacs/system-is-mswindows)
(w32-shell-execute "open" (replace-regexp-in-string "/" "\\\\" file-path)))
((spacemacs/system-is-mac) (shell-command (format "open \"%s\"" file-path)))
((spacemacs/system-is-linux) (let ((process-connection-type nil))
(start-process "" nil "xdg-open" file-path)))))
(defun spacemacs/open-file-or-directory-in-external-app (arg)
"Open current file in external application.
If the universal prefix argument is used then open the folder
containing the current file by the default explorer."
(interactive "P")
(if arg
(spacemacs//open-in-external-app (expand-file-name default-directory))
(let ((file-path (if (derived-mode-p 'dired-mode)
(dired-get-file-for-visit)
buffer-file-name)))
(if file-path
(spacemacs//open-in-external-app file-path)
(message "No file associated to this buffer.")))))
Calling spacemacs/open-file-or-directory-in-external-app over a filename in Dired, the file is opened with the default application associated with its type. If the current position in Dired is a directory (including . or ..), the file manager will open on that directory.
👍👍
ОтветитьMight be worth looking into calling xdg-open from the terminal or making some kind of binding to call it on the file at cursor in dired
ОтветитьIf one uses consult, then M-x consult-file-externally is also an option
ОтветитьHi, If I want to run a external application from dired, I type "!" over file in dired and I type name of application (libreoffice). It will open that file externally using that application. Emacs will be frozen until external app is closed. To avoid that, you can choose "&" instead of "!".
And also, you can set a default external application per extension. If configure this variable in your configuration file:
(require 'dired-x)
(setq dired-guess-shell-alist-user '(("\\.avi\\'" "totem")
("\\.doc\\'" "libreoffice")
("\\.docx\\'" "libreoffice")
("\\.mkv\\'" "totem")
("\\.mp3\\'" "totem")
("\\.mp4\\'" "totem")
("\\.odt\\'" "libreoffice")
("\\.pdf\\'" "evince")
("\\.ppt\\'" "libreoffice")
("\\.pptx\\'" "libreoffice")
("\\.webm\\'" "totem")
("\\.xls\\'" "libreoffice")))
With this config you type "!" or "&" and later ENTER because libreoffice is default for .odt files.
Other alternative is using shell-command (M-!) from dired, and type "libreoffice file.odf". It has autocompletion and use relative path from dired.
Both works for me.
Thank you for your videos!