Empty the bidi cache "stack" when it->sp is zeroed.
[emacs.git] / lisp / echistory.el
blobd5ee3003d68ee098d3be1af40eb7df5f42e9ffd7
1 ;;; echistory.el --- Electric Command History Mode
3 ;; Copyright (C) 1985, 2001-2011 Free Software Foundation, Inc.
5 ;; Author: K. Shane Hartman
6 ;; Maintainer: FSF
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 (require 'electric) ; command loop
28 (require 'chistory) ; history lister
30 ;; Dynamically bound in electric-command-history
31 (defvar electric-history-in-progress)
33 ;;;###autoload
34 (defun Electric-command-history-redo-expression (&optional noconfirm)
35 "Edit current history line in minibuffer and execute result.
36 With prefix arg NOCONFIRM, execute current line as-is without editing."
37 (interactive "P")
38 (let (todo)
39 (with-current-buffer "*Command History*"
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)))))))
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.")
88 (defvar electric-command-history-hook nil
89 "If non-nil, its value is called by `electric-command-history'.")
91 (defvar Helper-return-blurb) ; from helper.el
93 (defun electric-command-history ()
94 "\\<electric-history-map>Major mode for examining and redoing commands from `command-history'.
95 This pops up a window with the Command History listing.
96 The number of command listed is controlled by `list-command-history-max'.
97 The command history is filtered by `list-command-history-filter' if non-nil.
98 Combines typeout Command History list window with menu like selection
99 of an expression from the history for re-evaluation in the *original* buffer.
101 The history displayed is filtered by `list-command-history-filter' if non-nil.
103 Like Emacs-Lisp mode except that characters do not insert themselves and
104 Tab and Linefeed do not indent. Instead these commands are provided:
105 \\{electric-history-map}
107 Calls the value of `electric-command-history-hook' if that is non-nil.
108 The 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*")
120 (Command-history-setup)
121 (setq major-mode 'electric-command-history)
122 (setq mode-name "Electric History")
123 (use-local-map electric-history-map))
124 (Electric-pop-up-window "*Command History*")
125 (run-hooks 'electric-command-history-hook)
126 (if (eobp)
127 (progn (ding)
128 (message "No command history.")
129 (throw 'electric-history-quit nil))
130 (let ((Helper-return-blurb "return to History"))
131 (Electric-command-loop 'electric-history-quit
132 "->" t))))))
133 (set-buffer "*Command History*")
134 (command-history-mode)
135 (bury-buffer (current-buffer)))
136 (if (consp todo)
137 (progn (set-buffer old-buffer)
138 (if (car todo)
139 (apply (car (car (cdr todo))) (cdr (car (cdr todo))))
140 (edit-and-eval-command "Redo: " (car (cdr todo))))))))
142 (defun Electric-history-undefined ()
143 (interactive)
144 (ding)
145 (message "%s" (substitute-command-keys "Type \\[Helper-help] for help, ? for commands, C-c C-c to quit, Space to execute"))
146 (sit-for 4))
148 (defun Electric-history-quit ()
149 "Quit Electric Command History, restoring previous window configuration."
150 (interactive)
151 (if (boundp 'electric-history-in-progress)
152 (progn (message "")
153 (throw 'electric-history-quit nil))))
155 (provide 'echistory)
157 ;;; echistory.el ends here