all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Function that jumps to an entry with a certain CUSTOM_ID
@ 2015-03-31 16:36 Christoph LANGE
  2015-03-31 19:55 ` Nicolas Goaziou
  2015-04-06 18:16 ` Leo Ufimtsev
  0 siblings, 2 replies; 5+ messages in thread
From: Christoph LANGE @ 2015-03-31 16:36 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

Hi all,

the following function has served me well for a few years, so I thought 
I'd share it.  I would even be happy to contribute it to the codebase of 
org-mode (core or contrib); however in this case someone would have to 
point me to a fool-proof guide for how to do this.  I know that for 
contributing code I will have to sign some FSF copyright forms, and I 
know how to use git, but I don't know the exact org-mode specific steps 
of doing so.

--- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< ---
(defun org-jump-to-id ()
   "Asks for an identifier and searches for the first entry in the 
current file that has this identifier as a CUSTOM_ID property."
   (interactive)
   (let* ((property "CUSTOM_ID")
          (custom-id (org-icompleting-read "CUSTOM_ID of entry: "
                                           (mapcar 'list 
(org-property-values property)))))
       (org-link-search (concat "#" custom-id))))

(define-key org-mode-map (kbd "\C-cj") 'org-jump-to-id)
--- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< ---

This implementation works efficiently in a 4 MB org file with 100 IDs. 
Together with ido or helm I find it a very user-friendly way of jumping 
to frequently used headlines.

I noticed that org-babel-ref-goto-headline-id does something similar, so 
maybe some code could be shared among the two functions.

Cheers,

Christoph

-- 
Dr. Christoph Lange, Enterprise Information Systems Department
Applied Computer Science @ University of Bonn; Fraunhofer IAIS
http://langec.wordpress.com/about, Skype duke4701

→ Semantic Publishing Challenge: Assessing the Quality of Scientific Output
   ESWC, 31 May–4 June 2014, Portorož, Slovenia. 
https://tinyurl.com/SPChallenge15
   Submission deadline 27 March (abstracts: 20 March)

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

* Re: Function that jumps to an entry with a certain CUSTOM_ID
  2015-03-31 16:36 Function that jumps to an entry with a certain CUSTOM_ID Christoph LANGE
@ 2015-03-31 19:55 ` Nicolas Goaziou
  2015-03-31 20:59   ` Christoph Lange
  2015-04-06 18:16 ` Leo Ufimtsev
  1 sibling, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2015-03-31 19:55 UTC (permalink / raw)
  To: Christoph LANGE; +Cc: emacs-orgmode@gnu.org

Hello,

Christoph LANGE <math.semantic.web@gmail.com> writes:

> the following function has served me well for a few years, so
> I thought I'd share it.  I would even be happy to contribute it to the
> codebase of org-mode (core or contrib); however in this case someone
> would have to point me to a fool-proof guide for how to do this.
> I know that for contributing code I will have to sign some FSF
> copyright forms, and I know how to use git, but I don't know the exact
> org-mode specific steps of doing so.

The problem is that we're running out of interesting keybindings. "C-c
j" is not an option since it is reserved to users.

Another option would be to add it to Worg.

> --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< ---
> (defun org-jump-to-id ()
>   "Asks for an identifier and searches for the first entry in the
> current file that has this identifier as a CUSTOM_ID property."
>   (interactive)
>   (let* ((property "CUSTOM_ID")
>          (custom-id (org-icompleting-read "CUSTOM_ID of entry: "
>                                           (mapcar 'list
> (org-property-values property)))))
>       (org-link-search (concat "#" custom-id))))
>
> (define-key org-mode-map (kbd "\C-cj") 'org-jump-to-id)
> --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< ---
>
> This implementation works efficiently in a 4 MB org file with 100 IDs.
> Together with ido or helm I find it a very user-friendly way of
> jumping to frequently used headlines.

Note that you can use

  (let ((h (org-find-property "CUSTOM_ID" custom-id)))
    (when h (goto-char h)))

instead of

  (org-link-search ...)

for one less level of indirection.

> I noticed that org-babel-ref-goto-headline-id does something similar,
> so maybe some code could be shared among the two functions.

Indeed. I modified it so it uses `org-find-property'.

Regards,

-- 
Nicolas Goaziou

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

* Re: Function that jumps to an entry with a certain CUSTOM_ID
  2015-03-31 19:55 ` Nicolas Goaziou
@ 2015-03-31 20:59   ` Christoph Lange
  2015-04-01 20:21     ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Lange @ 2015-03-31 20:59 UTC (permalink / raw)
  To: Orgmode Mailing List

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

On Mar 31, 2015 9:53 PM, "Nicolas Goaziou" <mail@nicolasgoaziou.fr> wrote:
> The problem is that we're running out of interesting keybindings.

Let me ask the question differently: as all reasonable key bindings are
taken (a statement to which I tend to agree), is the suggestion of
interactive functions to be added to the core of org-mode no longer
appropriate? I.e. should I contribute them to Worg (with which I still need
to familiarise myself) rather than suggesting them here? Or, asking about a
middle course, what's the role of org's "contrib" directory? (Is it even
suitable for something that is not a complete plugin of its own right, but
rather just a single function?)

> "C-c
> j" is not an option since it is reserved to users.

Sorry, this was unfortunate in my initial post. I didn't intend to
hard-code this as the "default" key binding, but it was rather meant to be
read as "if you like this function, you could bind it, for example, to ...".

> Note that you can use
>
>   (let ((h (org-find-property "CUSTOM_ID" custom-id)))
>     (when h (goto-char h)))
>
> instead of
>
>   (org-link-search ...)
>
> for one less level of indirection.

Thanks - makes sense. However probably not if I write a tutorial in the
style of "if you want to do <something>, then copy the following lines to
your. emacs".

But I think I should rather aim at Worg's "contrib" directory, with a short
elisp file containing my function, plus a short HTML file explaining that
there exists an elisp file containing a function that does <a few words
about the functionality> - does this make sense?

Cheers, and thanks for your advice,

Christoph

-- 
Christoph Lange(-Bever)
http://langec.wordpress.com/about
Sent from a mobile device; please excuse my brevity.

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

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

* Re: Function that jumps to an entry with a certain CUSTOM_ID
  2015-03-31 20:59   ` Christoph Lange
@ 2015-04-01 20:21     ` Nicolas Goaziou
  0 siblings, 0 replies; 5+ messages in thread
From: Nicolas Goaziou @ 2015-04-01 20:21 UTC (permalink / raw)
  To: Christoph Lange; +Cc: Orgmode Mailing List

Christoph Lange <math.semantic.web@gmail.com> writes:

> On Mar 31, 2015 9:53 PM, "Nicolas Goaziou" <mail@nicolasgoaziou.fr> wrote:
>> The problem is that we're running out of interesting keybindings.
>
> Let me ask the question differently: as all reasonable key bindings are
> taken (a statement to which I tend to agree), is the suggestion of
> interactive functions to be added to the core of org-mode no longer
> appropriate?

IMO we can't afford maintaining all end-user functions imaginable in
"org.el". What is possible, however is to extend some existing
behaviour.

For example, `org-open-at-point' could be a good candidate: with C-u
C-u, it could offer to type in a link and open it. So, in order to jump
to a custom-id, you can use

  C-u C-u C-o #my-custom RET

Of course, you lose completion, in this case, which is a serious
drawback.

Another option would be to extend `org-goto' (C-c C-j) and offer to jump
to custom-id.

> But I think I should rather aim at Worg's "contrib" directory,

There's no such thing as Worg "contrib" directory. There's Worg, OT1H,
and a contrib/ directory OTOH, but they are not related.

Worg is a good place to share useful code snippets.


Regards,

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

* Re: Function that jumps to an entry with a certain CUSTOM_ID
  2015-03-31 16:36 Function that jumps to an entry with a certain CUSTOM_ID Christoph LANGE
  2015-03-31 19:55 ` Nicolas Goaziou
@ 2015-04-06 18:16 ` Leo Ufimtsev
  1 sibling, 0 replies; 5+ messages in thread
From: Leo Ufimtsev @ 2015-04-06 18:16 UTC (permalink / raw)
  To: Christoph LANGE; +Cc: emacs-orgmode

+1

* Non-technical feedback ::
 - Thank you so much for sharing. I've been looking for something like this for a while.
 - I hope it'll make it into org-mode some way or another, it seems like a valuable addition. 
 - imho the HELM integration is essential.

Leo Ufimtsev | Software Engineer @ Eclipse Team

----- Original Message -----
From: "Christoph LANGE" <math.semantic.web@gmail.com>
To: emacs-orgmode@gnu.org
Sent: Tuesday, March 31, 2015 12:36:45 PM
Subject: [O] Function that jumps to an entry with a certain CUSTOM_ID

Hi all,

the following function has served me well for a few years, so I thought 
I'd share it.  I would even be happy to contribute it to the codebase of 
org-mode (core or contrib); however in this case someone would have to 
point me to a fool-proof guide for how to do this.  I know that for 
contributing code I will have to sign some FSF copyright forms, and I 
know how to use git, but I don't know the exact org-mode specific steps 
of doing so.

--- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< ---
(defun org-jump-to-id ()
   "Asks for an identifier and searches for the first entry in the 
current file that has this identifier as a CUSTOM_ID property."
   (interactive)
   (let* ((property "CUSTOM_ID")
          (custom-id (org-icompleting-read "CUSTOM_ID of entry: "
                                           (mapcar 'list 
(org-property-values property)))))
       (org-link-search (concat "#" custom-id))))

(define-key org-mode-map (kbd "\C-cj") 'org-jump-to-id)
--- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< ---

This implementation works efficiently in a 4 MB org file with 100 IDs. 
Together with ido or helm I find it a very user-friendly way of jumping 
to frequently used headlines.

I noticed that org-babel-ref-goto-headline-id does something similar, so 
maybe some code could be shared among the two functions.

Cheers,

Christoph

-- 
Dr. Christoph Lange, Enterprise Information Systems Department
Applied Computer Science @ University of Bonn; Fraunhofer IAIS
http://langec.wordpress.com/about, Skype duke4701

→ Semantic Publishing Challenge: Assessing the Quality of Scientific Output
   ESWC, 31 May–4 June 2014, Portorož, Slovenia. 
https://tinyurl.com/SPChallenge15
   Submission deadline 27 March (abstracts: 20 March)

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

end of thread, other threads:[~2015-04-06 18:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-31 16:36 Function that jumps to an entry with a certain CUSTOM_ID Christoph LANGE
2015-03-31 19:55 ` Nicolas Goaziou
2015-03-31 20:59   ` Christoph Lange
2015-04-01 20:21     ` Nicolas Goaziou
2015-04-06 18:16 ` Leo Ufimtsev

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.