Annotation of 43BSD/contrib/emacs/lisp/chistory.el, revision 1.1.1.1

1.1       root        1: ;; chistory -- List command history
                      2: ;; Copyright (C) 1985 Richard M. Stallman and K. Shane Hartman
                      3: 
                      4: ;; This file is part of GNU Emacs.
                      5: 
                      6: ;; GNU Emacs is distributed in the hope that it will be useful,
                      7: ;; but WITHOUT ANY WARRANTY.  No author or distributor
                      8: ;; accepts responsibility to anyone for the consequences of using it
                      9: ;; or for whether it serves any particular purpose or works at all,
                     10: ;; unless he says so in writing.  Refer to the GNU Emacs General Public
                     11: ;; License for full details.
                     12: 
                     13: ;; Everyone is granted permission to copy, modify and redistribute
                     14: ;; GNU Emacs, but only under the conditions described in the
                     15: ;; GNU Emacs General Public License.   A copy of this license is
                     16: ;; supposed to have been given to you along with GNU Emacs so you
                     17: ;; can know your rights and responsibilities.  It should be in a
                     18: ;; file named COPYING.  Among other things, the copyright notice
                     19: ;; and this notice must be preserved on all copies.
                     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:     (goto-char (point-min))
                    105:     (if (eobp)
                    106:        (error "No command history.")
                    107:       (Command-history-setup))))
                    108: 
                    109: (defun Command-history-setup (&optional majormode modename keymap)
                    110:   (set-buffer "*Command History*")
                    111:   (use-local-map (or keymap command-history-map))
                    112:   (lisp-mode-variables)
                    113:   (set-syntax-table lisp-mode-syntax-table)
                    114:   (setq buffer-read-only t)
                    115:   (use-local-map (or keymap command-history-map))
                    116:   (setq major-mode (or majormode 'command-history-mode))
                    117:   (setq mode-name (or modename "Command History")))
                    118: 
                    119: (defvar command-history-hook nil
                    120:   "If non-nil, its value is called on entry to  command-history-mode.")
                    121: 
                    122: (defvar command-history-map nil)
                    123: (if command-history-map
                    124:     nil
                    125:   (setq command-history-map (make-keymap))
                    126:   (lisp-mode-commands command-history-map)
                    127:   (suppress-keymap command-history-map)
                    128:   (define-key command-history-map "\n" 'next-line)
                    129:   (define-key command-history-map "\r" 'next-line)
                    130:   (define-key command-history-map "\177" 'previous-line))
                    131: 
                    132: (defun command-history-mode ()
                    133:   "Major mode for examining commands from  command-history.
                    134: The number of commands listed is controlled by  list-command-history-max.
                    135: The command history is filtered by  list-command-history-filter  if non-nil.
                    136: 
                    137: Like Emacs-Lisp Mode except that characters do not insert themselves and
                    138: Digits provide prefix arguments.  Tab does not indent.
                    139: \\{command-history-map}
                    140: Calls the value of  command-history-hook  if that is non-nil
                    141: The Command History listing is recomputed each time this mode is
                    142: invoked."
                    143:   (interactive)
                    144:   (list-command-history)
                    145:   (pop-to-buffer "*Command History*")
                    146:   (run-hooks 'command-history-hook))
                    147: 
                    148: 
                    149:       

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.