aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/comint.el
diff options
context:
space:
mode:
authorChong Yidong2012-03-15 16:00:43 +0800
committerChong Yidong2012-03-15 16:00:43 +0800
commit3f2eafd1fbb706a8774a61b4b633d5f4e24b9cc1 (patch)
tree4858d050ba1396e494b9cc95907f8b1cbcadd174 /lisp/comint.el
parent663b16775f660c1a10caa52e8964ee9e196af88d (diff)
downloademacs-3f2eafd1fbb706a8774a61b4b633d5f4e24b9cc1.tar.gz
emacs-3f2eafd1fbb706a8774a61b4b633d5f4e24b9cc1.zip
Fix ring extension code in ring.el, and tweak comint-input-ring handling.
* lisp/emacs-lisp/ring.el (ring-extend): New function. (ring-insert+extend): Extend the ring correctly. * lisp/comint.el (comint-read-input-ring) (comint-add-to-input-history): Grow comint-input-ring lazily. Fixes: debbugs:11019
Diffstat (limited to 'lisp/comint.el')
-rw-r--r--lisp/comint.el49
1 files changed, 30 insertions, 19 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index 4c2229f2f83..9306bf8dbb2 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -922,15 +922,18 @@ See also `comint-input-ignoredups' and `comint-write-input-ring'."
922 (t 922 (t
923 (let* ((file comint-input-ring-file-name) 923 (let* ((file comint-input-ring-file-name)
924 (count 0) 924 (count 0)
925 (size comint-input-ring-size) 925 ;; Some users set HISTSIZE or `comint-input-ring-size'
926 (ring (make-ring size))) 926 ;; to huge numbers. Don't allocate a huge ring right
927 ;; away; there might not be that much history.
928 (ring-size (min 1500 comint-input-ring-size))
929 (ring (make-ring ring-size)))
927 (with-temp-buffer 930 (with-temp-buffer
928 (insert-file-contents file) 931 (insert-file-contents file)
929 ;; Save restriction in case file is already visited... 932 ;; Save restriction in case file is already visited...
930 ;; Watch for those date stamps in history files! 933 ;; Watch for those date stamps in history files!
931 (goto-char (point-max)) 934 (goto-char (point-max))
932 (let (start end history) 935 (let (start end history)
933 (while (and (< count size) 936 (while (and (< count comint-input-ring-size)
934 (re-search-backward comint-input-ring-separator 937 (re-search-backward comint-input-ring-separator
935 nil t) 938 nil t)
936 (setq end (match-beginning 0))) 939 (setq end (match-beginning 0)))
@@ -941,15 +944,18 @@ See also `comint-input-ignoredups' and `comint-write-input-ring'."
941 (point-min))) 944 (point-min)))
942 (setq history (buffer-substring start end)) 945 (setq history (buffer-substring start end))
943 (goto-char start) 946 (goto-char start)
944 (if (and (not (string-match comint-input-history-ignore 947 (when (and (not (string-match comint-input-history-ignore
945 history)) 948 history))
946 (or (null comint-input-ignoredups) 949 (or (null comint-input-ignoredups)
947 (ring-empty-p ring) 950 (ring-empty-p ring)
948 (not (string-equal (ring-ref ring 0) 951 (not (string-equal (ring-ref ring 0)
949 history)))) 952 history))))
950 (progn 953 (when (= count ring-size)
951 (ring-insert-at-beginning ring history) 954 (ring-extend ring (min (- comint-input-ring-size ring-size)
952 (setq count (1+ count))))))) 955 ring-size))
956 (setq ring-size (ring-size ring)))
957 (ring-insert-at-beginning ring history)
958 (setq count (1+ count))))))
953 (setq comint-input-ring ring 959 (setq comint-input-ring ring
954 comint-input-ring-index nil))))) 960 comint-input-ring-index nil)))))
955 961
@@ -1691,13 +1697,18 @@ Argument 0 is the command name."
1691(defun comint-add-to-input-history (cmd) 1697(defun comint-add-to-input-history (cmd)
1692 "Add CMD to the input history. 1698 "Add CMD to the input history.
1693Ignore duplicates if `comint-input-ignoredups' is non-nil." 1699Ignore duplicates if `comint-input-ignoredups' is non-nil."
1694 (if (and (funcall comint-input-filter cmd) 1700 (when (and (funcall comint-input-filter cmd)
1695 (or (null comint-input-ignoredups) 1701 (or (null comint-input-ignoredups)
1696 (not (ring-p comint-input-ring)) 1702 (not (ring-p comint-input-ring))
1697 (ring-empty-p comint-input-ring) 1703 (ring-empty-p comint-input-ring)
1698 (not (string-equal (ring-ref comint-input-ring 0) 1704 (not (string-equal (ring-ref comint-input-ring 0) cmd))))
1699 cmd)))) 1705 ;; If `comint-input-ring' is full, maybe grow it.
1700 (ring-insert comint-input-ring cmd))) 1706 (let ((size (ring-size comint-input-ring)))
1707 (and (= size (ring-length comint-input-ring))
1708 (< size comint-input-ring-size)
1709 (ring-extend comint-input-ring
1710 (min size (- comint-input-ring-size size)))))
1711 (ring-insert comint-input-ring cmd)))
1701 1712
1702(defun comint-send-input (&optional no-newline artificial) 1713(defun comint-send-input (&optional no-newline artificial)
1703 "Send input to process. 1714 "Send input to process.