1

I want to follow footnote links in org-mode by positioning the point over the link and hitting the return key.

In my init.el file, I have (setq org-return-follows-link t) which works fine for regular org-mode links but has no effect on footnotes, i.e., links of the form [fn:1].

Any ideas?

Update

I had an idea to add something like this to my init.el. But it's not working quite yet...

(global-set-key (kbd "<return>")
                (condition-case nil
                    (org-open-at-point)
                  (error (execute-kbd-macro (read-kbd-macro "<return>")))
                  ))
  • The built-in commands for following a footnote link are described in the manual: orgmode.org/manual/Footnotes.html Someone may wish to add this new return key feature, which can probably done without opening up a Pandora's Box [?]. – lawlist May 24 '17 at 21:50
  • Thanks @lawlist. Hey, I just added some code (above). It's not working yet. But maybe you have some insights? – Adam May 24 '17 at 22:31
  • @Adam Look at the documentation for functions global-set-key and the lower-level define-key (C-h f <function-name> RET). You should place the condition-case form within an interactive command, whether named (defun) or otherwise (lambda). – Basil May 25 '17 at 7:47
  • Thanks Basil. Can you elaborate on how to use interactive in this case? – Adam May 25 '17 at 11:51
  • @Adam See here, in particular this section. – Basil May 26 '17 at 18:11
1

I added a new condition to org-return, very similar to how it handles a link containing the org-link face property ..., with the new condition being triggered if the org-footnote face property is present. We use org-footnote-action to jump to/from. The code is from Org version 8.2.10 that ships with Emacs 25.2.1.

(require 'org)

(setq org-return-follows-link t)

(defun org-return (&optional indent)
  "Goto next table row or insert a newline.
Calls `org-table-next-row' or `newline', depending on context.
See the individual commands for more information."
  (interactive)
  (let (org-ts-what)
    (cond
      ((or (bobp) (org-in-src-block-p))
        (if indent (newline-and-indent) (newline)))
      ((org-at-table-p)
        (org-table-justify-field-maybe)
        (call-interactively 'org-table-next-row))
      ;; when `newline-and-indent' is called within a list, make sure
      ;; text moved stays inside the item.
      ((and (org-in-item-p) indent)
        (if (and (org-at-item-p) (>= (point) (match-end 0)))
          (progn
            (save-match-data (newline))
            (org-indent-line-to (length (match-string 0))))
          (let ((ind (org-get-indentation)))
            (newline)
            (if (org-looking-back org-list-end-re)
                (org-indent-line)
              (org-indent-line-to ind)))))
      ((and org-return-follows-link
        (org-at-timestamp-p t)
        (not (eq org-ts-what 'after)))
          (org-follow-timestamp-link))
      ((and org-return-follows-link
            (let ((tprop (get-text-property (point) 'face)))
              (or (eq tprop 'org-link)
                  (and (listp tprop) (memq 'org-link tprop)))))
         (call-interactively 'org-open-at-point))
      ;;; NEW CONDITION:  `org-footnote' face property => `org-footnote-action'
      ((and org-return-follows-link
            (let ((tprop (get-text-property (point) 'face)))
              (or (eq tprop 'org-footnote)
                  (and (listp tprop) (memq 'org-footnote tprop)))))
         (org-footnote-action))
      ((and (org-at-heading-p)
            (looking-at
              (org-re "\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)[ \t]*$")))
        (org-show-entry)
        (end-of-line 1)
        (newline))
     (t
        (if indent
          (newline-and-indent)
          (newline))))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.