emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Go to heading using LISP
@ 2013-06-08 13:52 Alexander Wingård
  2013-06-09  1:36 ` Eric Abrahamsen
  2013-06-10 19:00 ` Myles English
  0 siblings, 2 replies; 8+ messages in thread
From: Alexander Wingård @ 2013-06-08 13:52 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi!

I want to create special key-bindings that use the org-refile goto
interface to jump to specific headings.

My initial attempt was:
(org-refile 4 "gtd.org" "Projects/Work/Bugs")

But it seems specifying RFLOC is not that simple.

Someone have any idea how to achieve this or another way to jump to a
heading?

Best Regards /Alexander

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

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

* Re: Go to heading using LISP
  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 19:00 ` Myles English
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Abrahamsen @ 2013-06-09  1:36 UTC (permalink / raw)
  To: emacs-orgmode

Alexander Wingård <alexander.wingard@gmail.com> writes:

> Hi!
>
> I want to create special key-bindings that use the org-refile goto
> interface to jump to specific headings.
>
> My initial attempt was:
> (org-refile 4 "gtd.org" "Projects/Work/Bugs")
>
> But it seems specifying RFLOC is not that simple.
>
> Someone have any idea how to achieve this or another way to jump to a
> heading?

Is the `org-goto' interface close enough? It only does the current
buffer, but you can set org-goto-interface to make it behave a fair bit
like refile...

Yours
Eric

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

* Re: Go to heading using LISP
  2013-06-09  1:36 ` Eric Abrahamsen
@ 2013-06-09 14:43   ` Alexander Wingård
  2013-06-10  4:26     ` Eric Abrahamsen
  0 siblings, 1 reply; 8+ messages in thread
From: Alexander Wingård @ 2013-06-09 14:43 UTC (permalink / raw)
  To: emacs-orgmode

Eric Abrahamsen <eric <at> ericabrahamsen.net> writes:

> 
> Alexander Wingård <alexander.wingard <at> gmail.com> writes:
> 
> > Hi!
> >
> > I want to create special key-bindings that use the org-refile goto
> > interface to jump to specific headings.
More specific example, let's say I want to bind keys in my .emacs file:

"C-c b" -> find "gtd.org" and jump to "Projects/Work/Bugs"
"C-c m" -> find "gtd.org" and jump to "Projects/Work/Meetings"
> >
> > My initial attempt was:
> > (org-refile 4 "gtd.org" "Projects/Work/Bugs")
> >
> > But it seems specifying RFLOC is not that simple.
> >
> > Someone have any idea how to achieve this or another way to jump to a
> > heading?
> 
> Is the `org-goto' interface close enough? It only does the current
> buffer, but you can set org-goto-interface to make it behave a fair bit
> like refile...
I've looked at that function aswell but it seems even harder to achieve 
what I want with: Call it from lisp without any user interaction. If you think
that is possible I would love an example.
> 
> Yours
> Eric
> 
> 

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

* Re: Go to heading using LISP
  2013-06-09 14:43   ` Alexander Wingård
@ 2013-06-10  4:26     ` Eric Abrahamsen
  2013-06-10  5:53       ` Jambunathan K
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Abrahamsen @ 2013-06-10  4:26 UTC (permalink / raw)
  To: emacs-orgmode

Alexander Wingård <alexander.wingard@gmail.com> writes:

> Eric Abrahamsen <eric <at> ericabrahamsen.net> writes:
>
>> 
>> Alexander Wingård <alexander.wingard <at> gmail.com> writes:
>> 
>> > Hi!
>> >
>> > I want to create special key-bindings that use the org-refile goto
>> > interface to jump to specific headings.
> More specific example, let's say I want to bind keys in my .emacs file:
>
> "C-c b" -> find "gtd.org" and jump to "Projects/Work/Bugs"
> "C-c m" -> find "gtd.org" and jump to "Projects/Work/Meetings"
>> >
>> > My initial attempt was:
>> > (org-refile 4 "gtd.org" "Projects/Work/Bugs")
>> >
>> > But it seems specifying RFLOC is not that simple.
>> >
>> > Someone have any idea how to achieve this or another way to jump to a
>> > heading?
>> 
>> Is the `org-goto' interface close enough? It only does the current
>> buffer, but you can set org-goto-interface to make it behave a fair bit
>> like refile...
> I've looked at that function aswell but it seems even harder to achieve 
> what I want with: Call it from lisp without any user interaction. If you think
> that is possible I would love an example.

