* src/eval.c (Fbind_symbol): New function.
[bpt/emacs.git] / lisp / echistory.el
CommitLineData
c0274f38
ER
1;;; echistory.el --- Electric Command History Mode
2
ba318903 3;; Copyright (C) 1985, 2001-2014 Free Software Foundation, Inc.
3a801d0c 4
e5167999 5;; Author: K. Shane Hartman
34dc21db 6;; Maintainer: emacs-devel@gnu.org
e9e56e09
RS
7
8;; This file is part of GNU Emacs.
9
eb3fa2cf 10;; GNU Emacs is free software: you can redistribute it and/or modify
e9e56e09 11;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
e9e56e09
RS
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
eb3fa2cf 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
e9e56e09 22
55535639
PJ
23;;; Commentary:
24
e5167999 25;;; Code:
e9e56e09
RS
26
27(require 'electric) ; command loop
28(require 'chistory) ; history lister
29
06b60517
JB
30;; Dynamically bound in electric-command-history
31(defvar electric-history-in-progress)
32
f9f9507e 33;;;###autoload
e9e56e09
RS
34(defun Electric-command-history-redo-expression (&optional noconfirm)
35 "Edit current history line in minibuffer and execute result.
36With prefix arg NOCONFIRM, execute current line as-is without editing."
37 (interactive "P")
38 (let (todo)
7fdbcd83 39 (with-current-buffer "*Command History*"
e9e56e09
RS
40 (beginning-of-line)
41 (setq todo (read (current-buffer)))
42 (if (boundp 'electric-history-in-progress)
43 (if todo (throw 'electric-history-quit (list noconfirm todo)))))))
44
a0de8967
JPW
45(defvar electric-history-map
46 (let ((map (make-sparse-keymap)))
47 (define-key map [t] 'Electric-history-undefined)
48 (define-key map "\e" (make-sparse-keymap))
49 (define-key map [?\e t] 'Electric-history-undefined)
50 (define-key map "\C-u" 'universal-argument)
51 (define-key map " " 'Electric-command-history-redo-expression)
52 (define-key map "!" 'Electric-command-history-redo-expression)
53 (define-key map "\e\C-x" 'eval-sexp)
54 (define-key map "\e\C-d" 'down-list)
55 (define-key map "\e\C-u" 'backward-up-list)
56 (define-key map "\e\C-b" 'backward-sexp)
57 (define-key map "\e\C-f" 'forward-sexp)
58 (define-key map "\e\C-a" 'beginning-of-defun)
59 (define-key map "\e\C-e" 'end-of-defun)
60 (define-key map "\e\C-n" 'forward-list)
61 (define-key map "\e\C-p" 'backward-list)
62 (define-key map "q" 'Electric-history-quit)
63 (define-key map "\C-c" nil)
64 (define-key map "\C-c\C-c" 'Electric-history-quit)
65 (define-key map "\C-]" 'Electric-history-quit)
66 (define-key map "\C-z" 'suspend-frame)
67 (define-key map (char-to-string help-char) 'Helper-help)
68 (define-key map "?" 'Helper-describe-bindings)
69 (define-key map "\e>" 'end-of-buffer)
70 (define-key map "\e<" 'beginning-of-buffer)
71 (define-key map "\n" 'next-line)
72 (define-key map "\r" 'next-line)
73 (define-key map "\177" 'previous-line)
74 (define-key map "\C-n" 'next-line)
75 (define-key map "\C-p" 'previous-line)
76 (define-key map "\ev" 'scroll-down)
77 (define-key map "\C-v" 'scroll-up)
78 (define-key map [home] 'beginning-of-buffer)
79 (define-key map [down] 'next-line)
80 (define-key map [up] 'previous-line)
81 (define-key map [prior] 'scroll-down)
82 (define-key map [next] 'scroll-up)
83 (define-key map "\C-l" 'recenter)
84 (define-key map "\e\C-v" 'scroll-other-window)
85 map)
86 "Keymap for Electric Command History mode.")
e9e56e09
RS
87
88(defvar electric-command-history-hook nil
89 "If non-nil, its value is called by `electric-command-history'.")
90
06b60517
JB
91(defvar Helper-return-blurb) ; from helper.el
92
e9e56e09
RS
93(defun electric-command-history ()
94 "\\<electric-history-map>Major mode for examining and redoing commands from `command-history'.
95This pops up a window with the Command History listing.
96The number of command listed is controlled by `list-command-history-max'.
97The command history is filtered by `list-command-history-filter' if non-nil.
98Combines typeout Command History list window with menu like selection
99of an expression from the history for re-evaluation in the *original* buffer.
100
101The history displayed is filtered by `list-command-history-filter' if non-nil.
102
103Like Emacs-Lisp mode except that characters do not insert themselves and
104Tab and Linefeed do not indent. Instead these commands are provided:
105\\{electric-history-map}
106
107Calls the value of `electric-command-history-hook' if that is non-nil.
108The Command History listing is recomputed each time this mode is invoked."
109 (interactive)
110 (let ((electric-history-in-progress t)
111 (old-buffer (current-buffer))
112 (todo))
113 (unwind-protect
114 (setq todo
115 (catch 'electric-history-quit
116 (save-window-excursion
117 (save-window-excursion
118 (list-command-history)
119 (set-buffer "*Command History*")
e65f2cc0
RS
120 (setq major-mode 'electric-command-history)
121 (setq mode-name "Electric History")
122 (use-local-map electric-history-map))
e9e56e09
RS
123 (Electric-pop-up-window "*Command History*")
124 (run-hooks 'electric-command-history-hook)
125 (if (eobp)
126 (progn (ding)
127 (message "No command history.")
128 (throw 'electric-history-quit nil))
129 (let ((Helper-return-blurb "return to History"))
130 (Electric-command-loop 'electric-history-quit
131 "->" t))))))
132 (set-buffer "*Command History*")
e65f2cc0 133 (command-history-mode)
e9e56e09
RS
134 (bury-buffer (current-buffer)))
135 (if (consp todo)
136 (progn (set-buffer old-buffer)
137 (if (car todo)
138 (apply (car (car (cdr todo))) (cdr (car (cdr todo))))
139 (edit-and-eval-command "Redo: " (car (cdr todo))))))))
140
141(defun Electric-history-undefined ()
142 (interactive)
143 (ding)
8a26c165 144 (message "%s" (substitute-command-keys "Type \\[Helper-help] for help, ? for commands, C-c C-c to quit, Space to execute"))
e9e56e09
RS
145 (sit-for 4))
146
147(defun Electric-history-quit ()
148 "Quit Electric Command History, restoring previous window configuration."
149 (interactive)
150 (if (boundp 'electric-history-in-progress)
151 (progn (message "")
152 (throw 'electric-history-quit nil))))
c0274f38 153
896546cd
RS
154(provide 'echistory)
155
c0274f38 156;;; echistory.el ends here