Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all inbound links to a header in org-mode

Tags:

emacs

org-mode

Say I have an org-mode file with headers and links to headers in it (the links are in the file). Is there any way to list all inbound links to the current header in a buffer, and when I press Enter or click on one item, it jumps to the link?

Example:

* Header 1
  Contents of header 1.
* Header 2
  [[Header 1][Link 1]]
* Header 3
  [[Header 1][Link 2]]

When I am in Header 1, I want a list of all links in the file to Header 1 (i.e. "Link 1" and "Link 2") shown in a buffer; and when I click or press Enter on "Link 2" line, it jumps to Link 2, which is in Header 3.

like image 219
Truong Avatar asked Mar 23 '12 17:03

Truong


1 Answers

You can use occur to find the links by searching for [[Header Name][ and display the matching lines in an occur-mode buffer. Here is a function to automate this (using org-heading-components to get the current heading name):

(defun my/get-links-to-current-heading ()
  (interactive)
  (let ((title (nth 4 (org-heading-components))))
    (occur (concat "\\[\\[" title "\\]\\["))))

Using org-occur instead of occur will present you the list of matches as a sparse tree in the current org buffer.

like image 54
François Févotte Avatar answered Oct 15 '22 00:10

François Févotte