;;; bs.el --- menu for selecting and displaying buffers
;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007 Free Software Foundation, Inc.
+;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
;; Author: Olaf Sylvester <Olaf.Sylvester@netsurf.de>
;; Maintainer: Olaf Sylvester <Olaf.Sylvester@netsurf.de>
;; Keywords: convenience
(defvar bs--window-config-coming-from nil
"Window configuration before starting Buffer Selection Menu.")
-(make-variable-frame-local 'bs--window-config-coming-from)
(defvar bs--intern-show-never "^ \\|\\*buffer-selection\\*"
"Regular expression specifying which buffers never to show.
(format "Show buffer by configuration %S"
bs-current-configuration)))
-(defun bs-mode ()
+(defun bs--track-window-changes (frame)
+ "Track window changes to refresh the buffer list.
+Used from `window-size-change-functions'."
+ (let ((win (get-buffer-window "*buffer-selection*" frame)))
+ (when win
+ (with-selected-window win
+ (bs--set-window-height)))))
+
+(defun bs--remove-hooks ()
+ "Remove `bs--track-window-changes' and auxiliary hooks."
+ (remove-hook 'window-size-change-functions 'bs--track-window-changes)
+ ;; Remove itself
+ (remove-hook 'kill-buffer-hook 'bs--remove-hooks t)
+ (remove-hook 'change-major-mode-hook 'bs--remove-hooks t))
+
+(put 'bs-mode 'mode-class 'special)
+
+(define-derived-mode bs-mode () "Buffer-Selection-Menu"
"Major mode for editing a subset of Emacs' buffers.
\\<bs-mode-map>
Aside from two header lines each line describes one buffer.
to show always.
\\[bs-visit-tags-table] -- call `visit-tags-table' on current line's buffer.
\\[bs-help] -- display this help text."
- (interactive)
- (kill-all-local-variables)
- (use-local-map bs-mode-map)
(make-local-variable 'font-lock-defaults)
(make-local-variable 'font-lock-verbose)
+ (make-local-variable 'font-lock-global-modes)
(buffer-disable-undo)
- (setq major-mode 'bs-mode
- mode-name "Buffer-Selection-Menu"
- buffer-read-only t
+ (setq buffer-read-only t
truncate-lines t
show-trailing-whitespace nil
+ font-lock-global-modes '(not bs-mode)
font-lock-defaults '(bs-mode-font-lock-keywords t)
font-lock-verbose nil)
- (run-mode-hooks 'bs-mode-hook))
+ (add-hook 'window-size-change-functions 'bs--track-window-changes)
+ (add-hook 'kill-buffer-hook 'bs--remove-hooks nil t)
+ (add-hook 'change-major-mode-hook 'bs--remove-hooks nil t))
(defun bs--restore-window-config ()
"Restore window configuration on the current frame."
(when bs--window-config-coming-from
- (set-window-configuration bs--window-config-coming-from)
+ (let ((frame (selected-frame)))
+ (unwind-protect
+ (set-window-configuration bs--window-config-coming-from)
+ (select-frame frame)))
(setq bs--window-config-coming-from nil)))
(defun bs-kill ()
(defun bs-select ()
"Select current line's buffer and other marked buffers.
If there are no marked buffers the window configuration before starting
-Buffer Selectin Menu will be restored.
+Buffer Selection Menu will be restored.
If there are marked buffers each marked buffer and the current line's buffer
will be selected in a window.
Leave Buffer Selection Menu."
(defun bs-select-other-window ()
"Select current line's buffer by `switch-to-buffer-other-window'.
-The window configuration before starting Buffer Selectin Menu will be restored
+The window configuration before starting Buffer Selection Menu will be restored
unless there is no other window. In this case a new window will be created.
Leave Buffer Selection Menu."
(interactive)
(bs-up 1))))
(defun bs-show-sorted ()
- "Show buffer list sorted by buffer name."
+ "Show buffer list sorted by next sort aspect."
(interactive)
(setq bs--current-sort-function
(bs-next-config-aux (car bs--current-sort-function)
(active-window (get-window-with-predicate
(lambda (w)
(string= (buffer-name (window-buffer w))
- "*buffer-selection*")))))
+ "*buffer-selection*"))
+ nil (selected-frame))))
(if active-window
(select-window active-window)
- (modify-frame-parameters nil
- (list (cons 'bs--window-config-coming-from
- (current-window-configuration))))
+ (bs--restore-window-config)
+ (setq bs--window-config-coming-from (current-window-configuration))
(when (> (window-height (selected-window)) 7)
(split-window-vertically)
(other-window 1)))