45

Although it is convenient how org-mode shows hyperlinks, there are times when I want to see the underlying plain text, e.g. [[./file.org][Title]]. How can I do this?

I know about org-insert-link, but it is not what I want:

C-c C-l runs the command org-insert-link, which is an interactive compiled Lisp function in `org.el'.

...

If there is already a link at point, this command will allow you to edit link and description parts.

David J.
  • 1,809
  • 1
  • 13
  • 23

6 Answers6

45

I just found a nice function in the org source code: M-x org-toggle-link-display.

Here is the source code, just for fun:

(defun org-toggle-link-display ()
  "Toggle the literal or descriptive display of links."
  (interactive)
  (if org-descriptive-links
      (progn (org-remove-from-invisibility-spec '(org-link))
         (org-restart-font-lock)
         (setq org-descriptive-links nil))
    (progn (add-to-invisibility-spec '(org-link))
       (org-restart-font-lock)
       (setq org-descriptive-links t))))
David J.
  • 1,809
  • 1
  • 13
  • 23
  • 8
    This. Also, if you want to keep this behavior permanently, simply add `(setq org-descriptive-links nil)` to your init file. – undostres Dec 15 '14 at 02:01
  • 3
    Note this variable is accessible from the "Org > Hyperlinks" menu – Andrew Swann Dec 15 '14 at 08:22
  • 2
    Thanks - I just bound C-u C-c C-l to this. Very handy. `(define-key org-mode-map (kbd "C-u C-c C-l") 'org-toggle-link-display)` – Jake Jun 12 '22 at 00:58
21

A useful way to do this is

M-x font-lock-mode

which toggles font locking. When font locking is off, the hyperlink is visible in its undecorated form [[./file.org][Title]]. This can be a useful approach for seeing other pieces of mark-up in the buffer.

Andrew Swann
  • 3,436
  • 2
  • 15
  • 43
3

I've been using this function. It will toggle between fundamental-mode and the original mode (org-mode in this case). It's a bit weird, but I like it:

(defun illiterate ()
  (interactive)
  (let ((coding-system-for-read 'utf-8))
    (if (eq major-mode 'fundamental-mode)
        (revert-buffer nil t)
      (let ((pt (1+ (length
                     (encode-coding-string
                      (buffer-substring-no-properties (point-min) (point))
                      'utf-8))))
            (file-name (buffer-file-name)))
        (kill-buffer (current-buffer))
        (find-file-literally file-name)
        (goto-char pt)))))
abo-abo
  • 13,943
  • 1
  • 29
  • 43
2

Org mode achieves the link effect using the following code:

(if org-descriptive-links (add-to-invisibility-spec '(org-link)))

This adds org-link to the variable buffer-invisibility-spec which means that text which has its invisible property set to org-link will be hidden.

Using M-x visible-mode RET you can reset buffer-invisibility-spec temporary to nil, which means the hidden text will be shown from there on.

Using M-x visible-mode RET again you can reset buffer-invisibility-spec to its previous value, which will hide the relevant text parts again.

clemera
  • 3,401
  • 13
  • 40
2

A low-tech way is to move point to the beginning of the link text and type C-d (i.e., invoke org-delete-char). That removes the first "[" character, so that you no longer have a properly formatted hyperlink, and you can see the remainder of it as raw text. Then when you're done, just invoke undo to restore it to what you had previously.

user98761
  • 180
  • 3
  • 1
    This did not work for me in Emacs 24.4 (9.0) on Mac OS X with the default org installation. – David J. Dec 15 '14 at 15:56
  • (This is a comment to user98761's answer. Since I am not allowed to comment, I'll just write an answer here.) I like user98761's answer. Simple and straightforward. However, C-d does not work on the evil-mode EMACS on MY Mac, while the evil command 'x' works like a charm. More explicitly, move point to the beginning of the link text and type 'x'. – Jordan He Jan 13 '20 at 22:14
  • 1
    I'm no evil-mode expert. But surely 'x' as a Vi command does the same thing as C-d in regular Emacs. So it's really equivalent, I suspect. – user98761 Jan 15 '20 at 00:10
0

(Extending Andrew Swann above) Following may be a superset of what you want, but here goes:

I typically want to see all the markup (for everything, not just for links), occasionally switching back to the default/pretty display (mostly as a form of Org syntax validation). Hence I mostly set my display to

  1. turn off font-lock mode in my Org buffers, with effects as described by Swann above.
  2. wrap aka continue my lines (which in Emacsish is the opposite of truncating lines) to show all of each line.

But I am also still an Org noob, so I put the following comment at the top (TOF) of most of my Org files, ensuring that the 1st line in the comment is the 1st line of the file (thus becoming a local file variables list)

# -*- truncate-lines: nil; eval: (font-lock-mode -1); -*-
# 1. unset->wrap long lines in display, set->don't show continuation lines
# 2. unset->show undecorated text (e.g., don't prettify hyperlinks), set->display pretty

Eventually I'll either put this in my init file, or just adapt to the default Way of Org. But for now, it both

  1. configures the display behavior I want by default.
  2. reminds me what to do to get back to the default Org display. I don't yet want to put this in my init.el, because that makes it harder for me to remember how to toggle these display aspects.

Note also that

  1. truncate-lines is a normal variable, so one can just set it=nil as above. But ...
  2. font-lock-mode is a minor mode, so that requires the eval above to turn off, per The Fine Manual).
  3. You can also put the local-variables list at EOF with different syntax (RTFM again), but I'm more likely to see it at TOF.
TomRoche
  • 592
  • 3
  • 20