[Top][All Lists]
[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: |
Thu, 01 Jan 2004 13:22:17 +0100 |
User-agent: |
Gnus/5.1004 (Gnus v5.10.4) Emacs/21.3.50 (gnu/linux) |
Eli Zaretskii <address@hidden> writes:
>> From: Simon Josefsson <address@hidden>
>> Date: Wed, 31 Dec 2003 20:56:21 +0100
>>
>> 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.
>
> This addition should be followed by 2 documentation changes: (1) to
> the ELisp manual, and (2) to etc/NEWS.
Yes, although I waited with that until people said it was a good idea
to install it. Maybe that time is now? If so:
Index: etc/NEWS
===================================================================
RCS file: /cvsroot/emacs/emacs/etc/NEWS,v
retrieving revision 1.882
diff -u -p -r1.882 NEWS
--- etc/NEWS 30 Dec 2003 23:39:57 -0000 1.882
+++ etc/NEWS 1 Jan 2004 12:21:03 -0000
@@ -1,5 +1,5 @@
GNU Emacs NEWS -- history of user-visible changes. 2003-05-21
-Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
See the end for copying conditions.
Please send Emacs bug reports to address@hidden
@@ -1736,6 +1736,11 @@ a match if part of it has a read-only pr
configuration files.
* Lisp Changes in Emacs 21.4
+
+** The new hook `before-save-hook' is invoked by `basic-save-buffer'
+before saving buffers. This allows packages to perform various final
+tasks, for example; it can be used by the copyright package to make
+sure saved files have the current year in any copyright headers.
** The function `insert-for-yank' now supports strings where the
`yank-handler' property does not span the first character of the
Index: lisp/ChangeLog
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.5573
diff -u -p -r1.5573 ChangeLog
--- lisp/ChangeLog 31 Dec 2003 02:46:07 -0000 1.5573
+++ lisp/ChangeLog 1 Jan 2004 12:21:05 -0000
@@ -1,3 +1,11 @@
+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.
+
2003-12-31 John Paul Wallington <address@hidden>
* bindings.el (completion-ignored-extensions): Add .pfsl.
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 1 Jan 2004 12:21:06 -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 1 Jan 2004 12:21:06 -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:
Index: lispref/ChangeLog
===================================================================
RCS file: /cvsroot/emacs/emacs/lispref/ChangeLog,v
retrieving revision 1.140
diff -u -p -r1.140 ChangeLog
--- lispref/ChangeLog 1 Jan 2004 04:20:43 -0000 1.140
+++ lispref/ChangeLog 1 Jan 2004 12:21:07 -0000
@@ -1,3 +1,8 @@
+2004-01-01 Simon Josefsson <address@hidden>
+
+ * hooks.texi (Standard Hooks): Add before-save-hook.
+ * files.texi (Saving Buffers): Likewise.
+
2004-01-01 Miles Bader <address@hidden>
* display.texi (Buttons): New section.
Index: lispref/files.texi
===================================================================
RCS file: /cvsroot/emacs/emacs/lispref/files.texi,v
retrieving revision 1.59
diff -u -p -r1.59 files.texi
--- lispref/files.texi 29 Dec 2003 20:28:40 -0000 1.59
+++ lispref/files.texi 1 Jan 2004 12:21:07 -0000
@@ -1,6 +1,6 @@
@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
address@hidden Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
address@hidden Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999,
2004
@c Free Software Foundation, Inc.
@c See the file elisp.texi for copying conditions.
@setfilename ../info/files
@@ -408,6 +408,13 @@ major modes, as buffer-local bindings fo
This variable automatically becomes buffer-local whenever it is set;
switching to a new major mode always resets this variable.
address@hidden defvar
+
address@hidden before-save-hook
+This normal hook runs before a buffer has been saved in its visited
+file. One use of this hook is for the Copyright package; it uses this
+hook to make sure the file has the current year in the copyright
+header.
@end defvar
@c Emacs 19 feature
Index: lispref/hooks.texi
===================================================================
RCS file: /cvsroot/emacs/emacs/lispref/hooks.texi,v
retrieving revision 1.14
diff -u -p -r1.14 hooks.texi
--- lispref/hooks.texi 1 Sep 2003 15:45:41 -0000 1.14
+++ lispref/hooks.texi 1 Jan 2004 12:21:08 -0000
@@ -1,6 +1,6 @@
@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
address@hidden Copyright (C) 1990, 1991, 1992, 1993, 1998 Free Software
Foundation, Inc.
address@hidden Copyright (C) 1990, 1991, 1992, 1993, 1998, 2004 Free Software
Foundation, Inc.
@c See the file elisp.texi for copying conditions.
@setfilename ../info/hooks
@node Standard Hooks, Index, Standard Keymaps, Top
@@ -47,6 +47,7 @@ however, we have renamed all of those.)
@item before-init-hook
@item before-make-frame-hook
@item before-revert-hook
address@hidden before-save-hook
@item blink-paren-function
@item buffer-access-fontify-functions
@item c-mode-hook