Ah, I see. Well, if you're just looking for a lisp function to jump to a
headline, you could use `org-refile-get-targets' to produce a full table
of all the possible refile targets, and then choose among them. (assoc
"gtd.org/Projects/Work/Bugs" (org-refile-get-targets)) will find the
right heading, then I guess the value of point is in that heading
somewhere -- you can visit the file and goto-point.

But if you're just looking to bind a bunch of keys to "jump to specific
heading" commands, I'd use custom ids. Give all the headings in question
ID properties, and then just use something like this:

(global-set-key (kbd "C-c b") (lambda () (org-id-open
"f1d05552-1dce-4004-a914-d2b092d8470e")))

Hope that helps,
Eric

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

* Re: Go to heading using LISP
  2013-06-10  4:26     ` Eric Abrahamsen
@ 2013-06-10  5:53       ` Jambunathan K
  0 siblings, 0 replies; 8+ messages in thread
From: Jambunathan K @ 2013-06-10  5:53 UTC (permalink / raw)
  To: emacs-orgmode

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> if you're just looking for a lisp function to jump to a headline

One can use org-ctags and use Emacs and etags interface (M-. etc) to
jump to a headline.  One can also choose the headline via completion.

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

* Re: Go to heading using LISP
  2013-06-08 13:52 Go to heading using LISP Alexander Wingård
  2013-06-09  1:36 ` Eric Abrahamsen
@ 2013-06-10 19:00 ` Myles English
  2013-06-10 21:14   ` Alexander Wingård
  1 sibling, 1 reply; 8+ messages in thread
From: Myles English @ 2013-06-10 19:00 UTC (permalink / raw)
  To: Alexander Wingård; +Cc: emacs-orgmode


Hi Alexander,

Alexander Wingård writes:

> I want to create special key-bindings that use the org-refile goto
> interface to jump to specific headings.

It doesn't use org-refile but this is what I use:

(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

(defun gtd()
  (interactive)
  (my-goto-heading (concat org-directory "/gtd.org") "Daily work")
  (org-show-entry)
  ;;(org-show-subtree)
  (reposition-window)
  (org-agenda-list))

In the gtd function I also set org-agenda-files but left it out for
clarity.

Myles

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

* Re: Go to heading using LISP
  2013-06-10 19:00 ` Myles English
@ 2013-06-10 21:14   ` Alexander Wingård
  2013-06-19 18:24     ` Alexander Wingård
  0 siblings, 1 reply; 8+ messages in thread
From: Alexander Wingård @ 2013-06-10 21:14 UTC (permalink / raw)
  To: Myles English; +Cc: emacs-orgmode


On 10 jun 2013, at 21:00, Myles English <mylesenglish@gmail.com> wrote:

> 
> Hi Alexander,
> 
> Alexander Wingård writes:
> 
>> I want to create special key-bindings that use the org-refile goto
>> interface to jump to specific headings.
> 
> It doesn't use org-refile but this is what I use:
> 
> (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
> 

Thanks alot! This is exactly what I was asking for. This will suffice for me now.
Maybe some day I will learn some LISP and teach it to navigate the hierarchical structure.

Best Regards /Alexander

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

* Re: Go to heading using LISP
  2013-06-10 21:14   ` Alexander Wingård
@ 2013-06-19 18:24     ` Alexander Wingård
  0 siblings, 0 replies; 8+ messages in thread
From: Alexander Wingård @ 2013-06-19 18:24 UTC (permalink / raw)
  To: Myles English; +Cc: emacs-orgmode

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

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

end of thread, other threads:[~2013-06-19 18:24 UTC | newest]

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

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