From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 18859@debbugs.gnu.org, Reuben Thomas <rrt@sc3d.org>
Subject: bug#18859: 24.3; ibuffer-mark-by-file-name-regexp does not match displayed name
Date: Sun, 17 Jan 2021 16:32:57 +0000 [thread overview]
Message-ID: <87im7vy152.fsf@tcd.ie> (raw)
In-Reply-To: <87y2grzgxv.fsf@tcd.ie> (Basil L. Contovounesios's message of "Sun, 17 Jan 2021 16:06:20 +0000")
[-- Attachment #1: Type: text/plain, Size: 1394 bytes --]
"Basil L. Contovounesios" <contovob@tcd.ie> writes:
> Lars Ingebrigtsen <larsi@gnus.org> writes:
>
>> Reuben Thomas <rrt@sc3d.org> writes:
>>
>>> In the *IBuffer*, files in my home directory are displayed with names
>>> starting with ‘~’, but when I type % f ~ RET I get no matches. If I type
>>> instead % f /home/MYUSER RET then all files in my home directory are
>>> matched.
>>>
>>> I’m not convinced that the matches should be made in the second case,
>>> even; but certainly they _should_ be made in the first.
>>
>> The following patch fixes this by matching on the abbreviated file name
>> (which is what ibuffer uses to create the displayed file name).
>>
>> But I guess this could be a controversial change -- does anybody have an
>> objection to making this change?
>>
>> diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
>> index 1b69574a39..06a2248d40 100644
>> --- a/lisp/ibuf-ext.el
>> +++ b/lisp/ibuf-ext.el
>> @@ -1846,7 +1846,8 @@ ibuffer-mark-by-file-name-regexp
>> (stringp dired-directory)
>> dired-directory)))))
>> (when name
>> - (string-match regexp name))))))
>> + ;; Match on the displayed file name (which is abbreviated).
>> + (string-match regexp (abbreviate-file-name name)))))))
>
> Any objections to this followup fix for master?
Or rather, the improved patch attached.
--
Basil
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-ibuffer-mark-by-file-name-regexp-abbreviations.patch --]
[-- Type: text/x-diff, Size: 2875 bytes --]
From 4cf9d4f2be9095b3fa77ef4a54929f0a47c986dc Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Sun, 17 Jan 2021 15:53:53 +0000
Subject: [PATCH] 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 | 17 ++++++-----------
lisp/ibuffer.el | 9 ++++++---
2 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index 7be1b3d16c..a6523e10e4 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -1823,18 +1823,13 @@ ibuffer-mark-by-mode-regexp
;;;###autoload
(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)")))
(ibuffer-mark-on-buffer
- #'(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)
+ (let ((name (with-current-buffer buf (ibuffer-buffer-file-name))))
+ (when name
+ ;; Match on the displayed file name (which is abbreviated).
+ (string-match-p regexp (ibuffer--abbreviate-file-name name)))))))
;;;###autoload
(defun ibuffer-mark-by-content-regexp (regexp &optional all-buffers)
diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el
index 4800e0243d..84c53b16ac 100644
--- a/lisp/ibuffer.el
+++ b/lisp/ibuffer.el
@@ -1308,6 +1308,11 @@ ibuffer-buffer-file-name
(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 @@ filename
(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"
--
2.29.2
next prev parent reply other threads:[~2021-01-17 16:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-27 21:19 bug#18859: 24.3; ibuffer-mark-by-file-name-regexp does not match displayed name Reuben Thomas
2019-08-03 16:54 ` Lars Ingebrigtsen
2019-08-23 0:53 ` Lars Ingebrigtsen
2021-01-17 16:06 ` Basil L. Contovounesios
2021-01-17 16:32 ` Basil L. Contovounesios [this message]
2021-01-18 16:39 ` Lars Ingebrigtsen
2021-01-18 18:05 ` Basil L. Contovounesios
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87im7vy152.fsf@tcd.ie \
--to=contovob@tcd.ie \
--cc=18859@debbugs.gnu.org \
--cc=larsi@gnus.org \
--cc=rrt@sc3d.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.