all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Temporarily turning message logging off
@ 2007-05-24  3:56 Davin Pearson
  2007-05-24  5:03 ` Katsumi Yamaoka
  0 siblings, 1 reply; 10+ messages in thread
From: Davin Pearson @ 2007-05-24  3:56 UTC (permalink / raw)
  To: help-gnu-emacs


I would like to temporarily undefine the function message so that
messages are temporarily turned off.  Here is some Elisp code that I
have written to achieve this:


;;;
;;; (progn (message "hello") (sit-for 1))
;;;

(defun my-message--turn-messages-off ()
  (progn
    (fset 'message-old (symbol-function 'message))
    (defun message (string &rest arguments)
      ))
  )

(defun my-message--turn-messages-on ()
  (progn
    (fset 'message (symbol-function 'message-old)))
 )

Unfortunately it does not appear to work.  For example
when you save a file with messages turned off, it still
generates the message "Wrote <filename>"

What do I have to do to turn message logging off?

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

* Re: Temporarily turning message logging off
  2007-05-24  3:56 Temporarily turning message logging off Davin Pearson
@ 2007-05-24  5:03 ` Katsumi Yamaoka
  2007-05-24  7:56   ` Eli Zaretskii
       [not found]   ` <mailman.1132.1179993370.32220.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 10+ messages in thread
From: Katsumi Yamaoka @ 2007-05-24  5:03 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> In <1179979000.784693.89720@b40g2000prd.googlegroups.com>
>>>>>	Davin Pearson wrote:

> I would like to temporarily undefine the function message so that
> messages are temporarily turned off.  Here is some Elisp code that I
> have written to achieve this:

> ;;;
> ;;; (progn (message "hello") (sit-for 1))
> ;;;

> (defun my-message--turn-messages-off ()
>   (progn
>     (fset 'message-old (symbol-function 'message))
>     (defun message (string &rest arguments)
>       ))
>   )

> (defun my-message--turn-messages-on ()
>   (progn
>     (fset 'message (symbol-function 'message-old)))
>  )

> Unfortunately it does not appear to work.  For example
> when you save a file with messages turned off, it still
> generates the message "Wrote <filename>"

> What do I have to do to turn message logging off?

It seems that `write-region', which is a built-in function,
issues such messages.  How about this?

;; off
(fset 'write-region-old (symbol-function 'write-region))
(fset 'write-region
      (lambda (start end filename &optional append visit &rest args)
	(apply 'write-region-old start end filename append 'silent args)))

;; on
(fset 'write-region (symbol-function 'write-region-old))

Use this with care, since it also prevents programs from doing
something using the 5th argument VISIT[1].  In other words,
there is no way to do it entirely safely except for modifying
the C source code.

[1] See the documentation of the `write-region' function.

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

* Re: Temporarily turning message logging off
  2007-05-24  5:03 ` Katsumi Yamaoka
@ 2007-05-24  7:56   ` Eli Zaretskii
       [not found]   ` <mailman.1132.1179993370.32220.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2007-05-24  7:56 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Katsumi Yamaoka <yamaoka@jpl.org>
> Date: Thu, 24 May 2007 14:03:41 +0900
> 
> >>>>> In <1179979000.784693.89720@b40g2000prd.googlegroups.com>
> >>>>>	Davin Pearson wrote:
> 
> > What do I have to do to turn message logging off?
> 
> It seems that `write-region', which is a built-in function,
> issues such messages.  How about this?
> 
> ;; off
> (fset 'write-region-old (symbol-function 'write-region))
> (fset 'write-region
>       (lambda (start end filename &optional append visit &rest args)
> 	(apply 'write-region-old start end filename append 'silent args)))
> 
> ;; on
> (fset 'write-region (symbol-function 'write-region-old))

Isn't it easier and less invasive to temporarily bind message-log-max
to nil?

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

* Re: Temporarily turning message logging off
       [not found]   ` <mailman.1132.1179993370.32220.help-gnu-emacs@gnu.org>
@ 2007-05-24  8:25     ` Katsumi Yamaoka
  2007-05-24 10:47       ` Eli Zaretskii
       [not found]       ` <mailman.1141.1180003694.32220.help-gnu-emacs@gnu.org>
  2007-05-24  9:14     ` Tim X
  1 sibling, 2 replies; 10+ messages in thread
From: Katsumi Yamaoka @ 2007-05-24  8:25 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> In <mailman.1132.1179993370.32220.help-gnu-emacs@gnu.org>
>>>>>	Eli Zaretskii wrote:

> Isn't it easier and less invasive to temporarily bind message-log-max
> to nil?

That's the best if Davin only wants the *Messages* buffer not to
be filled.  If not, it might be insufficient.  For example:

emacs -batch -eval '(let (message-log-max) (write-region "foo" nil "testing"))'
Wrote /tmp/testing

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

* Re: Temporarily turning message logging off
       [not found]   ` <mailman.1132.1179993370.32220.help-gnu-emacs@gnu.org>
  2007-05-24  8:25     ` Katsumi Yamaoka
@ 2007-05-24  9:14     ` Tim X
  1 sibling, 0 replies; 10+ messages in thread
