;;; bs.el --- menu for selecting and displaying buffers
;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006 Free Software Foundation, Inc.
+;; 2005, 2006, 2007 Free Software Foundation, Inc.
;; Author: Olaf Sylvester <Olaf.Sylvester@netsurf.de>
;; Maintainer: Olaf Sylvester <Olaf.Sylvester@netsurf.de>
;; Keywords: convenience
(defvar bs--show-all nil
"Flag whether showing all buffers regardless of current configuration.
-Non nil means to show all buffers. Otherwise show buffers
+Non-nil means to show all buffers. Otherwise show buffers
defined by current configuration `bs-current-configuration'.")
(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.
(defun bs--redisplay (&optional keep-line-p sort-description)
"Redisplay whole Buffer Selection Menu.
-If KEEP-LINE-P is non nil the point will stay on current line.
-SORT-DESCRIPTION is an element of `bs-sort-functions'"
+If KEEP-LINE-P is non-nil the point will stay on current line.
+SORT-DESCRIPTION is an element of `bs-sort-functions'."
(let ((line (1+ (count-lines 1 (point)))))
(bs-show-in-buffer (bs-buffer-list nil sort-description))
(if keep-line-p
(use-local-map bs-mode-map)
(make-local-variable 'font-lock-defaults)
(make-local-variable 'font-lock-verbose)
+ (buffer-disable-undo)
(setq major-mode 'bs-mode
mode-name "Buffer-Selection-Menu"
buffer-read-only t
font-lock-verbose nil)
(run-mode-hooks 'bs-mode-hook))
+(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)
+ (setq bs--window-config-coming-from nil)))
+
(defun bs-kill ()
"Let buffer disappear and reset window-configuration."
(interactive)
(bury-buffer (current-buffer))
- (set-window-configuration bs--window-config-coming-from))
+ (bs--restore-window-config))
(defun bs-abort ()
"Ding and leave Buffer Selection Menu without a selection."
(interactive)
(bs--redisplay t))
-(defun bs--window-for-buffer (buffer-name)
- "Return a window showing a buffer with name BUFFER-NAME.
-Take only windows of current frame into account.
-Return nil if there is no such buffer."
- (let ((window nil))
- (walk-windows (lambda (wind)
- (if (string= (buffer-name (window-buffer wind))
- buffer-name)
- (setq window wind))))
- window))
-
(defun bs--set-window-height ()
"Change the height of the selected window to suit the current buffer list."
(unless (one-window-p t)
(interactive)
(let ((buffer (bs--current-buffer)))
(bury-buffer (current-buffer))
- (set-window-configuration bs--window-config-coming-from)
+ (bs--restore-window-config)
(switch-to-buffer buffer)
(if bs--marked-buffers
;; Some marked buffers for selection
(interactive)
(let ((buffer (bs--current-buffer)))
(bury-buffer (current-buffer))
- (set-window-configuration bs--window-config-coming-from)
+ (bs--restore-window-config)
(switch-to-buffer-other-window buffer)))
(defun bs-tmp-select-other-window ()
(interactive)
(let ((buffer (bs--current-buffer)))
(bury-buffer (current-buffer))
- (set-window-configuration bs--window-config-coming-from)
+ (bs--restore-window-config)
(switch-to-buffer-other-frame buffer)))
(defun bs-mouse-select-other-frame (event)
(defun bs--up ()
"Move cursor vertically up one line.
If on top of buffer list go to last line."
- (interactive "p")
(if (> (count-lines 1 (point)) bs-header-lines-length)
(forward-line -1)
(goto-char (point-max))
(bs--set-window-height)
(bs--goto-current-buffer)
(font-lock-fontify-buffer)
- (bs-apply-sort-faces)))
+ (bs-apply-sort-faces)
+ (set-buffer-modified-p nil)))
(defun bs-next-buffer (&optional buffer-list sorting-p)
"Return next buffer and buffer list for buffer cycling in BUFFER-LIST.
(or (cdr bs--cycle-list)
"this buffer"))))))
-
;;;###autoload
(defun bs-cycle-previous ()
"Select previous buffer defined by buffer cycling.
default directory.
START-BUFFER is the buffer where we started buffer selection.
ALL-BUFFERS is the list of buffer appearing in Buffer Selection Menu."
- (let ((string (copy-sequence (if (member major-mode
- '(shell-mode dired-mode))
- default-directory
- (or buffer-file-name "")))))
- (add-text-properties
- 0 (length string)
- '(mouse-face highlight
- help-echo "mouse-2: select this buffer, mouse-3: select in other frame")
- string)
- string))
+ (propertize (if (member major-mode '(shell-mode dired-mode))
+ default-directory
+ (or buffer-file-name ""))
+ 'mouse-face 'highlight
+ 'help-echo "mouse-2: select this buffer, mouse-3: select in other frame"))
(defun bs--insert-one-entry (buffer)
"Generate one entry for buffer BUFFER in Buffer Selection Menu.
(unless (string= "*buffer-selection*" (buffer-name))
;; Only when not in buffer *buffer-selection*
;; we have to set the buffer we started the command
- (progn
- (setq bs--buffer-coming-from (current-buffer))
- (setq bs--window-config-coming-from (current-window-configuration))))
+ (setq bs--buffer-coming-from (current-buffer)))
(let ((liste (bs-buffer-list))
- (active-window (bs--window-for-buffer "*buffer-selection*")))
+ (active-window (get-window-with-predicate
+ (lambda (w)
+ (string= (buffer-name (window-buffer w))
+ "*buffer-selection*")))))
(if active-window
(select-window active-window)
- (if (> (window-height (selected-window)) 7)
- (progn
- (split-window-vertically)
- (other-window 1))))
+ (modify-frame-parameters nil
+ (list (cons 'bs--window-config-coming-from
+ (current-window-configuration))))
+ (when (> (window-height (selected-window)) 7)
+ (split-window-vertically)
+ (other-window 1)))
(bs-show-in-buffer liste)
(bs-message-without-log "%s" (bs--current-config-message)))))