Subject: bug#7899: Unsatisfactory interaction between shell-mode-hook and comint-read-input-ring

From: Pete Beardmore <[email-masked]>
Date: Mon, 27 May 2013 08:44:25 +0100

[patches against bzr master attached (hopefully!)]

hi,

i believe this is a bug in comint-read-input-ring. shell-mode sets a  
buffer-local version of comint-read-input-size which is effectively  
ignored due to comint-read-input-ring's use of '(with-temp-buffer ...'  
. i've lost ~40000 line bash history on more than one occasion over  
the last several years and am elated to have finally pinned the  
problem on something

(very loosely) related to this issue is the question of why the  
default of 'comint-input-history-ignore' is set to anything at all?  
it's currently "^#", and therefore without having pro-actively made  
any changes to their emacs setup, a user's shell history (for  
instance) doesn't emerge unscathed from a trip through comint if it  
contains comments. if modifying this default touches too many other  
comint uses, perhaps an override in shell-mode.el?

cheers,
Pete
#------------------------------------------------------------
#revno: 112736
#committer: Pete Beardmore <[email-masked]>
#branch nick: bzr
#timestamp: Mon 2013-05-27 07:53:30 +0100
#message:
#  comint: ensure buffer local comint-input-ring-read-size variable is visible throughout input-read-ring logic
=== modified file 'lisp/comint.el'
--- lisp/comint.el	2013-05-25 02:40:33 +0000
+++ lisp/comint.el	2013-05-27 06:53:30 +0000
@@ -938,6 +938,7 @@
 		;; to huge numbers.  Don't allocate a huge ring right
 		;; away; there might not be that much history.
 		(ring-size (min 1500 comint-input-ring-size))
+		(ring-size-max (max 1500 comint-input-ring-size))
 		(ring (make-ring ring-size)))
 	   (with-temp-buffer
              (insert-file-contents file)
@@ -945,7 +946,7 @@
              ;; Watch for those date stamps in history files!
              (goto-char (point-max))
              (let (start end history)
-               (while (and (< count comint-input-ring-size)
+               (while (and (< count ring-size-max)
                            (re-search-backward comint-input-ring-separator
                                                nil t)
                            (setq end (match-beginning 0)))
@@ -963,7 +964,7 @@
 				(not (string-equal (ring-ref ring 0)
 						   history))))
 		   (when (= count ring-size)
-		     (ring-extend ring (min (- comint-input-ring-size ring-size)
+		     (ring-extend ring (min (- ring-size-max ring-size)
 					    ring-size))
 		     (setq ring-size (ring-size ring)))
 		   (ring-insert-at-beginning ring history)

#------------------------------------------------------------
#revno: 112737
#committer: Pete Beardmore <[email-masked]>
#branch nick: bzr
#timestamp: Mon 2013-05-27 08:12:04 +0100
#message:
#  comint: don't strip anything by default on comint-input-ring-read
=== modified file 'lisp/comint.el'
--- lisp/comint.el	2013-05-27 06:53:30 +0000
+++ lisp/comint.el	2013-05-27 07:12:04 +0000
@@ -318,7 +318,7 @@
 (defvar comint-input-ring-separator "\n"
   "Separator between commands in the history file.")
 
-(defvar comint-input-history-ignore "^#"
+(defvar comint-input-history-ignore ""
   "Regexp for history entries that should be ignored when Comint initializes.")
 
 (defcustom comint-process-echoes nil