Mercurial > emacs
annotate lisp/chistory.el @ 782:a6d00bdb2b60
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 15 Jul 1992 17:54:00 +0000 |
parents | 8a533acedb77 |
children | 4f28bd14272c |
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 |
411 | 3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
4 ;; Principal author K. Shane Hartman | |
5 | |
6 ;; This file is part of GNU Emacs. | |
7 | |
8 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
9 ;; it under the terms of the GNU General Public License as published by | |
10 ;; the Free Software Foundation; either version 1, or (at your option) | |
11 ;; any later version. | |
12 | |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | |
22 | |
23 ;; This really has nothing to do with list-command-history per se, but | |
24 ;; its a nice alternative to C-x ESC (repeat-complex-command) and | |
25 ;; functions as a lister if given no pattern. It's not important | |
26 ;; enough to warrant a file of its own. | |
27 | |
28 ;;;###autoload | |
29 (defun repeat-matching-complex-command (&optional pattern) | |
30 "Edit and re-evaluate complex command with name matching PATTERN. | |
31 Matching occurrences are displayed, most recent first, until you select | |
32 a form for evaluation. If PATTERN is empty (or nil), every form in the | |
33 command history is offered. The form is placed in the minibuffer for | |
34 editing and the result is evaluated." | |
35 (interactive "sRedo Command (regexp): ") | |
36 (if pattern | |
37 (if (equal (setq pattern | |
38 (substring pattern | |
39 (or (string-match "[ \t]*[^ \t]" pattern) | |
40 (length pattern)))) | |
41 "") | |
42 (setq pattern nil))) | |
43 (let ((history command-history) | |
44 (temp) | |
45 (what)) | |
46 (while (and history (not what)) | |
47 (setq temp (car history)) | |
48 (if (and (or (not pattern) (string-match pattern (symbol-name (car temp)))) | |
49 (y-or-n-p (format "Redo %s? " (setq temp (prin1-to-string temp))))) | |
50 (setq what (car history)) | |
51 (setq history (cdr history)))) | |
52 (if (not what) | |
53 (error "Command history exhausted") | |
54 ;; Try to remove any useless command history element for this command. | |
55 (if (eq (car (car command-history)) 'repeat-matching-complex-command) | |
56 (setq command-history (cdr command-history))) | |
57 (edit-and-eval-command "Redo: " what)))) | |
58 | |
59 (defvar default-command-history-filter-garbage | |
60 '(command-history-mode | |
61 list-command-history | |
62 electric-command-history) | |
63 "*A list of symbols. If `default-list-command-history-filter' is | |
64 given a list whose car is an element of this list, then it will return | |
65 non-nil (indicating the list should be discarded from the history). | |
66 Initially, all commands related to the command history are discarded.") | |
67 | |
68 (defvar list-command-history-filter 'default-command-history-filter | |
69 "If non-nil, should be the name of a function of one argument. | |
70 It is passed each element of the command history when | |
71 \\[list-command-history] is called. If the filter returns non-nil for | |
72 some element, that element is excluded from the history listing. The | |
73 default filter removes commands associated with the command-history.") | |
74 | |
75 (defun default-command-history-filter (frob) | |
76 "Filter commands matching `default-command-history-filter-garbage' list | |
77 from the command history." | |
78 (or (not (consp frob)) | |
79 (memq (car frob) default-command-history-filter-garbage))) | |
80 | |
81 (defvar list-command-history-max 32 | |
82 "*If non-nil, should be a positive number which specifies the maximum | |
83 length of the Command History listing produced by `list-command-history'.") | |
84 | |
85 ;;;###autoload | |
86 (defun list-command-history () | |
87 "List history of commands typed to minibuffer. | |
88 The number of commands listed is controlled by `list-command-history-max'. | |
89 Calls value of `list-command-history-filter' (if non-nil) on each history | |
90 element to judge if that element should be excluded from the list. | |
91 | |
92 The buffer is left in Command History mode." | |
93 (interactive) | |
94 (with-output-to-temp-buffer | |
95 "*Command History*" | |
96 (let ((history command-history) | |
97 (buffer-read-only nil) | |
98 (count (or list-command-history-max -1))) | |
99 (while (and (/= count 0) history) | |
100 (if (and (boundp 'list-command-history-filter) | |
101 list-command-history-filter | |
102 (funcall list-command-history-filter (car history))) | |
103 nil | |
104 (setq count (1- count)) | |
105 (prin1 (car history)) | |
106 (terpri)) | |
107 (setq history (cdr history)))) | |
108 (save-excursion | |
109 (set-buffer "*Command History*") | |
110 (goto-char (point-min)) | |
111 (if (eobp) | |
112 (error "No command history") | |
113 (Command-history-setup))))) | |
114 | |
115 (defun Command-history-setup (&optional majormode modename keymap) | |
116 (set-buffer "*Command History*") | |
117 (use-local-map (or keymap command-history-map)) | |
118 (lisp-mode-variables nil) | |
119 (set-syntax-table emacs-lisp-mode-syntax-table) | |
120 (setq buffer-read-only t) | |
121 (use-local-map (or keymap command-history-map)) | |
122 (setq major-mode (or majormode 'command-history-mode)) | |
123 (setq mode-name (or modename "Command History"))) | |
124 | |
125 (defvar command-history-hook nil | |
126 "If non-nil, its value is called on entry to `command-history-mode'.") | |
127 | |
128 (defvar command-history-map nil) | |
129 (if command-history-map | |
130 nil | |
131 (setq command-history-map | |
132 (nconc (make-sparse-keymap) shared-lisp-mode-map)) | |
133 (suppress-keymap command-history-map) | |
134 (define-key command-history-map "x" 'command-history-repeat) | |
135 (define-key command-history-map "\n" 'next-line) | |
136 (define-key command-history-map "\r" 'next-line) | |
137 (define-key command-history-map "\177" 'previous-line)) | |
138 | |
139 (defun command-history-repeat () | |
140 "Repeat the command shown on the current line. | |
141 The buffer for that command is the previous current buffer." | |
142 (interactive) | |
143 (save-excursion | |
144 (eval (prog1 | |
145 (save-excursion | |
146 (beginning-of-line) | |
147 (read (current-buffer))) | |
148 (set-buffer | |
149 (cdr (buffer-list))))))) | |
150 | |
151 ;;;###autoload | |
152 (defun command-history-mode () | |
153 "Major mode for examining commands from `command-history'. | |
154 The number of commands listed is controlled by `list-command-history-max'. | |
155 The command history is filtered by `list-command-history-filter' if non-nil. | |
156 Use \\<command-history-map>\\[command-history-repeat] to repeat the command on the current line. | |
157 | |
158 Otherwise much like Emacs-Lisp Mode except that there is no self-insertion | |
159 and digits provide prefix arguments. Tab does not indent. | |
160 \\{command-history-map} | |
161 Calls the value of `command-history-hook' if that is non-nil. | |
162 The Command History listing is recomputed each time this mode is invoked." | |
163 (interactive) | |
164 (list-command-history) | |
165 (pop-to-buffer "*Command History*") | |
166 (run-hooks 'command-history-hook)) | |
584 | 167 |
168 (provide 'chistory) | |
169 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
170 ;;; chistory.el ends here |