* How to set org-make-link-description-function
@ 2018-04-13 0:54 Eric Abrahamsen
2018-04-13 2:05 ` John Kitchin
0 siblings, 1 reply; 7+ messages in thread
From: Eric Abrahamsen @ 2018-04-13 0:54 UTC (permalink / raw)
To: emacs-orgmode
I've coded Org link support for EBDB, a contact management package,
where the :complete key looks like:
(lambda ()
(format "ebdb:uuid/%s"
(ebdb-record-uuid
(ebdb-prompt-for-record
(ebdb-records)))))
Which prompts for a record based on the contact name, then inserts the
contact's UUID as the link.
The problem is that Org then prompts for a link description. I'd like to
provide the contact name as a default description (the user has just
typed it in, after all), but haven't figured out how to do that.
Clearly `org-make-link-description-function' is meant to play this role,
and it would work perfectly, but I don't know to set it. I can't set it
globally, but also don't know how to let-bind it locally.
How am I supposed to use it?
Thanks,
Eric
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to set org-make-link-description-function
2018-04-13 0:54 How to set org-make-link-description-function Eric Abrahamsen
@ 2018-04-13 2:05 ` John Kitchin
2018-04-13 4:12 ` Eric Abrahamsen
0 siblings, 1 reply; 7+ messages in thread
From: John Kitchin @ 2018-04-13 2:05 UTC (permalink / raw)
To: Eric Abrahamsen; +Cc: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 1598 bytes --]
I don't know how to do that either. It does seem like you can set it
globally. You can try something like:
#+BEGIN_SRC emacs-lisp
(setq org-make-link-description-function
(lambda (link desc)
(cond
((s-starts-with? "ebdb:uuid/" link)
(replace-regexp-in-string "ebdb:uuid/" "" link))
(t
desc))))
#+END_SRC
It doesn't seem too ideal, as it seems like something that should get set
in the link parameters.
Does anyone else have an idea?
John
-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
On Thu, Apr 12, 2018 at 5:54 PM, Eric Abrahamsen <eric@ericabrahamsen.net>
wrote:
> I've coded Org link support for EBDB, a contact management package,
> where the :complete key looks like:
>
> (lambda ()
> (format "ebdb:uuid/%s"
> (ebdb-record-uuid
> (ebdb-prompt-for-record
> (ebdb-records)))))
>
> Which prompts for a record based on the contact name, then inserts the
> contact's UUID as the link.
>
> The problem is that Org then prompts for a link description. I'd like to
> provide the contact name as a default description (the user has just
> typed it in, after all), but haven't figured out how to do that.
>
> Clearly `org-make-link-description-function' is meant to play this role,
> and it would work perfectly, but I don't know to set it. I can't set it
> globally, but also don't know how to let-bind it locally.
>
> How am I supposed to use it?
>
> Thanks,
> Eric
>
>
>
[-- Attachment #2: Type: text/html, Size: 2713 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to set org-make-link-description-function
2018-04-13 2:05 ` John Kitchin
@ 2018-04-13 4:12 ` Eric Abrahamsen
2018-04-13 4:39 ` John Kitchin
0 siblings, 1 reply; 7+ messages in thread
From: Eric Abrahamsen @ 2018-04-13 4:12 UTC (permalink / raw)
To: emacs-orgmode
John Kitchin <jkitchin@andrew.cmu.edu> writes:
> I don't know how to do that either. It does seem like you can set it globally. You can try something
> like:
>
> #+BEGIN_SRC emacs-lisp
> (setq org-make-link-description-function
> (lambda (link desc)
> (cond
> ((s-starts-with? "ebdb:uuid/" link)
> (replace-regexp-in-string "ebdb:uuid/" "" link))
> (t
> desc))))
> #+END_SRC
>
> It doesn't seem too ideal, as it seems like something that should get
> set in the link parameters
Right, setting it globally doesn't seem feasible at all, it would just
be clobbering left and right...
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to set org-make-link-description-function
2018-04-13 4:12 ` Eric Abrahamsen
@ 2018-04-13 4:39 ` John Kitchin
2018-04-13 17:23 ` Eric Abrahamsen
0 siblings, 1 reply; 7+ messages in thread
From: John Kitchin @ 2018-04-13 4:39 UTC (permalink / raw)
To: Eric Abrahamsen; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1056 bytes --]
Not with the way I wrote it. It should only affect your links and pass
everything else through I think.
On Thu, Apr 12, 2018 at 9:15 PM Eric Abrahamsen <eric@ericabrahamsen.net>
wrote:
> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
> > I don't know how to do that either. It does seem like you can set it
> globally. You can try something
> > like:
> >
> > #+BEGIN_SRC emacs-lisp
> > (setq org-make-link-description-function
> > (lambda (link desc)
> > (cond
> > ((s-starts-with? "ebdb:uuid/" link)
> > (replace-regexp-in-string "ebdb:uuid/" "" link))
> > (t
> > desc))))
> > #+END_SRC
> >
> > It doesn't seem too ideal, as it seems like something that should get
> > set in the link parameters
>
> Right, setting it globally doesn't seem feasible at all, it would just
> be clobbering left and right...
>
>
> --
John
-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
[-- Attachment #2: Type: text/html, Size: 1786 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to set org-make-link-description-function
2018-04-13 4:39 ` John Kitchin
@ 2018-04-13 17:23 ` Eric Abrahamsen
2018-04-13 20:32 ` John Kitchin
0 siblings, 1 reply; 7+ messages in thread
From: Eric Abrahamsen @ 2018-04-13 17:23 UTC (permalink / raw)
To: emacs-orgmode
John Kitchin <jkitchin@andrew.cmu.edu> writes:
> Not with the way I wrote it. It should only affect your links and pass everything else through I
> think.
I just meant, you can only have one of these functions set. So if I
provide special behavior for ebdb links, no other function would be able
to do the equivalent for some other type of link.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to set org-make-link-description-function
2018-04-13 17:23 ` Eric Abrahamsen
@ 2018-04-13 20:32 ` John Kitchin
2018-04-13 23:58 ` Eric Abrahamsen
0 siblings, 1 reply; 7+ messages in thread
From: John Kitchin @ 2018-04-13 20:32 UTC (permalink / raw)
To: Eric Abrahamsen; +Cc: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 1602 bytes --]
Here is a globally defined version that would let you define a function for
any other kind of link I think. There are probably many variations on this
theme, like storing functions in some variable as an alist, etc. Something
like that is what would happen if this was defined in the link parameters.
#+BEGIN_SRC emacs-lisp
(defun my-comp (&optional arg)
(format "fruit:%s"
(completing-read "Choose a fruit: " '("apple" "orange" "grapes"
"kiwi"))))
(org-link-set-parameters "fruit"
:complete 'my-comp)
(defun org-fruit-make-link-description (link desc)
(replace-regexp-in-string "fruit:" "" link))
(setq org-make-link-description-function
(lambda (link desc)
(let* ((link-type (car (s-split ":" link)))
(make-func (intern (format "org-%s-make-link-description"
link-type))))
(if (fboundp make-func)
(funcall make-func link desc)
desc))))
#+END_SRC
John
-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
On Fri, Apr 13, 2018 at 10:23 AM, Eric Abrahamsen <eric@ericabrahamsen.net>
wrote:
> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
> > Not with the way I wrote it. It should only affect your links and pass
> everything else through I
> > think.
>
> I just meant, you can only have one of these functions set. So if I
> provide special behavior for ebdb links, no other function would be able
> to do the equivalent for some other type of link.
>
>
>
[-- Attachment #2: Type: text/html, Size: 2879 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to set org-make-link-description-function
2018-04-13 20:32 ` John Kitchin
@ 2018-04-13 23:58 ` Eric Abrahamsen
0 siblings, 0 replies; 7+ messages in thread
From: Eric Abrahamsen @ 2018-04-13 23:58 UTC (permalink / raw)
To: emacs-orgmode
John Kitchin <jkitchin@andrew.cmu.edu> writes:
> Here is a globally defined version that would let you define a function for any other kind of link I think. There are probably many
> variations on this theme, like storing functions in some variable as an alist, etc. Something like that is what would happen if this was
> defined in the link parameters.
I do think putting this in the link parameters is the way to go. I'm
impressed you got a working solution together so quickly, but that's way
more than package authors should have to deal with!
Actually, it could be something as simple as: if the :complete function
returns a cons cell, use the `car' as the link and the `cdr' as the
description default. Surely that would be enough?
Eric
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-04-13 23:58 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-13 0:54 How to set org-make-link-description-function Eric Abrahamsen
2018-04-13 2:05 ` John Kitchin
2018-04-13 4:12 ` Eric Abrahamsen
2018-04-13 4:39 ` John Kitchin
2018-04-13 17:23 ` Eric Abrahamsen
2018-04-13 20:32 ` John Kitchin
2018-04-13 23:58 ` Eric Abrahamsen
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).