;;; ibuffer.el --- operate on buffers like dired
-;; 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>
;; Created: 8 Sep 2000
;; Keywords: buffer, convenience
-;; This file is not currently part of GNU Emacs.
+;; This file is part of GNU Emacs.
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
(require 'ibuf-macs)
(require 'dired))
-;;; Compatibility
-(eval-and-compile
- (if (fboundp 'window-list)
- (defun ibuffer-window-list ()
- (window-list nil 'nomini))
- (defun ibuffer-window-list ()
- (let ((ibuffer-window-list-result nil))
- (walk-windows #'(lambda (win) (push win ibuffer-window-list-result)) 'nomini)
- (nreverse ibuffer-window-list-result))))
-
- (cond ((boundp 'global-font-lock-mode)
- (defsubst ibuffer-use-fontification ()
- (when (boundp 'font-lock-mode)
- font-lock-mode)))
- ((boundp 'font-lock-auto-fontify)
- (defsubst ibuffer-use-fontification ()
- font-lock-auto-fontify))
- (t
- (defsubst ibuffer-use-fontification ()
- nil))))
+(require 'font-core)
(defgroup ibuffer nil
"An advanced replacement for `buffer-menu'.
Ibuffer allows you to operate on buffers in a manner much like Dired.
Operations include sorting, marking by regular expression, and
the ability to filter the displayed buffers by various criteria."
+ :version "22.1"
:group 'convenience)
-(defcustom ibuffer-formats '((mark modified read-only " " (name 16 16 :left :elide)
- " " (size 6 -1 :right)
- " " (mode 16 16 :right :elide) " " filename)
+(defcustom ibuffer-formats '((mark modified read-only " " (name 18 18 :left :elide)
+ " " (size 9 -1 :right)
+ " " (mode 16 16 :right :elide) " " filename-and-process)
(mark " " (name 16 -1) " " filename))
"A list of ways to display buffer lines.
With Ibuffer, you are not limited to displaying just certain
attributes of a buffer such as size, name, and mode in a particular
-fashion. Through this variable, you can completely customize and
+order. Through this variable, you can completely customize and
control the appearance of an Ibuffer buffer. See also
`define-ibuffer-column', which allows you to define your own columns
for display.
read-only status, as well as the name of the buffer and its size. In
this format, the name is restricted to 16 characters (longer names
will be truncated, and shorter names will be padded with spaces), and
- the name is also aligned to the right. The size of the buffer will
+ the name is also aligned to the left. The size of the buffer will
be padded with spaces up to a minimum of six characters, but there is
no upper limit on its size. The size will also be aligned to the
right.
:group 'ibuffer)
(defcustom ibuffer-fontification-alist
- `((10 buffer-read-only font-lock-reference-face)
+ `((10 buffer-read-only font-lock-constant-face)
(15 (string-match "^*" (buffer-name)) font-lock-keyword-face)
- (20 (string-match "^ " (buffer-name)) font-lock-warning-face)
- (25 (memq major-mode '(help-mode apropos-mode info-mode)) font-lock-comment-face)
+ (20 (and (string-match "^ " (buffer-name))
+ (null buffer-file-name))
+ italic)
+ (25 (memq major-mode ibuffer-help-buffer-modes) font-lock-comment-face)
(30 (eq major-mode 'dired-mode) font-lock-function-name-face))
"An alist describing how to fontify buffers.
Each element should be of the form (PRIORITY FORM FACE), where
PRIORITY is an integer, FORM is an arbitrary form to evaluate in the
buffer, and FACE is the face to use for fontification. If the FORM
evaluates to non-nil, then FACE will be put on the buffer name. The
-element with the highest PRIORITY takes precedence."
+element with the highest PRIORITY takes precedence.
+
+If you change this variable, you must kill the Ibuffer buffer and
+recreate it for the change to take effect."
:type '(repeat
(list (integer :tag "Priority")
(sexp :tag "Test Form")
:group 'ibuffer)
(defcustom ibuffer-use-other-window nil
- "If non-nil, display the Ibuffer in another window by default."
+ "If non-nil, display Ibuffer in another window by default."
:type 'boolean
:group 'ibuffer)
:group 'ibuffer)
(defvar ibuffer-shrink-to-minimum-size nil)
+(defcustom ibuffer-display-summary t
+ "If non-nil, summarize Ibuffer columns."
+ :type 'boolean
+ :group 'ibuffer)
+
(defcustom ibuffer-truncate-lines t
"If non-nil, do not display continuation lines."
:type 'boolean
(defcustom ibuffer-default-sorting-mode 'recency
"The criteria by which to sort the buffers.
-Note that this variable is local to each ibuffer buffer. Thus, you
-can have multiple ibuffer buffers open, each with a different sorted
+Note that this variable is local to each Ibuffer buffer. Thus, you
+can have multiple Ibuffer buffers open, each with a different sorted
view of the buffers."
:type '(choice (const :tag "Last view time" :value recency)
(const :tag "Lexicographic" :value alphabetic)
(defcustom ibuffer-maybe-show-predicates `(,(lambda (buf)
(and (string-match "^ " (buffer-name buf))
(null buffer-file-name))))
- "A list of predicates (a regexp or function) for buffers to display conditionally.
+ "A list of predicates for buffers to display conditionally.
+
+A predicate can be a regexp or a function.
If a regexp, then it will be matched against the buffer's name.
If a function, it will be called with the buffer as an argument, and
should return non-nil if this buffer should be shown.
-Viewing of buffers hidden because of these predicates is enabled by
-giving a non-nil prefix argument to `ibuffer-update'. Note that this
-specialized filtering occurs before real filtering."
+Viewing of buffers hidden because of these predicates may be customized
+via `ibuffer-default-display-maybe-show-predicates' and is toggled by
+giving a non-nil prefix argument to `ibuffer-update'.
+Note that this specialized filtering occurs before real filtering."
:type '(repeat (choice regexp function))
:group 'ibuffer)
+(defcustom ibuffer-default-display-maybe-show-predicates nil
+ "Non-nil means show buffers that match `ibuffer-maybe-show-predicates'."
+ :type 'boolean
+ :group 'ibuffer)
+
+(defvar ibuffer-display-maybe-show-predicates nil)
+
(defvar ibuffer-current-format nil)
+(defcustom ibuffer-movement-cycle t
+ "If non-nil, then forward and backwards movement commands cycle."
+ :type 'boolean
+ :group 'ibuffer)
+
(defcustom ibuffer-modified-char ?*
"The character to display for modified buffers."
:type 'character
:group 'ibuffer)
(defcustom ibuffer-always-show-last-buffer nil
- "If non-nil, always display the previous buffer. This variable
-takes precedence over filtering, and even
+ "If non-nil, always display the previous buffer.
+This variable takes precedence over filtering, and even
`ibuffer-never-show-predicates'."
:type '(choice (const :tag "Always" :value t)
(const :tag "Never" :value nil)
(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.
-This feature only works on Emacs 21 or later."
+ "If non-nil, display a header line containing current filters."
:type 'boolean
:group 'ibuffer)
(defcustom ibuffer-default-directory nil
- "The default directory to use for a new ibuffer buffer.
+ "The default directory to use for a new Ibuffer buffer.
If nil, inherit the directory of the buffer in which `ibuffer' was
called. Otherwise, this variable should be a string naming a
directory, like `default-directory'."
string)
:group 'ibuffer)
-(defcustom ibuffer-hooks nil
- "Hooks run when `ibuffer' is called."
+(defcustom ibuffer-help-buffer-modes
+ '(help-mode apropos-mode Info-mode Info-edit-mode)
+ "List of \"Help\" major modes."
+ :type '(repeat function)
+ :group 'ibuffer)
+
+(defcustom ibuffer-hook nil
+ "Hook run when `ibuffer' is called."
+ :type 'hook
+ :group 'ibuffer)
+(defvaralias 'ibuffer-hooks 'ibuffer-hook)
+
+(defcustom ibuffer-mode-hook nil
+ "Hook run upon entry into `ibuffer-mode'."
:type 'hook
:group 'ibuffer)
+(defvaralias 'ibuffer-mode-hooks 'ibuffer-mode-hook)
-(defcustom ibuffer-mode-hooks nil
- "Hooks run upon entry into `ibuffer-mode'."
+(defcustom ibuffer-load-hook nil
+ "Hook run when Ibuffer is loaded."
:type 'hook
:group 'ibuffer)
:type 'face
:group 'ibuffer)
+(defcustom ibuffer-filter-group-name-face 'bold
+ "Face used for displaying filtering group names."
+ :type 'face
+ :group 'ibuffer)
+
(defcustom ibuffer-directory-abbrev-alist nil
"An alist of file name abbreviations like `directory-abbrev-alist'."
:type '(repeat (cons :format "%v"
(regexp :tag "To")))
:group 'ibuffer)
+
(defvar ibuffer-mode-map nil)
(defvar ibuffer-mode-operate-map nil)
+(defvar ibuffer-mode-groups-popup nil)
(unless ibuffer-mode-map
(let ((map (make-sparse-keymap))
- (operate-map (make-sparse-keymap "Operate")))
+ (operate-map (make-sparse-keymap "Operate"))
+ (groups-map (make-sparse-keymap "Filter Groups")))
(define-key map (kbd "0") 'digit-argument)
(define-key map (kbd "1") 'digit-argument)
(define-key map (kbd "2") 'digit-argument)
(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)
(define-key map (kbd "* e") 'ibuffer-mark-dissociated-buffers)
(define-key map (kbd "* h") 'ibuffer-mark-help-buffers)
(define-key map (kbd ".") 'ibuffer-mark-old-buffers)
-
+
(define-key map (kbd "d") 'ibuffer-mark-for-delete)
(define-key map (kbd "C-d") 'ibuffer-mark-for-delete-backwards)
(define-key map (kbd "k") 'ibuffer-mark-for-delete)
(define-key map (kbd "x") 'ibuffer-do-kill-on-deletion-marks)
-
+
;; immediate operations
(define-key map (kbd "n") 'ibuffer-forward-line)
+ (define-key map (kbd "<down>") 'ibuffer-forward-line)
(define-key map (kbd "SPC") 'forward-line)
(define-key map (kbd "p") 'ibuffer-backward-line)
+ (define-key map (kbd "<up>") 'ibuffer-backward-line)
(define-key map (kbd "M-}") 'ibuffer-forward-next-marked)
(define-key map (kbd "M-{") 'ibuffer-backwards-next-marked)
(define-key map (kbd "l") 'ibuffer-redisplay)
(define-key map (kbd "s m") 'ibuffer-do-sort-by-major-mode)
(define-key map (kbd "/ m") 'ibuffer-filter-by-mode)
+ (define-key map (kbd "/ M") 'ibuffer-filter-by-used-mode)
(define-key map (kbd "/ n") 'ibuffer-filter-by-name)
(define-key map (kbd "/ c") 'ibuffer-filter-by-content)
(define-key map (kbd "/ e") 'ibuffer-filter-by-predicate)
(define-key map (kbd "/ t") 'ibuffer-exchange-filters)
(define-key map (kbd "/ TAB") 'ibuffer-exchange-filters)
(define-key map (kbd "/ o") 'ibuffer-or-filter)
+ (define-key map (kbd "/ g") 'ibuffer-filters-to-filter-group)
+ (define-key map (kbd "/ P") 'ibuffer-pop-filter-group)
+ (define-key map (kbd "/ D") 'ibuffer-decompose-filter-group)
(define-key map (kbd "/ /") 'ibuffer-filter-disable)
-
+
+ (define-key map (kbd "M-n") 'ibuffer-forward-filter-group)
+ (define-key map (kbd "<right>") 'ibuffer-forward-filter-group)
+ (define-key map (kbd "M-p") 'ibuffer-backward-filter-group)
+ (define-key map (kbd "<left>") 'ibuffer-backward-filter-group)
+ (define-key map (kbd "M-j") 'ibuffer-jump-to-filter-group)
+ (define-key map (kbd "C-k") 'ibuffer-kill-line)
+ (define-key map (kbd "C-y") 'ibuffer-yank)
+ (define-key map (kbd "/ S") 'ibuffer-save-filter-groups)
+ (define-key map (kbd "/ R") 'ibuffer-switch-to-saved-filter-groups)
+ (define-key map (kbd "/ X") 'ibuffer-delete-saved-filter-groups)
+ (define-key map (kbd "/ \\") 'ibuffer-clear-filter-groups)
+
(define-key map (kbd "q") 'ibuffer-quit)
(define-key map (kbd "h") 'describe-mode)
(define-key map (kbd "?") 'describe-mode)
(define-key map (kbd "% n") 'ibuffer-mark-by-name-regexp)
(define-key map (kbd "% m") 'ibuffer-mark-by-mode-regexp)
(define-key map (kbd "% f") 'ibuffer-mark-by-file-name-regexp)
-
+
(define-key map (kbd "C-t") 'ibuffer-visit-tags-table)
(define-key map (kbd "|") 'ibuffer-do-shell-command-pipe)
(define-key map (kbd "V") 'ibuffer-do-revert)
(define-key map (kbd "W") 'ibuffer-do-view-and-eval)
(define-key map (kbd "X") 'ibuffer-do-shell-command-pipe)
-
+
(define-key map (kbd "k") 'ibuffer-do-kill-lines)
(define-key map (kbd "w") 'ibuffer-copy-filename-as-kill)
(cons "Sort" (make-sparse-keymap "Sort")))
(define-key-after map [menu-bar view sort do-sort-by-major-mode]
- '(menu-item "Sort by major mode" ibuffer-do-sort-by-major-mode
- :help "Sort by the alphabetic order of the buffer's major mode"))
+ '(menu-item "Sort by major mode" ibuffer-do-sort-by-major-mode))
(define-key-after map [menu-bar view sort do-sort-by-size]
- '(menu-item "Sort by buffer size" ibuffer-do-sort-by-size
- :help "Sort by the size of the buffer"))
+ '(menu-item "Sort by buffer size" ibuffer-do-sort-by-size))
(define-key-after map [menu-bar view sort do-sort-by-alphabetic]
'(menu-item "Sort lexicographically" ibuffer-do-sort-by-alphabetic
:help "Sort by the alphabetic order of buffer name"))
(define-key-after map [menu-bar view sort do-sort-by-recency]
'(menu-item "Sort by view time" ibuffer-do-sort-by-recency
:help "Sort by the last time the buffer was displayed"))
+ (define-key-after map [menu-bar view sort dashes]
+ '("--"))
(define-key-after map [menu-bar view sort invert-sorting]
'(menu-item "Reverse sorting order" ibuffer-invert-sorting))
(define-key-after map [menu-bar view sort toggle-sorting-mode]
(cons "Filter" (make-sparse-keymap "Filter")))
(define-key-after map [menu-bar view filter filter-disable]
- '(menu-item "Disable all filtering" ibuffer-filter-disable))
+ '(menu-item "Disable all filtering" ibuffer-filter-disable
+ :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)))
(define-key-after map [menu-bar view filter filter-by-mode]
- '(menu-item "Add filter by major mode..." ibuffer-filter-by-mode
- :help "Show only buffers in a major mode"))
+ '(menu-item "Add filter by major mode..." ibuffer-filter-by-mode))
+ (define-key-after map [menu-bar view filter filter-by-mode]
+ '(menu-item "Add filter by major mode in use..." ibuffer-filter-by-used-mode))
(define-key-after map [menu-bar view filter filter-by-name]
- '(menu-item "Add filter by buffer name..." ibuffer-filter-by-name
- :help "Show only buffers whose name matches a regexp"))
+ '(menu-item "Add filter by buffer name..." ibuffer-filter-by-name))
(define-key-after map [menu-bar view filter filter-by-filename]
- '(menu-item "Add filter by filename..." ibuffer-filter-by-filename
- :help "Show only buffers whose filename matches a regexp"))
+ '(menu-item "Add filter by filename..." ibuffer-filter-by-filename))
(define-key-after map [menu-bar view filter filter-by-size-lt]
- '(menu-item "Add filter by size less than..." ibuffer-filter-by-size-lt
- :help "Show only buffers of size less than..."))
+ '(menu-item "Add filter by size less than..." ibuffer-filter-by-size-lt))
(define-key-after map [menu-bar view filter filter-by-size-gt]
- '(menu-item "Add filter by size greater than..." ibuffer-filter-by-size-gt
- :help "Show only buffers of size greater than..."))
+ '(menu-item "Add filter by size greater than..." ibuffer-filter-by-size-gt))
(define-key-after map [menu-bar view filter filter-by-content]
- '(menu-item "Add filter by content (regexp)..." ibuffer-filter-by-content
- :help "Show only buffers containing a regexp"))
+ '(menu-item "Add filter by content (regexp)..." ibuffer-filter-by-content))
(define-key-after map [menu-bar view filter filter-by-predicate]
- '(menu-item "Add filter by Lisp predicate..." ibuffer-filter-by-predicate
- :help "Show only buffers for which a predicate is true"))
+ '(menu-item "Add filter by Lisp predicate..." ibuffer-filter-by-predicate))
(define-key-after map [menu-bar view filter pop-filter]
- '(menu-item "Remove top filter" ibuffer-pop-filter))
+ '(menu-item "Remove top filter" ibuffer-pop-filter
+ :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)))
(define-key-after map [menu-bar view filter or-filter]
'(menu-item "OR top two filters" ibuffer-or-filter
+ :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers
+ (cdr ibuffer-filtering-qualifiers))
:help "Create a new filter which is the logical OR of the top two filters"))
(define-key-after map [menu-bar view filter negate-filter]
- '(menu-item "Negate top filter" ibuffer-negate-filter))
+ '(menu-item "Negate top filter" ibuffer-negate-filter
+ :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)))
(define-key-after map [menu-bar view filter decompose-filter]
'(menu-item "Decompose top filter" ibuffer-decompose-filter
+ :enable (and (featurep 'ibuf-ext) (memq (car ibuffer-filtering-qualifiers) '(or saved not)))
:help "Break down a complex filter like OR or NOT"))
(define-key-after map [menu-bar view filter exchange-filters]
- '(menu-item "Swap top two filters" ibuffer-exchange-filters))
+ '(menu-item "Swap top two filters" ibuffer-exchange-filters
+ :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers
+ (cdr ibuffer-filtering-qualifiers))))
(define-key-after map [menu-bar view filter save-filters]
'(menu-item "Save current filters permanently..." ibuffer-save-filters
+ :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)
:help "Use a mnemnonic name to store current filter stack"))
(define-key-after map [menu-bar view filter switch-to-saved-filters]
'(menu-item "Restore permanently saved filters..." ibuffer-switch-to-saved-filters
+ :enable (and (featurep 'ibuf-ext) ibuffer-saved-filters)
:help "Replace current filters with a saved stack"))
(define-key-after map [menu-bar view filter add-saved-filters]
'(menu-item "Add to permanently saved filters..." ibuffer-add-saved-filters
- :help "Include current filters in an already saved stack"))
+ :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)
+ :help "Include already saved stack with current filters"))
(define-key-after map [menu-bar view filter delete-saved-filters]
- '(menu-item "Delete permanently saved filters..." ibuffer-delete-saved-filters
- :help "Remove stack of filters from saved list"))
+ '(menu-item "Delete permanently saved filters..."
+ ibuffer-delete-saved-filters
+ :enable (and (featurep 'ibuf-ext) ibuffer-saved-filters)))
+
+ ;; Filter groups
+
+ (define-key-after groups-map [filters-to-filter-group]
+ '(menu-item "Create filter group from current filters..."
+ ibuffer-filters-to-filter-group
+ :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)))
+ (define-key-after groups-map [forward-filter-group]
+ '(menu-item "Move point to the next filter group"
+ ibuffer-forward-filter-group))
+ (define-key-after groups-map [backward-filter-group]
+ '(menu-item "Move point to the previous filter group"
+ ibuffer-backward-filter-group))
+ (define-key-after groups-map [jump-to-filter-group]
+ '(menu-item "Move point to a specific filter group..."
+ ibuffer-jump-to-filter-group))
+ (define-key-after groups-map [kill-filter-group]
+ '(menu-item "Kill filter group named..."
+ ibuffer-kill-filter-group
+ :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)))
+ (define-key-after groups-map [yank-filter-group]
+ '(menu-item "Yank last killed filter group before..."
+ ibuffer-yank-filter-group
+ :enable (and (featurep 'ibuf-ext) ibuffer-filter-group-kill-ring)))
+ (define-key-after groups-map [pop-filter-group]
+ '(menu-item "Remove top filter group"
+ ibuffer-pop-filter-group
+ :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)))
+ (define-key-after groups-map [clear-filter-groups]
+ '(menu-item "Remove all filter groups"
+ ibuffer-clear-filter-groups
+ :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)))
+ (define-key-after groups-map [pop-filter-group]
+ '(menu-item "Decompose filter group..."
+ ibuffer-pop-filter-group
+ :help "\"Unmake\" a filter group"
+ :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)))
+ (define-key-after groups-map [save-filter-groups]
+ '(menu-item "Save current filter groups permanently..."
+ ibuffer-save-filter-groups
+ :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)
+ :help "Use a mnemnonic name to store current filter groups"))
+ (define-key-after groups-map [switch-to-saved-filter-groups]
+ '(menu-item "Restore permanently saved filters..."
+ ibuffer-switch-to-saved-filter-groups
+ :enable (and (featurep 'ibuf-ext) ibuffer-saved-filter-groups)
+ :help "Replace current filters with a saved stack"))
+ (define-key-after groups-map [delete-saved-filter-groups]
+ '(menu-item "Delete permanently saved filter groups..."
+ ibuffer-delete-saved-filter-groups
+ :enable (and (featurep 'ibuf-ext) ibuffer-saved-filter-groups)))
+ (define-key-after groups-map [set-filter-groups-by-mode]
+ '(menu-item "Set current filter groups to filter by mode"
+ ibuffer-set-filter-groups-by-mode))
+
+ (define-key-after map [menu-bar view filter-groups]
+ (cons "Filter Groups" groups-map))
+
(define-key-after map [menu-bar view dashes2]
'("--"))
(define-key-after map [menu-bar view diff-with-file]
'(menu-item "Toggle Auto Mode" ibuffer-auto-mode
:help "Attempt to automatically update the Ibuffer buffer"))
(define-key-after map [menu-bar view customize]
- '(menu-item "Customize Ibuffer" (lambda () (interactive)
- (customize-group 'ibuffer))
+ '(menu-item "Customize Ibuffer" ibuffer-customize
:help "Use Custom to customize Ibuffer"))
(define-key-after map [menu-bar mark]
:help "Mark buffers which have not been viewed recently"))
(define-key-after map [menu-bar mark unmark-all]
'(menu-item "Unmark All" ibuffer-unmark-all))
-
+
(define-key-after map [menu-bar mark dashes]
'("--"))
-
+
(define-key-after map [menu-bar mark mark-by-name-regexp]
'(menu-item "Mark by buffer name (regexp)..." ibuffer-mark-by-name-regexp
:help "Mark buffers whose name matches a regexp"))
(define-key-after operate-map [do-view-and-eval]
'(menu-item "Eval (viewing buffer)..." ibuffer-do-view-and-eval
:help "Evaluate a Lisp form in each marked buffer while viewing it"))
-
+
(setq ibuffer-mode-map map
- ibuffer-mode-operate-map operate-map)))
-
-(defvar ibuffer-name-map nil)
-(unless ibuffer-name-map
+ ibuffer-mode-operate-map operate-map
+ ibuffer-mode-groups-popup (copy-keymap groups-map))))
+
+(define-key ibuffer-mode-groups-popup [kill-filter-group]
+ '(menu-item "Kill filter group"
+ ibuffer-kill-line
+ :enable (and (featurep 'ibuf-ext)
+ ibuffer-filter-groups)))
+(define-key ibuffer-mode-groups-popup [yank-filter-group]
+ '(menu-item "Yank last killed filter group"
+ ibuffer-yank
+ :enable (and (featurep 'ibuf-ext)
+ ibuffer-filter-group-kill-ring)))
+
+(defvar ibuffer-name-map
(let ((map (make-sparse-keymap)))
- (set-keymap-parent map ibuffer-mode-map)
(define-key map [(mouse-1)] 'ibuffer-mouse-toggle-mark)
(define-key map [(mouse-2)] 'ibuffer-mouse-visit-buffer)
(define-key map [down-mouse-3] 'ibuffer-mouse-popup-menu)
- (setq ibuffer-name-map map)))
+ map))
-(defvar ibuffer-mode-name-map nil)
-(unless ibuffer-mode-name-map
+(defvar ibuffer-mode-name-map
(let ((map (make-sparse-keymap)))
- (set-keymap-parent map ibuffer-mode-map)
(define-key map [(mouse-2)] 'ibuffer-mouse-filter-by-mode)
(define-key map (kbd "RET") 'ibuffer-interactive-filter-by-mode)
- (setq ibuffer-mode-name-map map)))
+ map))
-;; quiet the byte-compiler
-(defvar ibuffer-mode-operate-menu nil)
-(defvar ibuffer-mode-mark-menu nil)
-(defvar ibuffer-mode-view-menu nil)
+(defvar ibuffer-mode-filter-group-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map [(mouse-1)] 'ibuffer-mouse-toggle-mark)
+ (define-key map [(mouse-2)] 'ibuffer-mouse-toggle-filter-group)
+ (define-key map (kbd "RET") 'ibuffer-toggle-filter-group)
+ (define-key map [down-mouse-3] 'ibuffer-mouse-popup-menu)
+ map))
-(defvar ibuffer-mode-hooks nil)
+(defvar ibuffer-restore-window-config-on-quit nil
+ "If non-nil, restore previous window configuration upon exiting `ibuffer'.")
-(defvar ibuffer-delete-window-on-quit nil
- "Whether or not to delete the window upon exiting `ibuffer'.")
+(defvar ibuffer-prev-window-config nil
+ "Window configuration before starting Ibuffer.")
(defvar ibuffer-did-modification nil)
(insert (pop list)))
(insert "\n")))))
-(defun ibuffer-accumulate-lines (count)
- (save-excursion
- (let ((forwardp (> count 0))
- (result nil))
- (while (not (or (zerop count)
- (if forwardp
- (eobp)
- (bobp))))
- (if forwardp
- (decf count)
- (incf count))
- (push
- (buffer-substring
- (line-beginning-position)
- (line-end-position))
- result)
- (forward-line (if forwardp 1 -1)))
- (nreverse result))))
-
(defsubst ibuffer-current-mark ()
(cadr (get-text-property (line-beginning-position)
'ibuffer-properties)))
"Toggle the marked status of the buffer chosen with the mouse."
(interactive "e")
(unwind-protect
- (save-excursion
- (mouse-set-point event)
- (let ((mark (ibuffer-current-mark)))
- (setq buffer-read-only nil)
- (if (eq mark ibuffer-marked-char)
- (ibuffer-set-mark ? )
- (ibuffer-set-mark ibuffer-marked-char))))
+ (let ((pt (save-excursion
+ (mouse-set-point event)
+ (point))))
+ (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name)
+ (ibuffer-toggle-marks it)
+ (goto-char pt)
+ (let ((mark (ibuffer-current-mark)))
+ (setq buffer-read-only nil)
+ (if (eq mark ibuffer-marked-char)
+ (ibuffer-set-mark ? )
+ (ibuffer-set-mark ibuffer-marked-char)))))
(setq buffer-read-only t)))
(defun ibuffer-find-file (file &optional wildcards)
default-directory)
default-directory))))
(list (read-file-name "Find file: " default-directory)
- current-prefix-arg)))
+ t)))
(find-file file wildcards))
(defun ibuffer-mouse-visit-buffer (event)
(switch-to-buffer
(save-excursion
(mouse-set-point event)
- (ibuffer-current-buffer))))
+ (ibuffer-current-buffer t))))
(defun ibuffer-mouse-popup-menu (event)
"Display a menu of operations."
(interactive "e")
- (let ((origline (count-lines (point-min) (point))))
+ (let ((eventpt (posn-point (event-end event)))
+ (origpt (point)))
(unwind-protect
- (progn
- (setq buffer-read-only nil)
- (ibuffer-save-marks
- ;; hm. we could probably do this in a better fashion
- (ibuffer-unmark-all ?\r)
- (setq buffer-read-only nil)
- (mouse-set-point event)
- (ibuffer-set-mark ibuffer-marked-char)
- (setq buffer-read-only nil)
- (save-excursion
- (popup-menu ibuffer-mode-operate-map))))
- (progn
- (setq buffer-read-only t)
- (goto-line (1+ origline))))))
+ (if (get-text-property eventpt 'ibuffer-filter-group-name)
+ (progn
+ (goto-char eventpt)
+ (popup-menu ibuffer-mode-groups-popup))
+ (let ((inhibit-read-only t))
+ (ibuffer-save-marks
+ ;; hm. we could probably do this in a better fashion
+ (ibuffer-unmark-all ?\r)
+ (save-excursion
+ (goto-char eventpt)
+ (ibuffer-set-mark ibuffer-marked-char))
+ (save-excursion
+ (popup-menu ibuffer-mode-operate-map)))))
+ (setq buffer-read-only t)
+ (if (= eventpt (point))
+ (goto-char origpt)))))
+
+(defun ibuffer-skip-properties (props direction)
+ (while (and (not (eobp))
+ (let ((hit nil))
+ (dolist (prop props hit)
+ (when (get-text-property (point) prop)
+ (setq hit t)))))
+ (forward-line direction)
+ (beginning-of-line)))
+
+(defun ibuffer-customize ()
+ "Begin customizing Ibuffer interactively."
+ (interactive)
+ (customize-group 'ibuffer))
-(defun ibuffer-backward-line (&optional arg)
+(defun ibuffer-backward-line (&optional arg skip-group-names)
"Move backwards ARG lines, wrapping around the list if necessary."
(interactive "P")
- (unless arg
- (setq arg 1))
+ (or arg (setq arg 1))
(beginning-of-line)
(while (> arg 0)
(forward-line -1)
- (when (get-text-property (point) 'ibuffer-title)
+ (when (and ibuffer-movement-cycle
+ (or (get-text-property (point) 'ibuffer-title)
+ (and skip-group-names
+ (get-text-property (point)
+ 'ibuffer-filter-group-name))))
(goto-char (point-max))
- (forward-line -1)
- (setq arg 0))
- (setq arg (1- arg))))
+ (beginning-of-line))
+ (ibuffer-skip-properties (append '(ibuffer-summary)
+ (when skip-group-names
+ '(ibuffer-filter-group-name)))
+ -1)
+ ;; Handle the special case of no buffers.
+ (when (get-text-property (point) 'ibuffer-title)
+ (forward-line 1)
+ (setq arg 1))
+ (decf arg)))
-(defun ibuffer-forward-line (&optional arg)
+(defun ibuffer-forward-line (&optional arg skip-group-names)
"Move forward ARG lines, wrapping around the list if necessary."
(interactive "P")
- (unless arg
- (setq arg 1))
+ (or arg (setq arg 1))
(beginning-of-line)
+ (when (and ibuffer-movement-cycle
+ (or (eobp)
+ (get-text-property (point) 'ibuffer-summary)))
+ (goto-char (point-min)))
+ (when (or (get-text-property (point) 'ibuffer-title)
+ (and skip-group-names
+ (get-text-property (point) 'ibuffer-filter-group-name)))
+ (when (> arg 0)
+ (decf arg))
+ (ibuffer-skip-properties (append '(ibuffer-title)
+ (when skip-group-names
+ '(ibuffer-filter-group-name)))
+ 1))
(if (< arg 0)
(ibuffer-backward-line (- arg))
- (progn
- (when (get-text-property (point) 'ibuffer-title)
- ;; If we're already on the title, moving past it counts as
- ;; moving a line.
- (decf arg)
- (while (and (get-text-property (point) 'ibuffer-title)
- (not (eobp)))
- (forward-line 1)))
- (while (> arg 0)
- (forward-line 1)
- (when (eobp)
- (goto-char (point-min)))
- (while (and (get-text-property (point) 'ibuffer-title)
- (not (eobp)))
- (forward-line 1))
- (setq arg (1- arg))))))
-
-(defun ibuffer-visit-buffer ()
- "Visit the buffer on this line."
- (interactive)
- (let ((buf (ibuffer-current-buffer)))
- (unless (buffer-live-p buf)
- (error "Buffer %s has been killed!" buf))
+ (while (> arg 0)
+ (forward-line 1)
+ (when (and ibuffer-movement-cycle
+ (or (eobp)
+ (get-text-property (point) 'ibuffer-summary)))
+ (goto-char (point-min)))
+ (decf arg)
+ (ibuffer-skip-properties (append '(ibuffer-title)
+ (when skip-group-names
+ '(ibuffer-filter-group-name)))
+ 1))))
+
+(defun ibuffer-visit-buffer (&optional single)
+ "Visit the buffer on this line.
+If optional argument SINGLE is non-nil, then also ensure there is only
+one window."
+ (interactive "P")
+ (let ((buf (ibuffer-current-buffer t)))
(bury-buffer (current-buffer))
- (switch-to-buffer buf)))
+ (switch-to-buffer buf)
+ (when single
+ (delete-other-windows))))
(defun ibuffer-visit-buffer-other-window (&optional noselect)
"Visit the buffer on this line in another window."
(interactive)
- (let ((buf (ibuffer-current-buffer)))
- (unless (buffer-live-p buf)
- (error "Buffer %s has been killed!" buf))
+ (let ((buf (ibuffer-current-buffer t)))
(bury-buffer (current-buffer))
(if noselect
(let ((curwin (selected-window)))
(defun ibuffer-visit-buffer-other-frame ()
"Visit the buffer on this line in another frame."
(interactive)
- (let ((buf (ibuffer-current-buffer)))
- (unless (buffer-live-p buf)
- (error "Buffer %s has been killed!" buf))
+ (let ((buf (ibuffer-current-buffer t)))
(bury-buffer (current-buffer))
(switch-to-buffer-other-frame buf)))
(defun ibuffer-visit-buffer-1-window ()
"Visit the buffer on this line, and delete other windows."
(interactive)
- (let ((buf (ibuffer-current-buffer)))
- (unless (buffer-live-p buf)
- (error "Buffer %s has been killed!" buf))
- (switch-to-buffer buf)
- (delete-other-windows)))
+ (ibuffer-visit-buffer t))
(defun ibuffer-bury-buffer ()
"Bury the buffer on this line."
(interactive)
- (let ((buf (ibuffer-current-buffer))
+ (let ((buf (ibuffer-current-buffer t))
(line (+ 1 (count-lines 1 (point)))))
- (unless (buffer-live-p buf)
- (error "Buffer %s has been killed!" buf))
(bury-buffer buf)
(ibuffer-update nil t)
(goto-line line)))
(defun ibuffer-visit-tags-table ()
"Visit the tags table in the buffer on this line. See `visit-tags-table'."
(interactive)
- (let ((file (buffer-file-name (ibuffer-current-buffer))))
+ (let ((file (buffer-file-name (ibuffer-current-buffer t))))
(if file
(visit-tags-table file)
(error "Specified buffer has no file"))))
(defun ibuffer-do-view-1 (type)
(let ((marked-bufs (ibuffer-get-marked-buffers)))
(when (null marked-bufs)
- (setq marked-bufs (list (ibuffer-current-buffer))))
+ (setq marked-bufs (list (ibuffer-current-buffer t))))
(unless (and (eq type 'other-frame)
(not ibuffer-expert)
(> (length marked-bufs) 3)
(not (y-or-n-p (format "Really create a new frame for %s buffers? "
(length marked-bufs)))))
- (set-buffer-modified-p nil)
+ (set-buffer-modified-p nil)
(delete-other-windows)
(switch-to-buffer (pop marked-bufs))
(let ((height (/ (1- (if (eq type 'horizontally) (frame-width)
- (frame-height)))
+ (frame-height)))
(1+ (length marked-bufs)))))
(mapcar (if (eq type 'other-frame)
#'(lambda (buf)
(let ((curframe (selected-frame)))
- (select-frame (new-frame))
+ (select-frame (make-frame))
(switch-to-buffer buf)
(select-frame curframe)))
#'(lambda (buf)
(ibuffer-columnize-and-insert-list names)
(goto-char (point-min))
(setq buffer-read-only t))
- (let ((lastwin (car (last (ibuffer-window-list)))))
+ (let ((lastwin (car (last (window-list nil 'nomini)))))
;; Now attempt to display the buffer...
(save-window-excursion
(select-window lastwin)
;; The window might be too small to split; in that case,
- ;; try a few times to increase its size before giving up.
+ ;; try a few times to increase its size before giving up.
(let ((attempts 0)
(trying t))
(while trying
;; Handle a failure
(if (or (> (incf attempts) 4)
(and (stringp (cadr err))
- ;; This definitely falls in the ghetto hack category...
+ ;; This definitely falls in the
+ ;; ghetto hack category...
(not (string-match "too small" (cadr err)))))
(apply #'signal err)
(enlarge-window 3))))))
- ;; This part doesn't work correctly sometimes under XEmacs.
(select-window (next-window))
(switch-to-buffer buf)
(unwind-protect
(defun ibuffer-buffer-names-with-mark (mark)
(let ((ibuffer-buffer-names-with-mark-result nil))
(ibuffer-map-lines-nomodify
- #'(lambda (buf mk beg end)
+ #'(lambda (buf mk)
(when (char-equal mark mk)
(push (buffer-name buf)
ibuffer-buffer-names-with-mark-result))))
(defun ibuffer-count-marked-lines (&optional all)
(if all
(ibuffer-map-lines-nomodify
- #'(lambda (buf mark beg end)
+ #'(lambda (buf mark)
(not (char-equal mark ? ))))
(ibuffer-map-lines-nomodify
- #'(lambda (buf mark beg end)
+ #'(lambda (buf mark)
(char-equal mark ibuffer-marked-char)))))
(defsubst ibuffer-count-deletion-lines ()
(ibuffer-map-lines-nomodify
- #'(lambda (buf mark beg end)
+ #'(lambda (buf mark)
(char-equal mark ibuffer-deletion-char))))
(defsubst ibuffer-map-deletion-lines (func)
(ibuffer-map-on-mark ibuffer-deletion-char func))
-(define-ibuffer-op save ()
+(define-ibuffer-op ibuffer-do-save ()
"Save marked buffers as with `save-buffer'."
(:complex t
:opstring "saved"
(save-buffer))))
t)
-(define-ibuffer-op toggle-modified ()
+(define-ibuffer-op ibuffer-do-toggle-modified ()
"Toggle modification flag of marked buffers."
(:opstring "(un)marked as modified"
:modifier-p t)
(set-buffer-modified-p (not (buffer-modified-p))))
-(define-ibuffer-op toggle-read-only ()
+(define-ibuffer-op ibuffer-do-toggle-read-only ()
"Toggle read only status in marked buffers."
(:opstring "toggled read only status in"
:modifier-p t)
(toggle-read-only))
-(define-ibuffer-op delete ()
+(define-ibuffer-op ibuffer-do-delete ()
"Kill marked buffers as with `kill-this-buffer'."
(:opstring "killed"
:active-opstring "kill"
'kill
nil))
-(define-ibuffer-op kill-on-deletion-marks ()
+(define-ibuffer-op ibuffer-do-kill-on-deletion-marks ()
"Kill buffers marked for deletion as with `kill-this-buffer'."
(:opstring "killed"
:active-opstring "kill"
(cond
((char-equal mark ibuffer-marked-char)
(ibuffer-map-marked-lines
- #'(lambda (buf mark beg end)
+ #'(lambda (buf mark)
(ibuffer-set-mark-1 ? )
t)))
((char-equal mark ibuffer-deletion-char)
(ibuffer-map-deletion-lines
- #'(lambda (buf mark beg end)
+ #'(lambda (buf mark)
(ibuffer-set-mark-1 ? )
t)))
(t
(ibuffer-map-lines
- #'(lambda (buf mark beg end)
+ #'(lambda (buf mark)
(when (not (char-equal mark ? ))
(ibuffer-set-mark-1 ? ))
t)))))
(ibuffer-redisplay t))
-(defun ibuffer-toggle-marks ()
+(defun ibuffer-toggle-marks (&optional group)
"Toggle which buffers are marked.
In other words, unmarked buffers become marked, and marked buffers
-become unmarked."
+become unmarked.
+If point is on a group name, then this function operates on that
+group."
(interactive)
+ (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name)
+ (setq group it))
(let ((count
(ibuffer-map-lines
- #'(lambda (buf mark beg end)
+ #'(lambda (buf mark)
(cond ((eq mark ibuffer-marked-char)
(ibuffer-set-mark-1 ? )
nil)
(ibuffer-set-mark-1 ibuffer-marked-char)
t)
(t
- nil))))))
+ nil)))
+ nil group)))
(message "%s buffers marked" count))
(ibuffer-redisplay t))
(defun ibuffer-mark-forward (arg)
- "Mark the buffer on this line, and move forward ARG lines."
+ "Mark the buffer on this line, and move forward ARG lines.
+If point is on a group name, this function operates on that group."
(interactive "P")
(ibuffer-mark-interactive arg ibuffer-marked-char 1))
(defun ibuffer-unmark-forward (arg)
- "Unmark the buffer on this line, and move forward ARG lines."
+ "Unmark the buffer on this line, and move forward ARG lines.
+If point is on a group name, this function operates on that group."
(interactive "P")
(ibuffer-mark-interactive arg ? 1))
(defun ibuffer-unmark-backward (arg)
- "Unmark the buffer on this line, and move backward ARG lines."
+ "Unmark the buffer on this line, and move backward ARG lines.
+If point is on a group name, this function operates on that group."
(interactive "P")
(ibuffer-mark-interactive arg ? -1))
(defun ibuffer-mark-interactive (arg mark movement)
(assert (eq major-mode 'ibuffer-mode))
- (unless arg
- (setq arg 1))
- (while (and (get-text-property (line-beginning-position)
- 'ibuffer-title)
- (not (eobp)))
- (forward-line 1))
-
- (let ((inhibit-read-only t))
- (while (> arg 0)
- (ibuffer-set-mark mark)
- (forward-line movement)
- (when (or (get-text-property (line-beginning-position)
- 'ibuffer-title)
- (eobp))
- (forward-line (- movement))
- (setq arg 0))
- (setq arg (1- arg)))))
+ (or arg (setq arg 1))
+ (ibuffer-forward-line 0)
+ (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name)
+ (progn
+ (require 'ibuf-ext)
+ (ibuffer-mark-on-buffer #'identity mark it))
+ (ibuffer-forward-line 0 t)
+ (let ((inhibit-read-only t))
+ (while (> arg 0)
+ (ibuffer-set-mark mark)
+ (ibuffer-forward-line movement t)
+ (setq arg (1- arg))))))
(defun ibuffer-set-mark (mark)
(assert (eq major-mode 'ibuffer-mode))
(let ((inhibit-read-only t))
(ibuffer-set-mark-1 mark)
(setq ibuffer-did-modification t)
- (ibuffer-redisplay-current)))
+ (ibuffer-redisplay-current)
+ (beginning-of-line)))
(defun ibuffer-set-mark-1 (mark)
(let ((beg (line-beginning-position))
mark))))
(defun ibuffer-mark-for-delete (arg)
- "Mark the buffers on ARG lines forward for deletion."
+ "Mark the buffers on ARG lines forward for deletion.
+If point is on a group name, this function operates on that group."
(interactive "P")
(ibuffer-mark-interactive arg ibuffer-deletion-char 1))
(defun ibuffer-mark-for-delete-backwards (arg)
- "Mark the buffers on ARG lines backward for deletion."
+ "Mark the buffers on ARG lines backward for deletion.
+If point is on a group name, this function operates on that group."
(interactive "P")
(ibuffer-mark-interactive arg ibuffer-deletion-char -1))
(defun ibuffer-current-buffer (&optional must-be-live)
(let ((buf (car (get-text-property (line-beginning-position)
'ibuffer-properties))))
- (when (and must-be-live
- (not (buffer-live-p buf)))
- (error "Buffer %s has been killed!" buf))
+ (when must-be-live
+ (if (bufferp buf)
+ (unless (buffer-live-p buf)
+ (error (substitute-command-keys "Buffer %s has been killed; use `\\[ibuffer-update]' to update") buf))
+ (error "No buffer on this line")))
buf))
(defun ibuffer-active-formats-name ()
(if uncompiledp
ibuffer-filter-format-alist
ibuffer-compiled-filter-formats))))))
-
+
(defun ibuffer-current-format (&optional uncompiledp)
(or ibuffer-current-format
(setq ibuffer-current-format 0))
- (nth ibuffer-current-format (ibuffer-current-formats uncompiledp)))
+ (nth ibuffer-current-format (ibuffer-current-formats uncompiledp)))
(defun ibuffer-expand-format-entry (form)
(if (or (consp form)
(symbolp form))
- (let ((sym (intern (concat "ibuffer-make-column-"
- (symbol-name (if (consp form)
- (car form)
- form))))))
- (unless (or (fboundp sym)
- (assq sym ibuffer-inline-columns))
- (error "Unknown column %s in ibuffer-formats" form))
- (let (min max align elide)
- (if (consp form)
- (setq min (or (nth 1 form) 0)
- max (or (nth 2 form) -1)
- align (or (nth 3 form) :left)
- elide (or (nth 4 form) nil))
- (setq min 0
- max -1
- align :left
- elide nil))
- (list sym min max align elide)))
+ (let ((sym (intern (concat "ibuffer-make-column-"
+ (symbol-name (if (consp form)
+ (car form)
+ form))))))
+ (unless (or (fboundp sym)
+ (assq sym ibuffer-inline-columns))
+ (error "Unknown column %s in ibuffer-formats" form))
+ (let (min max align elide)
+ (if (consp form)
+ (setq min (or (nth 1 form) 0)
+ max (or (nth 2 form) -1)
+ align (or (nth 3 form) :left)
+ elide (or (nth 4 form) nil))
+ (setq min 0
+ max -1
+ align :left
+ elide nil))
+ (list sym min max align elide)))
form))
-
+
(defun ibuffer-compile-make-eliding-form (strvar elide from-end-p)
- (let ((ellipsis (if (ibuffer-use-fontification)
- (propertize ibuffer-eliding-string 'face 'bold)
- ibuffer-eliding-string)))
+ (let ((ellipsis (propertize ibuffer-eliding-string 'font-lock-face 'bold)))
(if (or elide ibuffer-elide-long-columns)
`(if (> strlen 5)
,(if from-end-p
(defun ibuffer-compile-make-format-form (strvar widthform alignment)
(let* ((left `(make-string tmp2 ? ))
- (right `(make-string (- tmp1 tmp2) ? )))
+ (right `(make-string (- tmp1 tmp2) ? )))
`(progn
(setq tmp1 ,widthform
tmp2 (/ tmp1 2))
(defun ibuffer-compile-format (format)
(let ((result nil)
- str-used
- tmp1-used tmp2-used global-strlen-used)
+ ;; We use these variables to keep track of which variables
+ ;; inside the generated function we need to bind, since
+ ;; binding variables in Emacs takes time.
+ str-used tmp1-used tmp2-used global-strlen-used)
(dolist (form format)
(push
+ ;; Generate a form based on a particular format entry, like
+ ;; " ", mark, or (mode 16 16 :right).
(if (stringp form)
+ ;; It's a string; all we need to do is insert it.
`(insert ,form)
(let* ((form (ibuffer-expand-format-entry form))
(sym (nth 0 form))
maxform
min-used max-used strlen-used)
(when (or (not (integerp min)) (>= min 0))
+ ;; This is a complex case; they want it limited to a
+ ;; minimum size.
(setq min-used t)
(setq str-used t strlen-used t global-strlen-used t
tmp1-used t tmp2-used t)
+ ;; Generate code to limit the string to a minimum size.
(setq minform `(progn
(setq str
,(ibuffer-compile-make-format-form
align)))))
(when (or (not (integerp max)) (> max 0))
(setq str-used t max-used t)
+ ;; Generate code to limit the string to a maximum size.
(setq maxform `(progn
(setq str
,(ibuffer-compile-make-substring-form
,(ibuffer-compile-make-eliding-form 'str
elide
from-end-p)))))
- (let ((callform (ibuffer-aif (assq sym ibuffer-inline-columns)
- (nth 1 it)
- `(,sym buffer mark)))
+ ;; Now, put these forms together with the rest of the code.
+ (let ((callform
+ ;; Is this an "inline" column? This means we have
+ ;; to get the code from the
+ ;; `ibuffer-inline-columns' alist and insert it
+ ;; into our generated code. Otherwise, we just
+ ;; generate a call to the column function.
+ (ibuffer-aif (assq sym ibuffer-inline-columns)
+ (nth 1 it)
+ `(,sym buffer mark)))
+ ;; You're not expected to understand this. Hell, I
+ ;; don't even understand it, and I wrote it five
+ ;; minutes ago.
+ (insertgenfn (ibuffer-aif (get sym 'ibuffer-column-summarizer)
+ ;; I really, really wish Emacs Lisp had closures.
+ (lambda (arg sym)
+ `(insert
+ (let ((ret ,arg))
+ (put ',sym 'ibuffer-column-summary
+ (cons ret (get ',sym 'ibuffer-column-summary)))
+ ret)))
+ (lambda (arg sym)
+ `(insert ,arg))))
(mincompform `(< strlen ,(if (integerp min)
min
'min)))
(maxcompform `(> strlen ,(if (integerp max)
max
'max))))
- (if (or min-used max-used)
- (progn
- (when (and min-used (not (integerp min)))
- (push `(min ,min) letbindings))
- (when (and max-used (not (integerp max)))
- (push `(max ,max) letbindings))
- (push
- (if (and min-used max-used)
- `(if ,mincompform
- ,minform
- (if ,maxcompform
- ,maxform))
- (if min-used
- `(when ,mincompform
- ,minform)
- `(when ,maxcompform
- ,maxform)))
- outforms)
- (push (append
- `(setq str ,callform)
- (when strlen-used
- `(strlen (length str))))
- outforms)
- (setq outforms
- (append outforms `((insert str)))))
- (push `(insert ,callform) outforms))
- `(let ,letbindings
- ,@outforms)))))
+ (if (or min-used max-used)
+ ;; The complex case, where we have to limit the
+ ;; form to a maximum or minimum size.
+ (progn
+ (when (and min-used (not (integerp min)))
+ (push `(min ,min) letbindings))
+ (when (and max-used (not (integerp max)))
+ (push `(max ,max) letbindings))
+ (push
+ (if (and min-used max-used)
+ `(if ,mincompform
+ ,minform
+ (if ,maxcompform
+ ,maxform))
+ (if min-used
+ `(when ,mincompform
+ ,minform)
+ `(when ,maxcompform
+ ,maxform)))
+ outforms)
+ (push (append
+ `(setq str ,callform)
+ (when strlen-used
+ `(strlen (length str))))
+ outforms)
+ (setq outforms
+ (append outforms (list (funcall insertgenfn 'str sym)))))
+ ;; The simple case; just insert the string.
+ (push (funcall insertgenfn callform sym) outforms))
+ ;; Finally, return a `let' form which binds the
+ ;; variables in `letbindings', and contains all the
+ ;; code in `outforms'.
+ `(let ,letbindings
+ ,@outforms)))))
result))
(setq result
+ ;; We don't want to unconditionally load the byte-compiler.
(funcall (if (or ibuffer-always-compile-formats
(featurep 'bytecomp))
#'byte-compile
#'identity)
+ ;; Here, we actually create a lambda form which
+ ;; inserts all the generated forms for each entry
+ ;; in the format string.
(nconc (list 'lambda '(buffer mark))
`((let ,(append (when str-used
'(str))
"Recompile `ibuffer-formats'."
(interactive)
(setq ibuffer-compiled-formats
- (mapcar #'ibuffer-compile-format ibuffer-formats))
+ (mapcar #'ibuffer-compile-format ibuffer-formats))
(when (boundp 'ibuffer-filter-format-alist)
(setq ibuffer-compiled-filter-formats
(mapcar #'(lambda (entry)
(cdr entry))))
ibuffer-filter-format-alist))))
+(defun ibuffer-clear-summary-columns (format)
+ (dolist (form format)
+ (ibuffer-awhen (and (consp form)
+ (get (car form) 'ibuffer-column-summarizer))
+ (put (car form) 'ibuffer-column-summary nil))))
+
(defun ibuffer-check-formats ()
(when (null ibuffer-formats)
(error "No formats!"))
- (when (or (null ibuffer-compiled-formats)
- (null ibuffer-cached-formats)
- (not (eq ibuffer-cached-formats ibuffer-formats))
- (null ibuffer-cached-eliding-string)
- (not (equal ibuffer-cached-eliding-string ibuffer-eliding-string))
- (eql 0 ibuffer-cached-elide-long-columns)
- (not (eql ibuffer-cached-elide-long-columns
- ibuffer-elide-long-columns))
- (not (eq ibuffer-cached-filter-formats
- ibuffer-filter-format-alist))
- (and ibuffer-filter-format-alist
- (null ibuffer-compiled-filter-formats)))
- (message "Formats have changed, recompiling...")
- (ibuffer-recompile-formats)
- (setq ibuffer-cached-formats ibuffer-formats
- ibuffer-cached-eliding-string ibuffer-eliding-string
- ibuffer-cached-elide-long-columns ibuffer-elide-long-columns
- ibuffer-cached-filter-formats ibuffer-filter-format-alist)
- (message "Formats have changed, recompiling...done")))
+ (let ((ext-loaded (featurep 'ibuf-ext)))
+ (when (or (null ibuffer-compiled-formats)
+ (null ibuffer-cached-formats)
+ (not (eq ibuffer-cached-formats ibuffer-formats))
+ (null ibuffer-cached-eliding-string)
+ (not (equal ibuffer-cached-eliding-string ibuffer-eliding-string))
+ (eql 0 ibuffer-cached-elide-long-columns)
+ (not (eql ibuffer-cached-elide-long-columns
+ ibuffer-elide-long-columns))
+ (and ext-loaded
+ (not (eq ibuffer-cached-filter-formats
+ ibuffer-filter-format-alist))
+ (and ibuffer-filter-format-alist
+ (null ibuffer-compiled-filter-formats))))
+ (message "Formats have changed, recompiling...")
+ (ibuffer-recompile-formats)
+ (setq ibuffer-cached-formats ibuffer-formats
+ ibuffer-cached-eliding-string ibuffer-eliding-string
+ ibuffer-cached-elide-long-columns ibuffer-elide-long-columns)
+ (when ext-loaded
+ (setq ibuffer-cached-filter-formats ibuffer-filter-format-alist))
+ (message "Formats have changed, recompiling...done"))))
(defvar ibuffer-inline-columns nil)
(define-ibuffer-column read-only (:name "R" :inline t)
(if buffer-read-only
- "%"
+ (string ibuffer-read-only-char)
" "))
(define-ibuffer-column modified (:name "M" :inline t)
(string ibuffer-modified-char)
" "))
-(define-ibuffer-column name (:inline t
- :props
- ('mouse-face 'highlight 'keymap ibuffer-name-map
- 'ibuffer-name-column t
- 'help-echo "mouse-1: mark this buffer\nmouse-2: select this buffer\nmouse-3: operate on this buffer"))
- (buffer-name))
-
-(define-ibuffer-column size (:inline t)
+(define-ibuffer-column name
+ (:inline t
+ :props
+ ('mouse-face 'highlight 'keymap ibuffer-name-map
+ 'ibuffer-name-column t
+ 'help-echo '(if tooltip-mode
+ "mouse-1: mark this buffer\nmouse-2: select this buffer\nmouse-3: operate on this buffer"
+ "mouse-1: mark buffer mouse-2: select buffer mouse-3: operate"))
+ :summarizer
+ (lambda (strings)
+ (let ((bufs (length strings)))
+ (cond ((zerop bufs) "No buffers")
+ ((= 1 bufs) "1 buffer")
+ (t (format "%s buffers" bufs))))))
+ (propertize (buffer-name) 'font-lock-face (ibuffer-buffer-name-face buffer mark)))
+
+(define-ibuffer-column size
+ (:inline t
+ :summarizer
+ (lambda (column-strings)
+ (let ((total 0))
+ (dolist (string column-strings)
+ (setq total
+ ;; like, ewww ...
+ (+ (float (string-to-number string))
+ total)))
+ (format "%.0f" total))))
(format "%s" (buffer-size)))
-(define-ibuffer-column mode (:inline t
- :props
- ('mouse-face 'highlight
- 'keymap ibuffer-mode-name-map
- 'help-echo "mouse-2: filter by this mode"))
+(define-ibuffer-column mode
+ (:inline t
+ :props
+ ('mouse-face 'highlight
+ 'keymap ibuffer-mode-name-map
+ 'help-echo "mouse-2: filter by this mode"))
(format "%s" mode-name))
-(define-ibuffer-column process ()
- (let ((proc (get-buffer-process buffer)))
- (if proc
- (format "(%s %s)" proc (process-status proc))
- "none")))
-
-(define-ibuffer-column filename ()
+(define-ibuffer-column process
+ (:summarizer
+ (lambda (strings)
+ (let ((total (length (delete "" strings))))
+ (cond ((zerop total) "No processes")
+ ((= 1 total) "1 process")
+ (t (format "%d processes" total))))))
+ (ibuffer-aif (get-buffer-process buffer)
+ (format "(%s %s)" it (process-status it))
+ ""))
+
+(define-ibuffer-column filename
+ (:summarizer
+ (lambda (strings)
+ (let ((total (length (delete "" strings))))
+ (cond ((zerop total) "No files")
+ ((= 1 total) "1 file")
+ (t (format "%d files" total))))))
(let ((directory-abbrev-alist ibuffer-directory-abbrev-alist))
(abbreviate-file-name
(or buffer-file-name
(and (boundp 'dired-directory)
- dired-directory)
+ (if (stringp dired-directory)
+ dired-directory
+ (car dired-directory)))
""))))
+(define-ibuffer-column filename-and-process
+ (:name "Filename/Process"
+ :summarizer
+ (lambda (strings)
+ (setq strings (delete "" strings))
+ (let ((procs 0)
+ (files 0))
+ (dolist (string strings)
+ (if (string-match "\\(\?:\\`(\[\[:ascii:\]\]\+)\\)" string)
+ (progn (setq procs (1+ procs))
+ (if (< (match-end 0) (length string))
+ (setq files (1+ files))))
+ (setq files (1+ files))))
+ (concat (cond ((zerop files) "No files")
+ ((= 1 files) "1 file")
+ (t (format "%d files" files)))
+ ", "
+ (cond ((zerop procs) "no processes")
+ ((= 1 procs) "1 process")
+ (t (format "%d processes" procs)))))))
+ (let ((proc (get-buffer-process buffer))
+ (filename (ibuffer-make-column-filename buffer mark)))
+ (if proc
+ (concat (propertize (format "(%s %s)" proc (process-status proc))
+ 'font-lock-face 'italic)
+ (if (> (length filename) 0)
+ (format " %s" filename)
+ ""))
+ filename)))
+
(defun ibuffer-format-column (str width alignment)
(let ((left (make-string (/ width 2) ? ))
(right (make-string (- width (/ width 2)) ? )))
(:center (concat left str right))
(t (concat str left right)))))
-(defun ibuffer-fontify-region-function (beg end &optional verbose)
- (when verbose (message "Fontifying..."))
- (let ((inhibit-read-only t))
- (save-excursion
- (goto-char beg)
- (beginning-of-line)
- (while (< (point) end)
- (if (get-text-property (point) 'ibuffer-title-header)
- (put-text-property (point) (line-end-position) 'face ibuffer-title-face)
- (unless (get-text-property (point) 'ibuffer-title)
- (multiple-value-bind (buf mark)
- (get-text-property (point) 'ibuffer-properties)
- (let* ((namebeg (next-single-property-change (point) 'ibuffer-name-column
- nil (line-end-position)))
- (nameend (next-single-property-change namebeg 'ibuffer-name-column
- nil (line-end-position))))
- (put-text-property namebeg
- nameend
- 'face
- (cond ((char-equal mark ibuffer-marked-char)
- ibuffer-marked-face)
- ((char-equal mark ibuffer-deletion-char)
- ibuffer-deletion-face)
- (t
- (let ((level -1)
- result)
- (dolist (e ibuffer-fontification-alist result)
- (when (and (> (car e) level)
- (with-current-buffer buf
- (eval (cadr e))))
- (setq level (car e)
- result
- (if (symbolp (caddr e))
- (if (facep (caddr e))
- (caddr e)
- (symbol-value (caddr e)))))))))))))))
- (forward-line 1))))
- (when verbose (message "Fontifying...done")))
-
-(defun ibuffer-unfontify-region-function (beg end)
- (let ((inhibit-read-only t))
- (remove-text-properties beg end '(face nil))))
+(defun ibuffer-buffer-name-face (buf mark)
+ (cond ((char-equal mark ibuffer-marked-char)
+ ibuffer-marked-face)
+ ((char-equal mark ibuffer-deletion-char)
+ ibuffer-deletion-face)
+ (t
+ (let ((level -1)
+ result)
+ (dolist (e ibuffer-fontification-alist result)
+ (when (and (> (car e) level)
+ (with-current-buffer buf
+ (eval (nth 1 e))))
+ (setq level (car e)
+ result (nth 2 e))))))))
(defun ibuffer-insert-buffer-line (buffer mark format)
"Insert a line describing BUFFER and MARK using FORMAT."
(assert (eq major-mode 'ibuffer-mode))
(let ((beg (point)))
- ;; Here we inhibit `syntax-ppss-after-change-function' and other
- ;; things font-lock uses. Otherwise, updating is slowed down dramatically.
(funcall format buffer mark)
- (put-text-property beg (point) 'ibuffer-properties (list buffer mark))
- (insert "\n")
- (goto-char beg)))
+ (put-text-property beg (point) 'ibuffer-properties (list buffer mark)))
+ (insert "\n"))
+;; This function knows a bit too much of the internals. It would be
+;; nice if it was all abstracted away.
(defun ibuffer-redisplay-current ()
(assert (eq major-mode 'ibuffer-mode))
(when (eobp)
(forward-line -1))
(beginning-of-line)
- (let ((buf (ibuffer-current-buffer)))
- (when buf
- (let ((mark (ibuffer-current-mark)))
- (delete-region (point) (1+ (line-end-position)))
- (ibuffer-insert-buffer-line
- buf mark
- (ibuffer-current-format))
- (when ibuffer-shrink-to-minimum-size
- (ibuffer-shrink-to-fit))))))
-
+ (let ((curformat (mapcar #'ibuffer-expand-format-entry
+ (ibuffer-current-format t))))
+ (ibuffer-clear-summary-columns curformat)
+ (let ((buf (ibuffer-current-buffer)))
+ (when buf
+ (let ((mark (ibuffer-current-mark)))
+ (save-excursion
+ (delete-region (point) (1+ (line-end-position)))
+ (ibuffer-insert-buffer-line
+ buf mark
+ (ibuffer-current-format)))
+ (when ibuffer-shrink-to-minimum-size
+ (ibuffer-shrink-to-fit)))))))
+
(defun ibuffer-map-on-mark (mark func)
(ibuffer-map-lines
- #'(lambda (buf mk beg end)
+ #'(lambda (buf mk)
(if (char-equal mark mk)
- (funcall func buf mark beg end)
+ (funcall func buf mark)
nil))))
-(defun ibuffer-map-lines (function &optional nomodify)
- "Call FUNCTION for each buffer in an ibuffer.
+(defun ibuffer-map-lines (function &optional nomodify group)
+ "Call FUNCTION for each buffer.
Don't set the ibuffer modification flag iff NOMODIFY is non-nil.
- FUNCTION is called with four arguments: the buffer object itself, the
-current mark symbol, and the beginning and ending line positions."
+If optional argument GROUP is non-nil, then only call FUNCTION on
+buffers in filtering group GROUP.
+
+FUNCTION is called with two arguments:
+the buffer object itself and the current mark symbol."
(assert (eq major-mode 'ibuffer-mode))
- (let ((curline (count-lines (point-min)
- (line-beginning-position)))
- (deleted-lines-count 0)
- (ibuffer-map-lines-total 0)
- (ibuffer-map-lines-count 0))
+ (ibuffer-forward-line 0)
+ (let* ((orig-target-line (1+ (count-lines (save-excursion
+ (goto-char (point-min))
+ (ibuffer-forward-line 0)
+ (point))
+ (point))))
+ (target-line-offset orig-target-line)
+ (ibuffer-map-lines-total 0)
+ (ibuffer-map-lines-count 0))
(unwind-protect
- (progn
- (setq buffer-read-only nil)
- (goto-char (point-min))
- (while (and (get-text-property (point) 'ibuffer-title)
- (not (eobp)))
- (forward-line 1))
- (while (not (eobp))
- (let ((result
- (if (buffer-live-p (ibuffer-current-buffer))
- (save-excursion
- (funcall function
- (ibuffer-current-buffer)
- (ibuffer-current-mark)
- (line-beginning-position)
- (1+ (line-end-position))))
- ;; Kill the line if the buffer is dead
- 'kill)))
- ;; A given mapping function should return:
- ;; `nil' if it chose not to affect the buffer
- ;; `kill' means the remove line from the buffer list
- ;; `t' otherwise
- (incf ibuffer-map-lines-total)
- (cond ((null result)
- (forward-line 1))
- ((eq result 'kill)
- (delete-region (line-beginning-position)
- (1+ (line-end-position)))
- (incf deleted-lines-count)
- (incf ibuffer-map-lines-count))
- (t
- (incf ibuffer-map-lines-count)
- (forward-line 1)))))
- ibuffer-map-lines-count)
+ (progn
+ (setq buffer-read-only nil)
+ (goto-char (point-min))
+ (ibuffer-forward-line 0 t)
+ (while (and (not (eobp))
+ (not (get-text-property (point) 'ibuffer-summary))
+ (progn
+ (ibuffer-forward-line 0 t)
+ (and (not (eobp))
+ (not (get-text-property (point) 'ibuffer-summary)))))
+ (let ((result
+ (if (buffer-live-p (ibuffer-current-buffer))
+ (when (or (null group)
+ (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group)
+ (equal group it)))
+ (save-excursion
+ (funcall function
+ (ibuffer-current-buffer)
+ (ibuffer-current-mark))))
+ ;; Kill the line if the buffer is dead
+ 'kill)))
+ ;; A given mapping function should return:
+ ;; `nil' if it chose not to affect the buffer
+ ;; `kill' means the remove line from the buffer list
+ ;; `t' otherwise
+ (incf ibuffer-map-lines-total)
+ (cond ((null result)
+ (forward-line 1))
+ ((eq result 'kill)
+ (delete-region (line-beginning-position)
+ (1+ (line-end-position)))
+ (incf ibuffer-map-lines-count)
+ (when (< ibuffer-map-lines-total
+ orig-target-line)
+ (decf target-line-offset)))
+ (t
+ (incf ibuffer-map-lines-count)
+ (forward-line 1)))))
+ ibuffer-map-lines-count)
(progn
(setq buffer-read-only t)
(unless nomodify
(set-buffer-modified-p nil))
- (goto-line (- (1+ curline) deleted-lines-count))))))
+ (goto-char (point-min))
+ (ibuffer-forward-line 0)
+ (ibuffer-forward-line (1- target-line-offset))))))
(defun ibuffer-get-marked-buffers ()
"Return a list of buffer objects currently marked."
(car e)))
(ibuffer-current-state-list))))
-(defun ibuffer-current-state-list (&optional include-lines)
+(defun ibuffer-current-state-list (&optional pos)
"Return a list like (BUF . MARK) of all buffers in an ibuffer.
-If optional argument INCLUDE-LINES is non-nil, return a list like
- (BUF MARK BEGPOS)."
+If POS is non-nil, return a list like (BUF MARK POINT), where POINT is
+the value of point at the beginning of the line for that buffer."
(let ((ibuffer-current-state-list-tmp '()))
;; ah, if only we had closures. I bet this will mysteriously
;; break later. Don't blame me.
- (ibuffer-map-lines-nomodify
- (if include-lines
- #'(lambda (buf mark beg end)
+ (if pos
+ (ibuffer-map-lines-nomodify
+ #'(lambda (buf mark)
(when (buffer-live-p buf)
- (push (list buf mark beg) ibuffer-current-state-list-tmp)))
- #'(lambda (buf mark beg end)
+ (push (list buf mark (point)) ibuffer-current-state-list-tmp))))
+ (ibuffer-map-lines-nomodify
+ #'(lambda (buf mark)
(when (buffer-live-p buf)
(push (cons buf mark) ibuffer-current-state-list-tmp)))))
(nreverse ibuffer-current-state-list-tmp)))
-(defsubst ibuffer-canonicalize-state-list (bmarklist)
- "Order BMARKLIST in the same way as the current buffer list."
- (delq nil
- (mapcar #'(lambda (buf) (assq buf bmarklist)) (buffer-list))))
-
-(defun ibuffer-current-buffers-with-marks ()
+(defun ibuffer-current-buffers-with-marks (curbufs)
"Return a list like (BUF . MARK) of all open buffers."
(let ((bufs (ibuffer-current-state-list)))
(mapcar #'(lambda (buf) (let ((e (assq buf bufs)))
(if e
e
(cons buf ? ))))
- (buffer-list))))
+ curbufs)))
(defun ibuffer-buf-matches-predicates (buf predicates)
(let ((hit nil)
(funcall pred buf))
(setq hit t)))
hit))
-
+
(defun ibuffer-filter-buffers (ibuffer-buf last bmarklist all)
(let ((ext-loaded (featurep 'ibuf-ext)))
(delq nil
- (mapcar
- ;; element should be like (BUFFER . MARK)
- #'(lambda (e)
- (let* ((buf (car e)))
- (when
- ;; This takes precedence over anything else
- (or (and ibuffer-always-show-last-buffer
- (eq last buf))
- (funcall (if ext-loaded
- #'ibuffer-ext-visible-p
- #'ibuffer-visible-p)
- buf all ibuffer-buf))
- e)))
- bmarklist))))
+ (mapcar
+ ;; element should be like (BUFFER . MARK)
+ #'(lambda (e)
+ (let* ((buf (car e)))
+ (when
+ ;; This takes precedence over anything else
+ (or (and ibuffer-always-show-last-buffer
+ (eq last buf))
+ (funcall (if ext-loaded
+ #'ibuffer-ext-visible-p
+ #'ibuffer-visible-p)
+ buf all ibuffer-buf))
+ e)))
+ bmarklist))))
(defun ibuffer-visible-p (buf all &optional ibuffer-buf)
(and (or all
(not
(ibuffer-buf-matches-predicates buf ibuffer-maybe-show-predicates)))
(or ibuffer-view-ibuffer
- (and ibuffer-buf
+ (and ibuffer-buf
(not (eq ibuffer-buf buf))))))
;; This function is a special case; it's not defined by
(ibuffer-update-format)
(ibuffer-redisplay t))
-(defun ibuffer-update-title (format)
+(defun ibuffer-update-title-and-summary (format)
(assert (eq major-mode 'ibuffer-mode))
;; Don't do funky font-lock stuff here
(let ((after-change-functions nil))
(next-single-property-change
(point-min) 'ibuffer-title)))
(goto-char (point-min))
- (put-text-property
+ (add-text-properties
(point)
(progn
(let ((opos (point)))
;; Insert the title names.
- (dolist (element (mapcar #'ibuffer-expand-format-entry format))
+ (dolist (element format)
(insert
(if (stringp element)
element
(min (cadr element))
;; (max (caddr element))
(align (cadddr element)))
- ;; Ignore a negative min when we're inserting the title
+ ;; Ignore a negative min when we're inserting the title
(when (minusp min)
(setq min (- min)))
(let* ((name (or (get sym 'ibuffer-column-name)
(error "Unknown column %s in ibuffer-formats" sym)))
(len (length name)))
- (prog1
- (if (< len min)
- (ibuffer-format-column name
- (- min len)
- align)
- name)))))))
- (put-text-property opos (point) 'ibuffer-title-header t)
+ (if (< len min)
+ (ibuffer-format-column name
+ (- min len)
+ align)
+ name))))))
+ (add-text-properties opos (point) `(ibuffer-title-header t))
(insert "\n")
;; Add the underlines
(let ((str (save-excursion
str)))
(insert "\n"))
(point))
- 'ibuffer-title t)))
+ `(ibuffer-title t font-lock-face ,ibuffer-title-face))
+ ;; Now, insert the summary columns.
+ (goto-char (point-max))
+ (if (get-text-property (1- (point-max)) 'ibuffer-summary)
+ (delete-region (previous-single-property-change
+ (point-max) 'ibuffer-summary)
+ (point-max)))
+ (if ibuffer-display-summary
+ (add-text-properties
+ (point)
+ (progn
+ (insert "\n")
+ (dolist (element format)
+ (insert
+ (if (stringp element)
+ (make-string (length element) ? )
+ (let ((sym (car element)))
+ (let ((min (cadr element))
+ ;; (max (caddr element))
+ (align (cadddr element)))
+ ;; Ignore a negative min when we're inserting the title
+ (when (minusp min)
+ (setq min (- min)))
+ (let* ((summary (if (get sym 'ibuffer-column-summarizer)
+ (funcall (get sym 'ibuffer-column-summarizer)
+ (get sym 'ibuffer-column-summary))
+ (make-string (length (get sym 'ibuffer-column-name))
+ ? )))
+ (len (length summary)))
+ (if (< len min)
+ (ibuffer-format-column summary
+ (- min len)
+ align)
+ summary)))))))
+ (point))
+ `(ibuffer-summary t)))))
(defun ibuffer-update-mode-name ()
(setq mode-name (format "Ibuffer by %s" (if ibuffer-sorting-mode
ibuffer-sorting-mode
- "recency")))
+ "view time")))
(when ibuffer-sorting-reversep
(setq mode-name (concat mode-name " [rev]")))
(when (and (featurep 'ibuf-ext)
(defun ibuffer-redisplay (&optional silent)
"Redisplay the current list of buffers.
-
This does not show new buffers; use `ibuffer-update' for that.
-If SILENT is non-`nil', do not generate progress messages."
+If optional arg SILENT is non-nil, do not display progress messages."
(interactive)
+ (ibuffer-forward-line 0)
(unless silent
(message "Redisplaying current buffer list..."))
(let ((blist (ibuffer-current-state-list)))
(when (null blist)
(if (and (featurep 'ibuf-ext)
- ibuffer-filtering-qualifiers)
+ (or ibuffer-filtering-qualifiers ibuffer-hidden-filter-groups))
(message "No buffers! (note: filtering in effect)")
(error "No buffers!")))
- (ibuffer-insert-buffers-and-marks blist t)
+ (ibuffer-redisplay-engine blist t)
(ibuffer-update-mode-name)
(unless silent
- (message "Redisplaying current buffer list...done"))))
+ (message "Redisplaying current buffer list...done"))
+ (ibuffer-forward-line 0)))
(defun ibuffer-update (arg &optional silent)
"Regenerate the list of all buffers.
-Display buffers whose name matches one of `ibuffer-maybe-show-predicates'
-iff arg ARG is non-nil.
+Prefix arg non-nil means to toggle whether buffers that match
+`ibuffer-maybe-show-predicates' should be displayed.
-Do not display messages if SILENT is non-nil."
+If optional arg SILENT is non-nil, do not display progress messages."
(interactive "P")
+ (if arg
+ (setq ibuffer-display-maybe-show-predicates
+ (not ibuffer-display-maybe-show-predicates)))
+ (ibuffer-forward-line 0)
(let* ((bufs (buffer-list))
(blist (ibuffer-filter-buffers
- (current-buffer)
- (if (and
- (cadr bufs)
- (eq ibuffer-always-show-last-buffer
- :nomini)
- ;; This is a hack.
- (string-match " \\*Minibuf"
- (buffer-name (cadr bufs))))
- (caddr bufs)
- (cadr bufs))
- (ibuffer-current-buffers-with-marks)
- arg)))
+ (current-buffer)
+ (if (and
+ (cadr bufs)
+ (eq ibuffer-always-show-last-buffer
+ :nomini)
+ (minibufferp (cadr bufs)))
+ (caddr bufs)
+ (cadr bufs))
+ (ibuffer-current-buffers-with-marks bufs)
+ ibuffer-display-maybe-show-predicates)))
(when (null blist)
(if (and (featurep 'ibuf-ext)
ibuffer-filtering-qualifiers)
(error "No buffers!")))
(unless silent
(message "Updating buffer list..."))
- (ibuffer-insert-buffers-and-marks blist
- arg)
+ (ibuffer-redisplay-engine blist arg)
(ibuffer-update-mode-name)
(unless silent
(message "Updating buffer list...done")))
(ibuffer-shrink-to-fit)))
(ibuffer-forward-line 0))
-(defun ibuffer-insert-buffers-and-marks (bmarklist &optional all)
+(defun ibuffer-sort-bufferlist (bmarklist)
+ (let* ((sortdat (assq ibuffer-sorting-mode
+ ibuffer-sorting-functions-alist))
+ (func (caddr sortdat)))
+ (let ((result
+ ;; actually sort the buffers
+ (if (and sortdat func)
+ (sort bmarklist func)
+ bmarklist)))
+ ;; perhaps reverse the sorted buffer list
+ (if ibuffer-sorting-reversep
+ (nreverse result)
+ result))))
+
+(defun ibuffer-insert-filter-group (name display-name filter-string format bmarklist)
+ (add-text-properties
+ (point)
+ (progn
+ (insert "[ " display-name " ]")
+ (point))
+ `(ibuffer-filter-group-name
+ ,name
+ font-lock-face ,ibuffer-filter-group-name-face
+ keymap ,ibuffer-mode-filter-group-map
+ mouse-face highlight
+ help-echo ,(let ((echo '(if tooltip-mode
+ "mouse-1: toggle marks in this group\nmouse-2: hide/show this filtering group"
+ "mouse-1: toggle marks mouse-2: hide/show")))
+ (if (> (length filter-string) 0)
+ `(concat ,filter-string
+ (if tooltip-mode "\n" " ")
+ ,echo)
+ echo))))
+ (insert "\n")
+ (when bmarklist
+ (put-text-property
+ (point)
+ (progn
+ (dolist (entry bmarklist)
+ (ibuffer-insert-buffer-line (car entry) (cdr entry) format))
+ (point))
+ 'ibuffer-filter-group
+ name)))
+
+(defun ibuffer-redisplay-engine (bmarklist &optional ignore)
(assert (eq major-mode 'ibuffer-mode))
- (let ((--ibuffer-insert-buffers-and-marks-format
- (ibuffer-current-format))
- (orig (count-lines (point-min) (point)))
- ;; Inhibit font-lock caching tricks, since we're modifying the
- ;; entire buffer at once
- (after-change-functions nil))
+ (let* ((--ibuffer-insert-buffers-and-marks-format
+ (ibuffer-current-format))
+ (--ibuffer-expanded-format (mapcar #'ibuffer-expand-format-entry
+ (ibuffer-current-format t)))
+ (orig (count-lines (point-min) (point)))
+ ;; Inhibit font-lock caching tricks, since we're modifying the
+ ;; entire buffer at once
+ (after-change-functions nil)
+ (ext-loaded (featurep 'ibuf-ext))
+ (bgroups (if ext-loaded
+ (ibuffer-generate-filter-groups bmarklist)
+ (list (cons "Default" bmarklist)))))
+ (ibuffer-clear-summary-columns --ibuffer-expanded-format)
(unwind-protect
(progn
(setq buffer-read-only nil)
(erase-buffer)
(ibuffer-update-format)
- (let ((entries
- (let* ((sortdat (assq ibuffer-sorting-mode
- ibuffer-sorting-functions-alist))
- (func (caddr sortdat)))
- (let ((result
- ;; actually sort the buffers
- (if (and sortdat func)
- (sort bmarklist func)
- bmarklist)))
- ;; perhaps reverse the sorted buffer list
- (if ibuffer-sorting-reversep
- result
- (nreverse result))))))
- (dolist (entry entries)
- (ibuffer-insert-buffer-line
- (car entry)
- (cdr entry)
- --ibuffer-insert-buffers-and-marks-format)))
- (ibuffer-update-title (ibuffer-current-format t)))
+ (dolist (group (nreverse bgroups))
+ (let* ((name (car group))
+ (disabled (and ext-loaded
+ (member name ibuffer-hidden-filter-groups)))
+ (bmarklist (cdr group)))
+ (unless (and (null bmarklist)
+ (not disabled)
+ ext-loaded
+ (null ibuffer-show-empty-filter-groups))
+ (ibuffer-insert-filter-group
+ name
+ (if disabled (concat name " ...") name)
+ (if ext-loaded
+ (ibuffer-format-filter-group-data name)
+ "")
+ --ibuffer-insert-buffers-and-marks-format
+ (if disabled
+ nil
+ (ibuffer-sort-bufferlist bmarklist))))))
+ (ibuffer-update-title-and-summary --ibuffer-expanded-format))
(setq buffer-read-only t)
(set-buffer-modified-p ibuffer-did-modification)
(setq ibuffer-did-modification nil)
(defun ibuffer-quit ()
"Quit this `ibuffer' session.
-Delete the current window iff `ibuffer-delete-window-on-quit' is non-nil."
+Try to restore the previous window configuration iff
+`ibuffer-restore-window-config-on-quit' is non-nil."
(interactive)
- (if ibuffer-delete-window-on-quit
+ (if ibuffer-restore-window-config-on-quit
(progn
(bury-buffer)
(unless (= (count-windows) 1)
- (delete-window)))
+ (set-window-configuration ibuffer-prev-window-config)))
(bury-buffer)))
;;;###autoload
'((filename . ".*")))))
;;;###autoload
-(defun ibuffer (&optional other-window-p name qualifiers noselect shrink)
+(defun ibuffer (&optional other-window-p name qualifiers noselect
+ shrink filter-groups formats)
"Begin using `ibuffer' to edit a list of buffers.
Type 'h' after entering ibuffer for more information.
to use; see `ibuffer-filtering-qualifiers'.
Optional argument NOSELECT means don't select the Ibuffer buffer.
Optional argument SHRINK means shrink the buffer to minimal size. The
-special value `onewindow' means always use another window."
+special value `onewindow' means always use another window.
+Optional argument FILTER-GROUPS is an initial set of filtering
+groups to use; see `ibuffer-filter-groups'.
+Optional argument FORMATS is the value to use for `ibuffer-formats'.
+If specified, then the variable `ibuffer-formats' will have that value
+locally in this buffer."
(interactive "P")
-
- ;; The individual functions are lazy-loaded, via byte-compile-dynamic,
- ;; so we may as well load the file unconditionally now.
- (require 'ibuf-ext)
-
(when ibuffer-use-other-window
- (setq other-window-p (not other-window-p)))
- (let* ((buf (get-buffer-create (or name "*Ibuffer*")))
- (already-in (eq (current-buffer) buf))
- (need-update nil))
+ (setq other-window-p t))
+ (setq ibuffer-prev-window-config (current-window-configuration))
+ (let ((buf (get-buffer-create (or name "*Ibuffer*"))))
(if other-window-p
(funcall (if noselect #'(lambda (buf) (display-buffer buf t)) #'pop-to-buffer) buf)
(funcall (if noselect #'display-buffer #'switch-to-buffer) buf))
(with-current-buffer buf
- (let ((owin (selected-window)))
+ (save-selected-window
+ ;; We switch to the buffer's window in order to be able
+ ;; to modify the value of point
+ (select-window (get-buffer-window buf))
+ (or (eq major-mode 'ibuffer-mode)
+ (ibuffer-mode))
+ (setq ibuffer-restore-window-config-on-quit other-window-p)
+ (when shrink
+ (setq ibuffer-shrink-to-minimum-size shrink))
+ (when qualifiers
+ (require 'ibuf-ext)
+ (setq ibuffer-filtering-qualifiers qualifiers))
+ (when filter-groups
+ (require 'ibuf-ext)
+ (setq ibuffer-filter-groups filter-groups))
+ (when formats
+ (set (make-local-variable 'ibuffer-formats) formats))
+ (ibuffer-update nil)
+ ;; Skip the group name by default.
+ (ibuffer-forward-line 0 t)
(unwind-protect
(progn
- ;; We switch to the buffer's window in order to be able
- ;; to modify the value of point
- (select-window (get-buffer-window buf))
- (unless (eq major-mode 'ibuffer-mode)
- (ibuffer-mode)
- (setq need-update t))
- (when (ibuffer-use-fontification)
- (require 'font-lock))
- (setq ibuffer-delete-window-on-quit other-window-p)
- (when shrink
- (setq ibuffer-shrink-to-minimum-size shrink))
- (when qualifiers
- (setq ibuffer-filtering-qualifiers qualifiers))
- (ibuffer-update nil)
- (unwind-protect
- (progn
- (setq buffer-read-only nil)
- (run-hooks 'ibuffer-hooks))
- (setq buffer-read-only t))
- (unless ibuffer-expert
- (message "Commands: m, u, t, RET, g, k, S, D, Q; q to quit; h for help")))
- (select-window owin))))))
+ (setq buffer-read-only nil)
+ (run-hooks 'ibuffer-hook))
+ (setq buffer-read-only t))
+ (unless ibuffer-expert
+ (message "Commands: m, u, t, RET, g, k, S, D, Q; q to quit; h for help"))))))
+(put 'ibuffer-mode 'mode-class 'special)
(defun ibuffer-mode ()
"A major mode for viewing a list of buffers.
In ibuffer, you can conveniently perform many operations on the
Filtering commands:
'\\[ibuffer-filter-by-mode]' - Add a filter by major mode.
+ '\\[ibuffer-filter-by-used-mode]' - Add a filter by major mode now in use.
'\\[ibuffer-filter-by-name]' - Add a filter by buffer name.
'\\[ibuffer-filter-by-content]' - Add a filter by buffer content.
'\\[ibuffer-filter-by-filename]' - Add a filter by filename.
'\\[ibuffer-negate-filter]' - Invert the logical sense of the top filter.
'\\[ibuffer-decompose-filter]' - Break down the topmost filter.
'\\[ibuffer-filter-disable]' - Remove all filtering currently in effect.
-
+
+Filter group commands:
+
+ '\\[ibuffer-filters-to-filter-group]' - Create filter group from filters.
+ '\\[ibuffer-pop-filter-group]' - Remove top filter group.
+ '\\[ibuffer-forward-filter-group]' - Move to the next filter group.
+ '\\[ibuffer-backward-filter-group]' - Move to the previous filter group.
+ '\\[ibuffer-clear-filter-groups]' - Remove all active filter groups.
+ '\\[ibuffer-save-filter-groups]' - Save the current groups with a name.
+ '\\[ibuffer-switch-to-saved-filter-groups]' - Restore previously saved groups.
+ '\\[ibuffer-delete-saved-filter-groups]' - Delete previously saved groups.
+
Sorting commands:
'\\[ibuffer-toggle-sorting-mode]' - Rotate between the various sorting modes.
the new window.
'\\[ibuffer-bury-buffer]' - Bury (not kill!) the buffer on this line.
-Information on Filtering:
+** Information on Filtering:
You can filter your ibuffer view via different critera. Each Ibuffer
buffer has its own stack of active filters. For example, suppose you
To remove the top filter on the stack, use '\\[ibuffer-pop-filter]', and
to disable all filtering currently in effect, use
-'\\[ibuffer-filter-disable]'."
+'\\[ibuffer-filter-disable]'.
+
+** Filter Groups:
+
+Once one has mastered filters, the next logical step up is \"filter
+groups\". A filter group is basically a named group of buffers which
+match a filter, which are displayed together in an Ibuffer buffer. To
+create a filter group, simply use the regular functions to create a
+filter, and then type '\\[ibuffer-filters-to-filter-group]'.
+
+A quick example will make things clearer. Suppose that one wants to
+group all of one's Emacs Lisp buffers together. To do this, type
+
+'\\[ibuffer-filter-by-mode] emacs-lisp-mode RET \\[ibuffer-filters-to-filter-group] RET emacs lisp buffers RET'
+
+You may, of course, name the group whatever you want; it doesn't have
+to be \"emacs lisp buffers\". Filter groups may be composed of any
+arbitrary combination of filters.
+
+Just like filters themselves, filter groups act as a stack. Buffers
+will not be displayed multiple times if they would be included in
+multiple filter groups; instead, the first filter group is used. The
+filter groups are displayed in this order of precedence.
+
+You may rearrange filter groups by using the regular
+'\\[ibuffer-kill-line]' and '\\[ibuffer-yank]' pair. Yanked groups
+will be inserted before the group at point."
(kill-all-local-variables)
(use-local-map ibuffer-mode-map)
(setq major-mode 'ibuffer-mode)
;; This makes things less ugly for Emacs 21 users with a non-nil
;; `show-trailing-whitespace'.
(setq show-trailing-whitespace nil)
- ;; Dummy font-lock-defaults to make font-lock turn on. We want this
- ;; so we know when to enable ibuffer's internal fontification.
- (set (make-local-variable 'font-lock-defaults)
- '(nil t nil nil nil
- (font-lock-fontify-region-function . ibuffer-fontify-region-function)
- (font-lock-unfontify-region-function . ibuffer-unfontify-region-function)))
+ ;; disable `show-paren-mode' buffer-locally
+ (if (bound-and-true-p show-paren-mode)
+ (set (make-local-variable 'show-paren-mode) nil))
(set (make-local-variable 'revert-buffer-function)
#'ibuffer-update)
(set (make-local-variable 'ibuffer-sorting-mode)
ibuffer-default-sorting-reversep)
(set (make-local-variable 'ibuffer-shrink-to-minimum-size)
ibuffer-default-shrink-to-minimum-size)
+ (set (make-local-variable 'ibuffer-display-maybe-show-predicates)
+ ibuffer-default-display-maybe-show-predicates)
(set (make-local-variable 'ibuffer-filtering-qualifiers) nil)
+ (set (make-local-variable 'ibuffer-filter-groups) nil)
+ (set (make-local-variable 'ibuffer-filter-group-kill-ring) nil)
+ (set (make-local-variable 'ibuffer-hidden-filter-groups) nil)
(set (make-local-variable 'ibuffer-compiled-formats) nil)
(set (make-local-variable 'ibuffer-cached-formats) nil)
(set (make-local-variable 'ibuffer-cached-eliding-string) nil)
(set (make-local-variable 'ibuffer-cached-elide-long-columns) nil)
(set (make-local-variable 'ibuffer-current-format) nil)
- (set (make-local-variable 'ibuffer-did-modifiction) nil)
- (set (make-local-variable 'ibuffer-delete-window-on-quit) nil)
+ (set (make-local-variable 'ibuffer-restore-window-config-on-quit) nil)
(set (make-local-variable 'ibuffer-did-modification) nil)
- (when (featurep 'ibuf-ext)
- (set (make-local-variable 'ibuffer-tmp-hide-regexps) nil)
- (set (make-local-variable 'ibuffer-tmp-show-regexps) nil))
+ (set (make-local-variable 'ibuffer-tmp-hide-regexps) nil)
+ (set (make-local-variable 'ibuffer-tmp-show-regexps) nil)
(define-key ibuffer-mode-map [menu-bar edit] 'undefined)
(define-key ibuffer-mode-map [menu-bar operate] (cons "Operate" ibuffer-mode-operate-map))
(ibuffer-update-format)
(when ibuffer-default-directory
(setq default-directory ibuffer-default-directory))
- (run-hooks 'ibuffer-mode-hooks)
+ (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
+ (run-mode-hooks 'ibuffer-mode-hook)
;; called after mode hooks to allow the user to add filters
(ibuffer-update-mode-name))
(provide 'ibuffer)
+(run-hooks 'ibuffer-load-hook)
+
;; Local Variables:
;; coding: iso-8859-1
;; End:
+;;; arch-tag: 72581688-0603-4954-b8cf-837c700f62e8
;;; ibuffer.el ends here