From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?ISO-8859-1?Q?Alexander_Wing=E5rd?= Subject: Re: Go to heading using LISP Date: Wed, 19 Jun 2013 20:24:26 +0200 Message-ID: References: <87wqq1oknt.fsf@gmail.com> <83D22E2E-B091-4BA7-8311-56F2DA9D57C4@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0021cc0229c6928d0604df85f0e9 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpN3a-0008Mk-7p for emacs-orgmode@gnu.org; Wed, 19 Jun 2013 14:24:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpN3V-0000Mi-9z for emacs-orgmode@gnu.org; Wed, 19 Jun 2013 14:24:32 -0400 Received: from mail-qc0-x229.google.com ([2607:f8b0:400d:c01::229]:52951) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpN3V-0000MN-50 for emacs-orgmode@gnu.org; Wed, 19 Jun 2013 14:24:29 -0400 Received: by mail-qc0-f169.google.com with SMTP id c10so3245985qcz.0 for ; Wed, 19 Jun 2013 11:24:26 -0700 (PDT) In-Reply-To: <83D22E2E-B091-4BA7-8311-56F2DA9D57C4@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Myles English Cc: emacs-orgmode --0021cc0229c6928d0604df85f0e9 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Mon, Jun 10, 2013 at 11:14 PM, Alexander Wing=E5rd < 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 (=3D level (org-element-property :level x)) (string=3D (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 --0021cc0229c6928d0604df85f0e9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Mon, Jun 10, 2013 at 11:14 PM, Alexander Wing=E5rd <alexander.wingard@gmail.com> wrote:

Maybe some day I will learn some LISP and teach it to navigate the hierarch= ical structure.


I actually got curious and gave this a try and here's wha= t I came up with:
test.org:
* a
** b
*** h
** b
*** q
**** h
=
** c
*** d
=
Elisp:
(defun got= o-notes ()
=A0 (interactive)
=A0 (find-file "~/test.org")
=A0 (org-goto-subtree '("a" "b" "q" = "h"))
=A0 (org-show-context)
=A0 (org-show-en= try)
=A0 (show-children))

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

<= div>
My very first attempt at programming Elisp so any = feedback is appreciated.

Best regards
Alexander
--0021cc0229c6928d0604df85f0e9--