Commit dc0825db authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(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.
parent 9c545670
...@@ -616,27 +616,30 @@ See also `comint-input-ignoredups' and `comint-write-input-ring'." ...@@ -616,27 +616,30 @@ See also `comint-input-ignoredups' and `comint-write-input-ring'."
(message "Cannot read history file %s" (message "Cannot read history file %s"
comint-input-ring-file-name))) comint-input-ring-file-name)))
(t (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))) (ring (make-ring comint-input-ring-size)))
(save-excursion (unwind-protect
(set-buffer (or history-buf (save-excursion
(find-file-noselect comint-input-ring-file-name))) (set-buffer history-buf)
;; Save restriction in case file is already visited...
;; Watch for those date stamps in history files!
(save-excursion
(save-restriction
(widen) (widen)
(goto-char (point-min)) (erase-buffer)
(while (re-search-forward "^[ \t]*\\([^#\n].*\\)[ \t]*$" nil t) (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) (let ((history (buffer-substring (match-beginning 1)
(match-end 1)))) (match-end 1))))
(if (or (null comint-input-ignoredups) (if (or (null comint-input-ignoredups)
(ring-empty-p ring) (ring-empty-p ring)
(not (string-equal (ring-ref ring 0) history))) (not (string-equal (ring-ref ring 0) history)))
(ring-insert ring history))))) (ring-insert-at-beginning ring history)))
;; Kill buffer unless already visited. (setq count (1+ count))))
(if (null history-buf) (kill-buffer history-buf))
(kill-buffer nil))))
(setq comint-input-ring ring (setq comint-input-ring ring
comint-input-ring-index nil))))) comint-input-ring-index nil)))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment