diff options
| author | Richard M. Stallman | 1997-05-05 11:54:37 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-05-05 11:54:37 +0000 |
| commit | 93cee14b0a2362d010dac9a4795e741b309cc58f (patch) | |
| tree | 449f240e99de5197ff8cd1193a68453705f2dbfe | |
| parent | 4b51c8e7ef3eb774624dc52127ad2ba6b7634f95 (diff) | |
| download | emacs-93cee14b0a2362d010dac9a4795e741b309cc58f.tar.gz emacs-93cee14b0a2362d010dac9a4795e741b309cc58f.zip | |
(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).
| -rw-r--r-- | lisp/simple.el | 87 |
1 files changed, 38 insertions, 49 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index eb49bdd7d58..a6c99183352 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -600,6 +600,16 @@ contains expressions rather than strings.") | |||
| 600 | ("\er" . previous-matching-history-element) | 600 | ("\er" . previous-matching-history-element) |
| 601 | ("\es" . next-matching-history-element))) | 601 | ("\es" . next-matching-history-element))) |
| 602 | 602 | ||
| 603 | (defvar minibuffer-text-before-history nil | ||
| 604 | "Text that was in this minibuffer before any history commands. | ||
| 605 | This is nil if there have not yet been any history commands | ||
| 606 | in this use of the minibuffer.") | ||
| 607 | |||
| 608 | (add-hook 'minibuffer-setup-hook 'minibuffer-history-initialize) | ||
| 609 | |||
| 610 | (defun minibuffer-history-initialize () | ||
| 611 | (setq minibuffer-text-before-history nil)) | ||
| 612 | |||
| 603 | (defun previous-matching-history-element (regexp n) | 613 | (defun previous-matching-history-element (regexp n) |
| 604 | "Find the previous history element that matches REGEXP. | 614 | "Find the previous history element that matches REGEXP. |
| 605 | \(Previous history elements refer to earlier actions.) | 615 | \(Previous history elements refer to earlier actions.) |
| @@ -620,6 +630,9 @@ If N is negative, find the next or Nth next match." | |||
| 620 | (error "No previous history search regexp")) | 630 | (error "No previous history search regexp")) |
| 621 | regexp) | 631 | regexp) |
| 622 | (prefix-numeric-value current-prefix-arg)))) | 632 | (prefix-numeric-value current-prefix-arg)))) |
| 633 | (if (and (zerop minibuffer-history-position) | ||
| 634 | (null minibuffer-text-before-history)) | ||
| 635 | (setq minibuffer-text-before-history (buffer-string))) | ||
| 623 | (let ((history (symbol-value minibuffer-history-variable)) | 636 | (let ((history (symbol-value minibuffer-history-variable)) |
| 624 | prevpos | 637 | prevpos |
| 625 | (pos minibuffer-history-position)) | 638 | (pos minibuffer-history-position)) |
| @@ -673,25 +686,31 @@ If N is negative, find the previous or Nth previous match." | |||
| 673 | "Insert the next element of the minibuffer history into the minibuffer." | 686 | "Insert the next element of the minibuffer history into the minibuffer." |
| 674 | (interactive "p") | 687 | (interactive "p") |
| 675 | (or (zerop n) | 688 | (or (zerop n) |
| 676 | (let ((narg (min (max 1 (- minibuffer-history-position n)) | 689 | (let ((narg (- minibuffer-history-position n)) |
| 677 | (length (symbol-value minibuffer-history-variable))))) | 690 | (minimum (if minibuffer-default -1 0)) |
| 678 | (if (or (zerop narg) | 691 | elt) |
| 679 | (= minibuffer-history-position narg)) | 692 | (if (and (zerop minibuffer-history-position) |
| 680 | (error (if (if (zerop narg) | 693 | (null minibuffer-text-before-history)) |
| 681 | (> n 0) | 694 | (setq minibuffer-text-before-history (buffer-string))) |
| 682 | (= minibuffer-history-position 1)) | 695 | (if (< narg minimum) |
| 683 | "End of history; no next item" | 696 | (error "End of history; no next item")) |
| 684 | "Beginning of history; no preceding item")) | 697 | (if (> narg (length (symbol-value minibuffer-history-variable))) |
| 685 | (erase-buffer) | 698 | (error "Beginning of history; no preceding item")) |
| 686 | (setq minibuffer-history-position narg) | 699 | (erase-buffer) |
| 687 | (let ((elt (nth (1- minibuffer-history-position) | 700 | (setq minibuffer-history-position narg) |
| 688 | (symbol-value minibuffer-history-variable)))) | 701 | (cond ((= narg -1) |
| 689 | (insert | 702 | (setq elt minibuffer-default)) |
| 690 | (if minibuffer-history-sexp-flag | 703 | ((= narg 0) |
| 691 | (let ((print-level nil)) | 704 | (setq elt minibuffer-text-before-history) |
| 692 | (prin1-to-string elt)) | 705 | (setq minibuffer-text-before-history nil)) |
| 693 | elt))) | 706 | (t (setq elt (nth (1- minibuffer-history-position) |
| 694 | (goto-char (point-min)))))) | 707 | (symbol-value minibuffer-history-variable))))) |
| 708 | (insert | ||
| 709 | (if minibuffer-history-sexp-flag | ||
| 710 | (let ((print-level nil)) | ||
| 711 | (prin1-to-string elt)) | ||
| 712 | elt)) | ||
| 713 | (goto-char (point-min))))) | ||
| 695 | 714 | ||
| 696 | (defun previous-history-element (n) | 715 | (defun previous-history-element (n) |
| 697 | "Inserts the previous element of the minibuffer history into the minibuffer." | 716 | "Inserts the previous element of the minibuffer history into the minibuffer." |
| @@ -3044,36 +3063,6 @@ in the definition is used to check that VALUE is valid." | |||
| 3044 | (error "Value `%S' does not match type %S of %S" | 3063 | (error "Value `%S' does not match type %S of %S" |
| 3045 | val (car type) var)))) | 3064 | val (car type) var)))) |
| 3046 | (set var val)) | 3065 | (set var val)) |
| 3047 | |||
| 3048 | |||
| 3049 | (defun set-variable (var val) | ||
| 3050 | "Set VARIABLE to VALUE. VALUE is a Lisp object. | ||
| 3051 | When using this interactively, supply a Lisp expression for VALUE. | ||
| 3052 | If you want VALUE to be a string, you must surround it with doublequotes. | ||
| 3053 | |||
| 3054 | If VARIABLE has a `variable-interactive' property, that is used as if | ||
| 3055 | it were the arg to `interactive' (which see) to interactively read the value." | ||
| 3056 | (interactive | ||
| 3057 | (let* ((v (variable-at-point)) | ||
| 3058 | (enable-recursive-minibuffers t) | ||
| 3059 | (val (completing-read | ||
| 3060 | (if (user-variable-p v) | ||
| 3061 | (format "Set variable (default %s): " v) | ||
| 3062 | "Set variable: ") | ||
| 3063 | obarray 'user-variable-p t)) | ||
| 3064 | (var (if (equal val "") v (intern val))) | ||
| 3065 | ) | ||
| 3066 | (list var | ||
| 3067 | (let ((prop (get var 'variable-interactive))) | ||
| 3068 | (if prop | ||
| 3069 | ;; Use VAR's `variable-interactive' property | ||
| 3070 | ;; as an interactive spec for prompting. | ||
| 3071 | (call-interactively (list 'lambda '(arg) | ||
| 3072 | (list 'interactive prop) | ||
| 3073 | 'arg)) | ||
| 3074 | (eval-minibuffer (format "Set %s to value: " var))))))) | ||
| 3075 | (set var val)) | ||
| 3076 | |||
| 3077 | 3066 | ||
| 3078 | ;; Define the major mode for lists of completions. | 3067 | ;; Define the major mode for lists of completions. |
| 3079 | 3068 | ||