[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SOLVED: Re: What is better way to automatically generate set of function
From: |
Jean Louis |
Subject: |
SOLVED: Re: What is better way to automatically generate set of functions? |
Date: |
Sun, 16 May 2021 11:04:17 +0300 |
User-agent: |
Mutt/2.0.6 (2021-03-06) |
* Stefan Monnier <monnier@iro.umontreal.ca> [2021-05-16 01:54]:
> > For now, this here works, but is not elegant.
> >
> > (defun hyperscope-generate-the-add-function-by-hyperdocument-type (type id)
> > (let* ((type (downcase (string-replace " " "-" type)))
> > (function-name (intern (format "hyperscope-add-new-%s-hyperdocument"
> > type))))
> > (eval (list
> > 'defun function-name ()
> > (format "Add new `%s' hyperdocument to Hyperscope." type)
> > '(interactive)
> > `(let* ((parent (hyperscope-select-set))
> > (prompt ,(format "New `%s' hyperdocument name: " type))
> > (name (read-from-minibuffer prompt)))
> > (hlink-add-generic name "" ,id parent nil))))))
>
> I suspect you can to use `defmacro` at the top and remove the
> `eval`.
Thanks, I have done that, now this works, and I can continue from there.
(defmacro hyperscope-generate-the-add-function-by-hyperdocument-type (type id)
(let* ((original type)
(type (downcase (string-replace " " "-" type)))
(function-name (intern (format "hyperscope-add-new-%s-hyperdocument"
type))))
`(defun ,function-name ()
,(format "Add new `%s' hyperdocument to Hyperscope." original)
(interactive)
(let* ((parent (hyperscope-select-set))
(prompt ,(format "New `%s' hyperdocument name: " original))
(name (read-from-minibuffer prompt)))
(hlink-add-generic name "" ,id parent nil)))))
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/