mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-11 09:20:51 +00:00
* 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.
This commit is contained in:
parent
d404bb5bee
commit
f172ceda8a
@ -1918,12 +1918,13 @@ started Emacs, set `abbreviated-home-dir' to nil so it will be recalculated)."
|
||||
(unless abbreviated-home-dir
|
||||
(put 'abbreviated-home-dir 'home (expand-file-name "~"))
|
||||
(setq abbreviated-home-dir
|
||||
(let ((abbreviated-home-dir "$foo"))
|
||||
(setq abbreviated-home-dir
|
||||
(let* ((abbreviated-home-dir "\\`\\'.") ;Impossible regexp.
|
||||
(regexp
|
||||
(concat "\\`"
|
||||
(abbreviate-file-name
|
||||
(get 'abbreviated-home-dir 'home))
|
||||
"\\(/\\|\\'\\)"))
|
||||
(regexp-quote
|
||||
(abbreviate-file-name
|
||||
(get 'abbreviated-home-dir 'home)))
|
||||
"\\(/\\|\\'\\)")))
|
||||
;; Depending on whether default-directory does or
|
||||
;; doesn't include non-ASCII characters, the value
|
||||
;; 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)."
|
||||
;; it. Note that this function is called for the
|
||||
;; first time (from startup.el) when
|
||||
;; locale-coding-system is already set up.
|
||||
(if (multibyte-string-p abbreviated-home-dir)
|
||||
abbreviated-home-dir
|
||||
(decode-coding-string abbreviated-home-dir
|
||||
(if (multibyte-string-p regexp)
|
||||
regexp
|
||||
(decode-coding-string regexp
|
||||
(if (eq system-type 'windows-nt)
|
||||
'utf-8
|
||||
locale-coding-system))))))
|
||||
@ -1946,22 +1947,22 @@ started Emacs, set `abbreviated-home-dir' to nil so it will be recalculated)."
|
||||
;; is likely temporary (eg for testing).
|
||||
;; FIXME Is it even worth caching abbreviated-home-dir?
|
||||
;; Ref: https://debbugs.gnu.org/19657#20
|
||||
(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) ?/)))
|
||||
;; MS-DOS root directories can come with a drive letter;
|
||||
;; Novell Netware allows drive letters beyond `Z:'.
|
||||
(not (and (memq system-type '(ms-dos windows-nt cygwin))
|
||||
(save-match-data
|
||||
(string-match "^[a-zA-`]:/$" filename))))
|
||||
(equal (get 'abbreviated-home-dir 'home)
|
||||
(save-match-data (expand-file-name "~"))))
|
||||
(setq filename
|
||||
(concat "~"
|
||||
(match-string 1 filename)
|
||||
(substring filename (match-end 0)))))
|
||||
filename)))
|
||||
(let (mb1)
|
||||
(if (and (string-match abbreviated-home-dir filename)
|
||||
(setq mb1 (match-beginning 1))
|
||||
;; If the home dir is just /, don't change it.
|
||||
(not (and (= (match-end 0) 1)
|
||||
(= (aref filename 0) ?/)))
|
||||
;; MS-DOS root directories can come with a drive letter;
|
||||
;; Novell Netware allows drive letters beyond `Z:'.
|
||||
(not (and (memq system-type '(ms-dos windows-nt cygwin))
|
||||
(string-match "\\`[a-zA-`]:/\\'" filename)))
|
||||
(equal (get 'abbreviated-home-dir 'home)
|
||||
(expand-file-name "~")))
|
||||
(setq filename
|
||||
(concat "~"
|
||||
(substring filename mb1))))
|
||||
filename))))
|
||||
|
||||
(defun find-buffer-visiting (filename &optional predicate)
|
||||
"Return the buffer visiting file FILENAME (a string).
|
||||
@ -2323,9 +2324,9 @@ Do you want to revisit the file normally now? ")
|
||||
;; If they fail too, set error.
|
||||
(setq error t)))))
|
||||
;; Record the file's truename, and maybe use that as visited name.
|
||||
(if (equal filename buffer-file-name)
|
||||
(setq buffer-file-truename truename)
|
||||
(setq buffer-file-truename
|
||||
(setq buffer-file-truename
|
||||
(if (equal filename buffer-file-name)
|
||||
truename
|
||||
(abbreviate-file-name (file-truename buffer-file-name))))
|
||||
(setq buffer-file-number number)
|
||||
(if find-file-visit-truename
|
||||
@ -4010,6 +4011,8 @@ those in the first."
|
||||
(dolist (f (list file-2 file-1))
|
||||
(when (and f
|
||||
(file-readable-p f)
|
||||
;; FIXME: Aren't file-regular-p and
|
||||
;; file-directory-p mutually exclusive?
|
||||
(file-regular-p f)
|
||||
(not (file-directory-p f)))
|
||||
(push f out)))
|
||||
@ -6014,7 +6017,7 @@ an auto-save file."
|
||||
(interactive "FRecover file: ")
|
||||
(setq file (expand-file-name file))
|
||||
(if (auto-save-file-name-p (file-name-nondirectory file))
|
||||
(error "%s is an auto-save file" (abbreviate-file-name file)))
|
||||
(user-error "%s is an auto-save file" (abbreviate-file-name file)))
|
||||
(let ((file-name (let ((buffer-file-name file))
|
||||
(make-auto-save-file-name))))
|
||||
(cond ((and (file-exists-p file)
|
||||
@ -6024,8 +6027,8 @@ an auto-save file."
|
||||
((if (file-exists-p file)
|
||||
(not (file-newer-than-file-p file-name file))
|
||||
(not (file-exists-p file-name)))
|
||||
(error "Auto-save file %s not current"
|
||||
(abbreviate-file-name file-name)))
|
||||
(user-error "Auto-save file %s not current"
|
||||
(abbreviate-file-name file-name)))
|
||||
((with-temp-buffer-window
|
||||
"*Directory*" nil
|
||||
#'(lambda (window _value)
|
||||
|
Loading…
Reference in New Issue
Block a user