I use Emacs whenever I can (which is, nowadays, for almost all the work I do) but I still need to switch away occasionally for some apps. Usually this involves starting up Nautilus, navigating to a directory, finding some files (e.g. PDFs or web pages), and double-clicking them. I wrote some Emacs functions to do the equivalent from Dired, avoiding the need to use Nautilus at all. This makes Dired a lot more useful as a file manager/browser for all kinds of files, not just text files.
gnome-open opens a file using the same application which would have been used to open it had you double-clicked it in Nautilus (Evince for PDFs, OpenOffice for OO.o docs, etc.). The following function takes a file and calls gnome-open on it:
(defun gnome-open-file (filename) "gnome-opens the specified file." (interactive "fFile to open: ") (let ((process-connection-type nil)) (start-process "" nil "/usr/bin/gnome-open" filename)))
In a Dired buffer, the following function gnome-opens the file on which your cursor is sitting:
(defun dired-gnome-open-file () "Opens the current file in a Dired buffer." (interactive) (gnome-open-file (dired-get-file-for-visit)))
I bound it to 'E':
(add-hook 'dired-mode-hook (lambda () (local-set-key "E" 'dired-gnome-open-file)))
VERY helpful. Thanks man.
ReplyDelete