OpenWith is a simple but very useful package to make Emacs associate various file types with external applications. For example, Emacs can open PDFs, but you may want to open them with a dedicated PDF viewer instead. With OpenWith, you can do this seamlessly when you use C-x C-f. It also works with recentf and ido.
See also http://www.emacswiki.org/emacs/OpenWith.
After installation the command openwith-mode
, which enables the global minor mode, is autoloaded, you can call it without any additional configuration.
Having set up straight.el, add the following to your .emacs.d/init.el
, then restart your Emacs:
(straight-use-package
'(openwith :fork (:host github :repo "luisgerhorst/openwith")))
For a complete example configuration see example-configs/straight/init.el
. You can omit the parts already included in your init.el
.
To enable OpenWith automatically when the desktop environment is recognized, add the following to your .emacs.d/init.el
after installing it:
(require 'openwith)
(when openwith-desktop-environment-open
(openwith-mode t))
The following serves as documentation for contributors to easy development. If you just want to use this package as a end user this should not concern you.
Refer to the Makefile
for additional commands that may be useful.
Install cask, then:
make all
cask emacs
Load the example configuration into a vanilla instance of Emacs, this will install straight.el to ./example-config/straight
:
make test
- Implement that fulfills the following: We either want to open files or directories
- Certain files Emacs does not handle well (e.g. binary files for which the user has not specified a mode) should be opened in external programs by default. By default they should be opened with the program specified by the desktop environment (
xdg-open
,open
, etc.). The user should also be able to open those files in a program he specified (either in their config or by calling a special function that presents them a list of programs that may be suitable, similar to their desktop environment). - By default directories should be opened in dired. When the user calls a special command they can choose to open the directory in any other program (e.g. their file browser which we can do using
xdg-open
et al). They should also be able to open the file in a Terminal program (which may not be the default one).
- Certain files Emacs does not handle well (e.g. binary files for which the user has not specified a mode) should be opened in external programs by default. By default they should be opened with the program specified by the desktop environment (
- Is it a problem that we may prevent the opening of arbitrary (possibly scripted) pdf files in Emacs?
- Fuco1/dired-hacks/dired-open.el has a nice system determining how to open files. It's tighlty integrated into the hooks he uses but if maybe we can reuse it with some work and replace
openwith-associations
. - How does it behave over SSH?
- Call
dired-find-file
using a hook. - Only attempt to call the chosen command when it is atually available. This way we effectively auto-disable ourself when opening likely won't work.
- Replace
openwith-desktop-environment-open
withopenwith-default-open