2

I'd like my fixed-string searches to be always case insensitive, my regexp searches to be always case sensitive, and I don't want search-upper-case to change the case of my search strings. This should apply to Isearch, query-replace[-regexp], {flush,keep}-lines, etc.

The way I went about it is I made searches case sensitive by default,

(setq-default case-fold-search nil) (setq search-upper-case nil) 

and let-bound case-fold-search to t around functions that search using fixed strings:

(defun ignoring-case (orig-fn &rest args) "Make ORIG-FN match ignoring case." (let ((case-fold-search t)) (apply orig-fn args))) (advice-add 'isearch-backward :around #'ignoring-case) (advice-add 'isearch-forward :around #'ignoring-case) (advice-add 'query-replace :around #'ignoring-case) 

It works mostly alright, except query-replace's preview of matches is always case-sensitive:

problem

It's lying in the picture above. It will actually stop on all [Aa]'s to ask about replacing them:

enter image description here

How can I fix this?

6
  • When I add the advice and do M-x query-replace RET aa, all the matches (regardless of case) are highlighted. Does that not work for you? Am I missing something? Here is a screenshot . Commented Feb 1 at 6:23
  • Hi @NickD :-) If I use an init.el with just the code that I posted in the question I get case sensitive previews. Did you set the variables to nil? Commented Feb 1 at 10:53
  • D'oh - of course not!-) I'll try again... Commented Feb 1 at 16:36
  • @NickD have you got any news? Commented Feb 9 at 16:14
  • No, other than I was able to reproduce it when I followed your instructions to the letter :-) I tried to chase it down through some code but I quickly got lost and gave up. Commented Feb 9 at 18:13

1 Answer 1

0

Defining another function and rebinding the keys bound to query-replace, instead of advising query-replace, fixes it:

;; Rebind ‘M-%’ to case-insensitive query replacement (defun query-replace-ignoring-case () "Like ‘query-replace’ but match ignoring case." (interactive) (let ((case-fold-search t)) (call-interactively #'query-replace))) (keymap-global-set "M-%" #'query-replace-ignoring-case) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.