From mboxrd@z Thu Jan 1 00:00:00 1970 From: Myles English Subject: Re: org-goto-local-search-headings usage? Date: Wed, 16 May 2012 11:30:41 +0100 Message-ID: <877gwcl8oe.fsf@gmail.com> References: <87obpp31ln.fsf@ed.ac.uk> <4409.1337096935@alphaville> <87havhp2w9.fsf@gmail.com> <8801.1337117593@alphaville> <8896.1337118269@alphaville> Reply-To: emacs-orgmode Mode , Myles English Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from eggs.gnu.org ([208.118.235.92]:39811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUbQF-0007jq-Bj for emacs-orgmode@gnu.org; Wed, 16 May 2012 06:25:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SUbQ8-00030y-MX for emacs-orgmode@gnu.org; Wed, 16 May 2012 06:25:34 -0400 Received: from mail-ee0-f41.google.com ([74.125.83.41]:38321) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUbQ8-00030i-AP for emacs-orgmode@gnu.org; Wed, 16 May 2012 06:25:28 -0400 Received: by eekb47 with SMTP id b47so154774eek.0 for ; Wed, 16 May 2012 03:25:26 -0700 (PDT) In-Reply-To: <8896.1337118269@alphaville> (Nick Dokos's message of "Tue, 15 May 2012 17:44:29 -0400") 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: nicholas.dokos@hp.com Cc: emacs-orgmode Mode >> On Tue, 15 May 2012 17:44:29 -0400, Nick Dokos said: > Nick Dokos wrote: >> Myles English wrote: >> >> > >> On Tue, 15 May 2012 11:48:55 -0400, Nick Dokos said: >> > >> > > Myles English wrote: >> > >> >> > >> Hi, >> > >> >> > >> Can anyone see what I am doing wrong here? I just want to open a file >> > >> ~/tmp/gtd.org and goto the heading "* My workflow". So, starting like >> > >> this: >> > >> >> > >> emacs -Q -l ~/tmp/gtd >> > >> >> > >> with ~/tmp/gtd: >> > >> >> > >> (add-to-list 'load-path >> > >> "~/.emacs.d/plugins/org-mode/lisp") >> > >> (require 'org-install) ;; to use the emacs-org-mode rather than the one >> > >> ;; installed with emacs >> > >> >> > >> (defun gtd() >> > >> (interactive) >> > >> (find-file "~/tmp/gtd.org") >> > >> (goto-char (point-min)) >> > >> (setq wf "My workflow") >> > >> (org-goto-local-search-headings wf nil nil) >> > >> ) >> > >> >> > >> and ~/tmp/gtd.org: >> > >> >> > >> * My workflow >> > >> >> > >> then I do: >> > >> >> > >> M-x gtd >> > >> >> > >> and get the message: >> > >> >> > >> byte-code: Search failed: "My workflow" >> > >> >> > >> > > Works for me: the cursor is placed at the end of the headline. >> > > I tried both with just the one headline and also with half a >> > > dozen. >> > >> > Thanks for taking a look Nick. My real usage also uses a much bigger >> > file and sometimes it works when the .emacs file is open or if I have >> > been working in the gtd.org file but I haven't been able to track down >> > when it works or doesn't. Hence this MWE. >> > >> > > Maybe M-x toggle-debug-on-error and try again to get a backtrace? >> > > Or add >> > >> > > (setq debug-on-error t) >> > >> > > to your initialization file. >> > >> > Adding (setq debug-on-error t) to the top of the file gtd then >> > proceeding as before gives me the *Backtrace*: >> > >> > org-goto-local-search-headings("My workflow" nil nil) >> > gtd() >> > call-interactively(gtd t nil) >> > execute-extended-command(nil) >> > call-interactively(execute-extended-command nil nil) >> > >> > which doesn't even really look like an error, does it? >> > >> >> No, but there are missing stack frames: it fails on the search-backward >> that org-goto-local-search-headings does. In the best "let's cure the >> symptom, not the disease" manner, try changing the point-min to >> point-max in the definition of gtd. >> > I meant to comment on the use of isearch-forward inside > org-goto-local-search-headings. I'm not sure how it changes value (but > it does), and I really don't understand why org-glsh uses it at all. The > point is however that depending on the value of isearch-forward and > where you start in the buffer (min or max), you will get the error if > the variable is the "wrong" direction for your starting point. > IOW, you probably don't want to use the org-glsh function: define your > own that always goes in one direction (forward) and start at min. > Usual disclaimers apply, > Nick Thanks for the advice, I ended up using bit of org-element.el instead of org-goto-local-search-headings and doing this: #+BEGIN_SRC elisp (defun gotoWF(hl) (let ((title (car (org-element-property :title hl)))) (if (and (stringp title) (string= title "My workflow")) (progn (goto-char (org-element-property :begin hl)) (org-show-entry) (org-show-subtree)) nil))) (require 'org-element) (defun gtd() (interactive) (org-element-map (org-element-parse-buffer) 'headline 'gotoWF nil t) (org-agenda-list)) #+END_SRC -- `--[ Myles ]