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