annotate lisp/packages/chistory.el @ 8:4b173ad71786 r19-15b5

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