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

Consider orderless-annotation-ignore-case #184

Open
shipmints opened this issue Jan 31, 2025 · 8 comments
Open

Consider orderless-annotation-ignore-case #184

shipmints opened this issue Jan 31, 2025 · 8 comments

Comments

@shipmints
Copy link

shipmints commented Jan 31, 2025

Thank you for the implementation of orderless-annotation.

I'm trying to use the marginalia--symbol-class enhanced list of symbols via helpful-variable and narrow the list to those that are buffer local, i.e., marked as "Lv" or "lv" with case sensitive matches, so I'm inputting &Lv in the vertico-managed minibuffer.

To get case-sensitive annotation searches, I've resorted to trying this

    (defun my/orderless-annotation-advice (orig-fun &rest args)
      (let ((case-fold-search nil)
            (completion-ignore-case nil))
        (apply orig-fun args)))
    (advice-add #'orderless-annotation :around #'my/orderless-annotation-advice)

But it doesn't seem to work. I have to dig more.

It would be convenient for orderless to have a few more settings; e.g.,

;; nil means do not ignore case
;; t means ignore case
;; 'default uses completion-ignore-case
(setq orderless-annotation-ignore-case nil)

And I suppose other controls but I haven't looked into others.

-Stephane

minad added a commit that referenced this issue Feb 1, 2025
By not only checking the compiled regexp, smart case is also toggled when
matching on annotations, e.g., &Lv as in #184.
@minad
Copy link
Collaborator

minad commented Feb 1, 2025

I believe this problem is better fixed by improving orderless-smart-case, see commit c7cb044.

@shipmints
Copy link
Author

That seems in harmony with other Emacs behavior that defaults to folding with all lower case specified and mixed case when search criteria are mixed.

However, if I really want to force it to find only lower case as in "lv" vs. "Lv" in marginalia-adorned symbol metadata, how would this work? Perhaps another "flag" in orderless-affix-dispatch-alist to indicate case sensitivity is requested? I'm not an expert with orderless or completion frameworks (I'm impressed by the level of complexity you've had to take on board to do your completion work), so this suggestion could be off base.

@minad
Copy link
Collaborator

minad commented Feb 2, 2025

That seems in harmony with other Emacs behavior that defaults to folding with all lower case specified and mixed case when search criteria are mixed.

Yes, orderless-smart-case is exactly for this purpose, but it hasn't been respected before for the annotation matcher. This is at least fixed by c7cb044.

However, if I really want to force it to find only lower case as in "lv" vs. "Lv" in marginalia-adorned symbol metadata, how would this work? Perhaps another "flag" in orderless-affix-dispatch-alist to indicate case sensitivity is requested? I'm not an expert with orderless or completion frameworks (I'm impressed by the level of complexity you've had to take on board to do your completion work), so this suggestion could be off base.

Yes, an affix flag would be a possible solution to specify case sensitivity. But note that affix flags interfere with normal usage, so I am against adding more of them by default. For example when we introduced the annotation dispatcher we first used @ (which I still like), but this made matching literal @ more difficult, so we went with the an(d)notation instead for annotations, which seems to cause less interference.

Maybe we could reuse = to mean literal and exact case. However I am not sure how to implement this given that case sensitivity is a global property and not an individual property per filter word. Maybe one can construct the regexps somehow to match lower/upper case only.

@shipmints
Copy link
Author

I'd first assumed that = would be as literal as its description but it doesn't work in combination with & as in =& to engage literal metadata completion. If that can be made to work, that seems simpler then adding another affixation code. Or could be &= if order matters and if that can be made to work.

@minad
Copy link
Collaborator

minad commented Feb 2, 2025

Yes, the dispatchers compose, e.g., &=literal or &~flex, but the problem here is that I am not sure if it is possible to construct regexps which are case sensitive, even if case-fold-search=t or completion-ignore-case=t.

@shipmints
Copy link
Author

I think case-fold-search nil is the only way to guarantee case-sensitive matching. Perhaps a lambda could be used to wrap regexps and the default would respect user settings and when = is specified, it would bind to case-fold-search nil.

@minad
Copy link
Collaborator

minad commented Feb 2, 2025

I think case-fold-search nil is the only way to guarantee case-sensitive matching. Perhaps a lambda could be used to wrap regexps and the default would respect user settings and when = is specified, it would bind to case-fold-search nil.

Yes, the matcher could compile to a predicate function which matches exactly, which Orderless already does for certain special matchers like the not or annotation matcher. But that's pretty bad tbh for something as simple as the literal matcher.

@shipmints
Copy link
Author

It would be an interesting proposal to add regexp syntax to force case sensitivity as almost all other regexp engines support. I have a feeling that's been debated many times in the past.

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

2 participants