bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

circular command history patch


From: Thomas A. Horsley
Subject: circular command history patch
Date: Fri, 16 Aug 2002 17:42:12 +0000

I find the command history mechanism very useful for all kinds of stuff, but
I like having it wrap around rather than having to go all the way back if I
hit the end. Here is a patch that introduces a
minibuffer-history-is-circular variable. I've been using it for quite a
while now with no ill effects, so I think it works fairly well. Perhaps it
is worth including in the next release.

*** emacs-21.2/lisp/simple.el   Sun Jul  7 19:31:30 2002
--- emacs-21.2/lisp/simple.el   Fri Aug 16 13:19:57 2002
***************
*** 829,844 ****
  
  (defvar minibuffer-temporary-goal-position nil)
  
  (defun next-history-element (n)
    "Insert the next element of the minibuffer history into the minibuffer."
    (interactive "p")
    (or (zerop n)
        (let ((narg (- minibuffer-history-position n))
            (minimum (if minibuffer-default -1 0))
!           elt minibuffer-returned-to-present)
        (if (and (zerop minibuffer-history-position)
                 (null minibuffer-text-before-history))
            (setq minibuffer-text-before-history (field-string (point-max))))
        (if (< narg minimum)
            (if minibuffer-default
                (error "End of history; no next item")
--- 829,855 ----
  
  (defvar minibuffer-temporary-goal-position nil)
  
+ ; No doubt this should really be a defcustom entry, but I don't understand
+ ; how all that stuff works, so I just make it a defvar.
+ ;
+ (defvar minibuffer-history-is-circular nil
+ "*True if cycling through minibuffer history should wrap around.")
+ 
  (defun next-history-element (n)
    "Insert the next element of the minibuffer history into the minibuffer."
    (interactive "p")
    (or (zerop n)
        (let ((narg (- minibuffer-history-position n))
            (minimum (if minibuffer-default -1 0))
!           elt minibuffer-returned-to-present
!           (histlen (length (symbol-value minibuffer-history-variable))))
        (if (and (zerop minibuffer-history-position)
                 (null minibuffer-text-before-history))
            (setq minibuffer-text-before-history (field-string (point-max))))
+       (if (and minibuffer-history-is-circular (< narg minimum))
+          (setq narg histlen) )
+       (if (and minibuffer-history-is-circular (> narg histlen))
+          (setq narg minimum) )
        (if (< narg minimum)
            (if minibuffer-default
                (error "End of history; no next item")

As an example of some code where I find this mode of operation exceedingly
useful, here is the code I use instead of switch-to-buffer:

(defun select-buf-scrounge-info (blist)
"Given a list of buffers, return a list that looks like (NEXT (BLIST))
where car is the buffer to pick next and BLIST is a list of the
remaining buffers filtered by removing the current buffer, the NEXT
buffer, and any hidden buffers with names that start with space."
   (let
      ( nextbuf newlist b )
      (while blist
         (setq b (car blist))
         (setq blist (cdr blist))
         (if (not (or (eq b (current-buffer))
                      (string-equal (substring (buffer-name b) 0 1) " ")))
            (if nextbuf
               (setq newlist (cons (buffer-name b) newlist))
               (setq nextbuf (buffer-name b)) ) ) )
      (list nextbuf newlist) ) )

(defun select-buf-pick-one ()
"Select another buffer to display in the current window.  The minibuffer
is used to prompt for the buffer name, and the minibuffer history is
provided with a list of existing buffers so you can use the normal history
mechanism to select a buffer."
   (interactive)
   (let*
      ( (info (select-buf-scrounge-info (buffer-list)))
        (prompt (car info)) (hist (car (cdr info))) )
      (switch-to-buffer (read-string "Select another buffer: " prompt 'hist))))

If you like that feel free to include it as well (of course, it should
probably be integrated with all the bs-show stuff so the same buffer sorting
and selection algorithms could be used, but I wasn't that ambitious :-).
--
>>==>> The *Best* political site <URL:http://www.vote-smart.org/> >>==+
      email: address@hidden icbm: Delray Beach, FL      |
<URL:http://home.att.net/~Tom.Horsley> Free Software and Politics <<==+





reply via email to

[Prev in Thread] Current Thread [Next in Thread]