From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Joe Corneli Newsgroups: gmane.emacs.help Subject: defadvising `write-region' to be silent Date: Sat, 28 Aug 2004 13:21:19 -0500 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1093717313 5294 80.91.224.253 (28 Aug 2004 18:21:53 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 28 Aug 2004 18:21:53 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Aug 28 20:21:43 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1C17pe-0004G6-00 for ; Sat, 28 Aug 2004 20:21:42 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C17uM-0007dX-UJ for geh-help-gnu-emacs@m.gmane.org; Sat, 28 Aug 2004 14:26:34 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1C17uE-0007cf-ND for help-gnu-emacs@gnu.org; Sat, 28 Aug 2004 14:26:26 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1C17uD-0007cQ-QZ for help-gnu-emacs@gnu.org; Sat, 28 Aug 2004 14:26:26 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C17uD-0007cN-Mi for help-gnu-emacs@gnu.org; Sat, 28 Aug 2004 14:26:25 -0400 Original-Received: from [146.6.139.124] (helo=dell3.ma.utexas.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1C17pK-0004HR-94 for help-gnu-emacs@gnu.org; Sat, 28 Aug 2004 14:21:22 -0400 Original-Received: from linux183.ma.utexas.edu (mail@linux183.ma.utexas.edu [146.6.139.172]) by dell3.ma.utexas.edu (8.11.0.Beta3/8.10.2) with ESMTP id i7SILLF01442; Sat, 28 Aug 2004 13:21:21 -0500 Original-Received: from jcorneli by linux183.ma.utexas.edu with local (Exim 3.36 #1 (Debian)) id 1C17pH-00060I-00; Sat, 28 Aug 2004 13:21:19 -0500 Original-To: help-gnu-emacs@gnu.org X-all-your-base-are-belong-to-us: You are on the way to destruction. X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:20353 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:20353 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