all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* canonical verbose?
@ 2013-09-21  7:46 Andreas Röhler
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Röhler @ 2013-09-21  7:46 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org List

Hi,

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"
   (interactive)
   (let ((orig (point))
	(pps (syntax-ppss))
         erg)
     (and (nth 8 pps) (goto-char (nth 8 pps)))
     (ignore-errors (up-list))
     (and (< orig (point))(setq erg (point)))
     (when (interactive-p) (message "%s" erg))
     erg))

However, binding the message at interactive-usage alone seems not optimal.

Does Emacs provide some variable setting verbosity?

TIA,

Andreas



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: canonical verbose?
       [not found] <mailman.2626.1379749488.10748.help-gnu-emacs@gnu.org>
@ 2013-09-21 11:33 ` Barry Margolin
  0 siblings, 0 replies; 4+ messages in thread
From: Barry Margolin @ 2013-09-21 11:33 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1020 bytes --]

In article <mailman.2626.1379749488.10748.help-gnu-emacs@gnu.org>,
 Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:

> Hi,
> 
> 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"
>    (interactive)
>    (let ((orig (point))
> 	(pps (syntax-ppss))
>          erg)
>      (and (nth 8 pps) (goto-char (nth 8 pps)))
>      (ignore-errors (up-list))
>      (and (< orig (point))(setq erg (point)))
>      (when (interactive-p) (message "%s" erg))
>      erg))
> 
> However, binding the message at interactive-usage alone seems not optimal.
> 
> Does Emacs provide some variable setting verbosity?
> 
> TIA,
> 
> Andreas

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.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: canonical verbose?
       [not found] ` <<barmar-9D6D59.07331121092013@news.eternal-september.org>
@ 2013-09-21 14:03   ` Drew Adams
  2013-09-21 14:31     ` Andreas Röhler
  0 siblings, 1 reply; 4+ messages in thread
From: Drew Adams @ 2013-09-21 14:03 UTC (permalink / raw)
  To: Barry Margolin, help-gnu-emacs

> > 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"
> >    (interactive)...
> >    (when (interactive-p) (message "%s" erg))
> >    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)
       (interactive "p")
       (when print-message
         (message "foo")))

  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".



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: canonical verbose?
  2013-09-21 14:03   ` canonical verbose? Drew Adams
@ 2013-09-21 14:31     ` Andreas Röhler
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Röhler @ 2013-09-21 14:31 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: Barry Margolin

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"
>>>     (interactive)...
>>>     (when (interactive-p) (message "%s" erg))
>>>     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)
>         (interactive "p")
>         (when print-message
>           (message "foo")))
>
>    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".
>
>

Thanks.

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, bug-sourcing.
   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






^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-09-21 14:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <<mailman.2626.1379749488.10748.help-gnu-emacs@gnu.org>
     [not found] ` <<barmar-9D6D59.07331121092013@news.eternal-september.org>
2013-09-21 14:03   ` canonical verbose? Drew Adams
2013-09-21 14:31     ` Andreas Röhler
     [not found] <mailman.2626.1379749488.10748.help-gnu-emacs@gnu.org>
2013-09-21 11:33 ` Barry Margolin
2013-09-21  7:46 Andreas Röhler

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.