X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/e58cec15eb396522c37329e43192e9b6c3098ea2..e442c62b56414d1607adc107d7b4b94508d93526:/lisp/files.el diff --git a/lisp/files.el b/lisp/files.el index df63e016c6..61ccf00352 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -162,6 +162,7 @@ The truename of a file is found by chasing all links both at the file level and at the levels of the containing directories." :type 'boolean :group 'find-file) +(put 'find-file-visit-truename 'safe-local-variable 'boolean) (defcustom revert-without-query nil "*Specify which files should be reverted without query. @@ -249,6 +250,8 @@ nil means make them for files that have some already. (other :tag "Always" t)) :group 'backup :group 'vc) +(put 'version-control 'safe-local-variable + '(lambda (x) (or (booleanp x) (equal x 'never)))) (defcustom dired-kept-versions 2 "*When cleaning directory, number of versions to keep." @@ -268,12 +271,14 @@ If nil, ask confirmation. Any other value prevents any trimming." "*Number of oldest versions to keep when a new numbered backup is made." :type 'integer :group 'backup) +(put 'kept-old-versions 'safe-local-variable 'integerp) (defcustom kept-new-versions 2 "*Number of newest versions to keep when a new numbered backup is made. Includes the new backup. Must be > 0" :type 'integer :group 'backup) +(put 'kept-new-versions 'safe-local-variable 'integerp) (defcustom require-final-newline nil "*Whether to add a newline automatically at the end of the file. @@ -483,7 +488,7 @@ This variable does not affect the use of major modes specified in a -*- line.") (defcustom enable-local-eval 'maybe - "*Control processing of the \"variable\" `eval' in a file's local variables. + "Control processing of the \"variable\" `eval' in a file's local variables. The value can be t, nil or something else. A value of t means obey `eval' variables; nil means ignore them; anything else means query." @@ -1309,7 +1314,7 @@ removes automounter prefixes (see the variable `automount-dir-prefix')." (string-match "^[a-zA-`]:/$" filename))))) (setq filename (concat "~" - (substring filename (match-beginning 1) (match-end 1)) + (match-string 1 filename) (substring filename (match-end 0))))) filename)) @@ -1509,23 +1514,53 @@ the various files." ;; hexl-mode. (not (eq major-mode 'hexl-mode))) (if (buffer-modified-p) - (if (y-or-n-p (if rawfile - "Save file and revisit literally? " - "Save file and revisit non-literally? ")) + (if (y-or-n-p + (format + (if rawfile + "The file %s is already visited normally, +and you have edited the buffer. Now you have asked to visit it literally, +meaning no coding system handling, format conversion, or local variables. +Emacs can only visit a file in one way at a time. + +Do you want to save the file, and visit it literally instead? " + "The file %s is already visited literally, +meaning no coding system handling, format conversion, or local variables. +You have edited the buffer. Now you have asked to visit the file normally, +but Emacs can only visit a file in one way at a time. + +Do you want to save the file, and visit it normally instead? ") + (file-name-nondirectory filename))) (progn (save-buffer) (find-file-noselect-1 buf filename nowarn rawfile truename number)) - (if (y-or-n-p (if rawfile - "Discard your edits and revisit file literally? " - "Discard your edits and revisit file non-literally? ")) + (if (y-or-n-p + (format + (if rawfile + "\ +Do you want to discard your changes, and visit the file literally now? " + "\ +Do you want to discard your changes, and visit the file normally now? "))) (find-file-noselect-1 buf filename nowarn rawfile truename number) (error (if rawfile "File already visited non-literally" "File already visited literally")))) - (if (y-or-n-p (if rawfile - "Revisit file literally? " - "Revisit file non-literally? ")) + (if (y-or-n-p + (format + (if rawfile + "The file %s is already visited normally. +You have asked to visit it literally, +meaning no coding system decoding, format conversion, or local variables. +But Emacs can only visit a file in one way at a time. + +Do you want to revisit the file literally now? " + "The file %s is already visited literally, +meaning no coding system decoding, format conversion, or local variables. +You have asked to visit it normally, +but Emacs can only visit a file in one way at a time. + +Do you want to revisit the file normally now? ") + (file-name-nondirectory filename))) (find-file-noselect-1 buf filename nowarn rawfile truename number) (error (if rawfile "File already visited non-literally" @@ -1572,7 +1607,7 @@ the various files." (kill-buffer buf) (signal 'file-error (list "File is not readable" filename))) - ;; Run find-file-not-found-hooks until one returns non-nil. + ;; Run find-file-not-found-functions until one returns non-nil. (or (run-hook-with-args-until-success 'find-file-not-found-functions) ;; If they fail too, set error. (setq error t))))) @@ -1592,9 +1627,7 @@ the various files." (not (member logical find-file-not-true-dirname-list))) (setq buffer-file-name buffer-file-truename)) (if find-file-visit-truename - (setq buffer-file-name - (setq filename - (expand-file-name buffer-file-truename)))) + (setq buffer-file-name (expand-file-name buffer-file-truename))) ;; Set buffer's default directory to that of the file. (setq default-directory (file-name-directory buffer-file-name)) ;; Turn off backup files for certain file names. Since @@ -1842,13 +1875,14 @@ in that case, this function acts as if `enable-local-variables' were t." ("\\.ad[bs].dg\\'" . ada-mode) ("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode) ("Imakefile\\'" . makefile-imake-mode) + ("Makeppfile\\(?:\\.mk\\)?\\'" . makefile-makepp-mode) ; Put this before .mk + ("\\.makepp\\'" . makefile-makepp-mode) ,@(if (memq system-type '(berkeley-unix next-mach darwin)) '(("\\.mk\\'" . makefile-bsdmake-mode) ("GNUmakefile\\'" . makefile-gmake-mode) ("[Mm]akefile\\'" . makefile-bsdmake-mode)) '(("\\.mk\\'" . makefile-gmake-mode) ; Might be any make, give Gnu the host advantage ("[Mm]akefile\\'" . makefile-gmake-mode))) - ("Makeppfile\\'" . makefile-makepp-mode) ("\\.am\\'" . makefile-automake-mode) ;; Less common extensions come here ;; so more common ones above are found faster. @@ -1892,8 +1926,8 @@ in that case, this function acts as if `enable-local-variables' were t." ("\\.tar\\'" . tar-mode) ;; The list of archive file extensions should be in sync with ;; `auto-coding-alist' with `no-conversion' coding system. - ("\\.\\(arc\\|zip\\|lzh\\|zoo\\|[jew]ar\\|xpi\\)\\'" . archive-mode) - ("\\.\\(ARC\\|ZIP\\|LZH\\|ZOO\\|[JEW]AR\\|XPI\\)\\'" . archive-mode) + ("\\.\\(arc\\|zip\\|lzh\\|lha\\|zoo\\|[jew]ar\\|xpi\\)\\'" . archive-mode) + ("\\.\\(ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\)\\'" . archive-mode) ("\\.\\(sx[dmicw]\\|odt\\)\\'" . archive-mode) ; OpenOffice.org ;; Mailer puts message to be edited in ;; /tmp/Re.... or Message @@ -2349,31 +2383,14 @@ asking you for confirmation." ;; For variables defined in the C source code the declaration should go here: ;; FIXME: Some variables should be moved according to the rules above. -(let ((string-or-null (lambda (a) (or (stringp a) (null a))))) - (eval - `(mapc (lambda (pair) - (put (car pair) 'safe-local-variable (cdr pair))) - '((byte-compile-dynamic . t) - (byte-compile-dynamic-docstrings . t) - (byte-compile-warnings . t) - (c-basic-offset . integerp) - (c-file-style . stringp) - (c-indent-level . integerp) - (comment-column . integerp) - (compile-command . string-or-null-p) - (find-file-visit-truename . t) - (fill-column . integerp) - (fill-prefix . string-or-null-p) - (indent-tabs-mode . t) - (kept-old-versions . integerp) - (kept-new-versions . integerp) - (left-margin . t) - (no-byte-compile . t) - (no-update-autoloads . t) - (outline-regexp . string-or-null-p) - (tab-width . integerp) ;; C source code - (truncate-lines . t) ;; C source code - (version-control . t))))) +(mapc (lambda (pair) + (put (car pair) 'safe-local-variable (cdr pair))) + '((fill-column . integerp) ;; C source code + (indent-tabs-mode . booleanp) ;; C source code + (left-margin . integerp) ;; C source code + (no-update-autoloads . booleanp) + (tab-width . integerp) ;; C source code + (truncate-lines . booleanp))) ;; C source code (put 'c-set-style 'safe-local-eval-function t) @@ -2417,7 +2434,9 @@ n -- to ignore the local variables list.") (insert " "))) (princ (car elt) buf) (insert " : ") - (princ (cdr elt) buf) + ;; Make strings with embedded whitespace easier to read. + (let ((print-escape-newlines t)) + (prin1 (cdr elt) buf)) (insert "\n")) (setq prompt (format "Please type %s%s: " @@ -2488,9 +2507,7 @@ and VAL is the specified value." ;; There used to be a downcase here, ;; but the manual didn't say so, ;; and people want to set var names that aren't all lc. - (let ((key (intern (buffer-substring - (match-beginning 1) - (match-end 1)))) + (let ((key (intern (match-string 1))) (val (save-restriction (narrow-to-region (point) end) (read (current-buffer))))) @@ -2642,8 +2659,8 @@ is specified, returning t if it is specified." (hack-local-variables-confirm result unsafe-vars risky-vars)) (dolist (elt result) - (hack-one-local-variable (car elt) (cdr elt)))))) - (run-hooks 'hack-local-variables-hook)))))) + (hack-one-local-variable (car elt) (cdr elt))))))) + (run-hooks 'hack-local-variables-hook))))) (defun safe-local-variable-p (sym val) "Non-nil if SYM is safe as a file-local variable with value VAL. @@ -2652,15 +2669,11 @@ It is safe if any of these conditions are met: * There is a matching entry (SYM . VAL) in the `safe-local-variable-values' user option. - * The `safe-local-variable' property of SYM is t. - * The `safe-local-variable' property of SYM is a function that evaluates to a non-nil value with VAL as an argument." (or (member (cons sym val) safe-local-variable-values) (let ((safep (get sym 'safe-local-variable))) - (or (eq safep t) - (and (functionp safep) - (funcall safep val)))))) + (and (functionp safep) (funcall safep val))))) (defun risky-local-variable-p (sym &optional ignored) "Non-nil if SYM could be dangerous as a file-local variable. @@ -2705,7 +2718,10 @@ It is dangerous if either of these conditions are met: (or (numberp val) (equal val ''defun))) ((eq prop 'edebug-form-spec) ;; Only allow indirect form specs. - (edebug-basic-spec val))))) + ;; During bootstrapping, edebug-basic-spec might not be + ;; defined yet. + (and (fboundp 'edebug-basic-spec) + (edebug-basic-spec val)))))) ;; Allow expressions that the user requested. (member exp safe-local-eval-forms) ;; Certain functions can be allowed with safe arguments @@ -2730,17 +2746,16 @@ It is dangerous if either of these conditions are met: (defun hack-one-local-variable (var val) "Set local variable VAR with value VAL." (cond ((eq var 'mode) - (funcall (intern (concat (downcase (symbol-name val)) - "-mode")))) + (funcall (intern (concat (downcase (symbol-name val)) "-mode")))) ((eq var 'eval) (save-excursion (eval val))) - (t (make-local-variable var) - ;; Make sure the string has no text properties. - ;; Some text properties can get evaluated in various ways, - ;; so it is risky to put them on with a local variable list. - (if (stringp val) - (set-text-properties 0 (length val) nil val)) - (set var val)))) + (t + ;; Make sure the string has no text properties. + ;; Some text properties can get evaluated in various ways, + ;; so it is risky to put them on with a local variable list. + (if (stringp val) + (set-text-properties 0 (length val) nil val)) + (set (make-local-variable var) val)))) (defcustom change-major-mode-with-file-name t @@ -3010,7 +3025,7 @@ BACKUPNAME is the backup file name, which is the old file renamed." (condition-case nil (delete-file to-name) (file-error nil)) - (copy-file from-name to-name t t 'excl) + (copy-file from-name to-name nil t) nil) (file-already-exists t)) ;; The file was somehow created by someone else between @@ -3078,6 +3093,7 @@ except that a leading `.', if any, doesn't count." (defun file-name-extension (filename &optional period) "Return FILENAME's final \"extension\". The extension, in a file name, is the part that follows the last `.', +excluding version numbers and backup suffixes, except that a leading `.', if any, doesn't count. Return nil for extensionless file names such as `foo'. Return the empty string for file names such as `foo.'. @@ -3637,8 +3653,10 @@ Before and after saving the buffer, this function runs (set-visited-file-modtime old-modtime))) ;; Since we have created an entirely new file, ;; make sure it gets the right permission bits set. - (setq setmodes (or setmodes (cons (file-modes buffer-file-name) - buffer-file-name))) + (setq setmodes (or setmodes + (cons (or (file-modes buffer-file-name) + (logand ?\666 umask)) + buffer-file-name))) ;; We succeeded in writing the temp file, ;; so rename it. (rename-file tempname buffer-file-name t)) @@ -3935,7 +3953,7 @@ user. In such situations, one has to be careful with potentially time consuming operations. For more information on how this variable is used by Auto Revert mode, -see Info node `(emacs-xtra)Supporting additional buffers'.") +see Info node `(emacs)Supporting additional buffers'.") (defvar before-revert-hook nil "Normal hook for `revert-buffer' to run before reverting. @@ -4120,7 +4138,7 @@ non-nil, it is called instead of rereading visited file contents." (let ((inhibit-read-only t) ;; Keep the current buffer-file-coding-system. (coding-system buffer-file-coding-system) - ;; Auto-saved file shoule be read with special coding. + ;; Auto-saved file should be read with special coding. (coding-system-for-read 'auto-save-coding)) (erase-buffer) (insert-file-contents file-name nil) @@ -4195,9 +4213,7 @@ This command is used in the special Dired buffer created by (setq autofile (buffer-substring-no-properties (point) - (save-excursion - (end-of-line) - (point)))) + (line-end-position))) (setq thisfile (expand-file-name (substring