aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-06-23 23:11:23 +0000
committerRichard M. Stallman1994-06-23 23:11:23 +0000
commitdc0825dbe3f86a9d4f09c7b1bc6a0928e590770a (patch)
treea31d67c6996449937b40b8dad0a5efba86892013
parent9c545670f3bd969b1876faa95d93f2a149e6cb83 (diff)
downloademacs-dc0825dbe3f86a9d4f09c7b1bc6a0928e590770a.tar.gz
emacs-dc0825dbe3f86a9d4f09c7b1bc6a0928e590770a.zip
(comint-read-input-ring): Use ring-insert-at-beginning.
Insert most recent string first and only as many as we need. Don't visit the file, just read it.
-rw-r--r--lisp/comint.el31
1 files changed, 17 insertions, 14 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index 286536574a8..010889678ff 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -616,27 +616,30 @@ See also `comint-input-ignoredups' and `comint-write-input-ring'."
616 (message "Cannot read history file %s" 616 (message "Cannot read history file %s"
617 comint-input-ring-file-name))) 617 comint-input-ring-file-name)))
618 (t 618 (t
619 (let ((history-buf (get-file-buffer comint-input-ring-file-name)) 619 (let ((history-buf (get-buffer-create " *temp*"))
620 (file comint-input-ring-file-name)
621 (count 0)
620 (ring (make-ring comint-input-ring-size))) 622 (ring (make-ring comint-input-ring-size)))
621 (save-excursion 623 (unwind-protect
622 (set-buffer (or history-buf 624 (save-excursion
623 (find-file-noselect comint-input-ring-file-name))) 625 (set-buffer history-buf)
624 ;; Save restriction in case file is already visited...
625 ;; Watch for those date stamps in history files!
626 (save-excursion
627 (save-restriction
628 (widen) 626 (widen)
629 (goto-char (point-min)) 627 (erase-buffer)
630 (while (re-search-forward "^[ \t]*\\([^#\n].*\\)[ \t]*$" nil t) 628 (insert-file-contents file)
629 ;; Save restriction in case file is already visited...
630 ;; Watch for those date stamps in history files!
631 (goto-char (point-max))
632 (while (and (< count comint-input-ring-size)
633 (re-search-backward "^[ \t]*\\([^#\n].*\\)[ \t]*$"
634 nil t))
631 (let ((history (buffer-substring (match-beginning 1) 635 (let ((history (buffer-substring (match-beginning 1)
632 (match-end 1)))) 636 (match-end 1))))
633 (if (or (null comint-input-ignoredups) 637 (if (or (null comint-input-ignoredups)
634 (ring-empty-p ring) 638 (ring-empty-p ring)
635 (not (string-equal (ring-ref ring 0) history))) 639 (not (string-equal (ring-ref ring 0) history)))
636 (ring-insert ring history))))) 640 (ring-insert-at-beginning ring history)))
637 ;; Kill buffer unless already visited. 641 (setq count (1+ count))))
638 (if (null history-buf) 642 (kill-buffer history-buf))
639 (kill-buffer nil))))
640 (setq comint-input-ring ring 643 (setq comint-input-ring ring
641 comint-input-ring-index nil))))) 644 comint-input-ring-index nil)))))
642 645