*** empty log message ***
[emacs.git] / lisp / echistory.el
blobd3d495456a81a8ff4f586124fb689b675064e4e9
1 ;;; echistory.el --- Electric Command History Mode
3 ;; Author: K. Shane Hartman
4 ;; Maintainer: FSF
5 ;; Last-Modified: 09 May 1991
7 ;; Copyright (C) 1985 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 ;;; Code:
27 (require 'electric) ; command loop
28 (require 'chistory) ; history lister
30 ;;;###autoload
31 (defun Electric-command-history-redo-expression (&optional noconfirm)
32 "Edit current history line in minibuffer and execute result.
33 With prefix arg NOCONFIRM, execute current line as-is without editing."
34 (interactive "P")
35 (let (todo)
36 (save-excursion
37 (set-buffer "*Command History*")
38 (beginning-of-line)
39 (setq todo (read (current-buffer)))
40 (if (boundp 'electric-history-in-progress)
41 (if todo (throw 'electric-history-quit (list noconfirm todo)))))))
43 (defvar electric-history-map ())
44 (if electric-history-map
46 (setq electric-history-map (make-keymap))
47 (fillarray electric-history-map 'Electric-history-undefined)
48 (define-key electric-history-map "\e" (make-keymap))
49 (fillarray (lookup-key electric-history-map "\e") 'Electric-history-undefined)
50 (define-key electric-history-map "\C-u" 'universal-argument)
51 (define-key electric-history-map " " 'Electric-command-history-redo-expression)
52 (define-key electric-history-map "!" 'Electric-command-history-redo-expression)
53 (define-key electric-history-map "\e\C-x" 'eval-sexp)
54 (define-key electric-history-map "\e\C-d" 'down-list)
55 (define-key electric-history-map "\e\C-u" 'backward-up-list)
56 (define-key electric-history-map "\e\C-b" 'backward-sexp)
57 (define-key electric-history-map "\e\C-f" 'forward-sexp)
58 (define-key electric-history-map "\e\C-a" 'beginning-of-defun)
59 (define-key electric-history-map "\e\C-e" 'end-of-defun)
60 (define-key electric-history-map "\e\C-n" 'forward-list)
61 (define-key electric-history-map "\e\C-p" 'backward-list)
62 (define-key electric-history-map "q" 'Electric-history-quit)
63 (define-key electric-history-map "\C-c" nil)
64 (define-key electric-history-map "\C-c\C-c" 'Electric-history-quit)
65 (define-key electric-history-map "\C-]" 'Electric-history-quit)
66 (define-key electric-history-map "\C-z" 'suspend-emacs)
67 (define-key electric-history-map "\C-h" 'Helper-help)
68 (define-key electric-history-map "?" 'Helper-describe-bindings)
69 (define-key electric-history-map "\e>" 'end-of-buffer)
70 (define-key electric-history-map "\e<" 'beginning-of-buffer)
71 (define-key electric-history-map "\n" 'next-line)
72 (define-key electric-history-map "\r" 'next-line)
73 (define-key electric-history-map "\177" 'previous-line)
74 (define-key electric-history-map "\C-n" 'next-line)
75 (define-key electric-history-map "\C-p" 'previous-line)
76 (define-key electric-history-map "\ev" 'scroll-down)
77 (define-key electric-history-map "\C-v" 'scroll-up)
78 (define-key electric-history-map "\C-l" 'recenter)
79 (define-key electric-history-map "\e\C-v" 'scroll-other-window))
81 (defvar electric-command-history-hook nil
82 "If non-nil, its value is called by `electric-command-history'.")
84 (defun electric-command-history ()
85 "\\<electric-history-map>Major mode for examining and redoing commands from `command-history'.
86 This pops up a window with the Command History listing.
87 The number of command listed is controlled by `list-command-history-max'.
88 The command history is filtered by `list-command-history-filter' if non-nil.
89 Combines typeout Command History list window with menu like selection
90 of an expression from the history for re-evaluation in the *original* buffer.
92 The history displayed is filtered by `list-command-history-filter' if non-nil.
94 Like Emacs-Lisp mode except that characters do not insert themselves and
95 Tab and Linefeed do not indent. Instead these commands are provided:
96 \\{electric-history-map}
98 Calls the value of `electric-command-history-hook' if that is non-nil.
99 The Command History listing is recomputed each time this mode is invoked."
100 (interactive)
101 (let ((electric-history-in-progress t)
102 (old-buffer (current-buffer))
103 (todo))
104 (unwind-protect
105 (setq todo
106 (catch 'electric-history-quit
107 (save-window-excursion
108 (save-window-excursion
109 (list-command-history)
110 (set-buffer "*Command History*")
111 (Command-history-setup 'electric-command-history
112 "Electric History"
113 electric-history-map))
114 (Electric-pop-up-window "*Command History*")
115 (run-hooks 'electric-command-history-hook)
116 (if (eobp)
117 (progn (ding)
118 (message "No command history.")
119 (throw 'electric-history-quit nil))
120 (let ((Helper-return-blurb "return to History"))
121 (Electric-command-loop 'electric-history-quit
122 "->" t))))))
123 (set-buffer "*Command History*")
124 (Command-history-setup)
125 (bury-buffer (current-buffer)))
126 (if (consp todo)
127 (progn (set-buffer old-buffer)
128 (if (car todo)
129 (apply (car (car (cdr todo))) (cdr (car (cdr todo))))
130 (edit-and-eval-command "Redo: " (car (cdr todo))))))))
132 (defun Electric-history-undefined ()
133 (interactive)
134 (ding)
135 (message "Type C-h for help, ? for commands, C-c to quit, Space to execute")
136 (sit-for 4))
138 (defun Electric-history-quit ()
139 "Quit Electric Command History, restoring previous window configuration."
140 (interactive)
141 (if (boundp 'electric-history-in-progress)
142 (progn (message "")
143 (throw 'electric-history-quit nil))))
145 ;;; echistory.el ends here