简体   繁体   中英

Emacs Neotree: Open file at point in external application

I have to interact with Windows software projects for work but I like to do most of my programming in Emacs. I'm using emacs for Windows. I want to be able to switch to a Neotree buffer, and open the file at the point in an external app. An example would be a pdf file in Adobe or a project file in Visual Studio.

I'm not fluent enough in elisp to make my own command to do this, and I'm wondering if there is an easy way to either hook into Neotree or write some custom function to open the file externally.

I know I can open the current buffer file in an external app, I just don't know how to do it in Neotree (Which I have integrated with Projectile)

Any help would be appreciated.

Use the following:

(defun neotree-open-file-in-system-application ()
(interactive)
(shell-command (concat "start " (neo-buffer--get-filename-current-line))))

This overwrites the Neotree's default function. In the original neotree.el file they use the following code:

(defcustom neo-default-system-application "xdg-open"
"Name of the application that is used to open a file under point.
 By default it is xdg-open."
 :type 'string
 :group 'neotree)

(defun neotree-open-file-in-system-application ()
"Open a file under point in the system application."
(interactive)
(call-process neo-default-system-application nil 0 nil
            (neo-buffer--get-filename-current-line)))

I have tried changing the "xdg-open" to "start" , "start ","start-process" etc. but none of them worked. Replacing the call-process in the original function with a simple shell-command + file path seems to do the trick.

Note: Since we have overwritten the original function, all the shortcuts still work. Default shortcut to open a file with the default app is "o".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM