summaryrefslogtreecommitdiff
path: root/lisp/comint.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1994-06-23 23:11:23 +0000
committerRichard M. Stallman <rms@gnu.org>1994-06-23 23:11:23 +0000
commit552740a2f013459f5b152520cc4338d2d767be47 (patch)
treedb114de21dd2475a3439ff420b321fc08e30f8e3 /lisp/comint.el
parent47eb322e1b130892a8498dc6a9526e313586a5ae (diff)
downloademacs-552740a2f013459f5b152520cc4338d2d767be47.tar.gz
(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.
Diffstat (limited to 'lisp/comint.el')
-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'."
(message "Cannot read history file %s"
comint-input-ring-file-name)))
(t
- (let ((history-buf (get-file-buffer comint-input-ring-file-name))
+ (let ((history-buf (get-buffer-create " *temp*"))
+ (file comint-input-ring-file-name)
+ (count 0)
(ring (make-ring comint-input-ring-size)))
- (save-excursion
- (set-buffer (or history-buf
- (find-file-noselect comint-input-ring-file-name)))
- ;; Save restriction in case file is already visited...
- ;; Watch for those date stamps in history files!
- (save-excursion
- (save-restriction
+ (unwind-protect
+ (save-excursion
+ (set-buffer history-buf)
(widen)
- (goto-char (point-min))
- (while (re-search-forward "^[ \t]*\\([^#\n].*\\)[ \t]*$" nil t)
+ (erase-buffer)
+ (insert-file-contents file)
+ ;; Save restriction in case file is already visited...
+ ;; Watch for those date stamps in history files!
+ (goto-char (point-max))
+ (while (and (< count comint-input-ring-size)
+ (re-search-backward "^[ \t]*\\([^#\n].*\\)[ \t]*$"
+ nil t))
(let ((history (buffer-substring (match-beginning 1)
(match-end 1))))
(if (or (null comint-input-ignoredups)
(ring-empty-p ring)
(not (string-equal (ring-ref ring 0) history)))
- (ring-insert ring history)))))
- ;; Kill buffer unless already visited.
- (if (null history-buf)
- (kill-buffer nil))))
+ (ring-insert-at-beginning ring history)))
+ (setq count (1+ count))))
+ (kill-buffer history-buf))
(setq comint-input-ring ring
comint-input-ring-index nil)))))