;;; ebuff-menu.el --- electric-buffer-list mode;; Copyright (C) 1985, 1986, 1994 Free Software Foundation, Inc.;; Author: Richard Mlynarik <mly@ai.mit.edu>;; Maintainer: FSF;; 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;; the Free Software Foundation; either version 2, or (at your option);; 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;; along with GNU Emacs; see the file COPYING. If not, write to the;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,;; Boston, MA 02111-1307, USA.;;; Commentary:;; 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.;;; Code:(require'electric);; this depends on the format of list-buffers (from src/buffer.c) and;; on stuff in lisp/buff-menu.el(defvarelectric-buffer-menu-mode-mapnil);;;###autoload(defunelectric-buffer-list(arg)"Pops up a buffer describing the set of Emacs buffers.Vaguely like ITS lunar select buffer; combining typeoutoid bufferlisting with menuoid buffer selection.If the very next character typed is a space then the buffer listwindow disappears. Otherwise, one may move around in the buffer listwindow, marking buffers to be selected, saved or deleted.To exit and select a new buffer, type a space when the cursor is onthe appropriate line of the buffer-list window. Other commands aremuch like those of buffer-menu-mode.Calls value of `electric-buffer-menu-mode-hook' on entry if non-nil.\\{electric-buffer-menu-mode-map}"(interactive"P")(let(selectbuffer)(save-window-excursion(save-window-excursion(list-buffersarg))(setqbuffer(window-buffer(Electric-pop-up-window"*Buffer List*")))(unwind-protect(progn(set-bufferbuffer)(Electric-buffer-menu-mode)(setqselect(catch'electric-buffer-menu-select(message"<<< Press Return to bury the buffer list >>>")(if(eq(setqunread-command-events(list(read-event)))?\ )(progn(setqunread-command-eventsnil)(throw'electric-buffer-menu-selectnil)))(let((start-point(point))(first(progn(goto-char(point-min))(forward-line2)(point)))(last(progn(goto-char(point-max))(forward-line-1)(point)))(goal-column0));; Use start-point if it is meaningful.(goto-char(if(or(<start-pointfirst)(>start-pointlast))firststart-point))(Electric-command-loop'electric-buffer-menu-selectnilt'electric-buffer-menu-looper(consfirstlast))))))(set-bufferbuffer)(Buffer-menu-mode)(bury-bufferbuffer)(message"")))(ifselect(progn(set-bufferbuffer)(let((opoint(point-marker)))(Buffer-menu-execute)(goto-char(point-min))(if(prog1(search-forward"\n>"nilt)(goto-charopoint)(set-markeropointnil))(Buffer-menu-select)(switch-to-buffer(Buffer-menu-buffert))))))))(defunelectric-buffer-menu-looper(statecondition)(cond((andcondition(not(memq(carcondition)'(buffer-read-onlyend-of-bufferbeginning-of-buffer))))(signal(carcondition)(cdrcondition)))((<(point)(carstate))(goto-char(point-min))(forward-line2))((>(point)(cdrstate))(goto-char(point-max))(forward-line-1)(if(pos-visible-in-window-p(point-max))(recenter-1)))))(put'Electric-buffer-menu-mode'mode-class'special)(defunElectric-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}Entry to this mode via command electric-buffer-list calls the value ofelectric-buffer-menu-mode-hook if it is non-nil."(kill-all-local-variables)(use-local-mapelectric-buffer-menu-mode-map)(setqmode-name"Electric Buffer Menu")(setqmode-line-buffer-identification"Electric Buffer List")(make-local-variable'Helper-return-blurb)(setqHelper-return-blurb"return to buffer editing")(setqtruncate-linest)(setqbuffer-read-onlyt)(setqmajor-mode'Electric-buffer-menu-mode)(goto-char(point-min))(if(search-forward"\n."nilt)(forward-char-1))(run-hooks'electric-buffer-menu-mode-hook));; generally the same as Buffer-menu-mode-map;; (except we don't indirect to global-map)(put'Electric-buffer-menu-undefined'suppress-keymapt)(ifelectric-buffer-menu-mode-mapnil(let((map(make-keymap))(submap(make-keymap)))(fillarray(car(cdrmap))'Electric-buffer-menu-undefined)(define-keymap"\e"submap)(fillarray(car(cdrsubmap))'Electric-buffer-menu-undefined)(define-keymap"\C-z"'suspend-emacs)(define-keymap"v"'Electric-buffer-menu-mode-view-buffer)(define-keymap(char-to-stringhelp-char)'Helper-help)(define-keymap"?"'Helper-describe-bindings)(define-keymap"\C-c"nil)(define-keymap"\C-c\C-c"'Electric-buffer-menu-quit)(define-keymap"\C-]"'Electric-buffer-menu-quit)(define-keymap"q"'Electric-buffer-menu-quit)(define-keymap" "'Electric-buffer-menu-select)(define-keymap"\C-m"'Electric-buffer-menu-select)(define-keymap"\C-l"'recenter)(define-keymap"s"'Buffer-menu-save)(define-keymap"d"'Buffer-menu-delete)(define-keymap"k"'Buffer-menu-delete)(define-keymap"\C-d"'Buffer-menu-delete-backwards);(define-key map "\C-k" 'Buffer-menu-delete)(define-keymap"\177"'Buffer-menu-backup-unmark)(define-keymap"~"'Buffer-menu-not-modified)(define-keymap"u"'Buffer-menu-unmark)(let((i?0))(while(<=i?9)(define-keymap(char-to-stringi)'digit-argument)(define-keymap(concat"\e"(char-to-stringi))'digit-argument)(setqi(1+i))))(define-keymap"-"'negative-argument)(define-keymap"\e-"'negative-argument)(define-keymap"m"'Buffer-menu-mark)(define-keymap"\C-u"'universal-argument)(define-keymap"\C-p"'previous-line)(define-keymap"\C-n"'next-line)(define-keymap"p"'previous-line)(define-keymap"n"'next-line)(define-keymap"\C-v"'scroll-up)(define-keymap"\ev"'scroll-down)(define-keymap">"'scroll-right)(define-keymap"<"'scroll-left)(define-keymap"\e\C-v"'scroll-other-window)(define-keymap"\e>"'end-of-buffer)(define-keymap"\e<"'beginning-of-buffer)(define-keymap"\e\e"nil)(define-keymap"\e\e\e"'Electric-buffer-menu-quit)(define-keymap[escapeescapeescape]'Electric-buffer-menu-quit)(define-keymap[mouse-2]'Electric-buffer-menu-mouse-select)(setqelectric-buffer-menu-mode-mapmap)))(defunElectric-buffer-menu-exit()(interactive)(setqunread-command-events(listify-key-sequence(this-command-keys)));; for robustness(condition-case()(throw'electric-buffer-menu-selectnil)(error(Buffer-menu-mode)(other-buffer))))(defunElectric-buffer-menu-select()"Leave Electric Buffer Menu, selecting buffers and executing changes.Saves buffers marked \"S\". Deletes buffers marked \"K\".Selects buffer at point and displays buffers marked \">\" in other windows."(interactive)(throw'electric-buffer-menu-select(point)))(defunElectric-buffer-menu-mouse-select(event)(interactive"e")(select-window(posn-window(event-endevent)))(set-buffer(window-buffer(selected-window)))(goto-char(posn-point(event-endevent)))(throw'electric-buffer-menu-select(point)))(defunElectric-buffer-menu-quit()"Leave Electric Buffer Menu, restoring previous window configuration.Does not execute select, save, or delete commands."(interactive)(throw'electric-buffer-menu-selectnil))(defunElectric-buffer-menu-undefined()(interactive)(ding)(message"%s"(if(and(eq(key-binding"\C-c\C-c")'Electric-buffer-menu-quit)(eq(key-binding" ")'Electric-buffer-menu-select)(eq(key-binding(char-to-stringhelp-char))'Helper-help)(eq(key-binding"?")'Helper-describe-bindings))(substitute-command-keys"Type C-c C-c to exit, Space to select, \\[Helper-help] for help, ? for commands")(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-for4))(defunElectric-buffer-menu-mode-view-buffer()"View buffer on current line in Electric Buffer Menu.Returns to Electric Buffer Menu when done."(interactive)(let((bufnam(Buffer-menu-buffernil)))(ifbufnam(view-bufferbufnam)(ding)(message"Buffer %s does not exist!"bufnam)(sit-for4))))(provide'ebuff-menu);;; ebuff-menu.el ends here