Subject: bug#12986: Pressing backspace during isearch exits case-sensitive and word modes

From: Juri Linkov <[email-masked]>
Date: Sun, 02 Jun 2013 12:49:19 +0300

>> But it still seems to be a UI inconsistency: although the described
>> behavior happens for word mode and case-insensitivity mode, it
>> doesn't happen for regex mode, which it what led me to believe it was
>> a bug for the first two. If it's supposed to happen for the first two,
>> then shouldn't it happen for all three?
>
> Good point.  `isearch-delete-char' (that uses `isearch-pop-state')
> restores word mode but not regexp mode.  This looks like
> unaccountable inconsistency.  Perhaps it should restore
> regexp mode as well.
>
> Case-insensitivity is already restored when you type <backspace>
> but you can't see this because it has no indication in the prompt.
> Maybe it should momentarily flash a case sensitivity indicator
> when you type <backspace> like it does when you type `M-c'
> (but only when <backspace> changes the state of case-insensitivity).
>
> The recently added `isearch-lax-whitespace' could be saved/restored too.
>
> For customizability a new user option could be added to define a list
> of search states that the user wants to keep on the isearch stack.

This patch adds a new user option `isearch-keep-stack-variables'
intended to accompany another option `isearch-keep-mode-variables'
added in bug#11378.  It adds a new option but doesn't change
the default behavior - its default value is `isearch-regexp'
that means to not keep regexp mode when pressing backspace
(other search variables will be supported later as well).

=== modified file 'lisp/isearch.el'
--- lisp/isearch.el	2013-05-30 23:50:36 +0000
+++ lisp/isearch.el	2013-06-02 09:45:01 +0000
@@ -153,6 +153,17 @@ (defcustom isearch-hide-immediately t
   :type 'boolean
   :group 'isearch)
 
+(defcustom isearch-keep-stack-variables '(isearch-regexp)
+  "A set of search variables to keep and not to restore from the search stack."
+  :type '(set (const :tag "Regexp search" isearch-regexp)
+	      (const :tag "Case folding" isearch-case-fold-search)
+	      (const :tag "Invisible text" isearch-invisible)
+	      (const :tag "Filters" isearch-filter-predicates)
+	      (const :tag "Lax whitespace" isearch-lax-whitespace)
+	      (const :tag "Regexp lax whitespace" isearch-regexp-lax-whitespace))
+  :version "24.4"
+  :group 'isearch)
+
 (defcustom isearch-resume-in-command-history nil
   "If non-nil, `isearch-resume' commands are added to the command history.
 This allows you to resume earlier Isearch sessions through the
@@ -1109,6 +1143,7 @@ (cl-defstruct (isearch--state
                  (case-fold-search isearch-case-fold-search)
                  (pop-fun (if isearch-push-state-function
                               (funcall isearch-push-state-function)))
+		 (regexp isearch-regexp)
 		 (filter-predicates isearch-filter-predicates))))
   (string :read-only t)
   (message :read-only t)
@@ -1122,6 +1157,7 @@ (cl-defstruct (isearch--state
   (barrier :read-only t)
   (case-fold-search :read-only t)
   (pop-fun :read-only t)
+  (regexp :read-only t)
   (filter-predicates :read-only t))
 
 (defun isearch--set-state (cmd)
@@ -1136,6 +1172,8 @@ (defun isearch--set-state (cmd)
 	isearch-barrier (isearch--state-barrier cmd)
 	isearch-case-fold-search (isearch--state-case-fold-search cmd)
 	isearch-filter-predicates (isearch--state-filter-predicates cmd))
+  (unless (memq 'isearch-regexp isearch-keep-stack-variables)
+    (setq isearch-regexp (isearch--state-regexp cmd)))
   (if (functionp (isearch--state-pop-fun cmd))
       (funcall (isearch--state-pop-fun cmd) cmd))
   (goto-char (isearch--state-point cmd)))