;;; ibuf-ext.el --- extensions for ibuffer
-;; Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
+;; 2005 Free Software Foundation, Inc.
;; Author: Colin Walters <walters@verbum.org>
;; Maintainer: John Paul Wallington <jpw@gnu.org>
;; You should have received a copy of the GNU General Public License
;; along with this program ; see the file COPYING. If not, write to
-;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
(require 'ibuffer)
(eval-when-compile
- (require 'derived)
(require 'ibuf-macs)
(require 'cl))
(ibuffer-buf-matches-predicates buf ibuffer-always-show-predicates)))))
(defun ibuffer-auto-update-changed ()
- (when ibuffer-auto-buffers-changed
- (setq ibuffer-auto-buffers-changed nil)
+ (when (frame-or-buffer-changed-p 'ibuffer-auto-buffers-changed)
(mapcar #'(lambda (buf)
(ignore-errors
(with-current-buffer buf
(if arg
(plusp arg)
(not ibuffer-auto-mode)))
- (defadvice get-buffer-create (after ibuffer-notify-create activate)
- (setq ibuffer-auto-buffers-changed t))
- (defadvice kill-buffer (after ibuffer-notify-kill activate)
- (setq ibuffer-auto-buffers-changed t))
+ (frame-or-buffer-changed-p 'ibuffer-auto-buffers-changed)
(add-hook 'post-command-hook 'ibuffer-auto-update-changed)
(ibuffer-update-mode-name))
(cons (format "%s" mode) `((mode . ,mode))))
(let ((modes
(ibuffer-remove-duplicates
- (mapcar (lambda (buf) (with-current-buffer buf major-mode))
+ (mapcar (lambda (buf)
+ (with-current-buffer buf major-mode))
(buffer-list)))))
(if ibuffer-view-ibuffer
modes
;;;###autoload
(defun ibuffer-decompose-filter-group (group)
"Decompose the filter group GROUP into active filters."
- (interactive (list (ibuffer-read-filter-group-name "Decompose filter group: " t)))
+ (interactive
+ (list (ibuffer-read-filter-group-name "Decompose filter group: " t)))
(let ((data (cdr (assoc group ibuffer-filter-groups))))
(setq ibuffer-filter-groups (ibuffer-delete-alist
group ibuffer-filter-groups)
;;;###autoload
(defun ibuffer-jump-to-filter-group (name)
"Move point to the filter group whose name is NAME."
- (interactive (list (ibuffer-read-filter-group-name "Jump to filter group: ")))
+ (interactive
+ (list (ibuffer-read-filter-group-name "Jump to filter group: ")))
(ibuffer-aif (assoc name (ibuffer-current-filter-groups-with-position))
(goto-char (cdr it))
(error "No filter group with name %s" name)))
(ibuffer-update nil t))
;;;###autoload
-(defun ibuffer-kill-line (&optional arg)
+(defun ibuffer-kill-line (&optional arg interactive-p)
"Kill the filter group at point.
See also `ibuffer-kill-filter-group'."
- (interactive "P")
+ (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)
+ (funcall (if interactive-p #'call-interactively #'funcall)
#'kill-line arg)))
(defun ibuffer-insert-filter-group-before (newgroup group)
(setq groups (cdr groups))))
res)))
(cond ((not found)
- (setq ibuffer-filter-groups (nconc ibuffer-filter-groups (list newgroup))))
+ (setq ibuffer-filter-groups
+ (nconc ibuffer-filter-groups (list newgroup))))
((zerop pos)
(push newgroup ibuffer-filter-groups))
(t
"Disable all filters currently in effect in this buffer."
(interactive)
(setq ibuffer-filtering-qualifiers nil)
- (ibuffer-update nil t))
+ (let ((buf (ibuffer-current-buffer)))
+ (ibuffer-update nil t)
+ (when buf
+ (ibuffer-jump-to-buffer (buffer-name buf)))))
;;;###autoload
(defun ibuffer-pop-filter ()
(when (null ibuffer-filtering-qualifiers)
(error "No filters in effect"))
(pop ibuffer-filtering-qualifiers)
- (ibuffer-update nil t))
+ (let ((buf (ibuffer-current-buffer)))
+ (ibuffer-update nil t)
+ (when buf
+ (ibuffer-jump-to-buffer (buffer-name buf)))))
(defun ibuffer-push-filter (qualifier)
"Add QUALIFIER to `ibuffer-filtering-qualifiers'."
(not (eq 'or (caar ibuffer-filtering-qualifiers))))
(error "Top filter is not an OR"))
(let ((lim (pop ibuffer-filtering-qualifiers)))
- (setq ibuffer-filtering-qualifiers (nconc (cdr lim) ibuffer-filtering-qualifiers))))
+ (setq ibuffer-filtering-qualifiers
+ (nconc (cdr lim) ibuffer-filtering-qualifiers))))
(when (< (length ibuffer-filtering-qualifiers) 2)
(error "Need two filters to OR"))
;; If the second filter is an OR, just add to it.
(let ((first (pop ibuffer-filtering-qualifiers))
(second (pop ibuffer-filtering-qualifiers)))
(if (eq 'or (car second))
- (push (nconc (list 'or first) (cdr second)) ibuffer-filtering-qualifiers)
+ (push (nconc (list 'or first) (cdr second))
+ ibuffer-filtering-qualifiers)
(push (list 'or first second)
ibuffer-filtering-qualifiers))))
(ibuffer-update nil t))
(defun ibuffer-format-filter-group-data (filter)
(if (equal filter "Default")
""
- (concat "Filter: " (mapconcat #'ibuffer-format-qualifier
- (cdr (assq filter ibuffer-filter-groups))
- " ") "\n")))
+ (concat "Filter:" (mapconcat #'ibuffer-format-qualifier
+ (cdr (assq filter ibuffer-filter-groups))
+ " "))))
(defun ibuffer-format-qualifier (qualifier)
(if (eq (car-safe qualifier) 'not)
"Toggle current view to buffers with filename matching QUALIFIER."
(:description "filename"
:reader (read-from-minibuffer "Filter by filename (regexp): "))
- (ibuffer-awhen (buffer-file-name buf)
+ (ibuffer-awhen (with-current-buffer buf
+ (or buffer-file-name
+ (and (boundp 'dired-directory)
+ (if (stringp dired-directory)
+ dired-directory
+ (car dired-directory))
+ (expand-file-name dired-directory))))
(string-match qualifier it)))
;;;###autoload (autoload 'ibuffer-filter-by-size-gt "ibuf-ext.el")
;;;###autoload
(defun ibuffer-jump-to-buffer (name)
- "Move point to the buffer whose name is NAME."
- (interactive (list nil))
- (let ((table (mapcar #'(lambda (x)
- (cons (buffer-name (car x))
- (caddr x)))
- (ibuffer-current-state-list t))))
- (when (null table)
- (error "No buffers!"))
- (when (interactive-p)
- (setq name (completing-read "Jump to buffer: " table nil t)))
- (ibuffer-aif (assoc name table)
- (goto-char (cdr it))
- (error "No buffer with name %s" name))))
+ "Move point to the buffer whose name is NAME.
+
+If called interactively, prompt for a buffer name and go to the
+corresponding line in the Ibuffer buffer. If said buffer is in a
+hidden group filter, open it.
+
+If `ibuffer-jump-offer-only-visible-buffers' is non-nil, only offer
+visible buffers in the completion list. Calling the command with
+a prefix argument reverses the meaning of that variable."
+ (interactive (list
+ (let ((only-visible ibuffer-jump-offer-only-visible-buffers))
+ (when current-prefix-arg
+ (setq only-visible (not only-visible)))
+ (if only-visible
+ (let ((table (mapcar #'(lambda (x)
+ (buffer-name (car x)))
+ (ibuffer-current-state-list))))
+ (when (null table)
+ (error "No buffers!"))
+ (completing-read "Jump to buffer: "
+ table nil t))
+ (read-buffer "Jump to buffer: " nil t)))))
+ (when (not (string= "" name))
+ (let (buf-point)
+ ;; Blindly search for our buffer: it is very likely that it is
+ ;; not in a hidden filter group.
+ (ibuffer-map-lines #'(lambda (buf marks)
+ (when (string= (buffer-name buf) name)
+ (setq buf-point (point))
+ nil))
+ t nil)
+ (when (and
+ (null buf-point)
+ (not (null ibuffer-hidden-filter-groups)))
+ ;; We did not find our buffer. It must be in a hidden filter
+ ;; group, so go through all hidden filter groups to find it.
+ (catch 'found
+ (dolist (group ibuffer-hidden-filter-groups)
+ (ibuffer-jump-to-filter-group group)
+ (ibuffer-toggle-filter-group)
+ (ibuffer-map-lines #'(lambda (buf marks)
+ (when (string= (buffer-name buf) name)
+ (setq buf-point (point))
+ nil))
+ t group)
+ (if buf-point
+ (throw 'found nil)
+ (ibuffer-toggle-filter-group)))))
+ (if (null buf-point)
+ ;; Still not found even though we expanded all hidden filter
+ ;; groups: that must be because it's hidden by predicate:
+ ;; we won't bother trying to display it.
+ (error "No buffer with name %s" name)
+ (goto-char buf-point)))))
;;;###autoload
(defun ibuffer-diff-with-file ()
(provide 'ibuf-ext)
+;;; arch-tag: 9af21953-deda-4c30-b76d-f81d9128e76d
;;; ibuf-ext.el ends here