From: Tim X @ 2007-05-24  9:14 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Katsumi Yamaoka <yamaoka@jpl.org>
>> Date: Thu, 24 May 2007 14:03:41 +0900
>> 
>> >>>>> In <1179979000.784693.89720@b40g2000prd.googlegroups.com>
>> >>>>>	Davin Pearson wrote:
>> 
>> > What do I have to do to turn message logging off?
>> 
>> It seems that `write-region', which is a built-in function,
>> issues such messages.  How about this?
>> 
>> ;; off
>> (fset 'write-region-old (symbol-function 'write-region))
>> (fset 'write-region
>>       (lambda (start end filename &optional append visit &rest args)
>> 	(apply 'write-region-old start end filename append 'silent args)))
>> 
>> ;; on
>> (fset 'write-region (symbol-function 'write-region-old))
>
> Isn't it easier and less invasive to temporarily bind message-log-max
> to nil?
>
>

I wondering why the OP wants to do this? I just ignore the messages buffer
unless I have a problem, in which case I probbly need the info in there. 

I'm wondering if perhaps the OP wants to do this for the wrong reasons and
maybe some other solution would better fix whatever the issue is.

Tim

-- 
tcross (at) rapttech dot com dot au

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

* Re: Temporarily turning message logging off
  2007-05-24  8:25     ` Katsumi Yamaoka
@ 2007-05-24 10:47       ` Eli Zaretskii
       [not found]       ` <mailman.1141.1180003694.32220.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2007-05-24 10:47 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Katsumi Yamaoka <yamaoka@jpl.org>
> Date: Thu, 24 May 2007 17:25:36 +0900
> 
> >>>>> In <mailman.1132.1179993370.32220.help-gnu-emacs@gnu.org>
> >>>>>	Eli Zaretskii wrote:
> 
> > Isn't it easier and less invasive to temporarily bind message-log-max
> > to nil?
> 
> That's the best if Davin only wants the *Messages* buffer not to
> be filled.  If not, it might be insufficient.  For example:
> 
> emacs -batch -eval '(let (message-log-max) (write-region "foo" nil "testing"))'
> Wrote /tmp/testing

He said "What do I have to do to turn message _logging_ off?"
(emphasis added).  He didn't say he wanted to turn the _messages_
themselves off.  If he wanted the latter, then indeed my suggestion
will not help, but in that case, fsetting `message' itself, or
defadvising it, is probably the way to go.

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

* Re: Temporarily turning message logging off
       [not found]       ` <mailman.1141.1180003694.32220.help-gnu-emacs@gnu.org>
@ 2007-05-24 11:43         ` Katsumi Yamaoka
  2007-05-25  6:30         ` Davin Pearson
  1 sibling, 0 replies; 10+ messages in thread
From: Katsumi Yamaoka @ 2007-05-24 11:43 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> In <mailman.1141.1180003694.32220.help-gnu-emacs@gnu.org>
>>>>>	Eli Zaretskii wrote:

> He said "What do I have to do to turn message _logging_ off?"
> (emphasis added).  He didn't say he wanted to turn the _messages_
> themselves off.

I might have misunderstood.  Because the code he presented
silences the `message' function thoroughly and I sometimes do it
at that. ;-)

> If he wanted the latter, then indeed my suggestion
> will not help, but in that case, fsetting `message' itself, or
> defadvising it, is probably the way to go.

In addition, `message' will be required to return a value as
usual even if it is turned off, since there might be a program
that uses it.

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

* Re: Temporarily turning message logging off
       [not found]       ` <mailman.1141.1180003694.32220.help-gnu-emacs@gnu.org>
  2007-05-24 11:43         ` Katsumi Yamaoka
@ 2007-05-25  6:30         ` Davin Pearson
  2007-05-25  7:00           ` Katsumi Yamaoka
  2007-05-25  7:44           ` David Hansen
  1 sibling, 2 replies; 10+ messages in thread
From: Davin Pearson @ 2007-05-25  6:30 UTC (permalink / raw)
  To: help-gnu-emacs

