Subject: [PATCH] RE: bug#12988: isearch fails to persistently indicate case sensitivity

From: "Drew Adams" <[email-masked]>
Date: Sun, 25 Nov 2012 09:55:07 -0800

> > But if instead you do M-c, the minibuffer just momentarily flashes
> > a case sensitivity indicator, then gives no indication of case
> > sensitivity status while you type your search string.
> 
> Adding "case-sensitive" to the search prompt would make it too long.
> adding a shorter abbreviation like "cs" would make it too cryptic.

This is not an unsolvable problem.  There is probably more than one reasonable
way to solve it.

I think I've mentioned this way before, but perhaps not: In Isearch+, the
mode-line lighter makes clear (continually) whether searching is currently
case-sensitive.  Vanilla Emacs could do likewise.

 When   case-sensitive, the lighter is `Isearch'.
 When case-insensitive, the lighter is `ISEARCH'.

This is one simple way to make things clear to users.
It requires no extra space anywhere.

Here is a simplified version of the code I use.  (In Isearch+, the lighter also
indicates by its face whether search is wrapped - that is not done here.)  This
code should be usable by vanilla Isearch.

(defun isearch-highlight-lighter ()
  "Update minor-mode mode-line lighter to reflect case sensitivity."
  (let ((case-fold-search  isearch-case-fold-search))
    (when (and (eq case-fold-search t)  search-upper-case)
      (setq case-fold-search  
            (isearch-no-upper-case-p isearch-string isearch-regexp)))
    ;; Vanilla Isearch uses `isearch-mode', hence the first of these.
    (setq minor-mode-alist
          (delete '(isearch-mode isearch-mode) minor-mode-alist)
          minor-mode-alist
          (delete '(isearch-mode " ISEARCH")   minor-mode-alist)
          minor-mode-alist
          (delete '(isearch-mode " Isearch")   minor-mode-alist))
    (let ((lighter  (if case-fold-search " ISEARCH" " Isearch")))
      (add-to-list 'minor-mode-alist `(isearch-mode ,lighter))))
  (condition-case nil (redisplay t) (error nil)))

(add-hook 'isearch-update-post-hook 'isearch-highlight-lighter)

(defun isearch-toggle-case-fold ()
  "Toggle case folding in searching on or off."
  (interactive)
  (setq isearch-case-fold-search
        (if isearch-case-fold-search nil 'yes)
        isearch-success   t
        isearch-adjusted  t)
  (isearch-highlight-lighter)
  (let ((message-log-max  nil))
    (message "%s%s [case %ssensitive]"
             (isearch-message-prefix nil isearch-nonincremental)
	     isearch-message (if isearch-case-fold-search "in" "")))
  (sit-for 1)
  (isearch-update))

However, I notice that, from `emacs -Q' and this code, with an empty search
string the lighter does not change until you type something.  And (regardless of
the search string) the lighter does not change until after the delay for showing
the "case-[in]sensitive" message.

Neither of those problems exists for Isearch+.  I don't have the time to dig
into why they happen for vanilla Isearch.  If you are interested, the Isearch+
code is here.  Clearly something else in that code prevents these two minor
problems.
http://www.emacswiki.org/emacs-en/download/isearch%2b.el

HTH.