comparison lisp/files.el @ 53503:8995f4286209

(before-save-hook): Add. (basic-save-buffer): Use before-save-hook.
author Simon Josefsson <jas@extundo.com>
date Mon, 05 Jan 2004 18:17:41 +0000
parents 79093b308520
children 2e7e8047b338
comparison
equal deleted inserted replaced
53502:14a0119ceee0 53503:8995f4286209
2988 (set-buffer-auto-saved)))) 2988 (set-buffer-auto-saved))))
2989 2989
2990 (defvar auto-save-hook nil 2990 (defvar auto-save-hook nil
2991 "Normal hook run just before auto-saving.") 2991 "Normal hook run just before auto-saving.")
2992 2992
2993 (defcustom before-save-hook nil
2994 "Normal hook that is run before a buffer is saved to its file."
2995 :options '(copyright-update)
2996 :type 'hook
2997 :group 'files)
2998
2993 (defcustom after-save-hook nil 2999 (defcustom after-save-hook nil
2994 "Normal hook that is run after a buffer is saved to its file." 3000 "Normal hook that is run after a buffer is saved to its file."
2995 :options '(executable-make-buffer-file-executable-if-script-p) 3001 :options '(executable-make-buffer-file-executable-if-script-p)
2996 :type 'hook 3002 :type 'hook
2997 :group 'files) 3003 :group 'files)
3010 (defun basic-save-buffer () 3016 (defun basic-save-buffer ()
3011 "Save the current buffer in its visited file, if it has been modified. 3017 "Save the current buffer in its visited file, if it has been modified.
3012 The hooks `write-contents-functions' and `write-file-functions' get a chance 3018 The hooks `write-contents-functions' and `write-file-functions' get a chance
3013 to do the job of saving; if they do not, then the buffer is saved in 3019 to do the job of saving; if they do not, then the buffer is saved in
3014 the visited file file in the usual way. 3020 the visited file file in the usual way.
3015 After saving the buffer, this function runs `after-save-hook'." 3021 Before and after saving the buffer, this function runs
3022 `before-save-hook' and `after-save-hook', respectively."
3016 (interactive) 3023 (interactive)
3017 (save-current-buffer 3024 (save-current-buffer
3018 ;; In an indirect buffer, save its base buffer instead. 3025 ;; In an indirect buffer, save its base buffer instead.
3019 (if (buffer-base-buffer) 3026 (if (buffer-base-buffer)
3020 (set-buffer (buffer-base-buffer))) 3027 (set-buffer (buffer-base-buffer)))
3066 (save-excursion 3073 (save-excursion
3067 (goto-char (point-max)) 3074 (goto-char (point-max))
3068 (insert ?\n)))) 3075 (insert ?\n))))
3069 ;; Support VC version backups. 3076 ;; Support VC version backups.
3070 (vc-before-save) 3077 (vc-before-save)
3078 (run-hooks 'before-save-hook)
3071 (or (run-hook-with-args-until-success 'write-contents-functions) 3079 (or (run-hook-with-args-until-success 'write-contents-functions)
3072 (run-hook-with-args-until-success 'local-write-file-hooks) 3080 (run-hook-with-args-until-success 'local-write-file-hooks)
3073 (run-hook-with-args-until-success 'write-file-functions) 3081 (run-hook-with-args-until-success 'write-file-functions)
3074 ;; If a hook returned t, file is already "written". 3082 ;; If a hook returned t, file is already "written".
3075 ;; Otherwise, write it the usual way now. 3083 ;; Otherwise, write it the usual way now.