|
|
1.1 ! root 1: ;; Electric Command History Mode ! 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: (require 'electric) ; command loop ! 24: (require 'chistory) ; history lister ! 25: ! 26: (defun Electric-command-history-redo-expression (&optional noconfirm) ! 27: "Edit current history line in minibuffer and execute result. ! 28: With prefix argument NOCONFIRM, execute current line as is without editing." ! 29: (interactive "P") ! 30: (let (todo) ! 31: (save-excursion ! 32: (set-buffer "*Command History*") ! 33: (beginning-of-line) ! 34: (setq todo (read (current-buffer))) ! 35: (if (boundp 'electric-history-in-progress) ! 36: (if todo (throw 'electric-history-quit (list noconfirm todo))))))) ! 37: ! 38: (defvar electric-history-map ()) ! 39: (if electric-history-map ! 40: () ! 41: (setq electric-history-map (make-keymap)) ! 42: (fillarray electric-history-map 'Electric-history-undefined) ! 43: (define-key electric-history-map "\e" (make-keymap)) ! 44: (fillarray (lookup-key electric-history-map "\e") 'Electric-history-undefined) ! 45: (define-key electric-history-map "\C-u" 'universal-argument) ! 46: (define-key electric-history-map " " 'Electric-command-history-redo-expression) ! 47: (define-key electric-history-map "!" 'Electric-command-history-redo-expression) ! 48: (define-key electric-history-map "\e\C-x" 'eval-sexp) ! 49: (define-key electric-history-map "\e\C-d" 'down-list) ! 50: (define-key electric-history-map "\e\C-u" 'backward-up-list) ! 51: (define-key electric-history-map "\e\C-b" 'backward-sexp) ! 52: (define-key electric-history-map "\e\C-f" 'forward-sexp) ! 53: (define-key electric-history-map "\e\C-a" 'beginning-of-defun) ! 54: (define-key electric-history-map "\e\C-e" 'end-of-defun) ! 55: (define-key electric-history-map "\e\C-n" 'forward-list) ! 56: (define-key electric-history-map "\e\C-p" 'backward-list) ! 57: (define-key electric-history-map "q" 'Electric-history-quit) ! 58: (define-key electric-history-map "\C-c" nil) ! 59: (define-key electric-history-map "\C-c\C-c" 'Electric-history-quit) ! 60: (define-key electric-history-map "\C-]" 'Electric-history-quit) ! 61: (define-key electric-history-map "\C-z" 'suspend-emacs) ! 62: (define-key electric-history-map "\C-h" 'Helper-help) ! 63: (define-key electric-history-map "?" 'Helper-describe-bindings) ! 64: (define-key electric-history-map "\e>" 'end-of-buffer) ! 65: (define-key electric-history-map "\e<" 'beginning-of-buffer) ! 66: (define-key electric-history-map "\n" 'next-line) ! 67: (define-key electric-history-map "\r" 'next-line) ! 68: (define-key electric-history-map "\177" 'previous-line) ! 69: (define-key electric-history-map "\C-n" 'next-line) ! 70: (define-key electric-history-map "\C-p" 'previous-line) ! 71: (define-key electric-history-map "\ev" 'scroll-down) ! 72: (define-key electric-history-map "\C-v" 'scroll-up) ! 73: (define-key electric-history-map "\C-l" 'recenter) ! 74: (define-key electric-history-map "\e\C-v" 'scroll-other-window)) ! 75: ! 76: (defvar electric-command-history-hook nil ! 77: "If non-nil, its value is called by electric-command-history.") ! 78: ! 79: (defun electric-command-history () ! 80: "Major mode for examining and redoing commands from command-history. ! 81: The number of command listed is controlled by list-command-history-max. ! 82: The command history is filtered by list-command-history-filter if non-nil. ! 83: Combines typeout Command History list window with menu like selection ! 84: of an expression from the history for re-evaluation in the *original* buffer. ! 85: ! 86: The history displayed is filtered by list-command-history-filter if non-nil. ! 87: ! 88: This pops up a window with the Command History listing. If the very ! 89: next character typed is Space, the listing is killed and the previous ! 90: window configuration is restored. Otherwise, you can browse in the ! 91: Command History with Return moving down and Delete moving up, possibly ! 92: selecting an expression to be redone with Space or quitting with `Q'. ! 93: ! 94: Like Emacs-Lisp Mode except that characters do not insert themselves and ! 95: Tab and linefeed do not indent. Instead these commands are provided: ! 96: Space or ! edit then evaluate current line in history inside ! 97: the ORIGINAL buffer which invoked this mode. ! 98: The previous window configuration is restored ! 99: unless the invoked command changes it. ! 100: C-c C-c, C-], Q Quit and restore previous window configuration. ! 101: LFD, RET Move to the next line in the history. ! 102: DEL Move to the previous line in the history. ! 103: ? Provides a complete list of commands. ! 104: ! 105: Calls the value of electric-command-history-hook if that is non-nil ! 106: The Command History listing is recomputed each time this mode is invoked." ! 107: (interactive) ! 108: (let ((electric-history-in-progress t) ! 109: (old-buffer (current-buffer)) ! 110: (todo)) ! 111: (unwind-protect ! 112: (setq todo ! 113: (catch 'electric-history-quit ! 114: (save-window-excursion ! 115: (save-window-excursion ! 116: (list-command-history) ! 117: (set-buffer "*Command History*") ! 118: (Command-history-setup 'electric-command-history ! 119: "Electric History" ! 120: electric-history-map)) ! 121: (Electric-pop-up-window "*Command History*") ! 122: (run-hooks 'electric-command-history-hook) ! 123: (if (eobp) ! 124: (progn (ding) ! 125: (message "No command history.") ! 126: (throw 'electric-history-quit nil)) ! 127: (let ((Helper-return-blurb "return to History")) ! 128: (Electric-command-loop 'electric-history-quit ! 129: "->" t)))))) ! 130: (set-buffer "*Command History*") ! 131: (Command-history-setup) ! 132: (bury-buffer (current-buffer))) ! 133: (if (consp todo) ! 134: (progn (set-buffer old-buffer) ! 135: (if (car todo) ! 136: (apply (car (car (cdr todo))) (cdr (car (cdr todo)))) ! 137: (edit-and-eval-command "Redo: " (car (cdr todo)))))))) ! 138: ! 139: (defun Electric-history-undefined () ! 140: (interactive) ! 141: (ding) ! 142: (message "Type C-h for help, ? for commands, C-c to quit, Space to execute") ! 143: (sit-for 4)) ! 144: ! 145: (defun Electric-history-quit () ! 146: "Quit Electric Command History, restoring previous window configuration." ! 147: (interactive) ! 148: (if (boundp 'electric-history-in-progress) ! 149: (progn (message "") ! 150: (throw 'electric-history-quit nil))))
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.