X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/da09b92be71b760539882e97894a858606662954..cd30a521aa838f6bcf08ee6ffb62986cd2bf8daa:/lisp/files.el diff --git a/lisp/files.el b/lisp/files.el index 26f39169f8..7e3a01c1d6 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -172,13 +172,14 @@ If the buffer is visiting a new file, the value is nil.") (defvar file-name-invalid-regexp (cond ((and (eq system-type 'ms-dos) (not (msdos-long-file-names))) - (concat "\\(^\\([A-z]:\\)?/?.*:\\)\\|" ; colon except after drive + (concat "^\\([^A-Z[-`a-z]\\|..+\\)?:\\|" ; colon except after drive "[+, ;=|<>\"?*]\\|\\[\\|\\]\\|" ; invalid characters + "[\000-\031]\\|" ; control characters "\\(/\\.\\.?[^/]\\)\\|" ; leading dots "\\(/[^/.]+\\.[^/.]*\\.\\)")) ; more than a single dot ((memq system-type '(ms-dos windows-nt)) - (concat "\\(^\\([A-z]:\\)?/?.*:\\)\\|" ; colon except after drive - "[|<>\"?*]")) ; invalid characters + (concat "^\\([^A-Z[-`a-z]\\|..+\\)?:\\|" ; colon except after drive + "[|<>\"?*\000-\031]")) ; invalid characters (t "[\000]")) "Regexp recognizing file names which aren't allowed by the filesystem.") @@ -202,7 +203,9 @@ breaks any hard links between it and other files." t means make numeric backup versions unconditionally. nil means make them for files that have some already. `never' means do not make them." - :type 'boolean + :type '(choice (const :tag "Never" never) + (const :tag "If existing" nil) + (other :tag "Always" t)) :group 'backup :group 'vc) @@ -217,7 +220,7 @@ nil means make them for files that have some already. If nil, ask confirmation. Any other value prevents any trimming." :type '(choice (const :tag "Delete" t) (const :tag "Ask" nil) - (sexp :tag "Leave" :format "%t\n" other)) + (other :tag "Leave" other)) :group 'backup) (defcustom kept-old-versions 2 @@ -237,7 +240,7 @@ Non-nil but not t says ask user whether to add a newline when there isn't one. nil means don't add newlines." :type '(choice (const :tag "Off" nil) (const :tag "Add" t) - (sexp :tag "Ask" :format "%t\n" ask)) + (other :tag "Ask" ask)) :group 'editing-basics) (defcustom auto-save-default t @@ -328,7 +331,7 @@ The command \\[normal-mode] always obeys file local variable specifications and ignores this variable." :type '(choice (const :tag "Obey" t) (const :tag "Ignore" nil) - (sexp :tag "Query" :format "%t\n" other)) + (other :tag "Query" other)) :group 'find-file) (defvar local-enable-local-variables t @@ -346,7 +349,7 @@ The command \\[normal-mode] always obeys local-variables lists and ignores this variable." :type '(choice (const :tag "Obey" t) (const :tag "Ignore" nil) - (sexp :tag "Query" :format "%t\n" other)) + (other :tag "Query" other)) :group 'find-file) ;; Avoid losing in versions where CLASH_DETECTION is disabled. @@ -889,6 +892,7 @@ Optional second arg RAWFILE non-nil means the file is read literally." (if (or find-file-existing-other-name find-file-visit-truename) (setq buf other)))) (if buf + ;; We are using an existing buffer. (progn (or nowarn (verify-visited-file-modtime buf) @@ -947,19 +951,24 @@ Optional second arg RAWFILE non-nil means the file is read literally." (find-file-noselect-1 buf filename nowarn rawfile truename number) (error (if rawfile "File already visited non-literally" - "File already visited literally"))))))) - (progn - (setq buf (create-file-buffer filename)) - (set-buffer-major-mode buf) - (find-file-noselect-1 buf filename nowarn rawfile truename number))) - buf))) + "File already visited literally")))))) + ;; Return the buffer we are using. + buf) + ;; Create a new buffer. + (setq buf (create-file-buffer filename)) + (set-buffer-major-mode buf) + ;; find-file-noselect-1 may use a different buffer. + (find-file-noselect-1 buf filename nowarn + rawfile truename number))))) (defun find-file-noselect-1 (buf filename nowarn rawfile truename number) (let ((inhibit-read-only t) error) (with-current-buffer buf (kill-local-variable 'find-file-literally) - (setq buffer-file-coding-system nil) + ;; Needed in case we are re-visiting the file with a different + ;; text representation. + (kill-local-variable 'buffer-file-coding-system) (erase-buffer) (and (default-value 'enable-multibyte-characters) (not rawfile) @@ -1017,8 +1026,8 @@ Optional second arg RAWFILE non-nil means the file is read literally." (setq buffer-file-coding-system 'no-conversion) (make-local-variable 'find-file-literally) (setq find-file-literally t)) - (after-find-file error (not nowarn)) - (setq buf (current-buffer)))))) + (after-find-file error (not nowarn))) + (current-buffer)))) (defun insert-file-contents-literally (filename &optional visit beg end replace) "Like `insert-file-contents', but only reads in the file literally. @@ -1169,10 +1178,6 @@ run `normal-mode' explicitly." ("\\.tex\\'" . tex-mode) ("\\.ltx\\'" . latex-mode) ("\\.el\\'" . emacs-lisp-mode) - ("\\.mm\\'" . nroff-mode) - ("\\.me\\'" . nroff-mode) - ("\\.ms\\'" . nroff-mode) - ("\\.man\\'" . nroff-mode) ("\\.scm\\'" . scheme-mode) ("\\.l\\'" . lisp-mode) ("\\.lisp\\'" . lisp-mode) @@ -1197,7 +1202,7 @@ run `normal-mode' explicitly." ("\\.m\\'" . objc-mode) ("\\.java\\'" . java-mode) ("\\.mk\\'" . makefile-mode) - ("\\(M\\|m\\|GNUm\\)akefile\\(.in\\)?\\'" . makefile-mode) + ("\\(M\\|m\\|GNUm\\)akefile\\(\\.in\\)?\\'" . makefile-mode) ("\\.am\\'" . makefile-mode) ;For Automake. ;;; Less common extensions come here ;;; so more common ones above are found faster. @@ -1207,18 +1212,22 @@ run `normal-mode' explicitly." ("\\.S\\'" . asm-mode) ("\\.asm\\'" . asm-mode) ("ChangeLog\\'" . change-log-mode) - ("change.log\\'" . change-log-mode) + ("change\\.log\\'" . change-log-mode) ("changelo\\'" . change-log-mode) - ("ChangeLog.[0-9]+\\'" . change-log-mode) + ("ChangeLog\\.[0-9]+\\'" . change-log-mode) ;; for MSDOS and MS-Windows (which are case-insensitive) ("changelog\\'" . change-log-mode) - ("changelog.[0-9]+\\'" . change-log-mode) + ("changelog\\.[0-9]+\\'" . change-log-mode) ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode) ("\\.scm\\.[0-9]*\\'" . scheme-mode) ("\\.[ck]?sh\\'\\|\\.shar\\'\\|/\\.z?profile\\'" . sh-mode) - ("/\\.\\(bash_profile\\|z?login\\|bash_login\\|z?logout\\)\\'" . sh-mode) - ("/\\.\\(bash_logout\\|[kz]shrc\\|bashrc\\|t?cshrc\\|esrc\\)\\'" . sh-mode) - ("/\\.\\([kz]shenv\\|xinitrc\\|startxrc\\|xsession\\)\\'" . sh-mode) + ("\\(/\\|\\`\\)\\.\\(bash_profile\\|z?login\\|bash_login\\|z?logout\\)\\'" . sh-mode) + ("\\(/\\|\\`\\)\\.\\(bash_logout\\|[kz]shrc\\|bashrc\\|t?cshrc\\|esrc\\)\\'" . sh-mode) + ("\\(/\\|\\`\\)\\.\\([kz]shenv\\|xinitrc\\|startxrc\\|xsession\\)\\'" . sh-mode) + ("\\.mm\\'" . nroff-mode) + ("\\.me\\'" . nroff-mode) + ("\\.ms\\'" . nroff-mode) + ("\\.man\\'" . nroff-mode) ;;; The following should come after the ChangeLog pattern ;;; for the sake of ChangeLog.1, etc. ;;; and after the .scm.[0-9] pattern too. @@ -1262,15 +1271,24 @@ run `normal-mode' explicitly." ("\\.lex\\'" . c-mode) ("\\.oak\\'" . scheme-mode) ("\\.sgml?\\'" . sgml-mode) + ("\\.xml\\'" . sgml-mode) ("\\.dtd\\'" . sgml-mode) ("\\.ds\\(ss\\)?l\\'" . dsssl-mode) + ("\\.idl\\'" . idl-mode) ;; .emacs following a directory delimiter ;; in Unix, MSDOG or VMS syntax. ("[]>:/\\]\\..*emacs\\'" . emacs-lisp-mode) + ("\\`\\..*emacs\\'" . emacs-lisp-mode) ;; _emacs following a directory delimiter ;; in MsDos syntax ("[:/]_emacs\\'" . emacs-lisp-mode) - ("\\.ml\\'" . lisp-mode)) + ("\\.ml\\'" . lisp-mode) + ("\\.asn$" . snmp-mode) + ("\\.mib$" . snmp-mode) + ("\\.smi$" . snmp-mode) + ("\\.as2$" . snmpv2-mode) + ("\\.mi2$" . snmpv2-mode) + ("\\.sm2$" . snmpv2-mode)) "\ Alist of filename patterns vs corresponding major mode functions. Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL). @@ -2173,7 +2191,9 @@ We don't want excessive versions piling up, so there are variables Defaults are 2 old versions and 2 new. `dired-kept-versions' controls dired's clean-directory (.) command. If `delete-old-versions' is nil, system will query user - before trimming versions. Otherwise it does it silently." + before trimming versions. Otherwise it does it silently. + +See the subroutine `basic-save-buffer' for more information." (interactive "p") (let ((modp (buffer-modified-p)) (large (> (buffer-size) 50000)) @@ -2208,9 +2228,15 @@ Calling `write-region' for any purpose other than saving the buffer will still use `buffer-file-coding-system'; this variable has no effect in such cases.") +(make-variable-buffer-local 'save-buffer-coding-system) +(put 'save-buffer-coding-system 'permanent-local t) + (defun basic-save-buffer () "Save the current buffer in its visited file, if it has been modified. -After saving the buffer, run `after-save-hook'." +The hooks `write-contents-hooks', `local-write-file-hooks' and +`write-file-hooks' 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'." (interactive) (save-current-buffer ;; In an indirect buffer, save its base buffer instead. @@ -2294,10 +2320,13 @@ After saving the buffer, run `after-save-hook'." ;; but inhibited if one of write-file-hooks returns non-nil. ;; It returns a value to store in setmodes. (defun basic-save-buffer-1 () - (let ((buffer-file-coding-system - (or save-buffer-coding-system - buffer-file-coding-system)) - tempsetmodes setmodes) + (if save-buffer-coding-system + (let ((coding-system-for-write save-buffer-coding-system)) + (basic-save-buffer-2)) + (basic-save-buffer-2))) + +(defun basic-save-buffer-2 () + (let (tempsetmodes setmodes) (if (not (file-writable-p buffer-file-name)) (let ((dir (file-name-directory buffer-file-name))) (if (not (file-directory-p dir)) @@ -2724,10 +2753,12 @@ Then you'll be asked about a number of files to recover." (goto-char (point-min)) (or (looking-at "Move to the session you want to recover,") (let ((inhibit-read-only t)) - (insert "Move to the session you want to recover,\n" - "then type C-c C-c to select it.\n\n" - "You can also delete some of these files;\n" - "type d on a line to mark that file for deletion.\n\n"))) + ;; Each line starts with a space + ;; so that Font Lock mode won't highlight the first character. + (insert " Move to the session you want to recover,\n" + " then type C-c C-c to select it.\n\n" + " You can also delete some of these files;\n" + " type d on a line to mark that file for deletion.\n\n"))) (use-local-map (nconc (make-sparse-keymap) (current-local-map))) (define-key (current-local-map) "\C-c\C-c" 'recover-session-finish))