help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

defadvising `write-region' to be silent


From: Joe Corneli
Subject: defadvising `write-region' to be silent
Date: Sat, 28 Aug 2004 13:21:19 -0500

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]