doomemacs / doomemacs/core

Global toggle for "Smart Case" in searches/completions

Open
#6,148 2 comments 5 reactions 0 assignees View on GitHub
is:feature needs-triage
Dominant language
Emacs Lisp
Stars
22.7k
Forks
3.1k
Avg merge
10h 46m
Merged PRs (30d)
4

Description

### Describe your request

I often times want to search for a specific string that is completely lowercase. **Smart Case** handles this for strings that contain an uppercase character, but doesn't work for fully lowercase queries, and you end up with a bunch of results you don't want. I couldn't find an easy way to disable smart case across the board.

Below is the code I'm using in my personal config to basically toggle smart case off for vertico and orderless. I have this mapped to `SPC t S` (+toggle -> Smart case). If this seems useful, I can throw together a PR that implements this sort of functionality across the board.

```emacs-lisp
(after! vertico
(setq luv/smart-case-enabled t)
(defun luv/toggle-smart-case ()
(interactive)
(setq luv/smart-case-enabled (not luv/smart-case-enabled))
(setq orderless-smart-case luv/smart-case-enabled)
(message "Smart case %s." (if luv/smart-case-enabled "enabled" "disabled")))
(cl-defun luv/around-vertico-file-search (old-function &key query in all-files (recursive t) prompt args)
(unless luv/smart-case-enabled
(push "--case-sensitive" args))
(funcall old-function :query query :in in :all-files all-files :recursive recursive :prompt prompt :args args))
(advice-add #'+vertico-file-search :around #'luv/around-vertico-file-search))
```

### Briefly explain its use-case

Example scenario: I want to search for all instances of the `doom` CSS class name. But the search results will end up including the `const` and `class` lines as well.

```css
.doom {}
```

```javascript
const DOOM = 666
class Doom {}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.