Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive isearch #15

Open
asmeurer opened this issue Nov 20, 2015 · 11 comments
Open

Case insensitive isearch #15

asmeurer opened this issue Nov 20, 2015 · 11 comments

Comments

@asmeurer
Copy link

I have enabled case insensitivity in the vr/default-regexp-modifiers, but vr/isearch-forward is still case sensitive. Ideally vr/isearch-forward would be insensitive by default anyway (or use something similar to the default isearch behavior).

@benma
Copy link
Owner

benma commented Nov 27, 2015

In the search prompt of vr/replace, you can toggle the modifiers with C-c i, C-c m, etc., and they generate the proper prefix, i.e. (?im).

Adding the same feature to isearch would be quite a hassle, I believe.

You can always manually type (?i) before your search string to enable case insensitivity, as well as use any of the other modifiers. Is that enough as a workaround?

@asmeurer
Copy link
Author

I'd like it to always be insensitive. But maybe I can write up some code that always adds (?i) to the search.

@asmeurer
Copy link
Author

asmeurer commented Dec 8, 2015

Note that this is even if I have '(vr/default-regexp-modifiers (quote (:I t :M t :S nil :U t))) set in my customize configuration. It does appear that C-c i works in vr/isearch-forward, but the defaults from vr/default-regexp-modifiers are not respected.

@asmeurer
Copy link
Author

asmeurer commented Dec 8, 2015

The advice from #12 (comment) works for me as a workaround, but I don't see why this shouldn't work by default (assuming the isearch settings are configured to ignore case), and I especially don't see why it shouldn't respect the vr settings.

@benma
Copy link
Owner

benma commented Dec 9, 2015

It does appear that C-c i works in vr/isearch-forward

I don't think it does. It is defined in vr/minibuffer-regexp-keymap, which is not used during isearch.

As mentioned here, I obeyed the isearch case-fold-search variable in the past, but removed it, unfortunately without writing down the reason in the commit message :( I vaguely remember that there was some trouble with that. However, I don't see a problem in adding this feature if it doesn't break anything.

However, I don't see a reason not to implement this feature if it behaves okay.

So the task consists of two points:

  1. Add the key bindings to manipulate the modifiers to isearch.
  2. The vr modifiers have only been built for the Python engine and are visible in the prompt when you do the search/replace. They should also be visible in the isearch prompt I guess, because it is an input helper, producing a literal (?modifiers) prefix before the search string. If they are invisible, the search behaves in unexpected ways.

Then there is the question on whether to use the regular isearch key map to manipulate the case-fold-search, and whether to obey it in the first place, and how to handle it with the other engines (pcre2el).

Hence the

Adding the same feature to isearch would be quite a hassle, I believe.

From my first response.

@asmeurer
Copy link
Author

asmeurer commented Dec 9, 2015

C-c i is definitely working for me. I'm on the latest master for visual-regexp.el and visual-regexp-steroids.el. Maybe I have something in my configuration that is making it work.

@benma
Copy link
Owner

benma commented Dec 9, 2015

Can you check with emacs -q and loading only the vr packages? Hitting C-c i during vr/isearch-forward only quits the search for me, and I don't see any code in vr enabling this in isearch.

Do C-c m etc. also work for you, then?

@asmeurer
Copy link
Author

asmeurer commented Dec 9, 2015

I get the same behavior with emacs -q. I've got a few isearch customizations (including isearch+), so those may be interacting somehow. With my emacs configuration, C-c starts like it's going to cancel the search, but when I type i it adds the (?i) to the beginning. C-c m does not work for me.

@benma
Copy link
Owner

benma commented Dec 9, 2015

This is very bizarre. In vr/isearch-forward, there is no code to prepend the (?...) prefix, let alone make that visible in the prompt.

I've got a few isearch customizations (including isearch+), so those may be interacting somehow.

What do you mean? With emacs -q, nothing should be loaded that could interfere.

@asmeurer
Copy link
Author

asmeurer commented Dec 9, 2015

No I mean in my .emacs I do. With emacs -q it doesn't happen (sorry, I meant to type "I get the same behavior as you" above).

@scmanjarrez
Copy link

I've modified a bit the code provided in #12 (comment) to make it toggleable (sorry, I've little knowledge of elisp):

;; Togle case sensitiveness for vr/isearch
(defun toggle-vr-case-insensitive ()
  "Toggle case-insensitive search for visual-regexp."
  (interactive)
  (setq advice-list (list))
  (advice-mapc (lambda (advice _props) (push advice advice-list)) 'vr--isearch)
  (message "advices %d" (length advice-list))
  (if (= (length advice-list) 0)
      (message "Enabling case-insensitive search"
               (defadvice vr--isearch (around add-case-insensitive (forward string &optional bound noerror count) activate)
                 (setq string (concat "(?i)" string))
                 ad-do-it))
    (message "Disabling case-insensitive search"
             (advice-mapc (lambda (advice _props) (advice-remove 'vr--isearch advice)) 'vr--isearch)))
  )
(global-set-key (kbd "C-c t") 'toggle-vr-case-insensitive)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants