[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 8f4b3b8 2/2: Fix ibuffer-mark-by-file-name-regexp abbreviations

From: Basil L. Contovounesios
Subject: master 8f4b3b8 2/2: Fix ibuffer-mark-by-file-name-regexp abbreviations
Date: Mon, 18 Jan 2021 13:04:14 -0500 (EST)

branch: master
commit 8f4b3b812aab62a5a205bc2f8690c3b4c460ba09
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>

    Fix ibuffer-mark-by-file-name-regexp abbreviations
    * lisp/ibuffer.el (ibuffer--abbreviate-file-name): New function.
    (filename): Use it.
    * lisp/ibuf-ext.el (ibuffer-mark-by-file-name-regexp): Prefer
    read-regexp over read-string for reading regexps.  Determine file
    name using ibuffer-buffer-file-name for consistency.  Abbreviate
    file name using ibuffer-directory-abbrev-alist (bug#18859).
 lisp/ibuf-ext.el | 16 +++++-----------
 lisp/ibuffer.el  |  9 ++++++---
 2 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index 7be1b3d..ed5c9c0 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -1823,18 +1823,12 @@ When BUF nil, default to the buffer at current line."
 (defun ibuffer-mark-by-file-name-regexp (regexp)
   "Mark all buffers whose file name matches REGEXP."
-  (interactive "sMark by file name (regexp): ")
+  (interactive (list (read-regexp "Mark by file name (regexp)")))
-   #'(lambda (buf)
-       (let ((name (or (buffer-file-name buf)
-                      (with-current-buffer buf
-                        (and
-                         (boundp 'dired-directory)
-                         (stringp dired-directory)
-                         dired-directory)))))
-        (when name
-           ;; Match on the displayed file name (which is abbreviated).
-          (string-match regexp (abbreviate-file-name name)))))))
+   (lambda (buf)
+     (when-let ((name (with-current-buffer buf (ibuffer-buffer-file-name))))
+       ;; Match on the displayed file name (which is abbreviated).
+       (string-match-p regexp (ibuffer--abbreviate-file-name name))))))
 (defun ibuffer-mark-by-content-regexp (regexp &optional all-buffers)
diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el
index 4800e02..84c53b1 100644
--- a/lisp/ibuffer.el
+++ b/lisp/ibuffer.el
@@ -1308,6 +1308,11 @@ a new window in the current frame, splitting vertically."
                           (car dired-directory)))))
        (and dirname (expand-file-name dirname))))))
+(defun ibuffer--abbreviate-file-name (filename)
+  "Abbreviate FILENAME using `ibuffer-directory-abbrev-alist'."
+  (let ((directory-abbrev-alist ibuffer-directory-abbrev-alist))
+    (abbreviate-file-name filename)))
 (define-ibuffer-op ibuffer-do-save ()
   "Save marked buffers as with `save-buffer'."
   (:complex t
@@ -1885,9 +1890,7 @@ If point is on a group name, this function operates on 
that group."
        (cond ((zerop total) "No files")
             ((= 1 total) "1 file")
             (t (format "%d files" total))))))
-  (let ((directory-abbrev-alist ibuffer-directory-abbrev-alist))
-    (abbreviate-file-name
-     (or (ibuffer-buffer-file-name) ""))))
+  (ibuffer--abbreviate-file-name (or (ibuffer-buffer-file-name) "")))
 (define-ibuffer-column filename-and-process
   (:name "Filename/Process"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]