Commit 0370fe77 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

Rename (and mark as obsolete)

find-file-hooks to find-file-hook,
find-file-not-found-hooks to find-file-not-found-functions,
write-file-hooks to write-file-functions,
write-contents-hooks to write-contents-functions.
Mark local-write-file-hooks as obsolete.
(locate-file-completion): Don't cons uselessly.  Use test-completion.
(basic-save-buffer): Use (point-min) rather than 1.
(basic-save-buffer-2): Obey the `setmodes' returned by backup-buffer.
parent d24c52bb
...@@ -344,45 +344,44 @@ and should return either a buffer or nil." ...@@ -344,45 +344,44 @@ and should return either a buffer or nil."
;;;It is not useful to make this a local variable. ;;;It is not useful to make this a local variable.
;;;(put 'find-file-not-found-hooks 'permanent-local t) ;;;(put 'find-file-not-found-hooks 'permanent-local t)
(defvar find-file-not-found-hooks nil (defvar find-file-not-found-functions nil
"List of functions to be called for `find-file' on nonexistent file. "List of functions to be called for `find-file' on nonexistent file.
These functions are called as soon as the error is detected. These functions are called as soon as the error is detected.
Variable `buffer-file-name' is already set up. Variable `buffer-file-name' is already set up.
The functions are called in the order given until one of them returns non-nil.") The functions are called in the order given until one of them returns non-nil.")
(defvaralias 'find-file-not-found-hooks 'find-file-not-found-functions)
(make-obsolete-variable
'find-file-not-found-hooks 'find-file-not-found-functions "21.4")
;;;It is not useful to make this a local variable. ;;;It is not useful to make this a local variable.
;;;(put 'find-file-hooks 'permanent-local t) ;;;(put 'find-file-hooks 'permanent-local t)
(defvar find-file-hooks nil (defvar find-file-hook nil
"List of functions to be called after a buffer is loaded from a file. "List of functions to be called after a buffer is loaded from a file.
The buffer's local variables (if any) will have been processed before the The buffer's local variables (if any) will have been processed before the
functions are called.") functions are called.")
(defvaralias 'find-file-hooks 'find-file-hook)
(make-obsolete-variable 'find-file-hooks 'find-file-hook "21.4")
(defvar write-file-hooks nil (defvar write-file-functions nil
"List of functions to be called before writing out a buffer to a file. "List of functions to be called before writing out a buffer to a file.
If one of them returns non-nil, the file is considered already written If one of them returns non-nil, the file is considered already written
and the rest are not called. and the rest are not called.
These hooks are considered to pertain to the visited file. These hooks are considered to pertain to the visited file.
So any buffer-local binding of `write-file-hooks' is So any buffer-local binding of this variable is discarded if you change
discarded if you change the visited file name with \\[set-visited-file-name]. the visited file name with \\[set-visited-file-name], but not when you
change the major mode.
Don't make this variable buffer-local; instead, use `local-write-file-hooks'.
See also `write-contents-hooks'.") See also `write-contents-functions'.")
;;; However, in case someone does make it local... (put 'write-file-functions 'permanent-local t)
(put 'write-file-hooks 'permanent-local t) (defvaralias 'write-file-hooks 'write-file-functions)
(make-obsolete-variable 'write-file-hooks 'write-file-functions "21.4")
(defvar local-write-file-hooks nil
"Just like `write-file-hooks', except intended for per-buffer use. (defvar local-write-file-hooks nil)
The functions in this list are called before the ones in
`write-file-hooks'.
This variable is meant to be used for hooks that have to do with a
particular visited file. Therefore, it is a permanent local, so that
changing the major mode does not clear it. However, calling
`set-visited-file-name' does clear it.")
(make-variable-buffer-local 'local-write-file-hooks) (make-variable-buffer-local 'local-write-file-hooks)
(put 'local-write-file-hooks 'permanent-local t) (put 'local-write-file-hooks 'permanent-local t)
(make-obsolete-variable 'local-write-file-hooks 'write-file-functions "21.4")
(defvar write-contents-hooks nil (defvar write-contents-functions nil
"List of functions to be called before writing out a buffer to a file. "List of functions to be called before writing out a buffer to a file.
If one of them returns non-nil, the file is considered already written If one of them returns non-nil, the file is considered already written
and the rest are not called. and the rest are not called.
...@@ -392,12 +391,10 @@ buffer's contents, not to the particular visited file; thus, ...@@ -392,12 +391,10 @@ buffer's contents, not to the particular visited file; thus,
`set-visited-file-name' does not clear this variable; but changing the `set-visited-file-name' does not clear this variable; but changing the
major mode does clear it. major mode does clear it.
This variable automatically becomes buffer-local whenever it is set. See also `write-file-functions'.")
If you use `add-hook' to add elements to the list, use nil for the (make-variable-buffer-local 'write-contents-functions)
LOCAL argument. (defvaralias 'write-contents-hooks 'write-contents-functions)
(make-obsolete-variable 'write-contents-hooks 'write-contents-functions "21.4")
See also `write-file-hooks'.")
(make-variable-buffer-local 'write-contents-hooks)
(defcustom enable-local-variables t (defcustom enable-local-variables t
"*Control use of local variables in files you visit. "*Control use of local variables in files you visit.
...@@ -602,9 +599,10 @@ PATH-AND-SUFFIXES is a pair of lists (DIRECTORIES . SUFFIXES)." ...@@ -602,9 +599,10 @@ PATH-AND-SUFFIXES is a pair of lists (DIRECTORIES . SUFFIXES)."
(when (string-match suffix file) (when (string-match suffix file)
(setq file (substring file 0 (match-beginning 0))) (setq file (substring file 0 (match-beginning 0)))
(push (if string-dir (concat string-dir file) file) names))))) (push (if string-dir (concat string-dir file) file) names)))))
(if action (cond
(all-completions string (mapcar 'list names)) ((eq action t) (all-completions string names))
(try-completion string (mapcar 'list names)))))) ((null action) (try-completion string names))
(t (test-completion string names))))))
(defun load-library (library) (defun load-library (library)
"Load the library named LIBRARY. "Load the library named LIBRARY.
...@@ -1256,7 +1254,7 @@ that are visiting the various files." ...@@ -1256,7 +1254,7 @@ that are visiting the various files."
(signal 'file-error (list "File is not readable" (signal 'file-error (list "File is not readable"
filename))) filename)))
;; Run find-file-not-found-hooks until one returns non-nil. ;; Run find-file-not-found-hooks until one returns non-nil.
(or (run-hook-with-args-until-success 'find-file-not-found-hooks) (or (run-hook-with-args-until-success 'find-file-not-found-functions)
;; If they fail too, set error. ;; If they fail too, set error.
(setq error t))))) (setq error t)))))
;; Record the file's truename, and maybe use that as visited name. ;; Record the file's truename, and maybe use that as visited name.
...@@ -1299,7 +1297,7 @@ that are visiting the various files." ...@@ -1299,7 +1297,7 @@ that are visiting the various files."
"Like `insert-file-contents', but only reads in the file literally. "Like `insert-file-contents', but only reads in the file literally.
A buffer may be modified in several ways after reading into the buffer, A buffer may be modified in several ways after reading into the buffer,
to Emacs features such as format decoding, character code to Emacs features such as format decoding, character code
conversion, `find-file-hooks', automatic uncompression, etc. conversion, `find-file-hook', automatic uncompression, etc.
This function ensures that none of these modifications will take place." This function ensures that none of these modifications will take place."
(let ((format-alist nil) (let ((format-alist nil)
...@@ -1372,7 +1370,7 @@ NOAUTO means don't mess with auto-save mode. ...@@ -1372,7 +1370,7 @@ NOAUTO means don't mess with auto-save mode.
Fourth arg AFTER-FIND-FILE-FROM-REVERT-BUFFER non-nil Fourth arg AFTER-FIND-FILE-FROM-REVERT-BUFFER non-nil
means this call was from `revert-buffer'. means this call was from `revert-buffer'.
Fifth arg NOMODES non-nil means don't alter the file's modes. Fifth arg NOMODES non-nil means don't alter the file's modes.
Finishes by calling the functions in `find-file-hooks' Finishes by calling the functions in `find-file-hook'
unless NOMODES is non-nil." unless NOMODES is non-nil."
(setq buffer-read-only (not (file-writable-p buffer-file-name))) (setq buffer-read-only (not (file-writable-p buffer-file-name)))
(if noninteractive (if noninteractive
...@@ -1426,7 +1424,7 @@ unless NOMODES is non-nil." ...@@ -1426,7 +1424,7 @@ unless NOMODES is non-nil."
view-read-only view-read-only
(not (eq (get major-mode 'mode-class) 'special))) (not (eq (get major-mode 'mode-class) 'special)))
(view-mode-enter)) (view-mode-enter))
(run-hooks 'find-file-hooks))) (run-hooks 'find-file-hook)))
(defun normal-mode (&optional find-file) (defun normal-mode (&optional find-file)
"Choose the major mode for this buffer automatically. "Choose the major mode for this buffer automatically.
...@@ -2169,10 +2167,10 @@ the old visited file has been renamed to the new name FILENAME." ...@@ -2169,10 +2167,10 @@ the old visited file has been renamed to the new name FILENAME."
(if filename (if filename
(nthcdr 10 (file-attributes buffer-file-name)) (nthcdr 10 (file-attributes buffer-file-name))
nil))) nil)))
;; write-file-hooks is normally used for things like ftp-find-file ;; write-file-functions is normally used for things like ftp-find-file
;; that visit things that are not local files as if they were files. ;; that visit things that are not local files as if they were files.
;; Changing to visit an ordinary local file instead should flush the hook. ;; Changing to visit an ordinary local file instead should flush the hook.
(kill-local-variable 'write-file-hooks) (kill-local-variable 'write-file-functions)
(kill-local-variable 'local-write-file-hooks) (kill-local-variable 'local-write-file-hooks)
(kill-local-variable 'revert-buffer-function) (kill-local-variable 'revert-buffer-function)
(kill-local-variable 'backup-inhibited) (kill-local-variable 'backup-inhibited)
...@@ -2746,9 +2744,9 @@ in such cases.") ...@@ -2746,9 +2744,9 @@ in such cases.")
(defun basic-save-buffer () (defun basic-save-buffer ()
"Save the current buffer in its visited file, if it has been modified. "Save the current buffer in its visited file, if it has been modified.
The hooks `write-contents-hooks', `local-write-file-hooks' and The hooks `write-contents-functions' and `write-file-functions' get a chance
`write-file-hooks' get a chance to do the job of saving; if they do not, to do the job of saving; if they do not, then the buffer is saved in
then the buffer is saved in the visited file file in the usual way. the visited file file in the usual way.
After saving the buffer, this function runs `after-save-hook'." After saving the buffer, this function runs `after-save-hook'."
(interactive) (interactive)
(save-current-buffer (save-current-buffer
...@@ -2790,7 +2788,7 @@ After saving the buffer, this function runs `after-save-hook'." ...@@ -2790,7 +2788,7 @@ After saving the buffer, this function runs `after-save-hook'."
(save-restriction (save-restriction
(widen) (widen)
(save-excursion (save-excursion
(and (> (point-max) 1) (and (> (point-max) (point-min))
(not find-file-literally) (not find-file-literally)
(/= (char-after (1- (point-max))) ?\n) (/= (char-after (1- (point-max))) ?\n)
(not (and (eq selective-display t) (not (and (eq selective-display t)
...@@ -2805,9 +2803,9 @@ After saving the buffer, this function runs `after-save-hook'." ...@@ -2805,9 +2803,9 @@ After saving the buffer, this function runs `after-save-hook'."
(insert ?\n)))) (insert ?\n))))
;; Support VC version backups. ;; Support VC version backups.
(vc-before-save) (vc-before-save)
(or (run-hook-with-args-until-success 'write-contents-hooks) (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 'local-write-file-hooks)
(run-hook-with-args-until-success 'write-file-hooks) (run-hook-with-args-until-success 'write-file-functions)
;; If a hook returned t, file is already "written". ;; If a hook returned t, file is already "written".
;; Otherwise, write it the usual way now. ;; Otherwise, write it the usual way now.
(setq setmodes (basic-save-buffer-1))) (setq setmodes (basic-save-buffer-1)))
...@@ -2833,7 +2831,7 @@ After saving the buffer, this function runs `after-save-hook'." ...@@ -2833,7 +2831,7 @@ After saving the buffer, this function runs `after-save-hook'."
;; This does the "real job" of writing a buffer into its visited file ;; This does the "real job" of writing a buffer into its visited file
;; and making a backup file. This is what is normally done ;; and making a backup file. This is what is normally done
;; but inhibited if one of write-file-hooks returns non-nil. ;; but inhibited if one of write-file-functions returns non-nil.
;; It returns a value to store in setmodes. ;; It returns a value to store in setmodes.
(defun basic-save-buffer-1 () (defun basic-save-buffer-1 ()
(if save-buffer-coding-system (if save-buffer-coding-system
...@@ -2899,7 +2897,7 @@ After saving the buffer, this function runs `after-save-hook'." ...@@ -2899,7 +2897,7 @@ After saving the buffer, this function runs `after-save-hook'."
;; Since we have created an entirely new file ;; Since we have created an entirely new file
;; and renamed it, make sure it gets the ;; and renamed it, make sure it gets the
;; right permission bits set. ;; right permission bits set.
(setq setmodes (file-modes buffer-file-name)) (setq setmodes (or setmodes (file-modes buffer-file-name)))
;; We succeeded in writing the temp file, ;; We succeeded in writing the temp file,
;; so rename it. ;; so rename it.
(rename-file tempname buffer-file-name t)) (rename-file tempname buffer-file-name t))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment