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