Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs org-mode file/viewer associations

Tags:

In an Emacs org-mode file, when I click on a PDF the file opens in a PDF viewer. Similarly, when I click on a URL it opens in a web browser. But when I click on a path to an image file, the byte stream opens as text in the editor. How do I configure Emacs/org-mode to open images with a specified application, say an image editor or a browser?

like image 611
John D. Cook Avatar asked Oct 20 '10 00:10

John D. Cook


People also ask

How do I view .org files?

Since ORG files are saved in plain text, you can also open and edit them with a plain text or source code editor. Microsoft Notepad (Windows) and Apple TextEdit (macOS) are text editors bundled with their respective operating systems that support ORG files.

How do I use org Mode in Emacs?

Emacs does not actually understand you are editing an Org document, yet. To enable Org mode on your current document, type M-x org-mode which will enable the Org mode on the current document. Those are minuses, not underscores.

What are org mode files?

Org Mode (also: org-mode; /ˈɔːrɡ moʊd/) is a document editing, formatting, and organizing mode, designed for notes, planning, and authoring within the free software text editor Emacs.


2 Answers

In org-mode, this is org-file-apps that control what to do when clicking on a URL-like text.

It is configured by default to :

((auto-mode . emacs)  ("\\.mm\\'" . default)  ("\\.x?html?\\'" . default)  ("\\.pdf\\'" . default)) 

As said in org-file-apps help : auto-mode matches files that are matched by any entry in auto-mode-alist, so all files Emacs knows how to handle. Using this with command emacs will open most files in Emacs.

You may have image file extension configured in auto-mode-alist. You could override this alist by doing something like this in your .emacs (for example, for png files) :

(add-hook 'org-mode-hook       '(lambda ()              (setq org-file-apps                    (append '(                              ("\\.png\\'" . default)                              ) org-file-apps )))) 

With this code, when I click on a link like this :

file:///e:/jrx/emacs/image.png 

It opens the file outside emacs, using the default OS program associated to this file extension.

You don't have to change org-file-apps-defaults-windowsnt, org-file-apps-defaults-gnu or org-file-apps-defaults-macosx to use the OS default program associated to the file extension.

like image 54
Jérôme Radix Avatar answered Sep 29 '22 16:09

Jérôme Radix


It depends a bit on what operating system you use, but it should be configurable with org-file-apps.

  • On OS X, I would use open (or open -a Application.app) for opening files automagically
  • On Linux/BSD etc, I would use xdg-open (a bit tricky to setup, tho)
  • On windows, I guess I would use open (in the console)

Look at the variables org-file-apps-defaults-windowsnt, org-file-apps-defaults-gnu or org-file-apps-defaults-macosx depending on your plattform.

like image 31
monotux Avatar answered Sep 29 '22 16:09

monotux