[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why is defun not executed during load-file?
From: |
Stefan Monnier |
Subject: |
Re: Why is defun not executed during load-file? |
Date: |
Sun, 30 May 2021 12:32:47 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> I just did not find a way to make it working. Now I have put more care
> and I got this to work:
>
> (defmacro hyperscope-generate-the-add-function-by-hyperdocument-type
> (type-name id function-name)
> (list 'defun function-name '()
> (format "Add new `%s' hyperdocument to Hyperscope." type-name)
> '(interactive)
> '(let* ((parent (hyperscope-select-set))
> (prompt ,(format "New `%s' hyperdocument name: " type-name))
> (name (read-from-minibuffer prompt)))
> (hlink-add-generic name "" ,id parent nil))))
>
> (defun hyperscope-generate-add-functions-by-hyperdocument-types ()
> (let ((types (hyperscope-hyperdocument-types)))
> (while types
> (let* ((type (pop types))
> (id (nth 0 type))
> (type (nth 1 type))
> (type-name type)
> (type (downcase (string-replace " " "-" type)))
> (function-name (format "hyperscope-add-new-%s-hyperdocument"
> type)))
> (insert "\n" type-name " " id " " function-name)
> (hyperscope-generate-the-add-function-by-hyperdocument-type type-name
> id function-name)))))
>
> (hyperscope-generate-add-functions-by-hyperdocument-types)
Try to `M-: macroexpand-all '(defun
hyperscope-generate-add-functions-by-hyperdocument-types ...))
to see that your code doesn't do what you think:
`hyperscope-generate-add-functions-by-hyperdocument-types` needs to be
a macro.
Stefan
Re: Why is defun not executed during load-file?, Emanuel Berg, 2021/05/30