[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult 95f65c56da: Introduce pure variant of abbreviat
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult 95f65c56da: Introduce pure variant of abbreviate-file-name (Fix #766) |
Date: |
Tue, 14 Mar 2023 10:57:30 -0400 (EDT) |
branch: externals/consult
commit 95f65c56daadcfa0c4755c4fcd3c813b26706433
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Introduce pure variant of abbreviate-file-name (Fix #766)
---
consult.el | 59 ++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 38 insertions(+), 21 deletions(-)
diff --git a/consult.el b/consult.el
index 856b6bde4d..0c93b3628e 100644
--- a/consult.el
+++ b/consult.el
@@ -721,6 +721,22 @@ The line beginning/ending BEG/END is bound in BODY."
(kill-local-variable ',(cdr x))))
local)))))))
+(defvar consult--abbreviate-file-name-pure nil)
+(defun consult--abbreviate-file-name-pure (name)
+ "Return abbreviate file NAME.
+This function is a pure variant of `abbreviate-file-name', which
+does access the file system. This is important if we rely on the
+operation being fast, even for remote paths or paths on network
+file systems."
+ (save-match-data
+ (let (case-fold-search) ;; Assume that file system is case sensitive.
+ (setq name (directory-abbrev-apply name))
+ (let ((home (with-memoization consult--abbreviate-file-name-pure
+ (directory-abbrev-make-regexp (expand-file-name "~")))))
+ (if (string-match home name)
+ (concat "~" (substring name (match-beginning 1)))
+ name)))))
+
(defun consult--left-truncate-file (file)
"Return abbreviated file name of FILE for use in `completing-read' prompt."
(save-match-data
@@ -3671,8 +3687,7 @@ narrowing and the settings `consult-goto-line-numbers' and
(find-file
(consult--read
(or
- (let (file-name-handler-alist) ;; No Tramp slowdown please
- (mapcar #'abbreviate-file-name (bound-and-true-p recentf-list)))
+ (mapcar #'consult--abbreviate-file-name-pure (bound-and-true-p
recentf-list))
(user-error "No recent files, `recentf-mode' is %s"
(if recentf-mode "enabled" "disabled")))
:prompt "Find recent file: "
@@ -4444,21 +4459,22 @@ If NORECORD is non-nil, do not record the buffer switch
in the buffer list."
recentf-mode))
:items
,(lambda ()
- (when-let (root (consult--project-root))
- (let ((len (length root))
- (ht (consult--buffer-file-hash))
- file-name-handler-alist ;; No Tramp slowdown please.
- items)
- (dolist (file (bound-and-true-p recentf-list) (nreverse items))
- ;; Emacs 29 abbreviates file paths by default, see
- ;; `recentf-filename-handlers'.
- (unless (eq (aref file 0) ?/)
- (setq file (expand-file-name file)))
- (when (and (not (gethash file ht)) (string-prefix-p root file))
- (let ((part (substring file len)))
- (when (equal part "") (setq part "./"))
- (put-text-property 0 1 'multi-category `(file . ,file) part)
- (push part items))))))))
+ (when-let (root (consult--project-root))
+ (let ((len (length root))
+ (ht (consult--buffer-file-hash))
+ items)
+ (dolist (file (bound-and-true-p recentf-list) (nreverse items))
+ ;; Emacs 29 abbreviates file paths by default, see
+ ;; `recentf-filename-handlers'. I recommend to set
+ ;; recentf-filename-handlers to nil to avoid any slow down.
+ (unless (eq (aref file 0) ?/)
+ (let (file-name-handler-alist) ;; No Tramp slowdown please.
+ (setq file (expand-file-name file))))
+ (when (and (not (gethash file ht)) (string-prefix-p root file))
+ (let ((part (substring file len)))
+ (when (equal part "") (setq part "./"))
+ (put-text-property 0 1 'multi-category `(file . ,file) part)
+ (push part items))))))))
"Project file candidate source for `consult-buffer'.")
(defvar consult--source-hidden-buffer
@@ -4531,15 +4547,16 @@ If NORECORD is non-nil, do not record the buffer switch
in the buffer list."
:items
,(lambda ()
(let ((ht (consult--buffer-file-hash))
- file-name-handler-alist ;; No Tramp slowdown please.
items)
(dolist (file (bound-and-true-p recentf-list) (nreverse items))
;; Emacs 29 abbreviates file paths by default, see
- ;; `recentf-filename-handlers'.
+ ;; `recentf-filename-handlers'. I recommend to set
+ ;; `recentf-filename-handlers' to nil to avoid any slow down.
(unless (eq (aref file 0) ?/)
- (setq file (expand-file-name file)))
+ (let (file-name-handler-alist) ;; No Tramp slowdown please.
+ (setq file (expand-file-name file))))
(unless (gethash file ht)
- (push (abbreviate-file-name file) items))))))
+ (push (consult--abbreviate-file-name-pure file) items))))))
"Recent file candidate source for `consult-buffer'.")
;;;###autoload
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/consult 95f65c56da: Introduce pure variant of abbreviate-file-name (Fix #766),
ELPA Syncer <=