[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: canonical verbose?
Re: canonical verbose?
Sat, 21 Sep 2013 16:31:58 +0200
Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130801 Thunderbird/17.0.8
Am 21.09.2013 16:03, schrieb Drew Adams:
writing quite often commands which should give some reports when being
successful, like that:
(defun ar-up-list ()
"Returns position reached when successful, nil otherwise"
(when (interactive-p) (message "%s" erg))
However, binding the message at interactive-usage alone seems not optimal.
Does Emacs provide some variable setting verbosity?
Another option is to have two functions: one that does all the work, and
a command that calls the first function and then displays a message.
I do not know of a general, global approach. You could perhaps, for your own
code, use a macro or even add a global variable etc. But there is nothing
built in, AFAIK.
But I did want to mention, for those who might not be aware of it (not Barry or
Andreas, no doubt), what the Elisp manual (node `Distinguish Interactive')
recommends for an individual command:
Sometimes a command should display additional visual feedback (such as
an informative message in the echo area) for interactive calls only.
There are three ways to do this. The recommended way to test whether
the function was called using `call-interactively' is to give it an
optional argument `print-message' and use the `interactive' spec to
make it non-`nil' in interactive calls. Here's an example:
(defun foo (&optional print-message)
We use `"p"' because the numeric prefix argument is never `nil'.
Defined in this way, the function does display the message when called
from a keyboard macro.
The above method with the additional argument is usually best,
because it allows callers to say "treat this call as interactive".
Are downsides with this
- taste and circumstances differ. Some user may want it, others not. A variable
to switch verbosity would meet this.
BTW in python-mode.el that's done for example that way
(when (and py-verbose-p (interactive-p)) (message ....
- using the numeric arguments slot is a misuse somehow,
deteriorating for beginners learning "p", readability is downgraded that way
- "p" works only for commands. Relying on it in lower level is costly,
Related is to be said for "called-interactively"
OTOH all needed is an agreement having a global var verbosity....
Or maybe two of them, level 1 and 2