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