annotate lisp/packages/chistory.el @ 161:28f395d8dc7a r20-3b7

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