emacs-devel
[Top][All Lists]
Advanced

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

Re: Defcustom write-file-functions and write-contents-functions?


From: Simon Josefsson
Subject: Re: Defcustom write-file-functions and write-contents-functions?
Date: Wed, 31 Dec 2003 20:56:21 +0100
User-agent: Gnus/5.1004 (Gnus v5.10.4) Emacs/21.3.50 (gnu/linux)

You convinced me, thanks for the feedback.  How about this patch,
instead?

2003-12-31  Simon Josefsson  <address@hidden>

        * files.el (before-save-hook): Add.
        (basic-save-buffer): Use before-save-hook.

        * emacs-lisp/copyright.el: Use before-save-hook instead of
        write-file-functions.

Index: lisp/files.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/files.el,v
retrieving revision 1.673
diff -u -p -r1.673 files.el
--- lisp/files.el       29 Dec 2003 19:14:03 -0000      1.673
+++ lisp/files.el       31 Dec 2003 19:51:10 -0000
@@ -2990,6 +2990,12 @@ the last real save, but optional arg FOR
 (defvar auto-save-hook nil
   "Normal hook run just before auto-saving.")
 
+(defcustom before-save-hook nil
+  "Normal hook that is run before a buffer is saved to its file."
+  :options '(copyright-update)
+  :type 'hook
+  :group 'files)
+
 (defcustom after-save-hook nil
   "Normal hook that is run after a buffer is saved to its file."
   :options '(executable-make-buffer-file-executable-if-script-p)
@@ -3012,7 +3018,8 @@ in such cases.")
 The hooks `write-contents-functions' and `write-file-functions' get a chance
 to do the job of saving; if they do not, then the buffer is saved in
 the visited file file in the usual way.
-After saving the buffer, this function runs `after-save-hook'."
+Before and after saving the buffer, this function runs
+`before-save-hook' and `after-save-hook', respectively."
   (interactive)
   (save-current-buffer
     ;; In an indirect buffer, save its base buffer instead.
@@ -3068,6 +3075,7 @@ After saving the buffer, this function r
                     (insert ?\n))))
            ;; Support VC version backups.
            (vc-before-save)
+           (run-hooks 'before-save-hook)
            (or (run-hook-with-args-until-success 'write-contents-functions)
                (run-hook-with-args-until-success 'local-write-file-hooks)
                (run-hook-with-args-until-success 'write-file-functions)
Index: lisp/emacs-lisp/copyright.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/emacs-lisp/copyright.el,v
retrieving revision 1.43
diff -u -p -r1.43 copyright.el
--- lisp/emacs-lisp/copyright.el        1 Sep 2003 15:45:20 -0000       1.43
+++ lisp/emacs-lisp/copyright.el        31 Dec 2003 19:51:10 -0000
@@ -27,7 +27,8 @@
 
 ;; Allows updating the copyright year and above mentioned GPL version manually
 ;; or when saving a file.
-;; Do (add-hook 'write-file-functions 'copyright-update).
+;; Do (add-hook 'before-save-hook 'copyright-update), or use
+;; M-x customize-variable RET before-save-hook RET.
 
 ;;; Code:
 





reply via email to

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