aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2002-06-23 21:16:38 +0000
committerStefan Monnier2002-06-23 21:16:38 +0000
commit0370fe77f19447af23ad41055e836478d97a174c (patch)
treecd79b4311d807152a7e269300a52bf0debae8492
parentd24c52bbe52244103baf4e2035e9f420b94513f4 (diff)
downloademacs-0370fe77f19447af23ad41055e836478d97a174c.tar.gz
emacs-0370fe77f19447af23ad41055e836478d97a174c.zip
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.
-rw-r--r--lisp/files.el86
1 files changed, 42 insertions, 44 deletions
diff --git a/lisp/files.el b/lisp/files.el
index fc92d94825c..5c1396fc7b2 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -344,45 +344,44 @@ and should return either a buffer or nil."
344 344
345;;;It is not useful to make this a local variable. 345;;;It is not useful to make this a local variable.
346;;;(put 'find-file-not-found-hooks 'permanent-local t) 346;;;(put 'find-file-not-found-hooks 'permanent-local t)
347(defvar find-file-not-found-hooks nil 347(defvar find-file-not-found-functions nil
348 "List of functions to be called for `find-file' on nonexistent file. 348 "List of functions to be called for `find-file' on nonexistent file.
349These functions are called as soon as the error is detected. 349These functions are called as soon as the error is detected.
350Variable `buffer-file-name' is already set up. 350Variable `buffer-file-name' is already set up.
351The functions are called in the order given until one of them returns non-nil.") 351The functions are called in the order given until one of them returns non-nil.")
352(defvaralias 'find-file-not-found-hooks 'find-file-not-found-functions)
353(make-obsolete-variable
354 'find-file-not-found-hooks 'find-file-not-found-functions "21.4")
352 355
353;;;It is not useful to make this a local variable. 356;;;It is not useful to make this a local variable.
354;;;(put 'find-file-hooks 'permanent-local t) 357;;;(put 'find-file-hooks 'permanent-local t)
355(defvar find-file-hooks nil 358(defvar find-file-hook nil
356 "List of functions to be called after a buffer is loaded from a file. 359 "List of functions to be called after a buffer is loaded from a file.
357The buffer's local variables (if any) will have been processed before the 360The buffer's local variables (if any) will have been processed before the
358functions are called.") 361functions are called.")
362(defvaralias 'find-file-hooks 'find-file-hook)
363(make-obsolete-variable 'find-file-hooks 'find-file-hook "21.4")
359 364
360(defvar write-file-hooks nil 365(defvar write-file-functions nil
361 "List of functions to be called before writing out a buffer to a file. 366 "List of functions to be called before writing out a buffer to a file.
362If one of them returns non-nil, the file is considered already written 367If one of them returns non-nil, the file is considered already written
363and the rest are not called. 368and the rest are not called.
364These hooks are considered to pertain to the visited file. 369These hooks are considered to pertain to the visited file.
365So any buffer-local binding of `write-file-hooks' is 370So any buffer-local binding of this variable is discarded if you change
366discarded if you change the visited file name with \\[set-visited-file-name]. 371the visited file name with \\[set-visited-file-name], but not when you
367 372change the major mode.
368Don't make this variable buffer-local; instead, use `local-write-file-hooks'. 373
369See also `write-contents-hooks'.") 374See also `write-contents-functions'.")
370;;; However, in case someone does make it local... 375(put 'write-file-functions 'permanent-local t)
371(put 'write-file-hooks 'permanent-local t) 376(defvaralias 'write-file-hooks 'write-file-functions)
372 377(make-obsolete-variable 'write-file-hooks 'write-file-functions "21.4")
373(defvar local-write-file-hooks nil 378
374 "Just like `write-file-hooks', except intended for per-buffer use. 379(defvar local-write-file-hooks nil)
375The functions in this list are called before the ones in
376`write-file-hooks'.
377
378This variable is meant to be used for hooks that have to do with a
379particular visited file. Therefore, it is a permanent local, so that
380changing the major mode does not clear it. However, calling
381`set-visited-file-name' does clear it.")
382(make-variable-buffer-local 'local-write-file-hooks) 380(make-variable-buffer-local 'local-write-file-hooks)
383(put 'local-write-file-hooks 'permanent-local t) 381(put 'local-write-file-hooks 'permanent-local t)
382(make-obsolete-variable 'local-write-file-hooks 'write-file-functions "21.4")
384 383
385(defvar write-contents-hooks nil 384(defvar write-contents-functions nil
386 "List of functions to be called before writing out a buffer to a file. 385 "List of functions to be called before writing out a buffer to a file.
387If one of them returns non-nil, the file is considered already written 386If one of them returns non-nil, the file is considered already written
388and the rest are not called. 387and the rest are not called.
@@ -392,12 +391,10 @@ buffer's contents, not to the particular visited file; thus,
392`set-visited-file-name' does not clear this variable; but changing the 391`set-visited-file-name' does not clear this variable; but changing the
393major mode does clear it. 392major mode does clear it.
394 393
395This variable automatically becomes buffer-local whenever it is set. 394See also `write-file-functions'.")
396If you use `add-hook' to add elements to the list, use nil for the 395(make-variable-buffer-local 'write-contents-functions)
397LOCAL argument. 396(defvaralias 'write-contents-hooks 'write-contents-functions)
398 397(make-obsolete-variable 'write-contents-hooks 'write-contents-functions "21.4")
399See also `write-file-hooks'.")
400(make-variable-buffer-local 'write-contents-hooks)
401 398
402(defcustom enable-local-variables t 399(defcustom enable-local-variables t
403 "*Control use of local variables in files you visit. 400 "*Control use of local variables in files you visit.
@@ -602,9 +599,10 @@ PATH-AND-SUFFIXES is a pair of lists (DIRECTORIES . SUFFIXES)."
602 (when (string-match suffix file) 599 (when (string-match suffix file)
603 (setq file (substring file 0 (match-beginning 0))) 600 (setq file (substring file 0 (match-beginning 0)))
604 (push (if string-dir (concat string-dir file) file) names))))) 601 (push (if string-dir (concat string-dir file) file) names)))))
605 (if action 602 (cond
606 (all-completions string (mapcar 'list names)) 603 ((eq action t) (all-completions string names))
607 (try-completion string (mapcar 'list names)))))) 604 ((null action) (try-completion string names))
605 (t (test-completion string names))))))
608 606
609(defun load-library (library) 607(defun load-library (library)
610 "Load the library named LIBRARY. 608 "Load the library named LIBRARY.
@@ -1256,7 +1254,7 @@ that are visiting the various files."
1256 (signal 'file-error (list "File is not readable" 1254 (signal 'file-error (list "File is not readable"
1257 filename))) 1255 filename)))
1258 ;; Run find-file-not-found-hooks until one returns non-nil. 1256 ;; Run find-file-not-found-hooks until one returns non-nil.
1259 (or (run-hook-with-args-until-success 'find-file-not-found-hooks) 1257 (or (run-hook-with-args-until-success 'find-file-not-found-functions)
1260 ;; If they fail too, set error. 1258 ;; If they fail too, set error.
1261 (setq error t))))) 1259 (setq error t)))))
1262 ;; Record the file's truename, and maybe use that as visited name. 1260 ;; Record the file's truename, and maybe use that as visited name.
@@ -1299,7 +1297,7 @@ that are visiting the various files."
1299 "Like `insert-file-contents', but only reads in the file literally. 1297 "Like `insert-file-contents', but only reads in the file literally.
1300A buffer may be modified in several ways after reading into the buffer, 1298A buffer may be modified in several ways after reading into the buffer,
1301to Emacs features such as format decoding, character code 1299to Emacs features such as format decoding, character code
1302conversion, `find-file-hooks', automatic uncompression, etc. 1300conversion, `find-file-hook', automatic uncompression, etc.
1303 1301
1304This function ensures that none of these modifications will take place." 1302This function ensures that none of these modifications will take place."
1305 (let ((format-alist nil) 1303 (let ((format-alist nil)
@@ -1372,7 +1370,7 @@ NOAUTO means don't mess with auto-save mode.
1372Fourth arg AFTER-FIND-FILE-FROM-REVERT-BUFFER non-nil 1370Fourth arg AFTER-FIND-FILE-FROM-REVERT-BUFFER non-nil
1373 means this call was from `revert-buffer'. 1371 means this call was from `revert-buffer'.
1374Fifth arg NOMODES non-nil means don't alter the file's modes. 1372Fifth arg NOMODES non-nil means don't alter the file's modes.
1375Finishes by calling the functions in `find-file-hooks' 1373Finishes by calling the functions in `find-file-hook'
1376unless NOMODES is non-nil." 1374unless NOMODES is non-nil."
1377 (setq buffer-read-only (not (file-writable-p buffer-file-name))) 1375 (setq buffer-read-only (not (file-writable-p buffer-file-name)))
1378 (if noninteractive 1376 (if noninteractive
@@ -1426,7 +1424,7 @@ unless NOMODES is non-nil."
1426 view-read-only 1424 view-read-only
1427 (not (eq (get major-mode 'mode-class) 'special))) 1425 (not (eq (get major-mode 'mode-class) 'special)))
1428 (view-mode-enter)) 1426 (view-mode-enter))
1429 (run-hooks 'find-file-hooks))) 1427 (run-hooks 'find-file-hook)))
1430 1428
1431(defun normal-mode (&optional find-file) 1429(defun normal-mode (&optional find-file)
1432 "Choose the major mode for this buffer automatically. 1430 "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 (if filename 2167 (if filename
2170 (nthcdr 10 (file-attributes buffer-file-name)) 2168 (nthcdr 10 (file-attributes buffer-file-name))
2171 nil))) 2169 nil)))
2172 ;; write-file-hooks is normally used for things like ftp-find-file 2170 ;; write-file-functions is normally used for things like ftp-find-file
2173 ;; that visit things that are not local files as if they were files. 2171 ;; that visit things that are not local files as if they were files.
2174 ;; Changing to visit an ordinary local file instead should flush the hook. 2172 ;; Changing to visit an ordinary local file instead should flush the hook.
2175 (kill-local-variable 'write-file-hooks) 2173 (kill-local-variable 'write-file-functions)
2176 (kill-local-variable 'local-write-file-hooks) 2174 (kill-local-variable 'local-write-file-hooks)
2177 (kill-local-variable 'revert-buffer-function) 2175 (kill-local-variable 'revert-buffer-function)
2178 (kill-local-variable 'backup-inhibited) 2176 (kill-local-variable 'backup-inhibited)
@@ -2746,9 +2744,9 @@ in such cases.")
2746 2744
2747(defun basic-save-buffer () 2745(defun basic-save-buffer ()
2748 "Save the current buffer in its visited file, if it has been modified. 2746 "Save the current buffer in its visited file, if it has been modified.
2749The hooks `write-contents-hooks', `local-write-file-hooks' and 2747The hooks `write-contents-functions' and `write-file-functions' get a chance
2750`write-file-hooks' get a chance to do the job of saving; if they do not, 2748to do the job of saving; if they do not, then the buffer is saved in
2751then the buffer is saved in the visited file file in the usual way. 2749the visited file file in the usual way.
2752After saving the buffer, this function runs `after-save-hook'." 2750After saving the buffer, this function runs `after-save-hook'."
2753 (interactive) 2751 (interactive)
2754 (save-current-buffer 2752 (save-current-buffer
@@ -2790,7 +2788,7 @@ After saving the buffer, this function runs `after-save-hook'."
2790 (save-restriction 2788 (save-restriction
2791 (widen) 2789 (widen)
2792 (save-excursion 2790 (save-excursion
2793 (and (> (point-max) 1) 2791 (and (> (point-max) (point-min))
2794 (not find-file-literally) 2792 (not find-file-literally)
2795 (/= (char-after (1- (point-max))) ?\n) 2793 (/= (char-after (1- (point-max))) ?\n)
2796 (not (and (eq selective-display t) 2794 (not (and (eq selective-display t)
@@ -2805,9 +2803,9 @@ After saving the buffer, this function runs `after-save-hook'."
2805 (insert ?\n)))) 2803 (insert ?\n))))
2806 ;; Support VC version backups. 2804 ;; Support VC version backups.
2807 (vc-before-save) 2805 (vc-before-save)
2808 (or (run-hook-with-args-until-success 'write-contents-hooks) 2806 (or (run-hook-with-args-until-success 'write-contents-functions)
2809 (run-hook-with-args-until-success 'local-write-file-hooks) 2807 (run-hook-with-args-until-success 'local-write-file-hooks)
2810 (run-hook-with-args-until-success 'write-file-hooks) 2808 (run-hook-with-args-until-success 'write-file-functions)
2811 ;; If a hook returned t, file is already "written". 2809 ;; If a hook returned t, file is already "written".
2812 ;; Otherwise, write it the usual way now. 2810 ;; Otherwise, write it the usual way now.
2813 (setq setmodes (basic-save-buffer-1))) 2811 (setq setmodes (basic-save-buffer-1)))
@@ -2833,7 +2831,7 @@ After saving the buffer, this function runs `after-save-hook'."
2833 2831
2834;; This does the "real job" of writing a buffer into its visited file 2832;; This does the "real job" of writing a buffer into its visited file
2835;; and making a backup file. This is what is normally done 2833;; and making a backup file. This is what is normally done
2836;; but inhibited if one of write-file-hooks returns non-nil. 2834;; but inhibited if one of write-file-functions returns non-nil.
2837;; It returns a value to store in setmodes. 2835;; It returns a value to store in setmodes.
2838(defun basic-save-buffer-1 () 2836(defun basic-save-buffer-1 ()
2839 (if save-buffer-coding-system 2837 (if save-buffer-coding-system
@@ -2899,7 +2897,7 @@ After saving the buffer, this function runs `after-save-hook'."
2899 ;; Since we have created an entirely new file 2897 ;; Since we have created an entirely new file
2900 ;; and renamed it, make sure it gets the 2898 ;; and renamed it, make sure it gets the
2901 ;; right permission bits set. 2899 ;; right permission bits set.
2902 (setq setmodes (file-modes buffer-file-name)) 2900 (setq setmodes (or setmodes (file-modes buffer-file-name)))
2903 ;; We succeeded in writing the temp file, 2901 ;; We succeeded in writing the temp file,
2904 ;; so rename it. 2902 ;; so rename it.
2905 (rename-file tempname buffer-file-name t)) 2903 (rename-file tempname buffer-file-name t))