emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Myles English <mylesenglish@gmail.com>
To: Nicolas Goaziou <n.goaziou@gmail.com>
Cc: emacs-orgmode Mode <emacs-orgmode@gnu.org>
Subject: Re: org-goto-local-search-headings usage?
Date: Wed, 16 May 2012 21:37:53 +0100	[thread overview]
Message-ID: <87396zeuam.fsf@gmail.com> (raw)
In-Reply-To: <87txzgjhsi.fsf@gmail.com> (Nicolas Goaziou's message of "Wed, 16 May 2012 16:56:45 +0200")


>> On Wed, 16 May 2012 16:56:45 +0200, Nicolas Goaziou said:
  > I highly suggest to use (org-element-parse-buffer 'headline) instead of
  > plain (org-element-parse-buffer), since you really don't need to spend
  > time parsing the buffer down to the smallest object.

  > Also, you should check :raw-value property instead of :title, since the
  > latter is a secondary string (a list containing strings and objects)
  > which, as such, will never match a string. :raw-value, on the other
  > hand, is always a string and doesn't require the (stringp title) test.

Thanks for your advice, and thanks too for org-element!

I can't believe that no one else needs a function to goto a heading, and
I am sure to need it again myself so did this:

(require 'org-element)
(defun my-goto-heading(file heading-text)
  "Visit file `file' and goto headline `heading-text'"
  (find-file file)
  (org-element-map (org-element-parse-buffer 'headline) 'headline
		   (lambda (x)
		     (if (string= (org-element-property :raw-value x) heading-text)
			 (goto-char (org-element-property :begin x))
		       nil))
		   nil t)) ;; stop at first find

and use it like this, so that whenever I need to remind myself of what
to do and how to do it I press (M-x gtd) :

(defun gtd()
  (interactive)
  (my-goto-heading "~/org/org/gtd.org" "My workflow")
  (reposition-window)
  (org-show-entry)
  (org-show-subtree)
  (org-agenda-list))

  > Regards,

  > -- 
  > Nicolas Goaziou

-- 
  `--[ Myles ]

      reply	other threads:[~2012-05-16 20:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-15 15:28 org-goto-local-search-headings usage? Myles English
2012-05-15 15:48 ` Nick Dokos
2012-05-15 21:09   ` Myles English
2012-05-15 21:33     ` Nick Dokos
2012-05-15 21:44       ` Nick Dokos
2012-05-16 10:30         ` Myles English
2012-05-16 14:56           ` Nicolas Goaziou
2012-05-16 20:37             ` Myles English [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=87396zeuam.fsf@gmail.com \
    --to=mylesenglish@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=n.goaziou@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).