;;; bs.el --- menu for selecting and displaying buffers
-;; Copyright (C) 1998, 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+;; 2005, 2006 Free Software Foundation, Inc.
;; Author: Olaf Sylvester <Olaf.Sylvester@netsurf.de>
;; Maintainer: Olaf Sylvester <Olaf.Sylvester@netsurf.de>
;; Keywords: convenience
;;; Code:
+(defvar font-lock-verbose)
+
;; ----------------------------------------------------------------------
;; Globals for customization
;; ----------------------------------------------------------------------
:group 'bs-appearance
:type '(repeat sexp))
-(defvar bs--running-in-xemacs (string-match "XEmacs" (emacs-version))
- "Non-nil when running under XEmacs.")
-
(defun bs--make-header-match-string ()
"Return a regexp matching the first line of a Buffer Selection Menu buffer."
(let ((res "^\\(")
(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
(defun bs--set-window-height ()
"Change the height of the selected window to suit the current buffer list."
(unless (one-window-p t)
- (shrink-window (- (window-height (selected-window))
- ;; window-height in xemacs includes mode-line
- (+ (if bs--running-in-xemacs 3 1)
- bs-header-lines-length
- (min (length bs-current-list)
- bs-max-window-height))))))
+ (fit-window-to-buffer (selected-window) bs-max-window-height)))
(defun bs--current-buffer ()
"Return buffer on current line.
"Move cursor vertically up one line.
If on top of buffer list go to last line."
(interactive "p")
- (previous-line 1)
- (if (<= (count-lines 1 (point)) (1- bs-header-lines-length))
- (progn
- (goto-char (point-max))
- (beginning-of-line)
- (recenter -1))
- (beginning-of-line)))
+ (if (> (count-lines 1 (point)) bs-header-lines-length)
+ (forward-line -1)
+ (goto-char (point-max))
+ (beginning-of-line)
+ (recenter -1)))
(defun bs-down (arg)
"Move cursor vertically down ARG lines in Buffer Selection Menu."
(defun bs--down ()
"Move cursor vertically down one line.
If at end of buffer list go to first line."
- (let ((last (line-end-position)))
- (if (eq last (point-max))
- (goto-line (1+ bs-header-lines-length))
- (next-line 1))))
+ (if (eq (line-end-position) (point-max))
+ (goto-line (1+ bs-header-lines-length))
+ (forward-line 1)))
(defun bs-visits-non-file (buffer)
"Return t or nil whether BUFFER visits no file.
(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.
for mouse highlighting.
START-BUFFER is the buffer where we started buffer selection.
ALL-BUFFERS is the list of buffer appearing in Buffer Selection Menu."
- (let ((name (copy-sequence (buffer-name))))
- (add-text-properties
- 0 (length name)
- '(mouse-face highlight
- help-echo
- "mouse-2: select this buffer, mouse-3: select in other frame")
- name)
- (if (< (length name) bs--name-entry-length)
- (concat name
- (make-string (- bs--name-entry-length (length name)) ? ))
- name)))
+ (propertize (buffer-name)
+ 'help-echo "mouse-2: select this buffer, mouse-3: select in other frame"
+ 'mouse-face 'highlight))
(defun bs--get-mode-name (start-buffer all-buffers)
"Return the name of mode of current buffer for Buffer Selection Menu.
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.
(defun bs--format-aux (string align len)
"Generate a string with STRING with alignment ALIGN and length LEN.
ALIGN is one of the symbols `left', `middle', or `right'."
- (let ((length (length string)))
- (if (>= length len)
- string
- (if (eq 'right align)
- (concat (make-string (- len length) ? ) string)
- (concat string (make-string (- len length) ? ))))))
+ (let* ((width (length string))
+ (len (max len width)))
+ (format (format "%%%s%ds" (if (eq align 'right) "" "-") len)
+ (if (eq align 'middle)
+ (concat (make-string (/ (- len width) 2) ?\s) string)
+ string))))
(defun bs--show-header ()
"Insert header for Buffer Selection Menu in current buffer."