*** empty log message ***
[bpt/emacs.git] / lisp / ibuf-ext.el
CommitLineData
cea3be93 1;;; ibuf-ext.el --- extensions for ibuffer -*-byte-compile-dynamic: t;-*-
25d2f683 2
30c93a61 3;; Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
25d2f683
CW
4
5;; Author: Colin Walters <walters@verbum.org>
6;; Created: 2 Dec 2001
25d2f683
CW
7;; Keywords: buffer, convenience
8
9;; This file is not currently part of GNU Emacs.
10
11;; This program is free software; you can redistribute it and/or
12;; modify it under the terms of the GNU General Public License as
13;; published by the Free Software Foundation; either version 2, or (at
14;; your option) any later version.
15
16;; This program is distributed in the hope that it will be useful, but
17;; WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19;; General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with this program ; see the file COPYING. If not, write to
23;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
25
26;;; Commentary:
27
28;; These functions should be automatically loaded when called, but you
29;; can explicity (require 'ibuf-ext) in your ~/.emacs to have them
30;; preloaded.
31
32;;; Code:
33
34(require 'ibuffer)
35
36(eval-when-compile
37 (require 'derived)
38 (require 'ibuf-macs)
39 (require 'cl))
40
41;;; Utility functions
42(defun ibuffer-delete-alist (key alist)
43 "Delete all entries in ALIST that have a key equal to KEY."
44 (let (entry)
45 (while (setq entry (assoc key alist))
46 (setq alist (delete entry alist)))
47 alist))
48
49(defun ibuffer-depropertize-string (str &optional nocopy)
50 "Return a copy of STR with text properties removed.
51If optional argument NOCOPY is non-nil, actually modify the string directly."
52 (let ((str (if nocopy
53 str
54 (copy-sequence str))))
55 (set-text-properties 0 (length str) nil str)
56 str))
57
58(defcustom ibuffer-never-show-predicates nil
59 "A list of predicates (a regexp or function) for buffers not to display.
60If a regexp, then it will be matched against the buffer's name.
61If a function, it will be called with the buffer as an argument, and
62should return non-nil if this buffer should not be shown."
63 :type '(repeat (choice regexp function))
64 :group 'ibuffer)
65
66(defcustom ibuffer-always-show-predicates nil
67 "A list of predicates (a regexp or function) for buffers to always display.
68If a regexp, then it will be matched against the buffer's name.
69If a function, it will be called with the buffer as an argument, and
70should return non-nil if this buffer should be shown.
71Note that buffers matching one of these predicates will be shown
72regardless of any active filters in this buffer."
73 :type '(repeat (choice regexp function))
74 :group 'ibuffer)
75
76(defvar ibuffer-tmp-hide-regexps nil
77 "A list of regexps which should match buffer names to not show.")
78
79(defvar ibuffer-tmp-show-regexps nil
80 "A list of regexps which should match buffer names to always show.")
81
82(defvar ibuffer-auto-mode nil
83 "If non-nil, Ibuffer auto-mode should be enabled for this buffer.
84Do not set this variable directly! Use the function
85`ibuffer-auto-mode' instead.")
86
87(defvar ibuffer-auto-buffers-changed nil)
88
89(defcustom ibuffer-occur-match-face 'font-lock-warning-face
90 "Face used for displaying matched strings for `ibuffer-do-occur'."
91 :type 'face
92 :group 'ibuffer)
93
94(defcustom ibuffer-saved-filters '(("gnus"
95 ((or (mode . message-mode)
96 (mode . mail-mode)
97 (mode . gnus-group-mode)
98 (mode . gnus-summary-mode)
99 (mode . gnus-article-mode))))
100 ("programming"
101 ((or (mode . emacs-lisp-mode)
102 (mode . cperl-mode)
103 (mode . c-mode)
104 (mode . java-mode)
105 (mode . idl-mode)
106 (mode . lisp-mode)))))
107
108 "An alist of filter qualifiers to switch between.
109
110This variable should look like ((\"STRING\" QUALIFIERS)
111 (\"STRING\" QUALIFIERS) ...), where
112QUALIFIERS is a list of the same form as
113`ibuffer-filtering-qualifiers'.
114See also the variables `ibuffer-filtering-qualifiers',
115`ibuffer-filtering-alist', and the functions
116`ibuffer-switch-to-saved-filters', `ibuffer-save-filters'."
117 :type '(repeat sexp)
118 :group 'ibuffer)
119
120(defvar ibuffer-filtering-qualifiers nil
121 "A list like (SYMBOL . QUALIFIER) which filters the current buffer list.
122See also `ibuffer-filtering-alist'.")
123
124;; This is now frobbed by `define-ibuffer-filter'.
125(defvar ibuffer-filtering-alist nil
126 "An alist of (SYMBOL DESCRIPTION FUNCTION) which describes a filter.
127
128You most likely do not want to modify this variable directly; see
129`define-ibuffer-filter'.
130
131SYMBOL is the symbolic name of the filter. DESCRIPTION is used when
132displaying information to the user. FUNCTION is given a buffer and
133the value of the qualifier, and returns non-nil if and only if the
134buffer should be displayed.")
135
d98be487
CW
136(defcustom ibuffer-filter-format-alist nil
137 "An alist which has special formats used when a filter is active.
138The contents of this variable should look like:
139 ((FILTER (FORMAT FORMAT ...)) (FILTER (FORMAT FORMAT ...)) ...)
140
141For example, suppose that when you add a filter for buffers whose
142major mode is `emacs-lisp-mode', you only want to see the mark and the
143name of the buffer. You could accomplish that by adding:
144 (mode ((mark \" \" name)))
145to this variable.")
146
147(defvar ibuffer-cached-filter-formats nil)
148(defvar ibuffer-compiled-filter-formats nil)
149
2c1bb3d3
CW
150(defcustom ibuffer-old-time 72
151 "The number of hours before a buffer is considered \"old\"."
152 :type '(choice (const :tag "72 hours (3 days)" 72)
153 (const :tag "48 hours (2 days)" 48)
154 (const :tag "24 hours (1 day)" 24)
155 (integer :tag "hours"))
25d2f683
CW
156 :group 'ibuffer)
157
158(defcustom ibuffer-save-with-custom t
159 "If non-nil, then use Custom to save interactively changed variables.
160Currently, this only applies to `ibuffer-saved-filters'."
161 :type 'boolean
162 :group 'ibuffer)
163
164(defun ibuffer-ext-visible-p (buf all &optional ibuffer-buf)
165 (or
166 (ibuffer-buf-matches-predicates buf ibuffer-tmp-show-regexps)
167 (and (not
168 (or
169 (ibuffer-buf-matches-predicates buf ibuffer-tmp-hide-regexps)
170 (ibuffer-buf-matches-predicates buf ibuffer-never-show-predicates)))
171 (or all
172 (not
173 (ibuffer-buf-matches-predicates buf ibuffer-maybe-show-predicates)))
174 (or ibuffer-view-ibuffer
175 (and ibuffer-buf
176 (not (eq ibuffer-buf buf))))
177 (or
178 (ibuffer-included-in-filters-p buf ibuffer-filtering-qualifiers)
179 (ibuffer-buf-matches-predicates buf ibuffer-always-show-predicates)))))
180
181(defun ibuffer-auto-update-changed ()
182 (when ibuffer-auto-buffers-changed
183 (setq ibuffer-auto-buffers-changed nil)
184 (mapcar #'(lambda (buf)
185 (ignore-errors
186 (with-current-buffer buf
187 (when (and ibuffer-auto-mode
188 (eq major-mode 'ibuffer-mode))
189 (ibuffer-update nil t)))))
190 (buffer-list))))
191
192;;;###autoload
193(defun ibuffer-auto-mode (&optional arg)
194 "Toggle use of Ibuffer's auto-update facility.
195With numeric ARG, enable auto-update if and only if ARG is positive."
196 (interactive)
197 (unless (eq major-mode 'ibuffer-mode)
198 (error "This buffer is not in Ibuffer mode"))
199 (set (make-local-variable 'ibuffer-auto-mode)
200 (if arg
201 (plusp arg)
202 (not ibuffer-auto-mode)))
203 (defadvice get-buffer-create (after ibuffer-notify-create activate)
204 (setq ibuffer-auto-buffers-changed t))
205 (defadvice kill-buffer (after ibuffer-notify-kill activate)
206 (setq ibuffer-auto-buffers-changed t))
207 (add-hook 'post-command-hook 'ibuffer-auto-update-changed)
208 (ibuffer-update-mode-name))
209
210;;;###autoload
211(defun ibuffer-mouse-filter-by-mode (event)
212 "Enable or disable filtering by the major mode chosen via mouse."
213 (interactive "e")
214 (ibuffer-interactive-filter-by-mode event))
215
216;;;###autoload
217(defun ibuffer-interactive-filter-by-mode (event-or-point)
218 "Enable or disable filtering by the major mode at point."
219 (interactive "d")
220 (if (eventp event-or-point)
221 (mouse-set-point event-or-point)
222 (goto-char event-or-point))
223 (let ((buf (ibuffer-current-buffer)))
224 (if (assq 'mode ibuffer-filtering-qualifiers)
225 (setq ibuffer-filtering-qualifiers
226 (ibuffer-delete-alist 'mode ibuffer-filtering-qualifiers))
227 (ibuffer-push-filter (cons 'mode
228 (with-current-buffer buf
229 major-mode)))))
230 (ibuffer-update nil t))
231
25d2f683
CW
232(define-ibuffer-op shell-command-pipe (command)
233 "Pipe the contents of each marked buffer to shell command COMMAND."
234 (:interactive "sPipe to shell command: "
235 :opstring "Shell command executed on"
236 :modifier-p nil)
237 (shell-command-on-region
238 (point-min) (point-max) command
239 (get-buffer-create "* ibuffer-shell-output*")))
240
25d2f683
CW
241(define-ibuffer-op shell-command-pipe-replace (command)
242 "Replace the contents of marked buffers with output of pipe to COMMAND."
243 (:interactive "sPipe to shell command (replace): "
244 :opstring "Buffer contents replaced in"
245 :active-opstring "replace buffer contents in"
246 :dangerous t
247 :modifier-p t)
248 (with-current-buffer buf
249 (shell-command-on-region (point-min) (point-max)
250 command nil t)))
251
25d2f683
CW
252(define-ibuffer-op shell-command-file (command)
253 "Run shell command COMMAND separately on files of marked buffers."
254 (:interactive "sShell command on buffer's file: "
255 :opstring "Shell command executed on"
256 :modifier-p nil)
257 (shell-command (concat command " "
258 (shell-quote-argument
259 (if buffer-file-name
260 buffer-file-name
261 (make-temp-file
262 (substring (buffer-name) 0 (min 10 (length (buffer-name))))))))))
263
25d2f683
CW
264(define-ibuffer-op eval (form)
265 "Evaluate FORM in each of the buffers.
266Does not display the buffer during evaluation. See
267`ibuffer-do-view-and-eval' for that."
268 (:interactive "xEval in buffers (form): "
269 :opstring "evaluated in"
270 :modifier-p :maybe)
271 (eval form))
272
25d2f683
CW
273(define-ibuffer-op view-and-eval (form)
274 "Evaluate FORM while displaying each of the marked buffers.
275To evaluate a form without viewing the buffer, see `ibuffer-do-eval'."
276 (:interactive "xEval viewing buffers (form): "
277 :opstring "evaluated in"
278 :complex t
279 :modifier-p :maybe)
280 (let ((ibuffer-buf (current-buffer)))
281 (unwind-protect
282 (progn
283 (switch-to-buffer buf)
284 (eval form))
285 (switch-to-buffer ibuffer-buf))))
286
25d2f683
CW
287(define-ibuffer-op rename-uniquely ()
288 "Rename marked buffers as with `rename-uniquely'."
289 (:opstring "renamed"
290 :modifier-p t)
291 (rename-uniquely))
292
25d2f683
CW
293(define-ibuffer-op revert ()
294 "Revert marked buffers as with `revert-buffer'."
295 (:dangerous t
296 :opstring "reverted"
297 :active-opstring "revert"
298 :modifier-p :maybe)
299 (revert-buffer t t))
300
25d2f683
CW
301(define-ibuffer-op replace-regexp (from-str to-str)
302 "Perform a `replace-regexp' in marked buffers."
303 (:interactive
304 (let* ((from-str (read-from-minibuffer "Replace regexp: "))
305 (to-str (read-from-minibuffer (concat "Replace " from-str
306 " with: "))))
307 (list from-str to-str))
308 :opstring "replaced in"
309 :complex t
310 :modifier-p :maybe)
311 (save-window-excursion
312 (switch-to-buffer buf)
313 (save-excursion
314 (goto-char (point-min))
315 (let ((case-fold-search ibuffer-case-fold-search))
316 (while (re-search-forward from-str nil t)
317 (replace-match to-str))))
318 t))
319
25d2f683
CW
320(define-ibuffer-op query-replace (&rest args)
321 "Perform a `query-replace' in marked buffers."
322 (:interactive
323 (query-replace-read-args "Query replace" t)
324 :opstring "replaced in"
325 :complex t
326 :modifier-p :maybe)
327 (save-window-excursion
328 (switch-to-buffer buf)
329 (save-excursion
330 (let ((case-fold-search ibuffer-case-fold-search))
331 (goto-char (point-min))
332 (apply #'query-replace args)))
333 t))
334
25d2f683
CW
335(define-ibuffer-op query-replace-regexp (&rest args)
336 "Perform a `query-replace-regexp' in marked buffers."
337 (:interactive
338 (query-replace-read-args "Query replace regexp" t)
339 :opstring "replaced in"
340 :complex t
341 :modifier-p :maybe)
342 (save-window-excursion
343 (switch-to-buffer buf)
344 (save-excursion
345 (let ((case-fold-search ibuffer-case-fold-search))
346 (goto-char (point-min))
347 (apply #'query-replace-regexp args)))
348 t))
349
25d2f683
CW
350(define-ibuffer-op print ()
351 "Print marked buffers as with `print-buffer'."
352 (:opstring "printed"
353 :modifier-p nil)
354 (print-buffer))
355
356;;;###autoload
357(defun ibuffer-included-in-filters-p (buf filters)
358 (not
359 (memq nil ;; a filter will return nil if it failed
360 (mapcar
361 ;; filter should be like (TYPE . QUALIFIER), or
362 ;; (or (TYPE . QUALIFIER) (TYPE . QUALIFIER) ...)
363 #'(lambda (qual)
364 (ibuffer-included-in-filter-p buf qual))
365 filters))))
366
367(defun ibuffer-included-in-filter-p (buf filter)
368 (if (eq (car filter) 'not)
369 (not (ibuffer-included-in-filter-p-1 buf (cdr filter)))
370 (ibuffer-included-in-filter-p-1 buf filter)))
371
372(defun ibuffer-included-in-filter-p-1 (buf filter)
373 (not
374 (not
375 (case (car filter)
376 (or
377 (memq t (mapcar #'(lambda (x)
378 (ibuffer-included-in-filter-p buf x))
379 (cdr filter))))
380 (saved
381 (let ((data
382 (assoc (cdr filter)
383 ibuffer-saved-filters)))
384 (unless data
385 (ibuffer-filter-disable)
386 (error "Unknown saved filter %s" (cdr filter)))
387 (ibuffer-included-in-filters-p buf (cadr data))))
388 (t
389 (let ((filterdat (assq (car filter)
390 ibuffer-filtering-alist)))
391 ;; filterdat should be like (TYPE DESCRIPTION FUNC)
392 ;; just a sanity check
393 (unless filterdat
394 (ibuffer-filter-disable)
395 (error "Undefined filter %s" (car filter)))
396 (not
397 (not
398 (funcall (caddr filterdat)
399 buf
400 (cdr filter))))))))))
401
402;;;###autoload
403(defun ibuffer-filter-disable ()
404 "Disable all filters currently in effect in this buffer."
405 (interactive)
406 (setq ibuffer-filtering-qualifiers nil)
407 (ibuffer-update nil t))
408
409;;;###autoload
410(defun ibuffer-pop-filter ()
411 "Remove the top filter in this buffer."
412 (interactive)
413 (when (null ibuffer-filtering-qualifiers)
414 (error "No filters in effect"))
415 (pop ibuffer-filtering-qualifiers)
416 (ibuffer-update nil t))
417
418(defun ibuffer-push-filter (qualifier)
419 "Add QUALIFIER to `ibuffer-filtering-qualifiers'."
420 (push qualifier ibuffer-filtering-qualifiers))
421
422;;;###autoload
423(defun ibuffer-decompose-filter ()
424 "Separate the top compound filter (OR, NOT, or SAVED) in this buffer.
425
426This means that the topmost filter on the filtering stack, which must
427be a complex filter like (OR [name: foo] [mode: bar-mode]), will be
428turned into two separate filters [name: foo] and [mode: bar-mode]."
429 (interactive)
430 (when (null ibuffer-filtering-qualifiers)
431 (error "No filters in effect"))
432 (let ((lim (pop ibuffer-filtering-qualifiers)))
433 (case (car lim)
434 (or
435 (setq ibuffer-filtering-qualifiers (append
436 (cdr lim)
437 ibuffer-filtering-qualifiers)))
438 (saved
439 (let ((data
440 (assoc (cdr lim)
441 ibuffer-saved-filters)))
442 (unless data
443 (ibuffer-filter-disable)
444 (error "Unknown saved filter %s" (cdr lim)))
445 (setq ibuffer-filtering-qualifiers (append
446 (cadr data)
447 ibuffer-filtering-qualifiers))))
448 (not
449 (push (cdr lim)
450 ibuffer-filtering-qualifiers))
451 (t
452 (error "Filter type %s is not compound" (car lim)))))
453 (ibuffer-update nil t))
454
455;;;###autoload
456(defun ibuffer-exchange-filters ()
457 "Exchange the top two filters on the stack in this buffer."
458 (interactive)
459 (when (< (length ibuffer-filtering-qualifiers)
460 2)
461 (error "Need two filters to exchange"))
462 (let ((first (pop ibuffer-filtering-qualifiers))
463 (second (pop ibuffer-filtering-qualifiers)))
464 (push first ibuffer-filtering-qualifiers)
465 (push second ibuffer-filtering-qualifiers))
466 (ibuffer-update nil t))
467
468;;;###autoload
469(defun ibuffer-negate-filter ()
470 "Negate the sense of the top filter in the current buffer."
471 (interactive)
472 (when (null ibuffer-filtering-qualifiers)
473 (error "No filters in effect"))
474 (let ((lim (pop ibuffer-filtering-qualifiers)))
475 (push (if (eq (car lim) 'not)
476 (cdr lim)
477 (cons 'not lim))
478 ibuffer-filtering-qualifiers))
479 (ibuffer-update nil t))
480
481;;;###autoload
482(defun ibuffer-or-filter (&optional reverse)
483 "Replace the top two filters in this buffer with their logical OR.
484If optional argument REVERSE is non-nil, instead break the top OR
485filter into parts."
486 (interactive "P")
487 (if reverse
488 (progn
489 (when (or (null ibuffer-filtering-qualifiers)
490 (not (eq 'or (caar ibuffer-filtering-qualifiers))))
491 (error "Top filter is not an OR"))
492 (let ((lim (pop ibuffer-filtering-qualifiers)))
493 (setq ibuffer-filtering-qualifiers (nconc (cdr lim) ibuffer-filtering-qualifiers))))
494 (when (< (length ibuffer-filtering-qualifiers) 2)
495 (error "Need two filters to OR"))
496 ;; If the second filter is an OR, just add to it.
497 (let ((first (pop ibuffer-filtering-qualifiers))
498 (second (pop ibuffer-filtering-qualifiers)))
499 (if (eq 'or (car second))
500 (push (nconc (list 'or first) (cdr second)) ibuffer-filtering-qualifiers)
501 (push (list 'or first second)
502 ibuffer-filtering-qualifiers))))
503 (ibuffer-update nil t))
504
505(defun ibuffer-maybe-save-saved-filters ()
506 (when ibuffer-save-with-custom
507 (if (fboundp 'customize-save-variable)
508 (progn
509 (customize-save-variable 'ibuffer-saved-filters
510 ibuffer-saved-filters))
511 (message "Not saved permanently: Customize not available"))))
512
513;;;###autoload
514(defun ibuffer-save-filters (name filters)
515 "Save FILTERS in this buffer with name NAME in `ibuffer-saved-filters'.
516Interactively, prompt for NAME, and use the current filters."
517 (interactive
518 (if (null ibuffer-filtering-qualifiers)
519 (error "No filters currently in effect")
520 (list
521 (read-from-minibuffer "Save current filters as: ")
522 ibuffer-filtering-qualifiers)))
523 (ibuffer-aif (assoc name ibuffer-saved-filters)
524 (setcdr it filters)
525 (push (list name filters) ibuffer-saved-filters))
526 (ibuffer-maybe-save-saved-filters)
527 (ibuffer-update-mode-name))
528
529;;;###autoload
530(defun ibuffer-delete-saved-filters (name)
531 "Delete saved filters with NAME from `ibuffer-saved-filters'."
532 (interactive
533 (list
534 (if (null ibuffer-saved-filters)
535 (error "No saved filters")
536 (completing-read "Delete saved filters: "
537 ibuffer-saved-filters nil t))))
538 (setq ibuffer-saved-filters
539 (ibuffer-delete-alist name ibuffer-saved-filters))
540 (ibuffer-maybe-save-saved-filters)
541 (ibuffer-update nil t))
542
543;;;###autoload
544(defun ibuffer-add-saved-filters (name)
545 "Add saved filters from `ibuffer-saved-filters' to this buffer's filters."
546 (interactive
547 (list
548 (if (null ibuffer-saved-filters)
549 (error "No saved filters")
550 (completing-read "Add saved filters: "
551 ibuffer-saved-filters nil t))))
552 (push (cons 'saved name) ibuffer-filtering-qualifiers)
553 (ibuffer-update nil t))
554
555;;;###autoload
556(defun ibuffer-switch-to-saved-filters (name)
557 "Set this buffer's filters to filters with NAME from `ibuffer-saved-filters'.
558If prefix argument ADD is non-nil, then add the saved filters instead
559of replacing the current filters."
560 (interactive
561 (list
562 (if (null ibuffer-saved-filters)
563 (error "No saved filters")
564 (completing-read "Switch to saved filters: "
565 ibuffer-saved-filters nil t))))
566 (setq ibuffer-filtering-qualifiers (list (cons 'saved name)))
567 (ibuffer-update nil t))
568
569(defun ibuffer-format-qualifier (qualifier)
570 (if (eq (car-safe qualifier) 'not)
571 (concat " [NOT" (ibuffer-format-qualifier-1 (cdr qualifier)) "]")
572 (ibuffer-format-qualifier-1 qualifier)))
573
574(defun ibuffer-format-qualifier-1 (qualifier)
575 (case (car qualifier)
576 (saved
577 (concat " [filter: " (cdr qualifier) "]"))
578 (or
579 (concat " [OR" (mapconcat #'ibuffer-format-qualifier
580 (cdr qualifier) "") "]"))
581 (t
582 (let ((type (assq (car qualifier) ibuffer-filtering-alist)))
583 (unless qualifier
584 (error "Ibuffer: bad qualifier %s" qualifier))
585 (concat " [" (cadr type) ": " (format "%s]" (cdr qualifier)))))))
586
587;;; Extra operation definitions
588
25d2f683
CW
589(define-ibuffer-filter mode
590 "Toggle current view to buffers with major mode QUALIFIER."
591 (:description "major mode"
592 :reader
593 (intern
594 (completing-read "Filter by major mode: " obarray
595 #'(lambda (e)
596 (string-match "-mode$"
597 (symbol-name e)))
598 t
599 (let ((buf (ibuffer-current-buffer)))
600 (if (and buf (buffer-live-p buf))
601 (with-current-buffer buf
602 (symbol-name major-mode))
603 "")))))
604 (eq qualifier (with-current-buffer buf major-mode)))
605
25d2f683
CW
606(define-ibuffer-filter name
607 "Toggle current view to buffers with name matching QUALIFIER."
608 (:description "buffer name"
609 :reader
610 (read-from-minibuffer "Filter by name (regexp): "))
611 (string-match qualifier (buffer-name buf)))
612
25d2f683
CW
613(define-ibuffer-filter filename
614 "Toggle current view to buffers with filename matching QUALIFIER."
615 (:description "filename"
616 :reader
617 (read-from-minibuffer "Filter by filename (regexp): "))
618 (ibuffer-awhen (buffer-file-name buf)
619 (string-match qualifier it)))
620
25d2f683
CW
621(define-ibuffer-filter size-gt
622 "Toggle current view to buffers with size greater than QUALIFIER."
623 (:description "size greater than"
624 :reader
625 (string-to-number (read-from-minibuffer "Filter by size greater than: ")))
626 (> (with-current-buffer buf (buffer-size))
627 qualifier))
628
25d2f683
CW
629(define-ibuffer-filter size-lt
630 "Toggle current view to buffers with size less than QUALIFIER."
631 (:description "size less than"
632 :reader
633 (string-to-number (read-from-minibuffer "Filter by size less than: ")))
634 (< (with-current-buffer buf (buffer-size))
635 qualifier))
636
25d2f683
CW
637(define-ibuffer-filter content
638 "Toggle current view to buffers whose contents match QUALIFIER."
639 (:description "content"
640 :reader
641 (read-from-minibuffer "Filter by content (regexp): "))
642 (with-current-buffer buf
643 (save-excursion
644 (goto-char (point-min))
645 (re-search-forward qualifier nil t))))
646
25d2f683
CW
647(define-ibuffer-filter predicate
648 "Toggle current view to buffers for which QUALIFIER returns non-nil."
649 (:description "predicate"
650 :reader
651 (read-minibuffer "Filter by predicate (form): "))
652 (with-current-buffer buf
653 (eval qualifier)))
654
655;;; Sorting
656
657;;;###autoload
658(defun ibuffer-toggle-sorting-mode ()
659 "Toggle the current sorting mode.
13e14c51 660Default sorting modes are:
25d2f683
CW
661 Recency - the last time the buffer was viewed
662 Name - the name of the buffer
663 Major Mode - the name of the major mode of the buffer
664 Size - the size of the buffer"
665 (interactive)
13e14c51
CW
666 (let ((modes (mapcar 'car ibuffer-sorting-functions-alist)))
667 (add-to-list 'modes 'recency)
668 (setq modes (sort modes 'string-lessp))
669 (let ((next (or (find-if
670 (lambda (x) (string-lessp ibuffer-sorting-mode x)) modes)
671 (car modes))))
672 (setq ibuffer-sorting-mode next)
673 (message "Sorting by %s" next)))
25d2f683
CW
674 (ibuffer-redisplay t))
675
676;;;###autoload
677(defun ibuffer-invert-sorting ()
678 "Toggle whether or not sorting is in reverse order."
679 (interactive)
680 (setq ibuffer-sorting-reversep (not ibuffer-sorting-reversep))
681 (message "Sorting order %s"
682 (if ibuffer-sorting-reversep
683 "reversed"
684 "normal"))
685 (ibuffer-redisplay t))
686
25d2f683
CW
687(define-ibuffer-sorter major-mode
688 "Sort the buffers by major modes.
689Ordering is lexicographic."
690 (:description "major mode")
691 (string-lessp (downcase
692 (symbol-name (with-current-buffer
693 (car a)
694 major-mode)))
695 (downcase
696 (symbol-name (with-current-buffer
697 (car b)
698 major-mode)))))
699
25d2f683
CW
700(define-ibuffer-sorter alphabetic
701 "Sort the buffers by their names.
702Ordering is lexicographic."
703 (:description "buffer name")
704 (string-lessp
705 (buffer-name (car a))
706 (buffer-name (car b))))
707
25d2f683
CW
708(define-ibuffer-sorter size
709 "Sort the buffers by their size."
710 (:description "size")
711 (< (with-current-buffer (car a)
712 (buffer-size))
713 (with-current-buffer (car b)
714 (buffer-size))))
715
716;;; Functions to emulate bs.el
717
718;;;###autoload
719(defun ibuffer-bs-show ()
720 "Emulate `bs-show' from the bs.el package."
721 (interactive)
722 (ibuffer t "*Ibuffer-bs*" '((filename . ".*")) nil t)
723 (define-key (current-local-map) "a" 'ibuffer-bs-toggle-all))
724
725(defun ibuffer-bs-toggle-all ()
726 "Emulate `bs-toggle-show-all' from the bs.el package."
727 (interactive)
728 (if ibuffer-filtering-qualifiers
729 (ibuffer-pop-filter)
730 (progn (ibuffer-push-filter '(filename . ".*"))
731 (ibuffer-update nil t))))
732
733;;; Handy functions
734
735;;;###autoload
736(defun ibuffer-add-to-tmp-hide (regexp)
737 "Add REGEXP to `ibuffer-tmp-hide-regexps'.
738This means that buffers whose name matches REGEXP will not be shown
739for this ibuffer session."
740 (interactive
741 (list
742 (read-from-minibuffer "Never show buffers matching: "
743 (regexp-quote (buffer-name (ibuffer-current-buffer t))))))
744 (push regexp ibuffer-tmp-hide-regexps))
745
746;;;###autoload
747(defun ibuffer-add-to-tmp-show (regexp)
748 "Add REGEXP to `ibuffer-tmp-show-regexps'.
749This means that buffers whose name matches REGEXP will always be shown
750for this ibuffer session."
751 (interactive
752 (list
753 (read-from-minibuffer "Always show buffers matching: "
754 (regexp-quote (buffer-name (ibuffer-current-buffer t))))))
755 (push regexp ibuffer-tmp-show-regexps))
756
757;;;###autoload
758(defun ibuffer-forward-next-marked (&optional count mark direction)
759 "Move forward by COUNT marked buffers (default 1).
760
761If MARK is non-nil, it should be a character denoting the type of mark
762to move by. The default is `ibuffer-marked-char'.
763
764If DIRECTION is non-nil, it should be an integer; negative integers
765mean move backwards, non-negative integers mean move forwards."
766 (interactive "P")
767 (unless count
768 (setq count 1))
769 (unless mark
770 (setq mark ibuffer-marked-char))
771 (unless direction
772 (setq direction 1))
773 ;; Skip the title
774 (ibuffer-forward-line 0)
775 (let ((opos (point))
776 curmark)
777 (ibuffer-forward-line direction)
778 (while (not (or (= (point) opos)
779 (eq (setq curmark (ibuffer-current-mark))
780 mark)))
781 (ibuffer-forward-line direction))
782 (when (and (= (point) opos)
783 (not (eq (ibuffer-current-mark) mark)))
784 (error "No buffers with mark %c" mark))))
785
786;;;###autoload
787(defun ibuffer-backwards-next-marked (&optional count mark)
788 "Move backwards by COUNT marked buffers (default 1).
789
790If MARK is non-nil, it should be a character denoting the type of mark
791to move by. The default is `ibuffer-marked-char'."
792 (interactive "P")
793 (ibuffer-forward-next-marked count mark -1))
794
795;;;###autoload
796(defun ibuffer-do-kill-lines ()
797 "Hide all of the currently marked lines."
798 (interactive)
799 (if (= (ibuffer-count-marked-lines) 0)
800 (message "No buffers marked; use 'm' to mark a buffer")
801 (let ((count
802 (ibuffer-map-marked-lines
803 #'(lambda (buf mark beg end)
804 'kill))))
805 (message "Killed %s lines" count))))
806
807;;;###autoload
808(defun ibuffer-jump-to-buffer (name)
809 "Move point to the buffer whose name is NAME."
810 (interactive (list nil))
811 (let ((table (mapcar #'(lambda (x)
812 (cons (buffer-name (car x))
813 (caddr x)))
814 (ibuffer-current-state-list t))))
815 (when (null table)
816 (error "No buffers!"))
817 (when (interactive-p)
818 (setq name (completing-read "Jump to buffer: " table nil t)))
819 (ibuffer-aif (assoc name table)
820 (goto-char (cdr it))
821 (error "No buffer with name %s" name))))
822
823;;;###autoload
824(defun ibuffer-diff-with-file ()
825 "View the differences between this buffer and its associated file.
826This requires the external program \"diff\" to be in your `exec-path'."
827 (interactive)
828 (let* ((buf (ibuffer-current-buffer))
829 (buf-filename (with-current-buffer buf
830 buffer-file-name)))
831 (unless (buffer-live-p buf)
832 (error "Buffer %s has been killed" buf))
833 (unless buf-filename
834 (error "Buffer %s has no associated file" buf))
835 (let ((diff-buf (get-buffer-create "*Ibuffer-diff*")))
836 (with-current-buffer diff-buf
837 (setq buffer-read-only nil)
838 (erase-buffer))
839 (let ((tempfile (make-temp-file "ibuffer-diff-")))
840 (unwind-protect
841 (progn
842 (with-current-buffer buf
843 (write-region (point-min) (point-max) tempfile nil 'nomessage))
844 (if (zerop
845 (apply #'call-process "diff" nil diff-buf nil
846 (append
847 (when (and (boundp 'ediff-custom-diff-options)
848 (stringp ediff-custom-diff-options))
849 (list ediff-custom-diff-options))
850 (list buf-filename tempfile))))
851 (message "No differences found")
852 (progn
853 (with-current-buffer diff-buf
854 (goto-char (point-min))
855 (if (fboundp 'diff-mode)
856 (diff-mode)
857 (fundamental-mode)))
858 (display-buffer diff-buf))))
859 (when (file-exists-p tempfile)
860 (delete-file tempfile)))))
861 nil))
862
863;;;###autoload
864(defun ibuffer-copy-filename-as-kill (&optional arg)
865 "Copy filenames of marked buffers into the kill ring.
866The names are separated by a space.
867If a buffer has no filename, it is ignored.
868With a zero prefix arg, use the complete pathname of each marked file.
869
870You can then feed the file name(s) to other commands with C-y.
871
872 [ This docstring shamelessly stolen from the
873 `dired-copy-filename-as-kill' in \"dired-x\". ]"
874 ;; Add to docstring later:
875 ;; With C-u, use the relative pathname of each marked file.
876 (interactive "P")
877 (if (= (ibuffer-count-marked-lines) 0)
878 (message "No buffers marked; use 'm' to mark a buffer")
879 (let ((ibuffer-copy-filename-as-kill-result "")
880 (type (cond ((eql arg 0)
881 'full)
882 ;; ((eql arg 4)
883 ;; 'relative)
884 (t
885 'name))))
886 (ibuffer-map-marked-lines
887 #'(lambda (buf mark beg end)
888 (setq ibuffer-copy-filename-as-kill-result
889 (concat ibuffer-copy-filename-as-kill-result
890 (let ((name (buffer-file-name buf)))
891 (if name
892 (case type
893 (full
894 name)
895 (t
896 (file-name-nondirectory name)))
897 ""))
898 " "))))
899 (push ibuffer-copy-filename-as-kill-result kill-ring))))
900
901(defun ibuffer-mark-on-buffer (func)
902 (let ((count
903 (ibuffer-map-lines
904 #'(lambda (buf mark beg end)
905 (when (funcall func buf)
906 (ibuffer-set-mark-1 ibuffer-marked-char)
907 t)))))
908 (ibuffer-redisplay t)
909 (message "Marked %s buffers" count)))
910
911;;;###autoload
912(defun ibuffer-mark-by-name-regexp (regexp)
913 "Mark all buffers whose name matches REGEXP."
914 (interactive "sMark by name (regexp): ")
915 (ibuffer-mark-on-buffer
916 #'(lambda (buf)
917 (string-match regexp (buffer-name buf)))))
918
919;;;###autoload
920(defun ibuffer-mark-by-mode-regexp (regexp)
921 "Mark all buffers whose major mode matches REGEXP."
922 (interactive "sMark by major mode (regexp): ")
923 (ibuffer-mark-on-buffer
924 #'(lambda (buf)
925 (with-current-buffer buf
926 (string-match regexp mode-name)))))
927
928;;;###autoload
929(defun ibuffer-mark-by-file-name-regexp (regexp)
930 "Mark all buffers whose file name matches REGEXP."
931 (interactive "sMark by file name (regexp): ")
932 (ibuffer-mark-on-buffer
933 #'(lambda (buf)
934 (let ((name (or (buffer-file-name buf)
935 (with-current-buffer buf
936 (and
937 (boundp 'dired-directory)
938 (stringp dired-directory)
939 dired-directory)))))
940 (when name
941 (string-match regexp name))))))
942
943;;;###autoload
944(defun ibuffer-mark-by-mode (mode)
945 "Mark all buffers whose major mode equals MODE."
946 (interactive
947 (list (intern (completing-read "Mark by major mode: " obarray
948 #'(lambda (e)
949 ;; kind of a hack...
950 (and (fboundp e)
951 (string-match "-mode$"
952 (symbol-name e))))
953 t
954 (let ((buf (ibuffer-current-buffer)))
955 (if (and buf (buffer-live-p buf))
956 (with-current-buffer buf
957 (cons (symbol-name major-mode)
958 0))
959 ""))))))
960 (ibuffer-mark-on-buffer
961 #'(lambda (buf)
962 (with-current-buffer buf
963 (eq major-mode mode)))))
964
965;;;###autoload
966(defun ibuffer-mark-modified-buffers ()
967 "Mark all modified buffers."
968 (interactive)
969 (ibuffer-mark-on-buffer
970 #'(lambda (buf) (buffer-modified-p buf))))
971
972;;;###autoload
973(defun ibuffer-mark-unsaved-buffers ()
974 "Mark all modified buffers that have an associated file."
975 (interactive)
976 (ibuffer-mark-on-buffer
977 #'(lambda (buf) (and (with-current-buffer buf buffer-file-name)
978 (buffer-modified-p buf)))))
979
980;;;###autoload
981(defun ibuffer-mark-dissociated-buffers ()
982 "Mark all buffers whose associated file does not exist."
983 (interactive)
984 (ibuffer-mark-on-buffer
985 #'(lambda (buf)
986 (with-current-buffer buf
987 (or
988 (and buffer-file-name
989 (not (file-exists-p buffer-file-name)))
990 (and (eq major-mode 'dired-mode)
991 (boundp 'dired-directory)
992 (stringp dired-directory)
993 (not (file-exists-p (file-name-directory dired-directory)))))))))
994
995;;;###autoload
996(defun ibuffer-mark-help-buffers ()
997 "Mark buffers like *Help*, *Apropos*, *Info*."
998 (interactive)
999 (ibuffer-mark-on-buffer
1000 #'(lambda (buf)
1001 (with-current-buffer buf
1002 (or
1003 (eq major-mode 'apropos-mode)
1004 (eq major-mode 'help-mode)
1005 (eq major-mode 'info-mode))))))
1006
1007;;;###autoload
1008(defun ibuffer-mark-old-buffers ()
1009 "Mark buffers which have not been viewed in `ibuffer-old-time' days."
1010 (interactive)
1011 (ibuffer-mark-on-buffer
1012 #'(lambda (buf)
1013 (with-current-buffer buf
1014 ;; hacked from midnight.el
1015 (when buffer-display-time
1016 (let* ((tm (current-time))
1017 (now (+ (* (float (ash 1 16)) (car tm))
1018 (float (cadr tm)) (* 0.0000001 (caddr tm))))
1019 (then (+ (* (float (ash 1 16))
1020 (car buffer-display-time))
1021 (float (cadr buffer-display-time))
1022 (* 0.0000001 (caddr buffer-display-time)))))
2c1bb3d3 1023 (> (- now then) (* 60 60 ibuffer-old-time))))))))
25d2f683
CW
1024
1025;;;###autoload
1026(defun ibuffer-mark-special-buffers ()
1027 "Mark all buffers whose name begins and ends with '*'."
1028 (interactive)
1029 (ibuffer-mark-on-buffer
1030 #'(lambda (buf) (string-match "^\\*.+\\*$"
1031 (buffer-name buf)))))
1032
1033;;;###autoload
1034(defun ibuffer-mark-read-only-buffers ()
1035 "Mark all read-only buffers."
1036 (interactive)
1037 (ibuffer-mark-on-buffer
1038 #'(lambda (buf)
1039 (with-current-buffer buf
1040 buffer-read-only))))
1041
1042;;;###autoload
1043(defun ibuffer-mark-dired-buffers ()
1044 "Mark all `dired' buffers."
1045 (interactive)
1046 (ibuffer-mark-on-buffer
1047 #'(lambda (buf)
1048 (with-current-buffer buf
1049 (eq major-mode 'dired-mode)))))
1050
1051;;; An implementation of multi-buffer `occur'
1052
1053(defvar ibuffer-occur-props nil)
1054
1055(define-derived-mode ibuffer-occur-mode occur-mode "Ibuffer-Occur"
1056 "A special form of Occur mode for multiple buffers.
1057Note this major mode is not meant for interactive use!
1058See also `occur-mode'."
1059 (define-key ibuffer-occur-mode-map (kbd "n") 'forward-line)
1060 (define-key ibuffer-occur-mode-map (kbd "q") 'bury-buffer)
1061 (define-key ibuffer-occur-mode-map (kbd "p") 'previous-line)
1062 (define-key ibuffer-occur-mode-map (kbd "RET") 'ibuffer-occur-display-occurence)
1063 (define-key ibuffer-occur-mode-map (kbd "f") 'ibuffer-occur-goto-occurence)
1064 (define-key ibuffer-occur-mode-map [(mouse-2)] 'ibuffer-occur-mouse-display-occurence)
1065 (set (make-local-variable 'revert-buffer-function)
1066 #'ibuffer-occur-revert-buffer-function)
1067 (set (make-local-variable 'ibuffer-occur-props) nil)
1068 (setq buffer-read-only nil)
1069 (erase-buffer)
1070 (setq buffer-read-only t)
1071 (message (concat
1072 "Use RET "
1073 (if (or (and (< 21 emacs-major-version)
1074 window-system)
1075 (featurep 'mouse))
1076 "or mouse-2 ")
1077 "to display an occurence.")))
1078
1079(defun ibuffer-occur-mouse-display-occurence (e)
1080 "Display occurence on this line in another window."
1081 (interactive "e")
1082 (let* ((occurbuf (save-window-excursion (mouse-select-window e)
1083 (selected-window)))
1084 (target (with-current-buffer occurbuf
1085 (get-text-property (save-excursion
1086 (mouse-set-point e)
1087 (point))
1088 'ibuffer-occur-target))))
1089 (unless target
1090 (error "No occurence on this line"))
1091 (let ((buf (car target))
1092 (line (cdr target)))
1093 (switch-to-buffer occurbuf)
1094 (delete-other-windows)
1095 (pop-to-buffer buf)
1096 (goto-line line))))
1097
1098(defun ibuffer-occur-goto-occurence ()
1099 "Switch to the buffer which has the occurence on this line."
1100 (interactive)
1101 (ibuffer-occur-display-occurence t))
1102
1103(defun ibuffer-occur-display-occurence (&optional goto)
1104 "Display occurence on this line in another window."
1105 (interactive "P")
1106 (let ((target (get-text-property (point) 'ibuffer-occur-target)))
1107 (unless target
1108 (error "No occurence on this line"))
1109 (let ((buf (car target))
1110 (line (cdr target)))
1111 (delete-other-windows)
1112 (if goto
1113 (switch-to-buffer buf)
1114 (pop-to-buffer buf))
1115 (goto-line line))))
1116
1117;;;###autoload
1118(defun ibuffer-do-occur (regexp &optional nlines)
1119 "View lines which match REGEXP in all marked buffers.
1120Optional argument NLINES says how many lines of context to display: it
1121defaults to one."
1122 (interactive
1123 (list (let* ((default (car regexp-history))
1124 (input
1125 (read-from-minibuffer
1126 (if default
1127 (format "List lines matching regexp (default `%s'): "
1128 default)
1129 "List lines matching regexp: ")
1130 nil
1131 nil
1132 nil
1133 'regexp-history)))
1134 (if (equal input "")
1135 default
1136 input))
1137 current-prefix-arg))
1138 (if (or (not (integerp nlines))
1139 (< nlines 0))
1140 (setq nlines 1))
1141 (when (zerop (ibuffer-count-marked-lines))
1142 (ibuffer-set-mark 'ibuffer-marked-char))
1143 (let ((ibuffer-do-occur-bufs nil))
1144 ;; Accumulate a list of marked buffers
1145 (ibuffer-map-marked-lines
1146 #'(lambda (buf mark beg end)
1147 (push buf ibuffer-do-occur-bufs)))
1148 (ibuffer-do-occur-1 regexp ibuffer-do-occur-bufs
1149 (get-buffer-create "*Ibuffer-occur*")
1150 nlines)))
1151
1152(defun ibuffer-do-occur-1 (regexp buffers out-buf nlines)
1153 (let ((count (ibuffer-occur-engine regexp buffers out-buf nlines)))
1154 (if (> count 0)
1155 (progn
1156 (switch-to-buffer out-buf)
1157 (setq buffer-read-only t)
1158 (delete-other-windows)
1159 (goto-char (point-min))
1160 (message "Found %s matches in %s buffers" count (length buffers)))
1161 (message "No matches found"))))
1162
1163
1164(defun ibuffer-occur-revert-buffer-function (ignore-auto noconfirm)
1165 "Update the *Ibuffer occur* buffer."
1166 (assert (eq major-mode 'ibuffer-occur-mode))
1167 (ibuffer-do-occur-1 (car ibuffer-occur-props)
1168 (cadr ibuffer-occur-props)
1169 (current-buffer)
1170 (caddr ibuffer-occur-props)))
1171
1172(defun ibuffer-occur-engine (regexp buffers out-buf nlines)
1173 (macrolet ((insert-get-point
1174 (&rest args)
1175 `(progn
1176 (insert ,@args)
1177 (point)))
1178 (maybe-put-overlay
1179 (over prop value)
1180 `(when (ibuffer-use-fontification)
1181 (overlay-put ,over ,prop ,value)))
1182 (maybe-ibuffer-propertize
1183 (obj &rest args)
1184 (let ((objsym (gensym "--maybe-ibuffer-propertize-")))
1185 `(let ((,objsym ,obj))
1186 (if (ibuffer-use-fontification)
1187 (propertize ,objsym ,@args)
1188 ,objsym)))))
1189 (with-current-buffer out-buf
1190 (ibuffer-occur-mode)
1191 (setq buffer-read-only nil)
1192 (let ((globalcount 0))
1193 ;; Map over all the buffers
1194 (dolist (buf buffers)
1195 (when (buffer-live-p buf)
1196 (let ((c 0) ;; count of matched lines
1197 (l 1) ;; line count
1198 (headerpt (with-current-buffer out-buf (point))))
1199 (save-excursion
1200 (set-buffer buf)
1201 (save-excursion
1202 (goto-char (point-min)) ;; begin searching in the buffer
1203 (while (not (eobp))
1204 ;; The line we're matching against
1205 (let ((curline (buffer-substring
1206 (line-beginning-position)
1207 (line-end-position))))
1208 (when (string-match regexp curline)
1209 (incf c) ;; increment match count
1210 (incf globalcount)
1211 ;; Depropertize the string, and maybe highlight the matches
1212 (setq curline
1213 (progn
1214 (ibuffer-depropertize-string curline t)
1215 (when (ibuffer-use-fontification)
1216 (let ((len (length curline))
1217 (start 0))
1218 (while (and (< start len)
1219 (string-match regexp curline start))
1220 (put-text-property (match-beginning 0)
1221 (match-end 0)
1222 'face ibuffer-occur-match-face
1223 curline)
1224 (setq start (match-end 0)))))
1225 curline))
1226 ;; Generate the string to insert for this match
1227 (let ((data
1228 (if (= nlines 1)
1229 ;; The simple display style
1230 (concat (maybe-ibuffer-propertize
1231 (format "%-6d:" l)
1232 'face 'bold)
1233 curline
1234 "\n")
1235 ;; The complex multi-line display style
1236 (let ((prevlines (nreverse
1237 (ibuffer-accumulate-lines (- nlines))))
1238 (nextlines (ibuffer-accumulate-lines nlines))
1239 ;; The lack of `flet' seriously sucks.
1240 (fun #'(lambda (lines)
1241 (mapcar
1242 #'(lambda (line)
1243 (concat " :" line "\n"))
1244 lines))))
1245 (setq prevlines (funcall fun prevlines))
1246 (setq nextlines (funcall fun nextlines))
1247 ;; Yes, I am trying to win the award for the
1248 ;; most consing.
1249 (apply #'concat
1250 (nconc
1251 prevlines
1252 (list
1253 (concat
1254 (maybe-ibuffer-propertize
1255 (format "%-6d" l)
1256 'face 'bold)
1257 ":"
1258 curline
1259 "\n"))
1260 nextlines))))))
1261 ;; Actually insert the match display data
1262 (with-current-buffer out-buf
1263 (let ((beg (point))
1264 (end (insert-get-point
1265 data)))
1266 (unless (= nlines 1)
1267 (insert "-------\n"))
1268 (put-text-property
1269 beg (1- end) 'ibuffer-occur-target (cons buf l))
1270 (put-text-property
1271 beg (1- end) 'mouse-face 'highlight))))))
1272 ;; On to the next line...
1273 (incf l)
1274 (forward-line 1))))
1275 (when (not (zerop c)) ;; is the count zero?
1276 (with-current-buffer out-buf
1277 (goto-char headerpt)
1278 (let ((beg (point))
1279 (end (insert-get-point
1280 (format "%d lines matching \"%s\" in buffer %s\n"
1281 c regexp (buffer-name buf)))))
1282 (let ((o (make-overlay beg end)))
1283 (maybe-put-overlay o 'face 'underline)))
1284 (goto-char (point-max)))))))
1285 (setq ibuffer-occur-props (list regexp buffers nlines))
1286 ;; Return the number of matches
1287 globalcount))))
1288
1289(provide 'ibuf-ext)
1290
1291;;; ibuf-ext.el ends here