[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Example use of macro to minimize and generalize the code
From: |
Jean Louis |
Subject: |
Re: Example use of macro to minimize and generalize the code |
Date: |
Tue, 1 Jun 2021 19:33:36 +0300 |
User-agent: |
Mutt/2.0.7+183 (3d24855) (2021-05-28) |
* Michael Heerdegen <michael_heerdegen@web.de> [2021-06-01 17:03]:
> Jean Louis <bugs@gnu.support> writes:
>
> > (defmacro when-tabulated-id (table &rest body)
> > (declare (indent 2) (debug t))
> > ;;(ignore id)
> > `(if id
> > (progn
> > ,@body)
> > (if (or (eq ,table 'any)
> > (string-equal ,table rcd-current-table))
> > (let ((id (tabulated-list-get-id)))
> > (if id
> > (progn ,@body)
> > (message "Did not get ID")))
> > (message "This function is for table `%s' only" ,table))))
>
> Yes, better.
>
> The downside now is that using the macro hides the fact that the code
> depends on the id, and the resulting code is (still) hard to understand.
> Why don't you consider to make the id a real argument?
I wish I could fully understand but I don't, and I consider your
advises important.
How would I make the ID a real argument?
Each of those functions has &optional id as if function is not
capturing ID from tabulated-list-mode then it may receive it
programmatically.
Example:
(defun hyperscope-new-appointment (&optional id)
"Add new `Appointment' hyperdocument."
(interactive)
(when-tabulated-id "hyobjects"
(let ((parent (hlink-parent id)))
(hyperscope-add-new-appointment-hyperdocument parent))))
--
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/