[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 32906819ad: Allow shortening filenames in recentf-mode menu
From: |
Stefan Kangas |
Subject: |
master 32906819ad: Allow shortening filenames in recentf-mode menu |
Date: |
Tue, 21 Jun 2022 08:38:58 -0400 (EDT) |
branch: master
commit 32906819addde1aa952d4718699d332d3a58b004
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>
Allow shortening filenames in recentf-mode menu
* lisp/recentf.el (recentf-show-abbreviated): New function.
(recentf--filter-names): New helper function.
(recentf-show-basenames): Use above new helper function.
(recentf-menu-filter): Allow setting user option to new value
'recentf-show-abbreviated'.
---
etc/NEWS | 5 +++++
lisp/recentf.el | 22 +++++++++++++++++-----
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index c54a1cc42a..fdc2e99ca4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1840,6 +1840,11 @@ Enabling this minor mode turns on hiding header
material, like
If non-nil, files untracked by a VCS are considered to be part of
the project by a VC project based on that VCS.
+---
+*** The 'recentf-mode' menu can now use shortened filenames.
+Set the user option 'recentf-menu-filter' to
+'recentf-show-abbreviated' to enable it.
+
---
** The autoarg.el library is now marked obsolete.
This library provides the 'autoarg-mode' and 'autoarg-kp-mode' minor
diff --git a/lisp/recentf.el b/lisp/recentf.el
index 2de9831154..28aee0f17f 100644
--- a/lisp/recentf.el
+++ b/lisp/recentf.el
@@ -186,6 +186,8 @@ A nil value means no filter. The following functions are
predefined:
Sort menu items by directories in ascending order.
- `recentf-sort-directories-descending'
Sort menu items by directories in descending order.
+- `recentf-show-abbreviated'
+ Show shortened filenames.
- `recentf-show-basenames'
Show filenames sans directory in menu items.
- `recentf-show-basenames-ascending'
@@ -214,6 +216,7 @@ elements (see `recentf-make-menu-element' for menu element
form)."
(function-item recentf-sort-basenames-descending)
(function-item recentf-sort-directories-ascending)
(function-item recentf-sort-directories-descending)
+ (function-item recentf-show-abbreviated)
(function-item recentf-show-basenames)
(function-item recentf-show-basenames-ascending)
(function-item recentf-show-basenames-descending)
@@ -724,14 +727,11 @@ Compares directories then filenames to order the list."
(recentf-menu-element-value e2)
(recentf-menu-element-value e1)))))
-(defun recentf-show-basenames (l &optional no-dir)
- "Filter the list of menu elements L to show filenames sans directory.
-When a filename is duplicated, it is appended a sequence number if
-optional argument NO-DIR is non-nil, or its directory otherwise."
+(defun recentf--filter-names (l no-dir fun)
(let (filtered-names filtered-list full name counters sufx)
(dolist (elt l (nreverse filtered-list))
(setq full (recentf-menu-element-value elt)
- name (file-name-nondirectory full))
+ name (funcall fun full))
(if (not (member name filtered-names))
(push name filtered-names)
(if no-dir
@@ -743,6 +743,18 @@ optional argument NO-DIR is non-nil, or its directory
otherwise."
(setq name (format "%s(%s)" name sufx)))
(push (recentf-make-menu-element name full) filtered-list))))
+(defun recentf-show-abbreviated (l &optional no-dir)
+ "Filter the list of menu elements L to show shortened filenames.
+When a filename is duplicated, it is appended a sequence number if
+optional argument NO-DIR is non-nil, or its directory otherwise."
+ (recentf--filter-names l no-dir #'abbreviate-file-name))
+
+(defun recentf-show-basenames (l &optional no-dir)
+ "Filter the list of menu elements L to show filenames sans directory.
+When a filename is duplicated, it is appended a sequence number if
+optional argument NO-DIR is non-nil, or its directory otherwise."
+ (recentf--filter-names l no-dir #'file-name-nondirectory))
+
(defsubst recentf-show-basenames-ascending (l)
"Filter the list of menu elements L to show filenames sans directory.
Filenames are sorted in ascending order.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 32906819ad: Allow shortening filenames in recentf-mode menu,
Stefan Kangas <=