]> code.delx.au - gnu-emacs/commitdiff
2004-06-02 Romain Francoise <romain@orebokech.com>
authorJohn Paul Wallington <jpw@pobox.com>
Wed, 2 Jun 2004 22:07:42 +0000 (22:07 +0000)
committerJohn Paul Wallington <jpw@pobox.com>
Wed, 2 Jun 2004 22:07:42 +0000 (22:07 +0000)
* ibuf-ext.el (ibuffer-jump-to-buffer): Add support for filter
groups: if the user asks for a hidden buffer, open the
corresponding filter group to expose it.

* ibuffer.el (ibuffer-mode-map): Add key binding `M-g' to
`ibuffer-jump-to-buffer'.
(ibuffer-jump-offer-only-visible-buffers): New user option.

lisp/ChangeLog
lisp/ibuf-ext.el
lisp/ibuffer.el

index 2ecf59b55aab3b0854d061b1164a8b28082a657e..845d0c9f1d4b44172d677a0d017a45c43b989802 100644 (file)
@@ -1,3 +1,13 @@
+2004-06-02  Romain Francoise  <romain@orebokech.com>
+
+       * ibuf-ext.el (ibuffer-jump-to-buffer): Add support for filter
+       groups: if the user asks for a hidden buffer, open the
+       corresponding filter group to expose it.
+
+       * ibuffer.el (ibuffer-mode-map): Add key binding `M-g' to
+       `ibuffer-jump-to-buffer'.
+       (ibuffer-jump-offer-only-visible-buffers): New user option.
+
 2004-06-02  Juanma Barranquero  <lektu@terra.es>
 
        * faces.el (frame-update-faces): Add empty docstring so the one
index 9492d5565f665a71518e30d3dbabc1eef1097440..96678d2bc9a9f0831339a52c59fa63d6bc9c6660 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 Free Software Foundation, Inc.
 
 ;; Author: Colin Walters <walters@verbum.org>
 ;; Maintainer: John Paul Wallington <jpw@gnu.org>
@@ -1224,19 +1224,62 @@ 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."
+  "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 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))))
+  (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!"))
+         (when (interactive-p)
+           (setq name (completing-read "Jump to buffer: "
+                                       table nil t))))
+      (when (interactive-p)
+       (setq name (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 ()
index ab8290cfae89eeb1c6306ca16481a20894f76d91..fef9b7f811d0ed3abfe83f6b83be7e0a2f816deb 100644 (file)
@@ -1,6 +1,6 @@
 ;;; ibuffer.el --- operate on buffers like dired
 
-;; Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+;; Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
 
 ;; Author: Colin Walters <walters@verbum.org>
 ;; Maintainer: John Paul Wallington <jpw@gnu.org>
@@ -268,6 +268,12 @@ This variable takes precedence over filtering, and even
                 (const :tag "Always except minibuffer" :value :nomini))
   :group 'ibuffer)
 
+(defcustom ibuffer-jump-offer-only-visible-buffers nil
+  "If non-nil, only offer buffers visible in the Ibuffer buffer
+in completion lists of the `ibuffer-jump-to-buffer' command."
+  :type 'boolean
+  :group 'ibuffer)
+
 (defcustom ibuffer-use-header-line (boundp 'header-line-format)
   "If non-nil, display a header line containing current filters."
   :type 'boolean
@@ -357,6 +363,7 @@ directory, like `default-directory'."
     (define-key map (kbd "u") 'ibuffer-unmark-forward)
     (define-key map (kbd "=") 'ibuffer-diff-with-file)
     (define-key map (kbd "j") 'ibuffer-jump-to-buffer)
+    (define-key map (kbd "M-g") 'ibuffer-jump-to-buffer)
     (define-key map (kbd "DEL") 'ibuffer-unmark-backward)
     (define-key map (kbd "M-DEL") 'ibuffer-unmark-all)
     (define-key map (kbd "* *") 'ibuffer-unmark-all)