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