aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2018-10-26 13:04:31 -0400
committerStefan Monnier2018-10-26 13:04:31 -0400
commitf172ceda8aa5011c1ab79d812f2374a1dbe7a3ef (patch)
treeb1c6523f60c194c937e6c17c5aef169ea29ab4fc
parentd404bb5beeec6ccfef583dbb9c43e3d043df31cf (diff)
downloademacs-f172ceda8aa5011c1ab79d812f2374a1dbe7a3ef.tar.gz
emacs-f172ceda8aa5011c1ab79d812f2374a1dbe7a3ef.zip
* lisp/files.el (abbreviate-file-name): Avoid save-match-data
Also, don't assume homedir doesn't contain special regexp chars. And prefer \` ... \' over ^ ... $. (recover-file): Use user-error.
-rw-r--r--lisp/files.el63
1 files changed, 33 insertions, 30 deletions
diff --git a/lisp/files.el b/lisp/files.el
index b8f6c461467..ad032832ec5 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1918,12 +1918,13 @@ started Emacs, set `abbreviated-home-dir' to nil so it will be recalculated)."
1918 (unless abbreviated-home-dir 1918 (unless abbreviated-home-dir
1919 (put 'abbreviated-home-dir 'home (expand-file-name "~")) 1919 (put 'abbreviated-home-dir 'home (expand-file-name "~"))
1920 (setq abbreviated-home-dir 1920 (setq abbreviated-home-dir
1921 (let ((abbreviated-home-dir "$foo")) 1921 (let* ((abbreviated-home-dir "\\`\\'.") ;Impossible regexp.
1922 (setq abbreviated-home-dir 1922 (regexp
1923 (concat "\\`" 1923 (concat "\\`"
1924 (abbreviate-file-name 1924 (regexp-quote
1925 (get 'abbreviated-home-dir 'home)) 1925 (abbreviate-file-name
1926 "\\(/\\|\\'\\)")) 1926 (get 'abbreviated-home-dir 'home)))
1927 "\\(/\\|\\'\\)")))
1927 ;; Depending on whether default-directory does or 1928 ;; Depending on whether default-directory does or
1928 ;; doesn't include non-ASCII characters, the value 1929 ;; doesn't include non-ASCII characters, the value
1929 ;; of abbreviated-home-dir could be multibyte or 1930 ;; of abbreviated-home-dir could be multibyte or
@@ -1931,9 +1932,9 @@ started Emacs, set `abbreviated-home-dir' to nil so it will be recalculated)."
1931 ;; it. Note that this function is called for the 1932 ;; it. Note that this function is called for the
1932 ;; first time (from startup.el) when 1933 ;; first time (from startup.el) when
1933 ;; locale-coding-system is already set up. 1934 ;; locale-coding-system is already set up.
1934 (if (multibyte-string-p abbreviated-home-dir) 1935 (if (multibyte-string-p regexp)
1935 abbreviated-home-dir 1936 regexp
1936 (decode-coding-string abbreviated-home-dir 1937 (decode-coding-string regexp
1937 (if (eq system-type 'windows-nt) 1938 (if (eq system-type 'windows-nt)
1938 'utf-8 1939 'utf-8
1939 locale-coding-system)))))) 1940 locale-coding-system))))))
@@ -1946,22 +1947,22 @@ started Emacs, set `abbreviated-home-dir' to nil so it will be recalculated)."
1946 ;; is likely temporary (eg for testing). 1947 ;; is likely temporary (eg for testing).
1947 ;; FIXME Is it even worth caching abbreviated-home-dir? 1948 ;; FIXME Is it even worth caching abbreviated-home-dir?
1948 ;; Ref: https://debbugs.gnu.org/19657#20 1949 ;; Ref: https://debbugs.gnu.org/19657#20
1949 (if (and (string-match abbreviated-home-dir filename) 1950 (let (mb1)
1950 ;; If the home dir is just /, don't change it. 1951 (if (and (string-match abbreviated-home-dir filename)
1951 (not (and (= (match-end 0) 1) 1952 (setq mb1 (match-beginning 1))
1952 (= (aref filename 0) ?/))) 1953 ;; If the home dir is just /, don't change it.
1953 ;; MS-DOS root directories can come with a drive letter; 1954 (not (and (= (match-end 0) 1)
1954 ;; Novell Netware allows drive letters beyond `Z:'. 1955 (= (aref filename 0) ?/)))
1955 (not (and (memq system-type '(ms-dos windows-nt cygwin)) 1956 ;; MS-DOS root directories can come with a drive letter;
1956 (save-match-data 1957 ;; Novell Netware allows drive letters beyond `Z:'.
1957 (string-match "^[a-zA-`]:/$" filename)))) 1958 (not (and (memq system-type '(ms-dos windows-nt cygwin))
1958 (equal (get 'abbreviated-home-dir 'home) 1959 (string-match "\\`[a-zA-`]:/\\'" filename)))
1959 (save-match-data (expand-file-name "~")))) 1960 (equal (get 'abbreviated-home-dir 'home)
1960 (setq filename 1961 (expand-file-name "~")))
1961 (concat "~" 1962 (setq filename
1962 (match-string 1 filename) 1963 (concat "~"
1963 (substring filename (match-end 0))))) 1964 (substring filename mb1))))
1964 filename))) 1965 filename))))
1965 1966
1966(defun find-buffer-visiting (filename &optional predicate) 1967(defun find-buffer-visiting (filename &optional predicate)
1967 "Return the buffer visiting file FILENAME (a string). 1968 "Return the buffer visiting file FILENAME (a string).
@@ -2323,9 +2324,9 @@ Do you want to revisit the file normally now? ")
2323 ;; If they fail too, set error. 2324 ;; If they fail too, set error.
2324 (setq error t))))) 2325 (setq error t)))))
2325 ;; Record the file's truename, and maybe use that as visited name. 2326 ;; Record the file's truename, and maybe use that as visited name.
2326 (if (equal filename buffer-file-name) 2327 (setq buffer-file-truename
2327 (setq buffer-file-truename truename) 2328 (if (equal filename buffer-file-name)
2328 (setq buffer-file-truename 2329 truename
2329 (abbreviate-file-name (file-truename buffer-file-name)))) 2330 (abbreviate-file-name (file-truename buffer-file-name))))
2330 (setq buffer-file-number number) 2331 (setq buffer-file-number number)
2331 (if find-file-visit-truename 2332 (if find-file-visit-truename
@@ -4010,6 +4011,8 @@ those in the first."
4010 (dolist (f (list file-2 file-1)) 4011 (dolist (f (list file-2 file-1))
4011 (when (and f 4012 (when (and f
4012 (file-readable-p f) 4013 (file-readable-p f)
4014 ;; FIXME: Aren't file-regular-p and
4015 ;; file-directory-p mutually exclusive?
4013 (file-regular-p f) 4016 (file-regular-p f)
4014 (not (file-directory-p f))) 4017 (not (file-directory-p f)))
4015 (push f out))) 4018 (push f out)))
@@ -6014,7 +6017,7 @@ an auto-save file."
6014 (interactive "FRecover file: ") 6017 (interactive "FRecover file: ")
6015 (setq file (expand-file-name file)) 6018 (setq file (expand-file-name file))
6016 (if (auto-save-file-name-p (file-name-nondirectory file)) 6019 (if (auto-save-file-name-p (file-name-nondirectory file))
6017 (error "%s is an auto-save file" (abbreviate-file-name file))) 6020 (user-error "%s is an auto-save file" (abbreviate-file-name file)))
6018 (let ((file-name (let ((buffer-file-name file)) 6021 (let ((file-name (let ((buffer-file-name file))
6019 (make-auto-save-file-name)))) 6022 (make-auto-save-file-name))))
6020 (cond ((and (file-exists-p file) 6023 (cond ((and (file-exists-p file)
@@ -6024,8 +6027,8 @@ an auto-save file."
6024 ((if (file-exists-p file) 6027 ((if (file-exists-p file)
6025 (not (file-newer-than-file-p file-name file)) 6028 (not (file-newer-than-file-p file-name file))
6026 (not (file-exists-p file-name))) 6029 (not (file-exists-p file-name)))
6027 (error "Auto-save file %s not current" 6030 (user-error "Auto-save file %s not current"
6028 (abbreviate-file-name file-name))) 6031 (abbreviate-file-name file-name)))
6029 ((with-temp-buffer-window 6032 ((with-temp-buffer-window
6030 "*Directory*" nil 6033 "*Directory*" nil
6031 #'(lambda (window _value) 6034 #'(lambda (window _value)