Mercurial > emacs
annotate lisp/chistory.el @ 54596:652f611ba65c
(buffer-stale-function): Doc fix.
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Sat, 27 Mar 2004 03:54:41 +0000 |
parents | 695cf19ef79e |
children | 049538abf38f 375f2633d815 |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; chistory.el --- list command history |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
845 | 3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
4 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
5 ;; Author: K. Shane Hartman |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
6 ;; Maintainer: FSF |
45078 | 7 ;; Keywords: convenience |
411 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
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 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
411 | 14 ;; any later version. |
15 | |
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. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
411 | 25 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
26 ;;; Commentary: |
411 | 27 |
28 ;; This really has nothing to do with list-command-history per se, but | |
9626
e928e72d3342
(repeat-matching-complex-command): Fix check for empty pattern. Simplify.
Karl Heuer <kwzh@gnu.org>
parents:
2452
diff
changeset
|
29 ;; its a nice alternative to C-x ESC ESC (repeat-complex-command) and |
411 | 30 ;; functions as a lister if given no pattern. It's not important |
31 ;; enough to warrant a file of its own. | |
32 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
33 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
34 |
21088 | 35 (defgroup chistory nil |
36 "List command history." | |
37 :group 'keyboard) | |
38 | |
411 | 39 ;;;###autoload |
40 (defun repeat-matching-complex-command (&optional pattern) | |
41 "Edit and re-evaluate complex command with name matching PATTERN. | |
42 Matching occurrences are displayed, most recent first, until you select | |
43 a form for evaluation. If PATTERN is empty (or nil), every form in the | |
44 command history is offered. The form is placed in the minibuffer for | |
45 editing and the result is evaluated." | |
46 (interactive "sRedo Command (regexp): ") | |
47 (if pattern | |
9626
e928e72d3342
(repeat-matching-complex-command): Fix check for empty pattern. Simplify.
Karl Heuer <kwzh@gnu.org>
parents:
2452
diff
changeset
|
48 (if (string-match "[^ \t]" pattern) |
e928e72d3342
(repeat-matching-complex-command): Fix check for empty pattern. Simplify.
Karl Heuer <kwzh@gnu.org>
parents:
2452
diff
changeset
|
49 (setq pattern (substring pattern (match-beginning 0))) |
e928e72d3342
(repeat-matching-complex-command): Fix check for empty pattern. Simplify.
Karl Heuer <kwzh@gnu.org>
parents:
2452
diff
changeset
|
50 (setq pattern nil))) |
411 | 51 (let ((history command-history) |
52 (temp) | |
53 (what)) | |
54 (while (and history (not what)) | |
55 (setq temp (car history)) | |
56 (if (and (or (not pattern) (string-match pattern (symbol-name (car temp)))) | |
9626
e928e72d3342
(repeat-matching-complex-command): Fix check for empty pattern. Simplify.
Karl Heuer <kwzh@gnu.org>
parents:
2452
diff
changeset
|
57 (y-or-n-p (format "Redo %S? " temp))) |
411 | 58 (setq what (car history)) |
59 (setq history (cdr history)))) | |
60 (if (not what) | |
61 (error "Command history exhausted") | |
62 ;; Try to remove any useless command history element for this command. | |
63 (if (eq (car (car command-history)) 'repeat-matching-complex-command) | |
64 (setq command-history (cdr command-history))) | |
65 (edit-and-eval-command "Redo: " what)))) | |
66 | |
21088 | 67 (defcustom default-command-history-filter-garbage |
411 | 68 '(command-history-mode |
69 list-command-history | |
70 electric-command-history) | |
9626
e928e72d3342
(repeat-matching-complex-command): Fix check for empty pattern. Simplify.
Karl Heuer <kwzh@gnu.org>
parents:
2452
diff
changeset
|
71 "*A list of symbols to be ignored by `default-command-history-filter'. |
21088 | 72 If that function is given a list whose car is an element of this list, |
9626
e928e72d3342
(repeat-matching-complex-command): Fix check for empty pattern. Simplify.
Karl Heuer <kwzh@gnu.org>
parents:
2452
diff
changeset
|
73 then it will return non-nil (indicating the list should be discarded from |
e928e72d3342
(repeat-matching-complex-command): Fix check for empty pattern. Simplify.
Karl Heuer <kwzh@gnu.org>
parents:
2452
diff
changeset
|
74 the history). |
21088 | 75 Initially, all commands related to the command history are discarded." |
76 :type '(repeat symbol) | |
77 :group 'chistory) | |
411 | 78 |
79 (defvar list-command-history-filter 'default-command-history-filter | |
9626
e928e72d3342
(repeat-matching-complex-command): Fix check for empty pattern. Simplify.
Karl Heuer <kwzh@gnu.org>
parents:
2452
diff
changeset
|
80 "Predicate to test which commands should be excluded from the history listing. |
e928e72d3342
(repeat-matching-complex-command): Fix check for empty pattern. Simplify.
Karl Heuer <kwzh@gnu.org>
parents:
2452
diff
changeset
|
81 If non-nil, should be the name of a function of one argument. |
411 | 82 It is passed each element of the command history when |
83 \\[list-command-history] is called. If the filter returns non-nil for | |
84 some element, that element is excluded from the history listing. The | |
85 default filter removes commands associated with the command-history.") | |
86 | |
87 (defun default-command-history-filter (frob) | |
88 "Filter commands matching `default-command-history-filter-garbage' list | |
89 from the command history." | |
90 (or (not (consp frob)) | |
91 (memq (car frob) default-command-history-filter-garbage))) | |
92 | |
21088 | 93 (defcustom list-command-history-max 32 |
94 "*If non-nil, maximum length of the listing produced by `list-command-history'." | |
95 :type '(choice integer (const nil)) | |
96 :group 'chistory) | |
411 | 97 |
98 ;;;###autoload | |
99 (defun list-command-history () | |
100 "List history of commands typed to minibuffer. | |
101 The number of commands listed is controlled by `list-command-history-max'. | |
102 Calls value of `list-command-history-filter' (if non-nil) on each history | |
103 element to judge if that element should be excluded from the list. | |
104 | |
105 The buffer is left in Command History mode." | |
106 (interactive) | |
107 (with-output-to-temp-buffer | |
108 "*Command History*" | |
109 (let ((history command-history) | |
110 (buffer-read-only nil) | |
111 (count (or list-command-history-max -1))) | |
112 (while (and (/= count 0) history) | |
113 (if (and (boundp 'list-command-history-filter) | |
114 list-command-history-filter | |
115 (funcall list-command-history-filter (car history))) | |
116 nil | |
117 (setq count (1- count)) | |
118 (prin1 (car history)) | |
119 (terpri)) | |
120 (setq history (cdr history)))) | |
121 (save-excursion | |
122 (set-buffer "*Command History*") | |
123 (goto-char (point-min)) | |
124 (if (eobp) | |
125 (error "No command history") | |
27065
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
126 (command-history-mode))))) |
411 | 127 |
48915
36f7a48a9735
(command-history-map): Move definition up.
Richard M. Stallman <rms@gnu.org>
parents:
48778
diff
changeset
|
128 (defvar command-history-map nil) |
36f7a48a9735
(command-history-map): Move definition up.
Richard M. Stallman <rms@gnu.org>
parents:
48778
diff
changeset
|
129 (unless command-history-map |
36f7a48a9735
(command-history-map): Move definition up.
Richard M. Stallman <rms@gnu.org>
parents:
48778
diff
changeset
|
130 (setq command-history-map (make-sparse-keymap)) |
36f7a48a9735
(command-history-map): Move definition up.
Richard M. Stallman <rms@gnu.org>
parents:
48778
diff
changeset
|
131 (set-keymap-parent command-history-map lisp-mode-shared-map) |
36f7a48a9735
(command-history-map): Move definition up.
Richard M. Stallman <rms@gnu.org>
parents:
48778
diff
changeset
|
132 (suppress-keymap command-history-map) |
36f7a48a9735
(command-history-map): Move definition up.
Richard M. Stallman <rms@gnu.org>
parents:
48778
diff
changeset
|
133 (define-key command-history-map "x" 'command-history-repeat) |
36f7a48a9735
(command-history-map): Move definition up.
Richard M. Stallman <rms@gnu.org>
parents:
48778
diff
changeset
|
134 (define-key command-history-map "\n" 'next-line) |
36f7a48a9735
(command-history-map): Move definition up.
Richard M. Stallman <rms@gnu.org>
parents:
48778
diff
changeset
|
135 (define-key command-history-map "\r" 'next-line) |
36f7a48a9735
(command-history-map): Move definition up.
Richard M. Stallman <rms@gnu.org>
parents:
48778
diff
changeset
|
136 (define-key command-history-map "\177" 'previous-line)) |
36f7a48a9735
(command-history-map): Move definition up.
Richard M. Stallman <rms@gnu.org>
parents:
48778
diff
changeset
|
137 |
27065
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
138 (defun command-history-mode () |
48778
d414c281a629
* ibuffer.el (ibuffer-mode): If `show-paren-mode' is enabled,
John Paul Wallington <jpw@pobox.com>
parents:
45078
diff
changeset
|
139 "Major mode for listing and repeating recent commands. |
d414c281a629
* ibuffer.el (ibuffer-mode): If `show-paren-mode' is enabled,
John Paul Wallington <jpw@pobox.com>
parents:
45078
diff
changeset
|
140 |
d414c281a629
* ibuffer.el (ibuffer-mode): If `show-paren-mode' is enabled,
John Paul Wallington <jpw@pobox.com>
parents:
45078
diff
changeset
|
141 Keybindings: |
d414c281a629
* ibuffer.el (ibuffer-mode): If `show-paren-mode' is enabled,
John Paul Wallington <jpw@pobox.com>
parents:
45078
diff
changeset
|
142 \\{command-history-map}" |
d414c281a629
* ibuffer.el (ibuffer-mode): If `show-paren-mode' is enabled,
John Paul Wallington <jpw@pobox.com>
parents:
45078
diff
changeset
|
143 (interactive) |
27065
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
144 (Command-history-setup) |
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
145 (setq major-mode 'command-history-mode) |
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
146 (setq mode-name "Command History") |
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
147 (use-local-map command-history-map) |
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
148 (run-hooks 'command-history-mode-hook)) |
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
149 |
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
150 (defun Command-history-setup () |
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
151 (kill-all-local-variables) |
33941
10c41fa2dafe
(Command-history-setup): Remove extraneous `keymap'
Gerd Moellmann <gerd@gnu.org>
parents:
32367
diff
changeset
|
152 (use-local-map command-history-map) |
411 | 153 (lisp-mode-variables nil) |
154 (set-syntax-table emacs-lisp-mode-syntax-table) | |
27065
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
155 (setq buffer-read-only t)) |
411 | 156 |
21088 | 157 (defcustom command-history-hook nil |
158 "If non-nil, its value is called on entry to `command-history-mode'." | |
159 :type 'hook | |
160 :group 'chistory) | |
411 | 161 |
162 (defun command-history-repeat () | |
163 "Repeat the command shown on the current line. | |
164 The buffer for that command is the previous current buffer." | |
165 (interactive) | |
166 (save-excursion | |
167 (eval (prog1 | |
168 (save-excursion | |
169 (beginning-of-line) | |
170 (read (current-buffer))) | |
171 (set-buffer | |
2452
5c9d9b33f249
(repeat-history-command): Bug fix. Someone forgot a car.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
172 (car (cdr (buffer-list)))))))) |
411 | 173 |
174 ;;;###autoload | |
27065
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
175 (defun command-history () |
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
176 "Examine commands from `command-history' in a buffer. |
411 | 177 The number of commands listed is controlled by `list-command-history-max'. |
178 The command history is filtered by `list-command-history-filter' if non-nil. | |
179 Use \\<command-history-map>\\[command-history-repeat] to repeat the command on the current line. | |
180 | |
181 Otherwise much like Emacs-Lisp Mode except that there is no self-insertion | |
182 and digits provide prefix arguments. Tab does not indent. | |
183 \\{command-history-map} | |
27065
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
184 |
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
185 This command always recompiles the Command History listing |
bd4ad2d321a7
(command-history): Renamed from command-history-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
186 and runs the normal hook `command-history-hook'." |
411 | 187 (interactive) |
188 (list-command-history) | |
189 (pop-to-buffer "*Command History*") | |
190 (run-hooks 'command-history-hook)) | |
584 | 191 |
192 (provide 'chistory) | |
193 | |
52401 | 194 ;;; arch-tag: c201a0cd-89f2-4d39-a532-4cb309391dbd |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
195 ;;; chistory.el ends here |