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