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