198
|
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 (defun Electric-command-history-redo-expression (&optional noconfirm)
|
|
26 "Edit current history line in minibuffer and execute result.
|
|
27 With prefix arg NOCONFIRM, execute current line as-is without editing."
|
|
28 (interactive "P")
|
|
29 (let (todo)
|
|
30 (save-excursion
|
|
31 (set-buffer "*Command History*")
|
|
32 (beginning-of-line)
|
|
33 (setq todo (read (current-buffer)))
|
|
34 (if (boundp 'electric-history-in-progress)
|
|
35 (if todo (throw 'electric-history-quit (list noconfirm todo)))))))
|
|
36
|
|
37 (defvar electric-history-map ())
|
|
38 (if electric-history-map
|
|
39 ()
|
|
40 (setq electric-history-map (make-keymap))
|
|
41 (fillarray electric-history-map 'Electric-history-undefined)
|
|
42 (define-key electric-history-map "\e" (make-keymap))
|
|
43 (fillarray (lookup-key electric-history-map "\e") 'Electric-history-undefined)
|
|
44 (define-key electric-history-map "\C-u" 'universal-argument)
|
|
45 (define-key electric-history-map " " 'Electric-command-history-redo-expression)
|
|
46 (define-key electric-history-map "!" 'Electric-command-history-redo-expression)
|
|
47 (define-key electric-history-map "\e\C-x" 'eval-sexp)
|
|
48 (define-key electric-history-map "\e\C-d" 'down-list)
|
|
49 (define-key electric-history-map "\e\C-u" 'backward-up-list)
|
|
50 (define-key electric-history-map "\e\C-b" 'backward-sexp)
|
|
51 (define-key electric-history-map "\e\C-f" 'forward-sexp)
|
|
52 (define-key electric-history-map "\e\C-a" 'beginning-of-defun)
|
|
53 (define-key electric-history-map "\e\C-e" 'end-of-defun)
|
|
54 (define-key electric-history-map "\e\C-n" 'forward-list)
|
|
55 (define-key electric-history-map "\e\C-p" 'backward-list)
|
|
56 (define-key electric-history-map "q" 'Electric-history-quit)
|
|
57 (define-key electric-history-map "\C-c" nil)
|
|
58 (define-key electric-history-map "\C-c\C-c" 'Electric-history-quit)
|
|
59 (define-key electric-history-map "\C-]" 'Electric-history-quit)
|
|
60 (define-key electric-history-map "\C-z" 'suspend-emacs)
|
|
61 (define-key electric-history-map "\C-h" 'Helper-help)
|
|
62 (define-key electric-history-map "?" 'Helper-describe-bindings)
|
|
63 (define-key electric-history-map "\e>" 'end-of-buffer)
|
|
64 (define-key electric-history-map "\e<" 'beginning-of-buffer)
|
|
65 (define-key electric-history-map "\n" 'next-line)
|
|
66 (define-key electric-history-map "\r" 'next-line)
|
|
67 (define-key electric-history-map "\177" 'previous-line)
|
|
68 (define-key electric-history-map "\C-n" 'next-line)
|
|
69 (define-key electric-history-map "\C-p" 'previous-line)
|
|
70 (define-key electric-history-map "\ev" 'scroll-down)
|
|
71 (define-key electric-history-map "\C-v" 'scroll-up)
|
|
72 (define-key electric-history-map "\C-l" 'recenter)
|
|
73 (define-key electric-history-map "\e\C-v" 'scroll-other-window))
|
|
74
|
|
75 (defvar electric-command-history-hook nil
|
|
76 "If non-nil, its value is called by `electric-command-history'.")
|
|
77
|
|
78 (defun electric-command-history ()
|
|
79 "\\<electric-history-map>Major mode for examining and redoing commands from `command-history'.
|
|
80 This pops up a window with the Command History listing.
|
|
81 The number of command listed is controlled by `list-command-history-max'.
|
|
82 The command history is filtered by `list-command-history-filter' if non-nil.
|
|
83 Combines typeout Command History list window with menu like selection
|
|
84 of an expression from the history for re-evaluation in the *original* buffer.
|
|
85
|
|
86 The history displayed is filtered by `list-command-history-filter' if non-nil.
|
|
87
|
|
88 Like Emacs-Lisp mode except that characters do not insert themselves and
|
|
89 Tab and Linefeed do not indent. Instead these commands are provided:
|
|
90 \\{electric-history-map}
|
|
91
|
|
92 Calls the value of `electric-command-history-hook' if that is non-nil.
|
|
93 The Command History listing is recomputed each time this mode is invoked."
|
|
94 (interactive)
|
|
95 (let ((electric-history-in-progress t)
|
|
96 (old-buffer (current-buffer))
|
|
97 (todo))
|
|
98 (unwind-protect
|
|
99 (setq todo
|
|
100 (catch 'electric-history-quit
|
|
101 (save-window-excursion
|
|
102 (save-window-excursion
|
|
103 (list-command-history)
|
|
104 (set-buffer "*Command History*")
|
|
105 (Command-history-setup 'electric-command-history
|
|
106 "Electric History"
|
|
107 electric-history-map))
|
|
108 (Electric-pop-up-window "*Command History*")
|
|
109 (run-hooks 'electric-command-history-hook)
|
|
110 (if (eobp)
|
|
111 (progn (ding)
|
|
112 (message "No command history.")
|
|
113 (throw 'electric-history-quit nil))
|
|
114 (let ((Helper-return-blurb "return to History"))
|
|
115 (Electric-command-loop 'electric-history-quit
|
|
116 "->" t))))))
|
|
117 (set-buffer "*Command History*")
|
|
118 (Command-history-setup)
|
|
119 (bury-buffer (current-buffer)))
|
|
120 (if (consp todo)
|
|
121 (progn (set-buffer old-buffer)
|
|
122 (if (car todo)
|
|
123 (apply (car (car (cdr todo))) (cdr (car (cdr todo))))
|
|
124 (edit-and-eval-command "Redo: " (car (cdr todo))))))))
|
|
125
|
|
126 (defun Electric-history-undefined ()
|
|
127 (interactive)
|
|
128 (ding)
|
|
129 (message "Type C-h for help, ? for commands, C-c to quit, Space to execute")
|
|
130 (sit-for 4))
|
|
131
|
|
132 (defun Electric-history-quit ()
|
|
133 "Quit Electric Command History, restoring previous window configuration."
|
|
134 (interactive)
|
|
135 (if (boundp 'electric-history-in-progress)
|
|
136 (progn (message "")
|
|
137 (throw 'electric-history-quit nil))))
|