summaryrefslogtreecommitdiff
path: root/lisp/ibuf-ext.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/ibuf-ext.el')
-rw-r--r--lisp/ibuf-ext.el91
1 files changed, 40 insertions, 51 deletions
diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index 0e9f952221f..6b5cccec515 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -48,30 +48,12 @@
;;; Utility functions
(defun ibuffer-remove-alist (key alist)
"Remove all entries in ALIST that have a key equal to KEY."
- (while (ibuffer-awhen (assoc key alist)
- (setq alist (remove it alist)) it))
- alist)
-
-;; borrowed from Gnus
-(defun ibuffer-remove-duplicates (list)
- "Return a copy of LIST with duplicate elements removed."
- (let ((new nil)
- (tail list))
- (while tail
- (or (member (car tail) new)
- (setq new (cons (car tail) new)))
- (setq tail (cdr tail)))
- (nreverse new)))
-
-(defun ibuffer-split-list (ibuffer-split-list-fn ibuffer-split-list-elts)
- (let ((hip-crowd nil)
- (lamers nil))
- (dolist (ibuffer-split-list-elt ibuffer-split-list-elts)
- (if (funcall ibuffer-split-list-fn ibuffer-split-list-elt)
- (push ibuffer-split-list-elt hip-crowd)
- (push ibuffer-split-list-elt lamers)))
- ;; Too bad Emacs Lisp doesn't have multiple values.
- (list (nreverse hip-crowd) (nreverse lamers))))
+ (assoc-delete-all key (copy-sequence alist)))
+
+(defun ibuffer-split-list (fn elts)
+ (declare (obsolete seq-group-by "29.1"))
+ (let ((res (seq-group-by fn elts)))
+ (list (cdr (assq t res)) (cdr (assq nil res)))))
(defcustom ibuffer-never-show-predicates nil
"A list of predicates (a regexp or function) for buffers not to display.
@@ -769,11 +751,12 @@ specification, with the same structure as an element of the list
(i 0))
(dolist (filtergroup filter-group-alist)
(let ((filterset (cdr filtergroup)))
- (cl-destructuring-bind (hip-crowd lamers)
- (ibuffer-split-list (lambda (bufmark)
- (ibuffer-included-in-filters-p (car bufmark)
- filterset))
- bmarklist)
+ (let* ((res (seq-group-by (lambda (bufmark)
+ (ibuffer-included-in-filters-p (car bufmark)
+ filterset))
+ bmarklist))
+ (hip-crowd (cdr (assq t res)))
+ (lamers (cdr (assq nil res))))
(aset vec i hip-crowd)
(cl-incf i)
(setq bmarklist lamers))))
@@ -803,7 +786,7 @@ specification, with the same structure as an element of the list
(mapcar (lambda (mode)
(cons (format "%s" mode) `((mode . ,mode))))
(let ((modes
- (ibuffer-remove-duplicates
+ (seq-uniq
(mapcar (lambda (buf)
(buffer-local-value 'major-mode buf))
(buffer-list)))))
@@ -880,7 +863,7 @@ specification, with the same structure as an element of the list
"Move point to the filter group whose name is NAME."
(interactive
(list (ibuffer-read-filter-group-name "Jump to filter group: ")))
- (ibuffer-aif (assoc name (ibuffer-current-filter-groups-with-position))
+ (if-let ((it (assoc name (ibuffer-current-filter-groups-with-position))))
(goto-char (cdr it))
(error "No filter group with name %s" name)))
@@ -891,7 +874,7 @@ The group will be added to `ibuffer-filter-group-kill-ring'."
(interactive (list (ibuffer-read-filter-group-name "Kill filter group: " t)))
(when (equal name "Default")
(error "Can't kill default filter group"))
- (ibuffer-aif (assoc name ibuffer-filter-groups)
+ (if-let ((it (assoc name ibuffer-filter-groups)))
(progn
(push (copy-tree it) ibuffer-filter-group-kill-ring)
(setq ibuffer-filter-groups (ibuffer-remove-alist
@@ -906,13 +889,12 @@ The group will be added to `ibuffer-filter-group-kill-ring'."
"Kill the filter group at point.
See also `ibuffer-kill-filter-group'."
(interactive "P\np")
- (ibuffer-aif (save-excursion
- (ibuffer-forward-line 0)
- (get-text-property (point) 'ibuffer-filter-group-name))
- (progn
- (ibuffer-kill-filter-group it))
- (funcall (if interactive-p #'call-interactively #'funcall)
- #'kill-line arg)))
+ (if-let ((it (save-excursion
+ (ibuffer-forward-line 0)
+ (get-text-property (point) 'ibuffer-filter-group-name))))
+ (ibuffer-kill-filter-group it)
+ (funcall (if interactive-p #'call-interactively #'funcall)
+ #'kill-line arg)))
(defun ibuffer-insert-filter-group-before (newgroup group)
(let* ((found nil)
@@ -968,7 +950,7 @@ prompt for NAME, and use the current filters."
(list
(read-from-minibuffer "Save current filter groups as: ")
ibuffer-filter-groups)))
- (ibuffer-aif (assoc name ibuffer-saved-filter-groups)
+ (if-let ((it (assoc name ibuffer-saved-filter-groups)))
(setcdr it groups)
(push (cons name groups) ibuffer-saved-filter-groups))
(ibuffer-maybe-save-stuff))
@@ -1140,7 +1122,7 @@ Interactively, prompt for NAME, and use the current filters."
(list
(read-from-minibuffer "Save current filters as: ")
ibuffer-filtering-qualifiers)))
- (ibuffer-aif (assoc name ibuffer-saved-filters)
+ (if-let ((it (assoc name ibuffer-saved-filters)))
(setcdr it filters)
(push (cons name filters) ibuffer-saved-filters))
(ibuffer-maybe-save-stuff))
@@ -1211,7 +1193,9 @@ Interactively, prompt for NAME, and use the current filters."
(let ((type (assq (car qualifier) ibuffer-filtering-alist)))
(unless qualifier
(error "Ibuffer: Bad qualifier %s" qualifier))
- (concat " [" (cadr type) ": " (format "%s]" (cdr qualifier)))))))
+ (if (cdr qualifier)
+ (format " [%s: %s]" (cadr type) (cdr qualifier))
+ (format " [%s]" (cadr type)))))))
(defun ibuffer-list-buffer-modes (&optional include-parents)
"Create a completion table of buffer modes currently in use.
@@ -1315,7 +1299,7 @@ For example, for a buffer associated with file '/a/b/c.d', this
matches against '/a/b/c.d'."
(:description "full file name"
:reader (read-from-minibuffer "Filter by full file name (regexp): "))
- (ibuffer-awhen (with-current-buffer buf (ibuffer-buffer-file-name))
+ (when-let ((it (with-current-buffer buf (ibuffer-buffer-file-name))))
(string-match qualifier it)))
;;;###autoload (autoload 'ibuffer-filter-by-basename "ibuf-ext")
@@ -1327,7 +1311,7 @@ matches against `c.d'."
(:description "file basename"
:reader (read-from-minibuffer
"Filter by file name, without directory part (regex): "))
- (ibuffer-awhen (with-current-buffer buf (ibuffer-buffer-file-name))
+ (when-let ((it (with-current-buffer buf (ibuffer-buffer-file-name))))
(string-match qualifier (file-name-nondirectory it))))
;;;###autoload (autoload 'ibuffer-filter-by-file-extension "ibuf-ext")
@@ -1340,7 +1324,7 @@ pattern. For example, for a buffer associated with file
(:description "filename extension"
:reader (read-from-minibuffer
"Filter by filename extension without separator (regex): "))
- (ibuffer-awhen (with-current-buffer buf (ibuffer-buffer-file-name))
+ (when-let ((it (with-current-buffer buf (ibuffer-buffer-file-name))))
(string-match qualifier (or (file-name-extension it) ""))))
;;;###autoload (autoload 'ibuffer-filter-by-directory "ibuf-ext")
@@ -1350,11 +1334,11 @@ pattern. For example, for a buffer associated with file
For a buffer associated with file '/a/b/c.d', this matches
against '/a/b'. For a buffer not associated with a file, this
matches against the value of `default-directory' in that buffer."
- (:description "directory name"
- :reader (read-from-minibuffer "Filter by directory name (regex): "))
- (ibuffer-aif (with-current-buffer buf (ibuffer-buffer-file-name))
- (let ((dirname (file-name-directory it)))
- (when dirname (string-match qualifier dirname)))
+ ( :description "directory name"
+ :reader (read-from-minibuffer "Filter by directory name (regex): "))
+ (if-let ((it (with-current-buffer buf (ibuffer-buffer-file-name))))
+ (when-let ((dirname (file-name-directory it)))
+ (string-match qualifier dirname))
(when default-directory (string-match qualifier default-directory))))
;;;###autoload (autoload 'ibuffer-filter-by-size-gt "ibuf-ext")
@@ -1597,7 +1581,10 @@ to move by. The default is `ibuffer-marked-char'."
"Hide all of the currently marked lines."
(interactive)
(if (= (ibuffer-count-marked-lines) 0)
- (message "No buffers marked; use `m' to mark a buffer")
+ (message (substitute-command-keys
+ (concat
+ "No buffers marked; use \\<ibuffer-mode-map>"
+ "\\[ibuffer-mark-forward] to mark a buffer")))
(let ((count
(ibuffer-map-marked-lines
(lambda (_buf _mark)
@@ -1985,6 +1972,8 @@ defaults to one."
(push buf ibuffer-do-occur-bufs)))
(occur-1 regexp nlines ibuffer-do-occur-bufs)))
+(define-obsolete-function-alias 'ibuffer-remove-duplicates #'seq-uniq "29.1")
+
(provide 'ibuf-ext)
;; Local Variables: