emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Go to heading using LISP


From: Alexander Wingård
Subject: Re: [O] Go to heading using LISP
Date: Wed, 19 Jun 2013 20:24:26 +0200

On Mon, Jun 10, 2013 at 11:14 PM, Alexander Wingård <address@hidden> wrote:

Maybe some day I will learn some LISP and teach it to navigate the hierarchical structure.


I actually got curious and gave this a try and here's what I came up with:
test.org:
* a
** b
*** h
** b
*** q
**** h
** c
*** d

Elisp:
(defun goto-notes ()
  (interactive)
  (find-file "~/test.org")
  (org-goto-subtree '("a" "b" "q" "h"))
  (org-show-context)
  (org-show-entry)
  (show-children))

(defun org-goto-subtree (path)
  (let ((level 1))
    (org-element-map
        (org-element-parse-buffer 'headline)
        'headline
        (lambda (x)
          (if (< (org-element-property :level x) level)
              (setq level (org-element-property :level x)))
          (if (and (= level (org-element-property :level x))
                   (string= (nth (- level 1) path) (org-element-property :raw-value x)))
              (progn (setq level (+ level 1))
                     (if (> level (list-length path))
                         (goto-char (org-element-property :begin x))))))
        nil t)))

https://gist.github.com/AlexanderWingard/5814843

My very first attempt at programming Elisp so any feedback is appreciated.

Best regards
Alexander

reply via email to

[Prev in Thread] Current Thread [Next in Thread]