Mercurial > emacs
changeset 17662:9b1b6974b36f
(minibuffer-text-before-history): New variable.
(minibuffer-history-initialize): New fn, on minibuffer-setup-hook.
(next-history-element, previous-matching-history-element):
Initialize minibuffer-text-before-history.
(next-history-element): Use minibuffer-text-before-history
as "position 0" of the history list.
Use minibuffer-default as position -1, if it is non-nil.
Simplify error logic for beginning and end of history.
(set-variable): Delete old definition (duplicate).
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 05 May 1997 11:54:37 +0000 |
parents | e9949b093b46 |
children | d2c64a1563f7 |
files | lisp/simple.el |
diffstat | 1 files changed, 38 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/simple.el Mon May 05 05:45:46 1997 +0000 +++ b/lisp/simple.el Mon May 05 11:54:37 1997 +0000 @@ -600,6 +600,16 @@ ("\er" . previous-matching-history-element) ("\es" . next-matching-history-element))) +(defvar minibuffer-text-before-history nil + "Text that was in this minibuffer before any history commands. +This is nil if there have not yet been any history commands +in this use of the minibuffer.") + +(add-hook 'minibuffer-setup-hook 'minibuffer-history-initialize) + +(defun minibuffer-history-initialize () + (setq minibuffer-text-before-history nil)) + (defun previous-matching-history-element (regexp n) "Find the previous history element that matches REGEXP. \(Previous history elements refer to earlier actions.) @@ -620,6 +630,9 @@ (error "No previous history search regexp")) regexp) (prefix-numeric-value current-prefix-arg)))) + (if (and (zerop minibuffer-history-position) + (null minibuffer-text-before-history)) + (setq minibuffer-text-before-history (buffer-string))) (let ((history (symbol-value minibuffer-history-variable)) prevpos (pos minibuffer-history-position)) @@ -673,25 +686,31 @@ "Insert the next element of the minibuffer history into the minibuffer." (interactive "p") (or (zerop n) - (let ((narg (min (max 1 (- minibuffer-history-position n)) - (length (symbol-value minibuffer-history-variable))))) - (if (or (zerop narg) - (= minibuffer-history-position narg)) - (error (if (if (zerop narg) - (> n 0) - (= minibuffer-history-position 1)) - "End of history; no next item" - "Beginning of history; no preceding item")) - (erase-buffer) - (setq minibuffer-history-position narg) - (let ((elt (nth (1- minibuffer-history-position) - (symbol-value minibuffer-history-variable)))) - (insert - (if minibuffer-history-sexp-flag - (let ((print-level nil)) - (prin1-to-string elt)) - elt))) - (goto-char (point-min)))))) + (let ((narg (- minibuffer-history-position n)) + (minimum (if minibuffer-default -1 0)) + elt) + (if (and (zerop minibuffer-history-position) + (null minibuffer-text-before-history)) + (setq minibuffer-text-before-history (buffer-string))) + (if (< narg minimum) + (error "End of history; no next item")) + (if (> narg (length (symbol-value minibuffer-history-variable))) + (error "Beginning of history; no preceding item")) + (erase-buffer) + (setq minibuffer-history-position narg) + (cond ((= narg -1) + (setq elt minibuffer-default)) + ((= narg 0) + (setq elt minibuffer-text-before-history) + (setq minibuffer-text-before-history nil)) + (t (setq elt (nth (1- minibuffer-history-position) + (symbol-value minibuffer-history-variable))))) + (insert + (if minibuffer-history-sexp-flag + (let ((print-level nil)) + (prin1-to-string elt)) + elt)) + (goto-char (point-min))))) (defun previous-history-element (n) "Inserts the previous element of the minibuffer history into the minibuffer." @@ -3044,36 +3063,6 @@ (error "Value `%S' does not match type %S of %S" val (car type) var)))) (set var val)) - - -(defun set-variable (var val) - "Set VARIABLE to VALUE. VALUE is a Lisp object. -When using this interactively, supply a Lisp expression for VALUE. -If you want VALUE to be a string, you must surround it with doublequotes. - -If VARIABLE has a `variable-interactive' property, that is used as if -it were the arg to `interactive' (which see) to interactively read the value." - (interactive - (let* ((v (variable-at-point)) - (enable-recursive-minibuffers t) - (val (completing-read - (if (user-variable-p v) - (format "Set variable (default %s): " v) - "Set variable: ") - obarray 'user-variable-p t)) - (var (if (equal val "") v (intern val))) -) - (list var - (let ((prop (get var 'variable-interactive))) - (if prop - ;; Use VAR's `variable-interactive' property - ;; as an interactive spec for prompting. - (call-interactively (list 'lambda '(arg) - (list 'interactive prop) - 'arg)) - (eval-minibuffer (format "Set %s to value: " var))))))) - (set var val)) - ;; Define the major mode for lists of completions.