comparison lisp/simple.el @ 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 7dadfa677617
children d2c64a1563f7
comparison
equal deleted inserted replaced
17661:e9949b093b46 17662:9b1b6974b36f
598 ("\ep" . (previous-history-element . previous-complete-history-element)) 598 ("\ep" . (previous-history-element . previous-complete-history-element))
599 ([prior] . (previous-history-element . previous-complete-history-element)) 599 ([prior] . (previous-history-element . previous-complete-history-element))
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.)
606 With prefix argument N, search for Nth previous match. 616 With prefix argument N, search for Nth previous match.
607 If N is negative, find the next or Nth next match." 617 If N is negative, find the next or Nth next match."
618 (if minibuffer-history-search-history 628 (if minibuffer-history-search-history
619 (car minibuffer-history-search-history) 629 (car minibuffer-history-search-history)
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))
626 (while (/= n 0) 639 (while (/= n 0)
627 (setq prevpos pos) 640 (setq prevpos pos)
671 684
672 (defun next-history-element (n) 685 (defun next-history-element (n)
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."
698 (interactive "p") 717 (interactive "p")
699 (next-history-element (- n))) 718 (next-history-element (- n)))
3042 (setq type (widget-convert type)) 3061 (setq type (widget-convert type))
3043 (unless (widget-apply type :match val) 3062 (unless (widget-apply type :match val)
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
3080 (defvar completion-list-mode-map nil 3069 (defvar completion-list-mode-map nil
3081 "Local map for completion list buffers.") 3070 "Local map for completion list buffers.")