]> code.delx.au - gnu-emacs/blobdiff - lisp/ibuf-ext.el
Update years in copyright notice; nfc.
[gnu-emacs] / lisp / ibuf-ext.el
index 902b2f7cfbb17247bb62455685517ce5be378410..9aef1ed95be2d6942fda402828ec9fbe2b3beb38 100644 (file)
@@ -1,6 +1,6 @@
 ;;; 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>
@@ -21,8 +21,8 @@
 
 ;; 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:
 
@@ -35,7 +35,6 @@
 (require 'ibuffer)
 
 (eval-when-compile
-  (require 'derived)
   (require 'ibuf-macs)
   (require 'cl))
 
@@ -170,7 +169,6 @@ The QUALIFIER should be the same as QUALIFIER in
   :group 'ibuffer)
 
 (defcustom ibuffer-saved-filter-groups nil
-
   "An alist of filtering groups to switch between.
 
 This variable should look like ((\"STRING\" QUALIFIERS)
@@ -201,7 +199,7 @@ functions `ibuffer-switch-to-saved-filter-group',
 (defcustom ibuffer-save-with-custom t
   "If non-nil, then use Custom to save interactively changed variables.
 Currently, this only applies to `ibuffer-saved-filters' and
-`ibuffer-saved-filter-groups."
+`ibuffer-saved-filter-groups'."
   :type 'boolean
   :group 'ibuffer)
 
@@ -557,7 +555,8 @@ To evaluate a form without viewing the buffer, see `ibuffer-do-eval'."
                   (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
@@ -587,7 +586,8 @@ To evaluate a form without viewing the buffer, see `ibuffer-do-eval'."
 ;;;###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)
@@ -621,7 +621,8 @@ To evaluate a form without viewing the buffer, see `ibuffer-do-eval'."
 ;;;###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)))
@@ -644,16 +645,16 @@ The group will be added to `ibuffer-filter-group-kill-ring'."
   (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)
@@ -668,7 +669,8 @@ See also `ibuffer-kill-filter-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
@@ -751,7 +753,10 @@ of replacing the current filters."
   "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 ()
@@ -760,7 +765,10 @@ of replacing the current filters."
   (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'."
@@ -837,14 +845,16 @@ filter into parts."
                  (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))
@@ -918,9 +928,9 @@ of replacing the current filters."
 (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)
@@ -1011,7 +1021,13 @@ currently used by buffers."
   "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")
@@ -1150,7 +1166,7 @@ Ordering is lexicographic."
 (defun ibuffer-add-to-tmp-hide (regexp)
   "Add REGEXP to `ibuffer-tmp-hide-regexps'.
 This means that buffers whose name matches REGEXP will not be shown
-for this ibuffer session."
+for this Ibuffer session."
   (interactive
    (list
     (read-from-minibuffer "Never show buffers matching: "
@@ -1161,7 +1177,7 @@ for this ibuffer session."
 (defun ibuffer-add-to-tmp-show (regexp)
   "Add REGEXP to `ibuffer-tmp-show-regexps'.
 This means that buffers whose name matches REGEXP will always be shown
-for this ibuffer session."
+for this Ibuffer session."
   (interactive
    (list
     (read-from-minibuffer "Always show buffers matching: "
@@ -1220,19 +1236,60 @@ to move by.  The default is `ibuffer-marked-char'."
 
 ;;;###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 ()
@@ -1456,4 +1513,5 @@ defaults to one."
 
 (provide 'ibuf-ext)
 
+;;; arch-tag: 9af21953-deda-4c30-b76d-f81d9128e76d
 ;;; ibuf-ext.el ends here