annotate lisp/chistory.el @ 650:39f0e62a8511

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