[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 02:59:25 +0300 |
User-agent: |
Mutt/2.0.7+183 (3d24855) (2021-05-28) |
* Michael Heerdegen <michael_heerdegen@web.de> [2021-06-01 02:38]:
> Jean Louis <bugs@gnu.support> writes:
>
> > (defmacro when-tabulated-id (table id &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))))
>
> There is something wrong with that definition however: the variable `id'
> is completely ignored, specifying something at that argument position is
> redundant.
I appreciate all comments.
> Tt may "work" by accident if the symbol `id' happens to be dynamically
> bound to the same thing that you specify as argument, but only when that
> exact variable name is used and only in dynamically binding Lisp.
You guessed it well, I am using it this way:
(defun hyperscope-tabulated-action (&optional id)
(interactive)
(when-tabulated-id "hyobjects" id
(hyperscope-ring id)
(hyperscope-action id)))
As there are many different tables which all have its ID, so the macro
has to make sure it is invoked in the right table. There could be
other ways to check that.
Programs have their lexical binding true, maybe that one you did not
expect.
Such functions can be invoked programmatically or interactively,
interactively there is check if there is right database table in the
tabulated-list-mode, as otherwise it gives a warning that it is not
invoked in that other different table.
> Normally the byte compiler warns about this kind of problem - of course
> only if you don't silence it ;-)
That is why `ignore' is there. Ignore is there to suppress the byte
compiler warning just as you guessed it.
Otherwise:
In when-tabulated-id:
rcd-cf.el:165:45: Warning: Unused lexical argument `id'
--
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/
- Re: Why is defun not executed during load-file?, (continued)
- Re: Why is defun not executed during load-file?, Drew Adams, 2021/05/30
- Re: Why is defun not executed during load-file?, Emanuel Berg, 2021/05/30
- RE: [External] : Re: Why is defun not executed during load-file?, Drew Adams, 2021/05/30
- Re: [External] : Re: Why is defun not executed during load-file?, Emanuel Berg, 2021/05/30
- RE: [External] : Re: Why is defun not executed during load-file?, Drew Adams, 2021/05/31
- Re: [External] : Re: Why is defun not executed during load-file?, Emanuel Berg, 2021/05/31
- Re: [External] : Re: Why is defun not executed during load-file?, Stefan Monnier, 2021/05/31
- Re: [External] : Re: Why is defun not executed during load-file?, Marcin Borkowski, 2021/05/31
- Example use of macro to minimize and generalize the code, Jean Louis, 2021/05/31
- Re: Example use of macro to minimize and generalize the code, Michael Heerdegen, 2021/05/31
- Re: Example use of macro to minimize and generalize the code,
Jean Louis <=
- Re: Example use of macro to minimize and generalize the code, Michael Heerdegen, 2021/05/31
- Re: Example use of macro to minimize and generalize the code, Jean Louis, 2021/05/31
- Re: Example use of macro to minimize and generalize the code, Michael Heerdegen, 2021/05/31
- Re: Example use of macro to minimize and generalize the code, Jean Louis, 2021/05/31
- Example use of macro to minimize and generalize the code (2), Jean Louis, 2021/05/31
- Re: [External] : Re: Why is defun not executed during load-file?, Michael Heerdegen, 2021/05/31
- RE: [External] : Re: Why is defun not executed during load-file?, Drew Adams, 2021/05/31