emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Alexander Wingård" <alexander.wingard@gmail.com>
To: Myles English <mylesenglish@gmail.com>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Go to heading using LISP
Date: Wed, 19 Jun 2013 20:24:26 +0200	[thread overview]
Message-ID: <CAJDwVzJsn5+ViTEmx6tdoma9b1PqZqh6ZQb=g-1oNuMXA=8W0g@mail.gmail.com> (raw)
In-Reply-To: <83D22E2E-B091-4BA7-8311-56F2DA9D57C4@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1303 bytes --]

On Mon, Jun 10, 2013 at 11:14 PM, Alexander Wingård <
alexander.wingard@gmail.com> 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

[-- Attachment #2: Type: text/html, Size: 2616 bytes --]

      reply	other threads:[~2013-06-19 18:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-08 13:52 Go to heading using LISP Alexander Wingård
2013-06-09  1:36 ` Eric Abrahamsen
2013-06-09 14:43   ` Alexander Wingård
2013-06-10  4:26     ` Eric Abrahamsen
2013-06-10  5:53       ` Jambunathan K
2013-06-10 19:00 ` Myles English
2013-06-10 21:14   ` Alexander Wingård
2013-06-19 18:24     ` Alexander Wingård [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJDwVzJsn5+ViTEmx6tdoma9b1PqZqh6ZQb=g-1oNuMXA=8W0g@mail.gmail.com' \
    --to=alexander.wingard@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mylesenglish@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).