* defadvising `write-region' to be silent
@ 2004-08-28 18:21 Joe Corneli
0 siblings, 0 replies; 3+ messages in thread
From: Joe Corneli @ 2004-08-28 18:21 UTC (permalink / raw)
I am working on a program that edits a lot of files. I would like
to turn off most messages from Emacs while this program runs. I do
this as follows:
(defvar messaging-on nil
"Control whether or not messages will be printed; by default,
they are not.")
(defadvice message (around nomessage activate)
"Turn off messaging most of the time.
Whether or not messages are displayed is determined by the value
of the variable `messaging-on'."
(when messaging-on
ad-do-it))
This lets me control when messages print: if I want to write a
message to the user, I use this function:
(defun my-message (str)
"Send a message."
(let ((messaging-on t))
(message str)))
The problem I'm coming up against is that the "Wrote file" message
that is printed by `write-file' and `save-buffer' is not printed
using the `message' mechanism, but rather, is part of the C code for
the function `write-region'. So one has to turn off these messages
separately.
After studying the docstring for `write-region', I created this
piece of advice:
(defadvice write-region (around no-wrote-file activate)
"Turn off the printout associated with writing files.
This is necessary to add as a supplement to my `nomessage' advice
to turn off `message' because the \"Wrote file\" message is not
printed through the `message' mechanism. The observed effect of
this piece of advice should be that neither `save-buffer' nor
`write-file' will print anything out when they run."
(if messaging-on
ad-do-it
(ad-set-arg 4 1)
(ad-set-arg 6 nil)
ad-do-it))
This is a response to the following documentation:
Optional fifth argument visit if t means
set the last-save-file-modtime of buffer to this file's modtime
and mark buffer not modified.
If visit is a string, it is a second file name;
the output goes to filename, but the buffer is marked as visiting visit.
visit is also the file name to lock and unlock for clash detection.
If visit is neither t nor nil nor a string,
that means do not display the "Wrote file" message.
The problem is, with the fifth argument set to `1', the "Wrote file"
message is not printed, but if I try to save a buffer that has been
modified, I get the following message (and request for user input):
Buffer foo modified; kill anyway? (y or n)
Apparently you can't _both_ mark the buffer as not modified and get
rid of the "Wrote file" message by twiddling the argument `visit'.
Can anyone suggest a way to just get rid of the "Wrote file" message
and not introduce another interuption?
Thanks.
on GNU Emacs 21.3.50.1 (powerpc-apple-darwin7.4.0, X toolkit) of
2004-06-22 on hope-of-a-stone.local
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: defadvising `write-region' to be silent
[not found] <mailman.538.1093717588.1998.help-gnu-emacs@gnu.org>
@ 2004-08-29 19:58 ` Ian Zimmerman
0 siblings, 0 replies; 3+ messages in thread
From: Ian Zimmerman @ 2004-08-29 19:58 UTC (permalink / raw)
Joe> Apparently you can't _both_ mark the buffer as not modified and get
Joe> rid of the "Wrote file" message by twiddling the argument `visit'.
Can't you just add a call to `not-modified' to the false branch of the
advised write-file?
--
"It's not true or not." A reality show producer (real quote)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: defadvising `write-region' to be silent
@ 2004-08-30 2:00 Joe Corneli
0 siblings, 0 replies; 3+ messages in thread
From: Joe Corneli @ 2004-08-30 2:00 UTC (permalink / raw)
Can't you just add a call to `not-modified' to the false branch
of the advised write-file?
Worked like a charm, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-08-30 2:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-28 18:21 defadvising `write-region' to be silent Joe Corneli
[not found] <mailman.538.1093717588.1998.help-gnu-emacs@gnu.org>
2004-08-29 19:58 ` Ian Zimmerman
-- strict thread matches above, loose matches on Subject: below --
2004-08-30 2:00 Joe Corneli
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.