dajva / rg.el

Emacs search tool based on ripgrep
https://rgel.readthedocs.io
GNU General Public License v3.0
465 stars 38 forks source link

ignore user-specified built-in aliases #147

Closed mbunkus closed 1 year ago

mbunkus commented 1 year ago

This is a wish for a feature enhancement. I have several files I often work with whose file name patterns belong to more than one of ripgrep's built-in types. For example, *.rb is used both by puppet and by ruby, *.h is used by c and cpp and objc and so on.

Unfortunately the type aliases are sorted alphabetically. For me this means that rg.el's default-selected type is always wrong for these types of files:

It would be nice to have a customizable list of build-in file types that rg.el simply ignores (filters out from the list obtained by running rg --type-list).

At the moment I'm using something like the following to achieve this:

(use-package rg
  :defer t
  :config
  ;; Remove certain known types.
  (rg-get-type-aliases)
  (setq rg-builtin-type-aliases (--remove (s-match "^[ch]$\\|^cpp$\\|^objc\\|^sv$\\|^puppet$" (car it))
                                          rg-builtin-type-aliases)))

If anyone wants to copy this: it requires use-package, dash & s.

For C++ I then have a custom type called call (as in "C/C++ all") that contains all the extensions I usually use with C++.

Yeah, this works, but I guess other users might also have use for such a negative filter, and therefore it'd be nice to have one, especially as the snippet above relies on knowledge about how file types cached internally by rg.el and is therefore not trivial to obtain.

Really not urgent, obviously. But as I've stumbled across this issue several times now I've finally decided to whip up this feature request.

Thanks for your consideration, and generally for your work on rg.el!

dajva commented 1 year ago

Oh, missed this issue for some reason. Yeah, I kind of have the same problem myself but fixed it in the early days of this package so have totally forgot it. The workaround I am using is to define my own filter for C++, containing some additional non standard extension IIRC. In any case your own custom type aliases in rg-custom-type-aliases will be selected first. Not sure if you can use the same identifier as builtins though.

Not sure what solution would be good here though. Just removing aliases may not fit all if you for instance want c-mode in pure c files. Personally I use my own c++ alias but sometimes use the h alias to only search in header files. Maybe some kind of reordering or prioritization of aliases may solve most of these problems. Or do you see some case that would not work for your use cases?

dajva commented 1 year ago

Added an implementation of prioritized type aliases. Let me know if it solves your problems.