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