On May 24, 10:47 pm, Eli Zaretskii <e...@gnu.org> wrote:
> > From: Katsumi Yamaoka <yama...@jpl.org>
> > Date: Thu, 24 May 2007 17:25:36 +0900
>
> > >>>>> In <mailman.1132.1179993370.32220.help-gnu-em...@gnu.org>
> > >>>>>       Eli Zaretskii wrote:
>
> > > Isn't it easier and less invasive to temporarily bind message-log-max
> > > to nil?
>
> > That's the best if Davin only wants the *Messages* buffer not to
> > be filled.  If not, it might be insufficient.  For example:
>
> > emacs -batch -eval '(let (message-log-max) (write-region "foo" nil "testing"))'
> > Wrote /tmp/testing
>
> He said "What do I have to do to turn message _logging_ off?"
> (emphasis added).  He didn't say he wanted to turn the _messages_
> themselves off.  If he wanted the latter, then indeed my suggestion
> will not help, but in that case, fsetting `message' itself, or
> defadvising it, is probably the way to go.

Sorry for the misunderstanding.

I actually want to turn the messages themselves off AS WELL as the
message logging.

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

* Re: Temporarily turning message logging off
  2007-05-25  6:30         ` Davin Pearson
@ 2007-05-25  7:00           ` Katsumi Yamaoka
  2007-05-25  7:44           ` David Hansen
  1 sibling, 0 replies; 10+ messages in thread
From: Katsumi Yamaoka @ 2007-05-25  7:00 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> In <1180074638.776649.275300@n15g2000prd.googlegroups.com>
>>>>>	Davin Pearson wrote:

> I actually want to turn the messages themselves off AS WELL as the
> message logging.

Then, here's a `defcustom' version:

--8<---------------cut here---------------start------------->8---
(defvar my-message-silent-p nil)

(defadvice message (around shut-up (&rest args) activate)
  (if my-message-silent-p
      (setq ad-return-value (apply 'format args))
    ad-do-it))

(defadvice write-region (before shut-up activate)
  (if my-message-silent-p
      (ad-set-arg 4 'silent)))
--8<---------------cut here---------------end--------------->8---

Set (or bind using `let') `my-message-silent-p' to a non-nil
value when you don't want Emacs to issue messages.

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

* Re: Temporarily turning message logging off
  2007-05-25  6:30         ` Davin Pearson
  2007-05-25  7:00           ` Katsumi Yamaoka
@ 2007-05-25  7:44           ` David Hansen
  1 sibling, 0 replies; 10+ messages in thread
From: David Hansen @ 2007-05-25  7:44 UTC (permalink / raw)
  To: help-gnu-emacs

On 24 May 2007 23:30:38 -0700 Davin Pearson wrote:

> On May 24, 10:47 pm, Eli Zaretskii <e...@gnu.org> wrote:
>> > From: Katsumi Yamaoka <yama...@jpl.org>
>> > Date: Thu, 24 May 2007 17:25:36 +0900
>>
>> > >>>>> In <mailman.1132.1179993370.32220.help-gnu-em...@gnu.org>
>> > >>>>>       Eli Zaretskii wrote:
>>
>> > > Isn't it easier and less invasive to temporarily bind message-log-max
>> > > to nil?
>>
>> > That's the best if Davin only wants the *Messages* buffer not to
>> > be filled.  If not, it might be insufficient.  For example:
>>
>> > emacs -batch -eval '(let (message-log-max) (write-region "foo" nil "testing"))'
>> > Wrote /tmp/testing
>>
>> He said "What do I have to do to turn message _logging_ off?"
>> (emphasis added).  He didn't say he wanted to turn the _messages_
>> themselves off.  If he wanted the latter, then indeed my suggestion
>> will not help, but in that case, fsetting `message' itself, or
>> defadvising it, is probably the way to go.
>
> Sorry for the misunderstanding.
>
> I actually want to turn the messages themselves off AS WELL as the
> message logging.

How about

~/bin/emacs -batch -eval "(require 'cl) (flet ((message (format &rest args))) (write-region \"foo\" nil \"testing\"))"

David

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

end of thread, other threads:[~2007-05-25  7:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-24  3:56 Temporarily turning message logging off Davin Pearson
2007-05-24  5:03 ` Katsumi Yamaoka
2007-05-24  7:56   ` Eli Zaretskii
     [not found]   ` <mailman.1132.1179993370.32220.help-gnu-emacs@gnu.org>
2007-05-24  8:25     ` Katsumi Yamaoka
2007-05-24 10:47       ` Eli Zaretskii
     [not found]       ` <mailman.1141.1180003694.32220.help-gnu-emacs@gnu.org>
2007-05-24 11:43         ` Katsumi Yamaoka
2007-05-25  6:30         ` Davin Pearson
2007-05-25  7:00           ` Katsumi Yamaoka
2007-05-25  7:44           ` David Hansen
2007-05-24  9:14     ` Tim X

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.