* What is better way to automatically generate set of functions?
@ 2021-05-15 20:14 Jean Louis
2021-05-15 21:48 ` Stefan Monnier via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 5+ messages in thread
From: Jean Louis @ 2021-05-15 20:14 UTC (permalink / raw)
To: Help GNU Emacs
As I wish to create automatically set of functions, I have come up
with this solution that works:
(defun hyperscope-generate-function-by-hyperdocument-type (type)
(let* ((type (downcase (string-replace " " "-" type)))
(function-name (intern (format "hyperscope-add-new-%s-hyperdocument" type))))
`,(defalias function-name (lambda () (message "Hello")))))
(hyperscope-generate-function-by-hyperdocument-type "Asciidoc")
⇒ hyperscope-add-new-asciidoc-hyperdocument
(hyperscope-add-new-asciidoc-hyperdocument) ⇒ "Hello"
(hyperscope-generate-function-by-hyperdocument-type "Markdown")
⇒ hyperscope-add-new-markdown-hyperdocument
(hyperscope-add-new-markdown-hyperdocument) ⇒ "Hello"
But I would rather like it to be something like:
(defun hyperscope-generate-function-by-hyperdocument-type (type)
(let* ((type (downcase (string-replace " " "-" type)))
(function-name (intern (format "hyperscope-add-new-%s-hyperdocument" type))))
`,(defun ,function-name (lambda () (message "Hello")))))
Only that in the last case I am not getting it to work.
Is there a way to make it with `defun'?
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What is better way to automatically generate set of functions?
2021-05-15 20:14 What is better way to automatically generate set of functions? Jean Louis
@ 2021-05-15 21:48 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-05-15 22:17 ` Jean Louis
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2021-05-15 21:48 UTC (permalink / raw)
To: help-gnu-emacs
> `,(defalias function-name (lambda () (message "Hello")))))
"`," == ""
-- Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What is better way to automatically generate set of functions?
2021-05-15 21:48 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2021-05-15 22:17 ` Jean Louis
2021-05-15 22:53 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Jean Louis @ 2021-05-15 22:17 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
* Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-05-16 00:49]:
> > `,(defalias function-name (lambda () (message "Hello")))))
>
> "`," == ""
That too, yes. It was left from trying out to work with `defun'
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))))))
--
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What is better way to automatically generate set of functions?
2021-05-15 22:17 ` Jean Louis
@ 2021-05-15 22:53 ` Stefan Monnier
2021-05-16 8:04 ` SOLVED: " Jean Louis
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2021-05-15 22:53 UTC (permalink / raw)
To: help-gnu-emacs
> 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`.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* SOLVED: Re: What is better way to automatically generate set of functions?
2021-05-15 22:53 ` Stefan Monnier
@ 2021-05-16 8:04 ` Jean Louis
0 siblings, 0 replies; 5+ messages in thread
From: Jean Louis @ 2021-05-16 8:04 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
* 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/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-05-16 8:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-15 20:14 What is better way to automatically generate set of functions? Jean Louis
2021-05-15 21:48 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-05-15 22:17 ` Jean Louis
2021-05-15 22:53 ` Stefan Monnier
2021-05-16 8:04 ` SOLVED: " Jean Louis
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.