Tor-björn Claesson <[email protected]> writes:
> Clever! I had to put the let inside the lambda for it to work.
You probably do not have to once you use lexical binding (that is - not
C-x C-e ad-hoc, but put things into actual byte-compiled file)
But let inside the lambda body is perfectly fine.
> (defun org-cite-basic-follow--parse-suffix-specification (specification)
> (pcase specification
> (`(,key ,desc (lambda . ,fn-args) . ,other)
> (list key desc `(lambda ,@fn-args) ,other))
> (`(,key ,desc (,fn . ,fn-args) . ,other)
> `(,key ,desc
> (lambda ()
> (interactive)
> (let ((!citation (car (transient-scope)))
> (!prefix (cadr (transient-scope)))
> (!citation-key (org-element-property :key (car
> (transient-scope)))))
> (,fn ,@fn-args)))
> ,other))
> (other other)))
>
> Does it make sense to keep matching the lambda separately? This just
> keeps getting better=)
AFIU, you need to match against lambda simply to avoid the next clause
matching it. If so, you can change the clause to match all ,fn, except
lambda like the following:
`(,key
,desc
(,(and fn (guard (not (eq fn 'lambda))))
. ,fn-args)
. ,other)
This is getting ugly though.
An alternative would be simply
(defun org-cite-basic-follow--parse-suffix-specification (specification)
(pcase specification
((and val `(,key ,desc (,fn . ,fn-args) . ,other))
(if (eq fn 'lambda) val
`(,key ,desc
(lambda ()
(interactive)
(let ((!citation (car (transient-scope)))
(!prefix (cadr (transient-scope)))
(!citation-key (org-element-property :key (car
(transient-scope)))))
(,fn ,@fn-args)))
,@other)))
(other other)))
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>