1992-05-30 23:54:21 +00:00
|
|
|
;;; ebuff-menu.el --- electric-buffer-list mode
|
|
|
|
|
2006-12-05 06:15:26 +00:00
|
|
|
;; Copyright (C) 1985, 1986, 1994, 2001, 2002, 2003, 2004,
|
2007-01-21 03:53:13 +00:00
|
|
|
;; 2005, 2006, 2007 Free Software Foundation, Inc.
|
1991-12-21 09:29:41 +00:00
|
|
|
|
1992-07-22 04:22:42 +00:00
|
|
|
;; Author: Richard Mlynarik <mly@ai.mit.edu>
|
1998-03-03 02:02:53 +00:00
|
|
|
;; Maintainer: FSF
|
2000-09-12 12:37:36 +00:00
|
|
|
;; Keywords: convenience
|
1992-07-22 04:22:42 +00:00
|
|
|
|
1991-12-21 09:29:41 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
1992-07-16 21:47:34 +00:00
|
|
|
;; the Free Software Foundation; either version 2, or (at your option)
|
1991-12-21 09:29:41 +00:00
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
1996-01-14 07:34:30 +00:00
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
2005-07-04 23:32:44 +00:00
|
|
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
1991-12-21 09:29:41 +00:00
|
|
|
|
1992-07-16 21:47:34 +00:00
|
|
|
;;; Commentary:
|
|
|
|
|
1993-03-22 03:27:18 +00:00
|
|
|
;; Who says one can't have typeout windows in GNU Emacs? The entry
|
|
|
|
;; point, `electric-buffer-list' works like ^r select buffer from the
|
|
|
|
;; ITS Emacs lunar or tmacs libraries.
|
1992-07-16 21:47:34 +00:00
|
|
|
|
|
|
|
;;; Code:
|
1991-12-21 09:29:41 +00:00
|
|
|
|
|
|
|
(require 'electric)
|
|
|
|
|
|
|
|
;; this depends on the format of list-buffers (from src/buffer.c) and
|
|
|
|
;; on stuff in lisp/buff-menu.el
|
|
|
|
|
|
|
|
(defvar electric-buffer-menu-mode-map nil)
|
|
|
|
|
2004-11-10 10:45:59 +00:00
|
|
|
(defvar electric-buffer-menu-mode-hook nil
|
|
|
|
"Normal hook run by `electric-buffer-list'.")
|
|
|
|
|
1991-12-21 09:29:41 +00:00
|
|
|
;;;###autoload
|
|
|
|
(defun electric-buffer-list (arg)
|
2004-11-10 10:45:59 +00:00
|
|
|
"Pop up a buffer describing the set of Emacs buffers.
|
1991-12-21 09:29:41 +00:00
|
|
|
Vaguely like ITS lunar select buffer; combining typeoutoid buffer
|
|
|
|
listing with menuoid buffer selection.
|
|
|
|
|
|
|
|
If the very next character typed is a space then the buffer list
|
|
|
|
window disappears. Otherwise, one may move around in the buffer list
|
|
|
|
window, marking buffers to be selected, saved or deleted.
|
|
|
|
|
|
|
|
To exit and select a new buffer, type a space when the cursor is on
|
|
|
|
the appropriate line of the buffer-list window. Other commands are
|
2004-11-10 10:45:59 +00:00
|
|
|
much like those of `Buffer-menu-mode'.
|
1991-12-21 09:29:41 +00:00
|
|
|
|
2004-11-10 10:45:59 +00:00
|
|
|
Run hooks in `electric-buffer-menu-mode-hook' on entry.
|
1991-12-21 09:29:41 +00:00
|
|
|
|
2003-02-04 11:26:42 +00:00
|
|
|
\\{electric-buffer-menu-mode-map}"
|
1991-12-21 09:29:41 +00:00
|
|
|
(interactive "P")
|
|
|
|
(let (select buffer)
|
|
|
|
(save-window-excursion
|
2001-08-23 22:17:34 +00:00
|
|
|
(setq buffer (list-buffers-noselect arg))
|
|
|
|
(Electric-pop-up-window buffer)
|
1991-12-21 09:29:41 +00:00
|
|
|
(unwind-protect
|
|
|
|
(progn
|
|
|
|
(set-buffer buffer)
|
|
|
|
(Electric-buffer-menu-mode)
|
2001-11-13 17:29:40 +00:00
|
|
|
(electric-buffer-update-highlight)
|
1991-12-21 09:29:41 +00:00
|
|
|
(setq select
|
|
|
|
(catch 'electric-buffer-menu-select
|
1994-07-02 17:01:41 +00:00
|
|
|
(message "<<< Press Return to bury the buffer list >>>")
|
1993-03-06 06:05:12 +00:00
|
|
|
(if (eq (setq unread-command-events (list (read-event)))
|
2006-11-27 13:48:25 +00:00
|
|
|
?\s)
|
1993-01-26 01:58:16 +00:00
|
|
|
(progn (setq unread-command-events nil)
|
1991-12-21 09:29:41 +00:00
|
|
|
(throw 'electric-buffer-menu-select nil)))
|
1995-07-17 23:09:48 +00:00
|
|
|
(let ((start-point (point))
|
|
|
|
(first (progn (goto-char (point-min))
|
2003-03-06 10:52:39 +00:00
|
|
|
(unless Buffer-menu-use-header-line
|
|
|
|
(forward-line 2))
|
1991-12-21 09:29:41 +00:00
|
|
|
(point)))
|
|
|
|
(last (progn (goto-char (point-max))
|
|
|
|
(forward-line -1)
|
|
|
|
(point)))
|
|
|
|
(goal-column 0))
|
1995-07-17 23:09:48 +00:00
|
|
|
;; Use start-point if it is meaningful.
|
|
|
|
(goto-char (if (or (< start-point first)
|
|
|
|
(> start-point last))
|
|
|
|
first
|
|
|
|
start-point))
|
1991-12-21 09:29:41 +00:00
|
|
|
(Electric-command-loop 'electric-buffer-menu-select
|
|
|
|
nil
|
|
|
|
t
|
|
|
|
'electric-buffer-menu-looper
|
|
|
|
(cons first last))))))
|
|
|
|
(set-buffer buffer)
|
|
|
|
(Buffer-menu-mode)
|
|
|
|
(bury-buffer buffer)
|
|
|
|
(message "")))
|
|
|
|
(if select
|
|
|
|
(progn (set-buffer buffer)
|
|
|
|
(let ((opoint (point-marker)))
|
|
|
|
(Buffer-menu-execute)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(if (prog1 (search-forward "\n>" nil t)
|
|
|
|
(goto-char opoint) (set-marker opoint nil))
|
|
|
|
(Buffer-menu-select)
|
|
|
|
(switch-to-buffer (Buffer-menu-buffer t))))))))
|
|
|
|
|
|
|
|
(defun electric-buffer-menu-looper (state condition)
|
|
|
|
(cond ((and condition
|
|
|
|
(not (memq (car condition) '(buffer-read-only
|
|
|
|
end-of-buffer
|
|
|
|
beginning-of-buffer))))
|
|
|
|
(signal (car condition) (cdr condition)))
|
|
|
|
((< (point) (car state))
|
|
|
|
(goto-char (point-min))
|
2003-03-06 10:52:39 +00:00
|
|
|
(unless Buffer-menu-use-header-line
|
|
|
|
(forward-line 2)))
|
1991-12-21 09:29:41 +00:00
|
|
|
((> (point) (cdr state))
|
|
|
|
(goto-char (point-max))
|
|
|
|
(forward-line -1)
|
|
|
|
(if (pos-visible-in-window-p (point-max))
|
2001-11-13 17:29:40 +00:00
|
|
|
(recenter -1))))
|
|
|
|
(electric-buffer-update-highlight))
|
1991-12-21 09:29:41 +00:00
|
|
|
|
2005-08-09 02:53:39 +00:00
|
|
|
(defvar Helper-return-blurb)
|
|
|
|
|
1991-12-21 09:29:41 +00:00
|
|
|
(put 'Electric-buffer-menu-mode 'mode-class 'special)
|
|
|
|
(defun Electric-buffer-menu-mode ()
|
|
|
|
"Major mode for editing a list of buffers.
|
|
|
|
Each line describes one of the buffers in Emacs.
|
|
|
|
Letters do not insert themselves; instead, they are commands.
|
|
|
|
\\<electric-buffer-menu-mode-map>
|
|
|
|
\\[keyboard-quit] or \\[Electric-buffer-menu-quit] -- exit buffer menu, returning to previous window and buffer
|
|
|
|
configuration. If the very first character typed is a space, it
|
|
|
|
also has this effect.
|
|
|
|
\\[Electric-buffer-menu-select] -- select buffer of line point is on.
|
|
|
|
Also show buffers marked with m in other windows,
|
|
|
|
deletes buffers marked with \"D\", and saves those marked with \"S\".
|
|
|
|
\\[Buffer-menu-mark] -- mark buffer to be displayed.
|
|
|
|
\\[Buffer-menu-not-modified] -- clear modified-flag on that buffer.
|
|
|
|
\\[Buffer-menu-save] -- mark that buffer to be saved.
|
|
|
|
\\[Buffer-menu-delete] or \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted.
|
|
|
|
\\[Buffer-menu-unmark] -- remove all kinds of marks from current line.
|
|
|
|
\\[Electric-buffer-menu-mode-view-buffer] -- view buffer, returning when done.
|
|
|
|
\\[Buffer-menu-backup-unmark] -- back up a line and remove marks.
|
|
|
|
|
|
|
|
\\{electric-buffer-menu-mode-map}
|
|
|
|
|
2004-11-10 10:45:59 +00:00
|
|
|
Entry to this mode via command `electric-buffer-list' calls the value of
|
|
|
|
`electric-buffer-menu-mode-hook'."
|
2005-01-10 11:56:07 +00:00
|
|
|
(let ((saved header-line-format))
|
|
|
|
(kill-all-local-variables)
|
|
|
|
(setq header-line-format saved))
|
1991-12-21 09:29:41 +00:00
|
|
|
(use-local-map electric-buffer-menu-mode-map)
|
|
|
|
(setq mode-name "Electric Buffer Menu")
|
|
|
|
(setq mode-line-buffer-identification "Electric Buffer List")
|
|
|
|
(make-local-variable 'Helper-return-blurb)
|
|
|
|
(setq Helper-return-blurb "return to buffer editing")
|
|
|
|
(setq truncate-lines t)
|
|
|
|
(setq buffer-read-only t)
|
|
|
|
(setq major-mode 'Electric-buffer-menu-mode)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(if (search-forward "\n." nil t) (forward-char -1))
|
2005-05-26 12:43:17 +00:00
|
|
|
(run-mode-hooks 'electric-buffer-menu-mode-hook))
|
1991-12-21 09:29:41 +00:00
|
|
|
|
|
|
|
;; generally the same as Buffer-menu-mode-map
|
|
|
|
;; (except we don't indirect to global-map)
|
|
|
|
(put 'Electric-buffer-menu-undefined 'suppress-keymap t)
|
|
|
|
(if electric-buffer-menu-mode-map
|
|
|
|
nil
|
1998-08-12 22:21:47 +00:00
|
|
|
(let ((map (make-keymap)))
|
1993-03-28 06:24:33 +00:00
|
|
|
(fillarray (car (cdr map)) 'Electric-buffer-menu-undefined)
|
1998-08-12 22:21:47 +00:00
|
|
|
(define-key map "\e" nil)
|
1991-12-21 09:29:41 +00:00
|
|
|
(define-key map "\C-z" 'suspend-emacs)
|
|
|
|
(define-key map "v" 'Electric-buffer-menu-mode-view-buffer)
|
1992-08-03 22:05:14 +00:00
|
|
|
(define-key map (char-to-string help-char) 'Helper-help)
|
1991-12-21 09:29:41 +00:00
|
|
|
(define-key map "?" 'Helper-describe-bindings)
|
|
|
|
(define-key map "\C-c" nil)
|
|
|
|
(define-key map "\C-c\C-c" 'Electric-buffer-menu-quit)
|
|
|
|
(define-key map "\C-]" 'Electric-buffer-menu-quit)
|
|
|
|
(define-key map "q" 'Electric-buffer-menu-quit)
|
|
|
|
(define-key map " " 'Electric-buffer-menu-select)
|
1994-07-02 17:01:41 +00:00
|
|
|
(define-key map "\C-m" 'Electric-buffer-menu-select)
|
1991-12-21 09:29:41 +00:00
|
|
|
(define-key map "\C-l" 'recenter)
|
|
|
|
(define-key map "s" 'Buffer-menu-save)
|
|
|
|
(define-key map "d" 'Buffer-menu-delete)
|
|
|
|
(define-key map "k" 'Buffer-menu-delete)
|
|
|
|
(define-key map "\C-d" 'Buffer-menu-delete-backwards)
|
|
|
|
;(define-key map "\C-k" 'Buffer-menu-delete)
|
|
|
|
(define-key map "\177" 'Buffer-menu-backup-unmark)
|
|
|
|
(define-key map "~" 'Buffer-menu-not-modified)
|
|
|
|
(define-key map "u" 'Buffer-menu-unmark)
|
|
|
|
(let ((i ?0))
|
|
|
|
(while (<= i ?9)
|
|
|
|
(define-key map (char-to-string i) 'digit-argument)
|
|
|
|
(define-key map (concat "\e" (char-to-string i)) 'digit-argument)
|
|
|
|
(setq i (1+ i))))
|
|
|
|
(define-key map "-" 'negative-argument)
|
|
|
|
(define-key map "\e-" 'negative-argument)
|
|
|
|
(define-key map "m" 'Buffer-menu-mark)
|
|
|
|
(define-key map "\C-u" 'universal-argument)
|
|
|
|
(define-key map "\C-p" 'previous-line)
|
|
|
|
(define-key map "\C-n" 'next-line)
|
|
|
|
(define-key map "p" 'previous-line)
|
|
|
|
(define-key map "n" 'next-line)
|
|
|
|
(define-key map "\C-v" 'scroll-up)
|
|
|
|
(define-key map "\ev" 'scroll-down)
|
|
|
|
(define-key map ">" 'scroll-right)
|
|
|
|
(define-key map "<" 'scroll-left)
|
|
|
|
(define-key map "\e\C-v" 'scroll-other-window)
|
|
|
|
(define-key map "\e>" 'end-of-buffer)
|
|
|
|
(define-key map "\e<" 'beginning-of-buffer)
|
1995-04-07 22:17:54 +00:00
|
|
|
(define-key map "\e\e" nil)
|
1994-12-05 11:01:40 +00:00
|
|
|
(define-key map "\e\e\e" 'Electric-buffer-menu-quit)
|
|
|
|
(define-key map [escape escape escape] 'Electric-buffer-menu-quit)
|
1994-04-21 14:39:40 +00:00
|
|
|
(define-key map [mouse-2] 'Electric-buffer-menu-mouse-select)
|
1991-12-21 09:29:41 +00:00
|
|
|
(setq electric-buffer-menu-mode-map map)))
|
2003-02-04 11:26:42 +00:00
|
|
|
|
1991-12-21 09:29:41 +00:00
|
|
|
(defun Electric-buffer-menu-exit ()
|
|
|
|
(interactive)
|
1993-03-06 06:05:12 +00:00
|
|
|
(setq unread-command-events (listify-key-sequence (this-command-keys)))
|
1991-12-21 09:29:41 +00:00
|
|
|
;; for robustness
|
|
|
|
(condition-case ()
|
|
|
|
(throw 'electric-buffer-menu-select nil)
|
|
|
|
(error (Buffer-menu-mode)
|
|
|
|
(other-buffer))))
|
|
|
|
|
|
|
|
(defun Electric-buffer-menu-select ()
|
|
|
|
"Leave Electric Buffer Menu, selecting buffers and executing changes.
|
2004-11-10 10:45:59 +00:00
|
|
|
Save buffers marked \"S\". Delete buffers marked \"K\".
|
|
|
|
Select buffer at point and display buffers marked \">\" in other windows."
|
1991-12-21 09:29:41 +00:00
|
|
|
(interactive)
|
|
|
|
(throw 'electric-buffer-menu-select (point)))
|
|
|
|
|
1994-04-21 14:39:40 +00:00
|
|
|
(defun Electric-buffer-menu-mouse-select (event)
|
|
|
|
(interactive "e")
|
|
|
|
(select-window (posn-window (event-end event)))
|
|
|
|
(set-buffer (window-buffer (selected-window)))
|
|
|
|
(goto-char (posn-point (event-end event)))
|
|
|
|
(throw 'electric-buffer-menu-select (point)))
|
|
|
|
|
1991-12-21 09:29:41 +00:00
|
|
|
(defun Electric-buffer-menu-quit ()
|
|
|
|
"Leave Electric Buffer Menu, restoring previous window configuration.
|
2004-11-10 10:45:59 +00:00
|
|
|
Skip execution of select, save, and delete commands."
|
1991-12-21 09:29:41 +00:00
|
|
|
(interactive)
|
|
|
|
(throw 'electric-buffer-menu-select nil))
|
|
|
|
|
|
|
|
(defun Electric-buffer-menu-undefined ()
|
|
|
|
(interactive)
|
|
|
|
(ding)
|
1996-01-25 00:53:08 +00:00
|
|
|
(message "%s"
|
|
|
|
(if (and (eq (key-binding "\C-c\C-c") 'Electric-buffer-menu-quit)
|
1991-12-21 09:29:41 +00:00
|
|
|
(eq (key-binding " ") 'Electric-buffer-menu-select)
|
1992-08-03 22:07:34 +00:00
|
|
|
(eq (key-binding (char-to-string help-char)) 'Helper-help)
|
1991-12-21 09:29:41 +00:00
|
|
|
(eq (key-binding "?") 'Helper-describe-bindings))
|
1992-08-03 21:32:21 +00:00
|
|
|
(substitute-command-keys "Type C-c C-c to exit, Space to select, \\[Helper-help] for help, ? for commands")
|
1991-12-21 09:29:41 +00:00
|
|
|
(substitute-command-keys "\
|
|
|
|
Type \\[Electric-buffer-menu-quit] to exit, \
|
|
|
|
\\[Electric-buffer-menu-select] to select, \
|
|
|
|
\\[Helper-help] for help, \\[Helper-describe-bindings] for commands.")))
|
|
|
|
(sit-for 4))
|
|
|
|
|
|
|
|
(defun Electric-buffer-menu-mode-view-buffer ()
|
|
|
|
"View buffer on current line in Electric Buffer Menu.
|
2004-11-10 10:45:59 +00:00
|
|
|
Return to Electric Buffer Menu when done."
|
1991-12-21 09:29:41 +00:00
|
|
|
(interactive)
|
|
|
|
(let ((bufnam (Buffer-menu-buffer nil)))
|
|
|
|
(if bufnam
|
|
|
|
(view-buffer bufnam)
|
|
|
|
(ding)
|
|
|
|
(message "Buffer %s does not exist!" bufnam)
|
|
|
|
(sit-for 4))))
|
|
|
|
|
2001-11-13 17:29:40 +00:00
|
|
|
(defvar electric-buffer-overlay nil)
|
|
|
|
(defun electric-buffer-update-highlight ()
|
2003-03-10 03:06:13 +00:00
|
|
|
(when (eq major-mode 'Electric-buffer-menu-mode)
|
|
|
|
;; Make sure we have an overlay to use.
|
|
|
|
(or electric-buffer-overlay
|
|
|
|
(progn
|
|
|
|
(make-local-variable 'electric-buffer-overlay)
|
|
|
|
(setq electric-buffer-overlay (make-overlay (point) (point)))))
|
|
|
|
(move-overlay electric-buffer-overlay
|
|
|
|
(save-excursion (beginning-of-line) (point))
|
|
|
|
(save-excursion (end-of-line) (point)))
|
|
|
|
(overlay-put electric-buffer-overlay 'face 'highlight)))
|
2001-11-13 17:29:40 +00:00
|
|
|
|
1997-06-22 18:57:55 +00:00
|
|
|
(provide 'ebuff-menu)
|
|
|
|
|
2003-09-01 15:45:59 +00:00
|
|
|
;;; arch-tag: 1d4509b3-eece-4d4f-95ea-77c83eaf0275
|
1992-05-30 23:54:21 +00:00
|
|
|
;;; ebuff-menu.el ends here
|