X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lisp%2Ffiles.el;h=8116b071106d1e1b54e1c5c9c942b06d60080f70;hb=44ea030ec31ae441e59974eb9f6b2a9404611cd8;hp=8aee89c67c5d22403d28bd69fc6279c07e81dbc1;hpb=efdb31fd4c8db81d2414c32d491f1bf994263c74;p=chise%2Fxemacs-chise.git.1 diff --git a/lisp/files.el b/lisp/files.el index 8aee89c..186043f 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -291,11 +291,11 @@ changing the major mode does not clear it. However, calling (defvar after-set-visited-file-name-hooks nil "List of functions to be called after \\[set-visited-file-name] or during \\[write-file]. -You can use this hook to restore local values of `write-file-hooks', -`after-save-hook', and `revert-buffer-function', which pertain +You can use this hook to restore local values of write-file-hooks, +after-save-hook, and revert-buffer-function, which pertain to a specific file and therefore are normally killed by a rename. -Put hooks pertaining to the buffer contents on `write-contents-hooks' -and `revert-buffer-insert-file-contents-function'.") +Put hooks pertaining to the buffer contents on write-contents-hooks +and revert-buffer-insert-file-contents-function.") (defvar write-contents-hooks nil "List of functions to be called before writing out a buffer to a file. @@ -371,22 +371,11 @@ and ignores this variable." ; (apply op args)) (defun convert-standard-filename (filename) - "Convert a standard file's name to something suitable for the current OS." - (if (eq system-type 'windows-nt) - (let ((name (copy-sequence filename)) - (start 0)) - ;; leave ':' if part of drive specifier - (if (eq (aref name 1) ?:) - (setq start 2)) - ;; destructively replace invalid filename characters with ! - (while (string-match "[?*:<>|\"\000-\037]" name start) - (aset name (match-beginning 0) ?!) - (setq start (match-end 0))) - ;; FSF: [convert directory separators to Windows format ...] - ;; unneeded in XEmacs. - name) - filename)) - + "Convert a standard file's name to something suitable for the current OS. +This function's standard definition is trivial; it just returns the argument. +However, on some systems, the function is redefined +with a definition that really does change some file names." + filename) (defun pwd () "Show the current default directory." @@ -805,36 +794,29 @@ If optional argument HACK-HOMEDIR is non-nil, then this also substitutes (setq tail (cdr tail)))) (when hack-homedir ;; Compute and save the abbreviated homedir name. - ;; We defer computing this until the first time it's needed, - ;; to give time for directory-abbrev-alist to be set properly. - ;; We include the separator at the end, to avoid spurious - ;; matches such as `/usr/foobar' when the home dir is - ;; `/usr/foo'. + ;; We defer computing this until the first time it's needed, to + ;; give time for directory-abbrev-alist to be set properly. + ;; We include a slash at the end, to avoid spurious matches + ;; such as `/usr/foobar' when the home dir is `/usr/foo'. (or abbreviated-home-dir (setq abbreviated-home-dir (let ((abbreviated-home-dir "$foo")) - (concat "\\`" - (regexp-quote - (abbreviate-file-name (expand-file-name "~"))) - "\\(" - (regexp-quote (string directory-sep-char)) - "\\|\\'\\)")))) + (concat "\\`" (regexp-quote (abbreviate-file-name + (expand-file-name "~"))) + "\\(/\\|\\'\\)")))) ;; If FILENAME starts with the abbreviated homedir, ;; make it start with `~' instead. (if (and (string-match abbreviated-home-dir filename) ;; If the home dir is just /, don't change it. - (not (and (= (match-end 0) 1) - (= (aref filename 0) directory-sep-char))) - (not (and (eq system-type 'windows-nt) + (not (and (= (match-end 0) 1) ;#### unix-specific + (= (aref filename 0) ?/))) + (not (and (memq system-type '(ms-dos windows-nt)) (save-match-data - (string-match (concat "\\`[a-zA-Z]:" - (regexp-quote - (string directory-sep-char)) - "\\'") - filename))))) + (string-match "^[a-zA-Z]:/$" filename))))) (setq filename (concat "~" - (match-string 1 filename) + (substring filename + (match-beginning 1) (match-end 1)) (substring filename (match-end 0)))))) filename))) @@ -881,34 +863,26 @@ If there is no such live buffer, return nil." (setq list (cdr list)))) found)))) -(defun insert-file-contents-literally (filename &optional visit start end replace) +(defun insert-file-contents-literally (filename &optional visit beg end replace) "Like `insert-file-contents', q.v., but only reads in the file. A buffer may be modified in several ways after reading into the buffer due -to advanced Emacs features, such as format decoding, character code -conversion, find-file-hooks, automatic uncompression, etc. - +to advanced Emacs features, such as file-name-handlers, format decoding, +find-file-hooks, etc. This function ensures that none of these modifications will take place." - (let ((wrap-func (find-file-name-handler filename - 'insert-file-contents-literally))) - (if wrap-func - (funcall wrap-func 'insert-file-contents-literally filename - visit start end replace) - (let ((file-name-handler-alist nil) - (format-alist nil) - (after-insert-file-functions nil) - (coding-system-for-read 'binary) - (coding-system-for-write 'binary) - (find-buffer-file-type-function - (if (fboundp 'find-buffer-file-type) - (symbol-function 'find-buffer-file-type) - nil))) - (unwind-protect - (progn - (fset 'find-buffer-file-type (lambda (filename) t)) - (insert-file-contents filename visit start end replace)) - (if find-buffer-file-type-function - (fset 'find-buffer-file-type find-buffer-file-type-function) - (fmakunbound 'find-buffer-file-type))))))) + (let ((file-name-handler-alist nil) + (format-alist nil) + (after-insert-file-functions nil) + (find-buffer-file-type-function + (if (fboundp 'find-buffer-file-type) + (symbol-function 'find-buffer-file-type) + nil))) + (unwind-protect + (progn + (fset 'find-buffer-file-type (lambda (filename) t)) + (insert-file-contents filename visit beg end replace)) + (if find-buffer-file-type-function + (fset 'find-buffer-file-type find-buffer-file-type-function) + (fmakunbound 'find-buffer-file-type))))) (defun find-file-noselect (filename &optional nowarn rawfile) "Read file FILENAME into a buffer and return the buffer. @@ -1047,8 +1021,7 @@ If RAWFILE is non-nil, the file is read literally." (setq buf (current-buffer)))) (t (kill-buffer buf) - (signal (car data) (cdr data)))) - )) + (signal (car data) (cdr data)))))) buf))) ;; FSF has `insert-file-literally' and `find-file-literally' here. @@ -1184,12 +1157,10 @@ run `normal-mode' explicitly." ("\\.m\\(?:[mes]\\|an\\)\\'" . nroff-mode) ("\\.icn\\'" . icon-mode) ("\\.\\(?:[ckz]?sh\\|shar\\)\\'" . sh-mode) - ("\\.[Pp][Rr][Oo]\\'" . idlwave-mode) ;; #### Unix-specific! ("/\\.\\(?:bash_\\|z\\)?\\(profile\\|login\\|logout\\)\\'" . sh-mode) ("/\\.\\(?:[ckz]sh\\|bash\\|tcsh\\|es\\|xinit\\|startx\\)rc\\'" . sh-mode) ("/\\.\\(?:[kz]shenv\\|xsession\\)\\'" . sh-mode) - ("\\.m?spec$" .sh-mode) ;; The following come after the ChangeLog pattern for the sake of ;; ChangeLog.1, etc. and after the .scm.[0-9] pattern too. ("\\.[12345678]\\'" . nroff-mode) @@ -1214,9 +1185,8 @@ run `normal-mode' explicitly." ("\\.lex\\'" . c-mode) ("\\.m\\'" . objc-mode) ("\\.oak\\'" . scheme-mode) - ("\\.[sj]?html?\\'" . html-mode) - ("\\.jsp\\'" . html-mode) - ("\\.xml\\'" . xml-mode) + ("\\.s?html?\\'" . html-mode) + ("\\.htm?l?3\\'" . html3-mode) ("\\.\\(?:sgml?\\|dtd\\)\\'" . sgml-mode) ("\\.c?ps\\'" . postscript-mode) ;; .emacs following a directory delimiter in either Unix or @@ -1225,7 +1195,7 @@ run `normal-mode' explicitly." ("\\.m4\\'" . autoconf-mode) ("configure\\.in\\'" . autoconf-mode) ("\\.ml\\'" . lisp-mode) - ("\\.ma?ke?\\'" . makefile-mode) + ("\\.ma?k\\'" . makefile-mode) ("[Mm]akefile\\(\\.\\|\\'\\)" . makefile-mode) ("\\.X\\(defaults\\|environment\\|resources\\|modmap\\)\\'" . xrdb-mode) ;; #### The following three are Unix-specific (but do we care?) @@ -1251,9 +1221,7 @@ REGEXP and search the list again for another match.") ("python" . python-mode) ("awk\\b" . awk-mode) ("rexx" . rexx-mode) - ("scm\\|guile" . scheme-mode) - ("emacs" . emacs-lisp-mode) - ("make" . makefile-mode) + ("scm" . scheme-mode) ("^:" . sh-mode)) "Alist mapping interpreter names to major modes. This alist is used to guess the major mode of a file based on the @@ -1270,7 +1238,8 @@ with the name of the interpreter specified in the first line. If it matches, mode MODE is selected.") (defvar binary-file-regexps - '("\\.\\(?:bz2\\|elc\\|g\\(if\\|z\\)\\|jp\\(eg\\|g\\)\\|png\\|t\\(ar\\|gz\\|iff\\)\\|[Zo]\\)\\'") + (purecopy + '("\\.\\(?:bz2\\|elc\\|g\\(if\\|z\\)\\|jp\\(eg\\|g\\)\\|png\\|t\\(ar\\|gz\\|iff\\)\\|[Zo]\\)\\'")) "List of regexps of filenames containing binary (non-text) data.") ; (eval-when-compile @@ -1290,9 +1259,9 @@ If it matches, mode MODE is selected.") ; "tiff" ; "jpg" ; "jpeg")))))) - + (defvar inhibit-first-line-modes-regexps - binary-file-regexps + (purecopy binary-file-regexps) "List of regexps; if one matches a file name, don't look for `-*-'.") (defvar inhibit-first-line-modes-suffixes nil @@ -1301,7 +1270,7 @@ When checking `inhibit-first-line-modes-regexps', we first discard from the end of the file name anything that matches one of these regexps.") (defvar user-init-file - nil ; set by command-line + "" ; set by command-line "File name including directory of user's initialization file.") (defun set-auto-mode (&optional just-from-file-name) @@ -1340,15 +1309,9 @@ and we don't even do that unless it would come from the file name." (setq keep-going nil) (let ((alist auto-mode-alist) (mode nil)) - ;; Find first matching alist entry. - - ;; #### This is incorrect. In NT, case sensitivity is a volume - ;; property. For instance, NFS mounts *are* case sensitive. - ;; Need internal function (file-name-case-sensitive f), F - ;; being file or directory name. - kkm (let ((case-fold-search - (eq system-type 'windows-nt))) + (memq system-type '(windows-nt)))) (while (and (not mode) alist) (if (string-match (car (car alist)) name) (if (and (consp (cdr (car alist))) @@ -1490,7 +1453,7 @@ for current buffer." (or force (hack-local-variables-p nil)))) (let ((continue t) - prefix prefixlen suffix start + prefix prefixlen suffix beg (enable-local-eval enable-local-eval)) ;; The prefix is what comes before "local variables:" in its line. ;; The suffix is what comes after "local variables:" in its line. @@ -1517,11 +1480,11 @@ for current buffer." (error "Local variables entry is missing the prefix"))) ;; Find the variable name; strip whitespace. (skip-chars-forward " \t") - (setq start (point)) + (setq beg (point)) (skip-chars-forward "^:\n") (if (eolp) (error "Missing colon in local variables entry")) (skip-chars-backward " \t") - (let* ((str (buffer-substring start (point))) + (let* ((str (buffer-substring beg (point))) (var (read str)) val) ;; Setting variable named "end" means end of list. @@ -1560,7 +1523,7 @@ for current buffer." (cond ((not (search-forward "-*-" end t)) ;; doesn't have one. (setq force t)) - ((looking-at "[ \t]*\\([^ \t\n\r:;]+?\\)\\([ \t]*-\\*-\\)") + ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)") ;; Antiquated form: "-*- ModeName -*-". (setq result (list (cons 'mode @@ -1852,7 +1815,7 @@ with a prefix argument, you will be prompted for the coding system." (buffer-local-variables))) nil nil (buffer-name))) t - (if (and current-prefix-arg (featurep 'file-coding)) + (if (and current-prefix-arg (featurep 'mule)) (read-coding-system "Coding system: ")))) (and (eq (current-buffer) mouse-grabbed-buffer) (error "Can't write minibuffer window")) @@ -1906,7 +1869,7 @@ of the new file to agree with the old modes." (let ((delete-old-versions ;; If have old versions to maybe delete, ;; ask the user to confirm now, before doing anything. - ;; But don't actually delete till later. + ;; But don't actually delete til later. (and targets (or (eq delete-old-versions t) (eq delete-old-versions nil)) @@ -1938,9 +1901,7 @@ of the new file to agree with the old modes." (setq setmodes (file-modes backupname))) (file-error ;; If trouble writing the backup, write it in ~. - (setq backupname - (expand-file-name - (convert-standard-filename "~/%backup%~"))) + (setq backupname (expand-file-name "~/%backup%~")) (message "Cannot write backup file; backing up in ~/%%backup%%~") (sleep-for 1) (condition-case () @@ -2026,14 +1987,21 @@ the value is \"\"." (defun make-backup-file-name (file) "Create the non-numeric backup file name for FILE. This is a separate function so you can redefine it for customization." - ;; FSF has code here for MS-DOS short filenames, not supported in XEmacs. - (concat file "~")) + (if (eq system-type 'ms-dos) + (let ((fn (file-name-nondirectory file))) + (concat (file-name-directory file) + (if (string-match "\\([^.]*\\)\\(\\..*\\)?" fn) + (substring fn 0 (match-end 1))) + ".bak")) + (concat file "~"))) (defun backup-file-name-p (file) "Return non-nil if FILE is a backup file name (numeric or not). This is a separate function so you can redefine it for customization. You may need to redefine `file-name-sans-versions' as well." - (string-match "~\\'" file)) + (if (eq system-type 'ms-dos) + (string-match "\\.bak\\'" file) + (string-match "~\\'" file))) ;; This is used in various files. ;; The usage of bv-length is not very clean, @@ -2054,7 +2022,6 @@ the index in the name where the version number begins." Value is a list whose car is the name for the backup file and whose cdr is a list of old versions to consider deleting now. If the value is nil, don't make a backup." - (declare (special bv-length)) (let ((handler (find-file-name-handler fn 'find-backup-file-name))) ;; Run a handler for this function so that ange-ftp can refuse to do it. (if handler @@ -2105,15 +2072,16 @@ If the value is nil, don't make a backup." "Convert FILENAME to be relative to DIRECTORY (default: default-directory). This function returns a relative file name which is equivalent to FILENAME when used with that default directory as the default. -If this is impossible (which can happen on MS Windows when the file name -and directory use different drive names) then it returns FILENAME." +If this is impossible (which can happen on MSDOS and Windows +when the file name and directory use different drive names) +then it returns FILENAME." (save-match-data (let ((fname (expand-file-name filename))) (setq directory (file-name-as-directory (expand-file-name (or directory default-directory)))) ;; On Microsoft OSes, if FILENAME and DIRECTORY have different ;; drive names, they can't be relative, so return the absolute name. - (if (and (eq system-type 'windows-nt) + (if (and (memq system-type '(ms-dos windows-nt)) (not (string-equal (substring fname 0 2) (substring directory 0 2)))) filename @@ -2243,22 +2211,20 @@ After saving the buffer, run `after-save-hook'." (error "Save not confirmed")) (save-restriction (widen) - - ;; Add final newline if required. See `require-final-newline'. - (when (and (not (eq (char-before (point-max)) ?\n)) ; common case - (char-before (point-max)) ; empty buffer? - (not (and (eq selective-display t) - (eq (char-before (point-max)) ?\r))) - (or (eq require-final-newline t) - (and require-final-newline - (y-or-n-p - (format "Buffer %s does not end in newline. Add one? " - (buffer-name)))))) - (save-excursion - (goto-char (point-max)) - (insert ?\n))) - - ;; Run the write-file-hooks until one returns non-nil. + (and (> (point-max) 1) + (/= (char-after (1- (point-max))) ?\n) + (not (and (eq selective-display t) + (= (char-after (1- (point-max))) ?\r))) + (or (eq require-final-newline t) + (and require-final-newline + (y-or-n-p + (format "Buffer %s does not end in newline. Add one? " + (buffer-name))))) + (save-excursion + (goto-char (point-max)) + (insert ?\n))) + ;; + ;; Run the write-file-hooks until one returns non-null. ;; Bind after-save-hook to nil while running the ;; write-file-hooks so that if this function is called ;; recursively (from inside a write-file-hook) the @@ -2374,9 +2340,9 @@ After saving the buffer, run `after-save-hook'." "Provide a clean way for a write-file-hook to wrap AROUND the execution of the remaining hooks and writing to disk. Do not call this function except from a functions -on the `write-file-hooks' or `write-contents-hooks' list. +on the write-file-hooks or write-contents-hooks list. A hook that calls this function must return non-nil, -to signal completion to its caller. `continue-save-buffer' +to signal completion to its caller. continue-save-buffer always returns non-nil." (let ((hooks (cdr (or continue-save-buffer-hooks-tail (error @@ -2483,7 +2449,7 @@ Optional second argument EXITING means ask about certain non-file buffers (recursive-edit) ;; Return nil to ask about BUF again. nil) - "%_Display Buffer")))) + "display the current buffer")))) (abbrevs-done (and save-abbrevs abbrevs-changed (progn @@ -2714,7 +2680,7 @@ non-nil, it is called instead of rereading visited file contents." file-name))) (run-hooks 'before-revert-hook) ;; If file was backed up but has changed since, - ;; we should make another backup. + ;; we shd make another backup. (and (not auto-save-p) (not (verify-visited-file-modtime (current-buffer))) (setq buffer-backed-up nil)) @@ -2776,7 +2742,7 @@ non-nil, it is called instead of rereading visited file contents." 'recover-file)))) (if handler (funcall handler 'recover-file file) - (if (auto-save-file-name-p (file-name-nondirectory file)) + (if (auto-save-file-name-p file) (error "%s is an auto-save file" file)) (let ((file-name (let ((buffer-file-name file)) (make-auto-save-file-name)))) @@ -2785,17 +2751,11 @@ non-nil, it is called instead of rereading visited file contents." (not (file-exists-p file-name))) (error "Auto-save file %s not current" file-name)) ((save-window-excursion - ;; XEmacs change: use insert-directory instead of - ;; calling ls directly. (with-output-to-temp-buffer "*Directory*" (buffer-disable-undo standard-output) - (save-excursion - (set-buffer "*Directory*") - (setq default-directory (file-name-directory file)) - (insert-directory file - (if (file-symlink-p file) "-lL" "-l")) - (setq default-directory (file-name-directory file-name)) - (insert-directory file-name "-l"))) + (call-process "ls" nil standard-output nil + (if (file-symlink-p file) "-lL" "-l") + file file-name)) (yes-or-no-p (format "Recover auto save file %s? " file-name))) (switch-to-buffer (find-file-noselect file t)) (let ((buffer-read-only nil)) @@ -2961,9 +2921,72 @@ Also rename any existing auto save file, if it was made in this session." (recent-auto-save-p)) (rename-file osave buffer-auto-save-file-name t)))) -;; make-auto-save-file-name and auto-save-file-name-p are now only in -;; auto-save.el. - +;; see also ../packages/auto-save.el +(defun make-auto-save-file-name (&optional filename) + "Return file name to use for auto-saves of current buffer. +Does not consider `auto-save-visited-file-name' as that variable is checked +before calling this function. You can redefine this for customization. +See also `auto-save-file-name-p'." + (let ((fname (or filename buffer-file-name)) + name) + (setq name + (if fname + (concat (file-name-directory fname) + "#" + (file-name-nondirectory fname) + "#") + + ;; Deal with buffers that don't have any associated files. (Mail + ;; mode tends to create a good number of these.) + + (let ((buffer-name (buffer-name)) + (limit 0)) + ;; Use technique from Sebastian Kremer's auto-save + ;; package to turn slashes into \\!. This ensures that + ;; the auto-save buffer name is unique. + + ;; #### - yuck! yuck! yuck! move this functionality + ;; somewhere else and make the name translation customizable. + ;; Using "\!" as part of a filename on a UNIX filesystem is nearly + ;; IMPOSSIBLE to get past a shell parser. -stig + + (while (string-match "[/\\]" buffer-name limit) + (setq buffer-name + (concat (substring buffer-name 0 (match-beginning 0)) + (if (string= (substring buffer-name + (match-beginning 0) + (match-end 0)) + "/") + "\\!" + "\\\\") + (substring buffer-name (match-end 0)))) + (setq limit (1+ (match-end 0)))) + + ;; (expand-file-name (format "#%s#%s#" (buffer-name) (make-temp-name ""))) + + ;; jwz: putting the emacs PID in the auto-save file name + ;; is bad news, because that defeats auto-save-recovery of + ;; *mail* buffers -- the (sensible) code in sendmail.el + ;; calls (make-auto-save-file-name) to determine whether + ;; there is unsent, auto-saved mail to recover. If that + ;; mail came from a previous emacs process (far and away + ;; the most likely case) then this can never succeed as + ;; the pid differs. + + (expand-file-name (format "#%s#" buffer-name))) + )) + ;; don't try to write auto-save files in unwritable places. Unless + ;; there's already an autosave file here, put ours somewhere safe. --Stig + (if (or (file-writable-p name) + (file-exists-p name)) + name + (expand-file-name (concat "~/" (file-name-nondirectory name)))))) + +(defun auto-save-file-name-p (filename) + "Return non-nil if FILENAME can be yielded by `make-auto-save-file-name'. +FILENAME should lack slashes. +You can redefine this for customization." + (string-match "\\`#.*#\\'" filename)) (defun wildcard-to-regexp (wildcard) "Given a shell file name pattern WILDCARD, return an equivalent regexp. @@ -3107,9 +3130,6 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'." (funcall handler 'insert-directory file switches wildcard full-directory-p) (cond - ;; [mswindows-insert-directory should be called - ;; nt-insert-directory - kkm]. not true any more according to - ;; my new naming scheme. --ben ((and (fboundp 'mswindows-insert-directory) (eq system-type 'windows-nt)) (mswindows-insert-directory file switches wildcard full-directory-p)) @@ -3121,19 +3141,19 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'." (file-name-directory file) (file-name-directory (expand-file-name file)))) (pattern (file-name-nondirectory file)) - (start 0)) + (beg 0)) ;; Quote some characters that have special meanings in shells; ;; but don't quote the wildcards--we want them to be special. ;; We also currently don't quote the quoting characters ;; in case people want to use them explicitly to quote ;; wildcard characters. ;;#### Unix-specific - (while (string-match "[ \t\n;<>&|()#$]" pattern start) + (while (string-match "[ \t\n;<>&|()#$]" pattern beg) (setq pattern (concat (substring pattern 0 (match-beginning 0)) "\\" (substring pattern (match-beginning 0))) - start (1+ (match-end 0)))) + beg (1+ (match-end 0)))) (call-process shell-file-name nil t nil "-c" (concat "\\" ;; Disregard shell aliases! insert-directory-program