comparison lisp/ibuf-ext.el @ 55888:3d233a8d8d1f

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.
author John Paul Wallington <jpw@pobox.com>
date Wed, 02 Jun 2004 22:05:17 +0000
parents 695cf19ef79e
children eeb2a6261d0d 4c90ffeb71c5
comparison
equal deleted inserted replaced
55887:4825e30273d1 55888:3d233a8d8d1f
1 ;;; ibuf-ext.el --- extensions for ibuffer 1 ;;; ibuf-ext.el --- extensions for ibuffer
2 2
3 ;; Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. 3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 4
5 ;; Author: Colin Walters <walters@verbum.org> 5 ;; Author: Colin Walters <walters@verbum.org>
6 ;; Maintainer: John Paul Wallington <jpw@gnu.org> 6 ;; Maintainer: John Paul Wallington <jpw@gnu.org>
7 ;; Created: 2 Dec 2001 7 ;; Created: 2 Dec 2001
8 ;; Keywords: buffer, convenience 8 ;; Keywords: buffer, convenience
1222 'kill)))) 1222 'kill))))
1223 (message "Killed %s lines" count)))) 1223 (message "Killed %s lines" count))))
1224 1224
1225 ;;;###autoload 1225 ;;;###autoload
1226 (defun ibuffer-jump-to-buffer (name) 1226 (defun ibuffer-jump-to-buffer (name)
1227 "Move point to the buffer whose name is NAME." 1227 "Move point to the buffer whose name is NAME.
1228
1229 If called interactively, prompt for a buffer name and go to the
1230 corresponding line in the Ibuffer buffer. If said buffer is in a
1231 hidden group filter, open it.
1232
1233 If `ibuffer-jump-offer-only-visible-buffers' is non-nil, only offer
1234 visible buffers in the completion list. Calling the command with
1235 a prefix argument reverses the meaning of that variable."
1228 (interactive (list nil)) 1236 (interactive (list nil))
1229 (let ((table (mapcar #'(lambda (x) 1237 (let ((only-visible ibuffer-jump-offer-only-visible-buffers))
1230 (cons (buffer-name (car x)) 1238 (when current-prefix-arg
1231 (caddr x))) 1239 (setq only-visible (not only-visible)))
1232 (ibuffer-current-state-list t)))) 1240 (if only-visible
1233 (when (null table) 1241 (let ((table (mapcar #'(lambda (x)
1234 (error "No buffers!")) 1242 (buffer-name (car x)))
1235 (when (interactive-p) 1243 (ibuffer-current-state-list))))
1236 (setq name (completing-read "Jump to buffer: " table nil t))) 1244 (when (null table)
1237 (ibuffer-aif (assoc name table) 1245 (error "No buffers!"))
1238 (goto-char (cdr it)) 1246 (when (interactive-p)
1239 (error "No buffer with name %s" name)))) 1247 (setq name (completing-read "Jump to buffer: "
1248 table nil t))))
1249 (when (interactive-p)
1250 (setq name (read-buffer "Jump to buffer: " nil t))))
1251 (when (not (string= "" name))
1252 (let (buf-point)
1253 ;; Blindly search for our buffer: it is very likely that it is
1254 ;; not in a hidden filter group.
1255 (ibuffer-map-lines #'(lambda (buf marks)
1256 (when (string= (buffer-name buf) name)
1257 (setq buf-point (point))
1258 nil))
1259 t nil)
1260 (when (and
1261 (null buf-point)
1262 (not (null ibuffer-hidden-filter-groups)))
1263 ;; We did not find our buffer. It must be in a hidden filter
1264 ;; group, so go through all hidden filter groups to find it.
1265 (catch 'found
1266 (dolist (group ibuffer-hidden-filter-groups)
1267 (ibuffer-jump-to-filter-group group)
1268 (ibuffer-toggle-filter-group)
1269 (ibuffer-map-lines #'(lambda (buf marks)
1270 (when (string= (buffer-name buf) name)
1271 (setq buf-point (point))
1272 nil))
1273 t group)
1274 (if buf-point
1275 (throw 'found nil)
1276 (ibuffer-toggle-filter-group)))))
1277 (if (null buf-point)
1278 ;; Still not found even though we expanded all hidden filter
1279 ;; groups: that must be because it's hidden by predicate:
1280 ;; we won't bother trying to display it.
1281 (error "No buffer with name %s" name)
1282 (goto-char buf-point))))))
1240 1283
1241 ;;;###autoload 1284 ;;;###autoload
1242 (defun ibuffer-diff-with-file () 1285 (defun ibuffer-diff-with-file ()
1243 "View the differences between this buffer and its associated file. 1286 "View the differences between this buffer and its associated file.
1244 This requires the external program \"diff\" to be in your `exec-path'." 1287 This requires the external program \"diff\" to be in your `exec-path'."