aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2022-06-21 14:27:51 +0200
committerStefan Kangas2022-06-21 14:38:45 +0200
commit32906819addde1aa952d4718699d332d3a58b004 (patch)
tree2df7199d7c2701a73937f54266bdbac9473005ce
parent3518ab51d1f08165c2eb74517873877a998e38a5 (diff)
downloademacs-32906819addde1aa952d4718699d332d3a58b004.tar.gz
emacs-32906819addde1aa952d4718699d332d3a58b004.zip
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'.
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/recentf.el22
2 files changed, 22 insertions, 5 deletions
diff --git a/etc/NEWS b/etc/NEWS
index c54a1cc42a2..fdc2e99ca46 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1841,6 +1841,11 @@ If non-nil, files untracked by a VCS are considered to be part of
1841the project by a VC project based on that VCS. 1841the project by a VC project based on that VCS.
1842 1842
1843--- 1843---
1844*** The 'recentf-mode' menu can now use shortened filenames.
1845Set the user option 'recentf-menu-filter' to
1846'recentf-show-abbreviated' to enable it.
1847
1848---
1844** The autoarg.el library is now marked obsolete. 1849** The autoarg.el library is now marked obsolete.
1845This library provides the 'autoarg-mode' and 'autoarg-kp-mode' minor 1850This library provides the 'autoarg-mode' and 'autoarg-kp-mode' minor
1846modes to emulate the behavior of the historical editor Twenex Emacs. 1851modes to emulate the behavior of the historical editor Twenex Emacs.
diff --git a/lisp/recentf.el b/lisp/recentf.el
index 2de98311540..28aee0f17fd 100644
--- a/lisp/recentf.el
+++ b/lisp/recentf.el
@@ -186,6 +186,8 @@ A nil value means no filter. The following functions are predefined:
186 Sort menu items by directories in ascending order. 186 Sort menu items by directories in ascending order.
187- `recentf-sort-directories-descending' 187- `recentf-sort-directories-descending'
188 Sort menu items by directories in descending order. 188 Sort menu items by directories in descending order.
189- `recentf-show-abbreviated'
190 Show shortened filenames.
189- `recentf-show-basenames' 191- `recentf-show-basenames'
190 Show filenames sans directory in menu items. 192 Show filenames sans directory in menu items.
191- `recentf-show-basenames-ascending' 193- `recentf-show-basenames-ascending'
@@ -214,6 +216,7 @@ elements (see `recentf-make-menu-element' for menu element form)."
214 (function-item recentf-sort-basenames-descending) 216 (function-item recentf-sort-basenames-descending)
215 (function-item recentf-sort-directories-ascending) 217 (function-item recentf-sort-directories-ascending)
216 (function-item recentf-sort-directories-descending) 218 (function-item recentf-sort-directories-descending)
219 (function-item recentf-show-abbreviated)
217 (function-item recentf-show-basenames) 220 (function-item recentf-show-basenames)
218 (function-item recentf-show-basenames-ascending) 221 (function-item recentf-show-basenames-ascending)
219 (function-item recentf-show-basenames-descending) 222 (function-item recentf-show-basenames-descending)
@@ -724,14 +727,11 @@ Compares directories then filenames to order the list."
724 (recentf-menu-element-value e2) 727 (recentf-menu-element-value e2)
725 (recentf-menu-element-value e1))))) 728 (recentf-menu-element-value e1)))))
726 729
727(defun recentf-show-basenames (l &optional no-dir) 730(defun recentf--filter-names (l no-dir fun)
728 "Filter the list of menu elements L to show filenames sans directory.
729When a filename is duplicated, it is appended a sequence number if
730optional argument NO-DIR is non-nil, or its directory otherwise."
731 (let (filtered-names filtered-list full name counters sufx) 731 (let (filtered-names filtered-list full name counters sufx)
732 (dolist (elt l (nreverse filtered-list)) 732 (dolist (elt l (nreverse filtered-list))
733 (setq full (recentf-menu-element-value elt) 733 (setq full (recentf-menu-element-value elt)
734 name (file-name-nondirectory full)) 734 name (funcall fun full))
735 (if (not (member name filtered-names)) 735 (if (not (member name filtered-names))
736 (push name filtered-names) 736 (push name filtered-names)
737 (if no-dir 737 (if no-dir
@@ -743,6 +743,18 @@ optional argument NO-DIR is non-nil, or its directory otherwise."
743 (setq name (format "%s(%s)" name sufx))) 743 (setq name (format "%s(%s)" name sufx)))
744 (push (recentf-make-menu-element name full) filtered-list)))) 744 (push (recentf-make-menu-element name full) filtered-list))))
745 745
746(defun recentf-show-abbreviated (l &optional no-dir)
747 "Filter the list of menu elements L to show shortened filenames.
748When a filename is duplicated, it is appended a sequence number if
749optional argument NO-DIR is non-nil, or its directory otherwise."
750 (recentf--filter-names l no-dir #'abbreviate-file-name))
751
752(defun recentf-show-basenames (l &optional no-dir)
753 "Filter the list of menu elements L to show filenames sans directory.
754When a filename is duplicated, it is appended a sequence number if
755optional argument NO-DIR is non-nil, or its directory otherwise."
756 (recentf--filter-names l no-dir #'file-name-nondirectory))
757
746(defsubst recentf-show-basenames-ascending (l) 758(defsubst recentf-show-basenames-ascending (l)
747 "Filter the list of menu elements L to show filenames sans directory. 759 "Filter the list of menu elements L to show filenames sans directory.
748Filenames are sorted in ascending order. 760Filenames are sorted in ascending order.