emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-goto-local-search-headings usage?
@ 2012-05-15 15:28 Myles English
  2012-05-15 15:48 ` Nick Dokos
  0 siblings, 1 reply; 8+ messages in thread
From: Myles English @ 2012-05-15 15:28 UTC (permalink / raw)
  To: emacs-orgmode Mode


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"

I have tried edebugging but didn't get anywhere, perhaps I am not using
it properly.

Thanks,

-- 
  `--[ Myles ]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: org-goto-local-search-headings usage?
  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
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Dokos @ 2012-05-15 15:48 UTC (permalink / raw)
  To: emacs-orgmode Mode, Myles English

Myles English <mylesenglish@gmail.com> 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.

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.

Nick

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: org-goto-local-search-headings usage?
  2012-05-15 15:48 ` Nick Dokos
@ 2012-05-15 21:09   ` Myles English
  2012-05-15 21:33     ` Nick Dokos
  0 siblings, 1 reply; 8+ messages in thread
From: Myles English @ 2012-05-15 21:09 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: emacs-orgmode Mode

>> On Tue, 15 May 2012 11:48:55 -0400, Nick Dokos said:

  > Myles English <mylesenglish@gmail.com> 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?

-- 
  `--[ Myles ]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: org-goto-local-search-headings usage?
  2012-05-15 21:09   ` Myles English
@ 2012-05-15 21:33     ` Nick Dokos
  2012-05-15 21:44       ` Nick Dokos
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Dokos @ 2012-05-15 21:33 UTC (permalink / raw)
  To: emacs-orgmode Mode, Myles English

Myles English <mylesenglish@gmail.com> wrote:

> >> On Tue, 15 May 2012 11:48:55 -0400, Nick Dokos said:
> 
>   > Myles English <mylesenglish@gmail.com> 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.

Nick

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: org-goto-local-search-headings usage?
  2012-05-15 21:33     ` Nick Dokos
@ 2012-05-15 21:44       ` Nick Dokos
  2012-05-16 10:30         ` Myles English
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Dokos @ 2012-05-15 21:44 UTC (permalink / raw)
  To: emacs-orgmode Mode, Myles English

Nick Dokos <nicholas.dokos@hp.com> wrote:

> Myles English <mylesenglish@gmail.com> wrote:
> 
> > >> On Tue, 15 May 2012 11:48:55 -0400, Nick Dokos said:
> > 
> >   > Myles English <mylesenglish@gmail.com> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: org-goto-local-search-headings usage?
  2012-05-15 21:44       ` Nick Dokos
@ 2012-05-16 10:30         ` Myles English
  2012-05-16 14:56           ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Myles English @ 2012-05-16 10:30 UTC (permalink / raw)
  To: nicholas.dokos; +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 ]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: org-goto-local-search-headings usage?
  2012-05-16 10:30         ` Myles English
@ 2012-05-16 14:56           ` Nicolas Goaziou
  2012-05-16 20:37             ` Myles English
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2012-05-16 14:56 UTC (permalink / raw)
  To: emacs-orgmode Mode; +Cc: Myles English, nicholas.dokos

Hello,

Myles English <mylesenglish@gmail.com> writes:

> 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

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.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: org-goto-local-search-headings usage?
  2012-05-16 14:56           ` Nicolas Goaziou
@ 2012-05-16 20:37             ` Myles English
  0 siblings, 0 replies; 8+ messages in thread
From: Myles English @ 2012-05-16 20:37 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode Mode


>> 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 ]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-05-16 20:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

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).