Giter Site home page Giter Site logo

dajva / rg.el Goto Github PK

View Code? Open in Web Editor NEW
464.0 9.0 37.0 1.05 MB

Emacs search tool based on ripgrep

Home Page: https://rgel.readthedocs.io

License: GNU General Public License v3.0

Emacs Lisp 97.73% Makefile 1.65% Dockerfile 0.62%
ripgrep emacs melpa search grep

rg.el's Introduction

rg.el

License GPL 3 MELPA Stable MELPA Build Status Coverage Status

Use ripgrep in Emacs.

Ripgrep is a replacement for both grep like (search one file) and ag like (search many files) tools. It's fast and versatile and written in Rust. For some introduction and benchmarks, see ripgrep is faster than {grep, ag, git grep, ucg, pt, sift}.

screenshot

Installation

This package is available on MELPA Stable and MELPA. Install with M-x package-install RET rg from within Emacs.

It is also available in GNU Guix as emacs-rg. Install with guix package -i emacs-rg.

If you want to install manually just put rg.el and the rest of the elisp files somewhere in your load path and add require the package:

(require 'rg)

rg and friends are autoloaded symbols which means it's also possible to defer loading if you have autoloading setup.

Setup key bindings

This will setup the default key bindings in a non lazy way. If you care about startup performance see the next example.

(rg-enable-default-bindings)

See documentation for how to handle lazy loading.

Use old defaults

rg.el 2.0.0 will use new default settings to improve look and feel, more consistent key bindings etc. If you want to use the old defaults add this to your init.el:

(rg-use-old-defaults)

rg-menu

If you prefer to use a magit like interface as a complement to regular key maps, replace (rg-enable-default-bindings) with (rg-enable-menu). The menus are built with transient, which means that the menus can be modified in the same way as in magit.

Documentation

Info documentation is included in the package. Online documentation: https://rgel.readthedocs.io

Contribute

  • Install cask.
  • Install dependencies:
make deps
  • Run tests:
make test

License

See LICENSE.

rg.el's People

Contributors

cwittern avatar dajva avatar damiencassou avatar drvink avatar dsedivec avatar ergus avatar feng-qi avatar jobor avatar kidd avatar lafrenierejm avatar mbunkus avatar mernst avatar mjs avatar muffinmad avatar muirmanders avatar nbarrientos avatar nicolamontecchio avatar nverno avatar qwerbzuio avatar raxod502 avatar s-d-m avatar sje30 avatar wedens avatar wyuenho avatar zonotope avatar zonuexe avatar zulu-inuoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rg.el's Issues

Error when spaces in `rg-executable` path

Hello,

There seems to be an error invoking rg when there's a space in the path to the rg executable.
The problem seems to be in rg-list-builtin-type-aliases when it executes via shell-command-to-string:

(concat (rg-executable) " --type-list")
; =>
"d:/Users/Wilfredo Velazquez/AppData/Local/scoop/shims/rg.exe --type-list"
(shell-command-to-string (concat (rg-executable) " --type-list"))
; =>
"'d:/Users/Wilfredo' is not recognized as an internal or external command,
operable program or batch file.
"

Invalid processing regexp while searching words including "("

`GNU Emacs 25.2 on macOS 10.12.6, with configurations

When searching (lambda ( via rg, return errors.

-*- mode: rg; default-directory: "~/.emacs.d/lisp/" -*-
rg started at Sat Sep  9 02:20:28

rg --color always --colors match:fg:red -n --type elisp --column --heading -i -e \(lambda\ \( .
Error parsing regex near 'mbda (' at character offset 8: Unclosed parenthesis.

rg exited abnormally with code 1 at Sat Sep  9 02:20:28

if change to \(lambda \(, rg works well. But (lambda ( works fine with ag and rgrep. And I think ag.el handle it with search the words at point gracefully.

Good

rg --color always --colors match:fg:red -n --type elisp --column --heading -i -e \\\(lambda\ \\\( .
ag --literal --group --line-number --column --color --color-match 30\;43 --color-path 1\;32 --smart-case --stats -- \(lambda\ \( .

Please take a look into this issue. Thanks!

More flexibility in rg-define-search :format

Would it be possible to allow more flexibility in rg-define-search, eg. to provide a replacement for projectile's ripgrep command which uses ripgrep.el, I'm trying the following

(rg-define-search nvp-rg-projectile
  :query (or (thing-at-point 'symbol) (read-from-minibuffer "Search: "))
  :dir project
  :format literal
  :files (concat
          (mapconcat
           #'identity
           (--map (concat "--glob !" it)
                  (append projectile-globally-ignored-files
                          projectile-globally-ignored-directories)) " "))
  :flags '("--type all"))

But, it would be nice if :format could evaluate forms, so, for example, with a prefix it would do a regex search, and a literal otherwise, eg. something like

:format (not current-prefix-arg) ; do a literal search by default, regexp with a prefix arg

grep-highlight-matches is broken in Emacs 25.1

Reported by @syohex in melpa/melpa#4485

rg --no-heading --color always --colors match:fg:red --type-add 'gn:*.gn' --type-add 'gn:*.gni' --type-add 'g\ yp:*.gyp' --type-add 'gyp:*.gypi' --type all --color -i when error: The argument '--color <WHEN>' was provided more than once, but cannot be used multiple times
I got above error. If you specify --colors option by default(by rg-command variable), I suppose you should not pass <C> placeholder to grep-expand-template(<C> placeholder is expanded to --color -i )

This is because the --color flag was moved from grep-options to <C> placeholder in Emacs 25.1.

Q: Hide command in *rg* buffer

Hello I have a question

Is there a way to hide the command that is run with ripgrep. I mean this:

rg --color always --colors match:fg:red -n --type js --fixed-strings --no-heading --type-add gn:*.gn --type-add gn:*.gni --type-add gyp:*.gyp --type-add gyp:*.gypi -e someTestString .

The problem is that if you search with rg.el then if you want to replace the searched string with wgrep the replace will match the someTestString from the command and it will prevent the replacing with Text is read-only.

Before replacing:
image

After replacing - Text is read-only
image

rg-build-template deletes duplicate args

The rg documentation states that flags like -g, -i, and --ignore-file may be used multiple times. Unfortunately, if you try to build command line flags like so:

(let ((rg-command-line-flags (mapcan #'(lambda (dir) (list "-g" ...)) ignored-directories)))
  (rg ...))

rg will actually get invoked as:

rg ... -g DIR1 DIR2 DIR3 ...

rather than having multiple -g options, as intended.

how can I pass in additonal arguments like -w, -s

Additional arguments doesn't work when passing additional arguments. Can you please add this to readme too.

I am passing in -w SEARCH_PATTERN here is the command and error I see

Now I see you have rg-command-line-flags how can I pass flags to this variable? I need the ability to pass random flags to different searches.


rg --color always --colors match:fg:red --type less --no-heading --type-add 'gn:*.gn' --type-add 'gn:*.gni' --type-add 'gyp:*.gyp' --type-add 'gyp:*.gypi' -i -w\ onboarding
error: Found argument '- ' which wasn't expected, or isn't valid in this context

rg-mode-map should inherit from grep-mode-map

rg-mode-map shouldn't just copy grep-mode-map but should inherit it via set-keymap-parent so that my customations to grep-mode-map apply to it too.

Also, while it's unresolved, see this emacs bug report for possible unified keybindings between wdired, occur, and grep modes.

A rg-define-search example for the documentation

I'd like to propose this or something like this (the :dir path is for macOS) as an example in the documentation.

(rg-define-search rg-emacs 
    :dir "/Applications/Emacs.app/Contents/Resources/lisp" 
    :flags '("-z") 
    :files "*.{el,el.gz}" 
    :menu ("Custom" "L" "lisp"))

It seems like it would be a useful example, as I expect many emacs users search the emacs lisp source while customizing emacs. It took me a long time to get this working as emacs' lisp directory has mostly .el.gz files.

First I was surprised that just rg -z --type elisp didn't work, but that's the way ripgrep works. Then I put:

--type-add
elispgz:*.{el,el.gz}

in my ~/.ripgreprc file and that made a command line like rg -z --type elispgz work but it didn't work in rg.el in emacs. First I was using :files "elispgz" but found out that was incorrect. Then I tried :flags '("-z" "-telispgz") but that didn't work because rg-ignore-ripgreprc is t. It would help if it's documentation explained better what might break if it's nil. I really didn't want to replicate my --type-adds in rg-custom-type-aliases so I found the above worked.

Lastly I added the :menu part. At first I used "Search" from the rg-define-search documenation example but found that put this (and some others I defined) in the existing first column of rg-menu and that seemed out of place. "Custom" seems better as an example as is used in the rg manual section called The menu . I also suggest adding the various keyword arguments like :dir, :flags, etc to the rg.info index.

Doesn't find project root when invoking rg-project in dired

If you use rg-project when you're in dired, it searches the current directory rather than the project root. I was able to fix this locally by changing:

  ;; dir binding
  (unless (eq dir-opt 'ask)
    (let ((dirs (cond ((eq dir-opt 'project) '(rg-project-root
                                               buffer-file-name))
                      ((eq dir-opt 'current) 'default-directory)
                      (t dir-opt))))
      (setq binding-list (append binding-list `((dir ,dirs))))))

to:

  ;; dir binding
  (unless (eq dir-opt 'ask)
    (let ((dirs (cond ((eq dir-opt 'project) '(rg-project-root
                                               (or buffer-file-name default-directory)))
                      ((eq dir-opt 'current) 'default-directory)
                      (t dir-opt))))
      (setq binding-list (append binding-list `((dir ,dirs))))))

Great package, BTW - very handy indeed!

Ripgreprc not followed

I have a .ripgreprc in my project root. ripgrep / rg works one way from the command line and a different way when it runs within emacs. I've even added --debug to the command and this is what I see. Note that from the command line the first step is processing .ripgreprc. That does not happen in emacs.

What am I doing wrong?

Command line:

--> /usr/local/bin/rg --color always --colors match:fg:red -n --type-add gn\:\*.gn --type-add gn\:\*.gni --type-add gyp\:\*.gyp --type-add gyp\:\*.gypi --debug -i --no-heading --type py -e booger                                                                                                              [master]  [direnv: python-3.5.4]
DEBUG|rg::config|src/config.rs:40: /Users/rrosen/dev/filing/.ripgreprc: arguments loaded from config file: ["--max-columns=150", "--max-columns-preview", "--glob", "!app/Resources", "--glob", "!app/submodules", "--glob", "!package-lock.json"]
DEBUG|rg::args|src/args.rs:560: final argv: ["/usr/local/bin/rg", "--max-columns=150", "--max-columns-preview", "--glob", "!app/Resources", "--glob", "!app/submodules", "--glob", "!package-lock.json", "--color", "always", "--colors", "match:fg:red", "-n", "--type-add", "gn:*.gn", "--type-add", "gn:*.gni", "--type-add", "gyp:*.gyp", "--type-add", "gyp:*.gypi", "--debug", "-i", "--no-heading", "--type", "py", "-e", "booger"]
DEBUG|grep_regex::literal|grep-regex/src/literal.rs:105: required literals found: [Cut(BOOGE), Cut(bOOGE), Cut(BoOGE), Cut(boOGE), Cut(BOoGE), Cut(bOoGE), Cut(BooGE), Cut(booGE), Cut(BOOgE), Cut(bOOgE), Cut(BoOgE), Cut(boOgE), Cut(BOogE), Cut(bOogE), Cut(BoogE), Cut(boogE), Cut(BOOGe), Cut(bOOGe), Cut(BoOGe), Cut(boOGe), Cut(BOoGe), Cut(bOoGe), Cut(BooGe), Cut(booGe), Cut(BOOge), Cut(bOOge), Cut(BoOge), Cut(boOge), Cut(BOoge), Cut(bOoge), Cut(Booge), Cut(booge)]
DEBUG|globset|globset/src/lib.rs:435: built glob set; 2 literals, 1 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes

From within emacs

-*- mode: rg; default-directory: "~/dev/filing/" -*-
rg started at Tue Sep 10 08:18:30

/usr/local/bin/rg --color always --colors match:fg:red -n --type-add gn\:\*.gn --type-add gn\:\*.gni --type-add gyp\:\*.gyp --type-add gyp\:\*.gypi --debug -i --no-heading --type py -e booger

DEBUG|grep_regex::literal|grep-regex/src/literal.rs:105: required literals found: [Cut(BOOGE), Cut(bOOGE), Cut(BoOGE), Cut(boOGE), Cut(BOoGE), Cut(bOoGE), Cut(BooGE), Cut(booGE), Cut(BOOgE), Cut(bOOgE), Cut(BoOgE), Cut(boOgE), Cut(BOogE), Cut(bOogE), Cut(BoogE), Cut(boogE), Cut(BOOGe), Cut(bOOGe), Cut(BoOGe), Cut(boOGe), Cut(BOoGe), Cut(bOoGe), Cut(BooGe), Cut(booGe), Cut(BOOge), Cut(bOOge), Cut(BoOge), Cut(boOge), Cut(BOoge), Cut(bOoge), Cut(Booge), Cut(booge)]
DEBUG|globset|globset/src/lib.rs:435: built glob set; 0 literals, 0 basenames, 0 extensions, 0 prefixes, 0 suffixes, 1 required extensions, 0 regexes

navigate through latest searches

sometimes I find myself searching something with rg (using rg or rg-dwim), and just realize that I'd like to list results of the last search again.
I'm thinking something like Help mode's c-c c-b and c-c c-f. Do you think it's useful enough to be merged? which approach do you recommend? I'll try to send a PR

rg opens a new window for each result file

Currently, rg opens a new window for every file when I press Enter in the *rg* buffer.
I would prefer rg to only open a new window once when I visit a result. rg should then reuse that newly opened window when I press Enter on another result. Is that possible?

What about adding rg-dwim-current-file?

I love the way rg-dwim works, the fact that I can narrow down the search to the current directory with c-u is awesome.

Trying to go a step further, I wanted to implement something like:

;;;###autoload
(defun rg-dwim (&optional curdir)
  "Run ripgrep without user interaction figuring out the intention by magic(!).
The default magic searches for thing at
point in files matching current file under project root
directory.  With \\[universal-argument] prefix (CURDIR), search is
done in current dir instead of project root."
  (interactive "P")
  (case curdir
    (4  (rg-dwim-current-dir))
    (16 (rg-dwim-current-file))
    (t (rg-dwim-project-dir))))

but the "files" option in rg-define-search is thought for aliases only. Would there be an easy way to search only (buffer-file-name)?

make the default default match type configurable

I'd prefer the default to be "everything" rather than "all" file types when I search, and there is no more specific default available. Unfortunately, that is hard-coded into the rg-default-alias method right now, so I have to do horrible things like edit the package code, or advise it, to get that.

A simple configurable option would probably work equally well in context, and would make this vastly more accessible.

Pad line numbers or align results

An option to pad line numbers or otherwise align results would be useful. Likewise, an option to change or hide the line number separator (currently a :) would help reduce visual clutter.

Unaligned:
5:fifth line
15:fifteenth line

Aligned:
 5:fifth line
15:fifteenth line

Custom separator:
 5┊fifth line
15┊fifteenth line

custom color settings in .ripgreprc and xterm-color-filter break rg-results

It took me a bit to figure out what was wrong here, and I don't think it is documented
anywhere. Here are a couple issues I ran into:

  1. If custom colors are defined in ~/.ripgreprc, eg. --colors=path:fg:cyan etc. then
    font-locking and other functions in the rg-results buffer don't work.

  2. Using xterm-color-filter also breaks rg's compilation (from xterm-color library)
    I usually use xterm-color-filter in my compilation-start-hook to interpret shell escapes,
    however, since rg (like ag.el) relies on shell escapes for parsing, font-lock/other functions
    also break in the rg-results buffer.

Quick fix is to remove xterm-color support around rg-run

(define-advice rg-run (:around (orig-fn &rest args) "no-xterm-color")
  (let ((compilation-start-hook
         (remove 'my-compilation-start-hook compilation-start-hook))
        compilation-environment)
    (apply orig-fn args)))

It looks like it would probably be out-of-the question to add support to rg-results that
didn't rely on escape codes, but it might be helpful to mention incompatibilities somewhere.

Command line

Thanks for this amazing tool! I love it.

Can you add an empty line after the command line? It's annoying to combine commd line and results together. Thank you so much!

image

"w" not bound in rg buffer

The README suggest "w" is bound to wgrep-change-to-wgrep-mode in rg buffers, but it doesn't appear to actually be.

Awesome Package

Thanks for this package, are there any plans to put this on Melpa? Also would you be able to add some details about how to install this package, I am new to emacs and found installation a bit tricky.

[Need help] use rg.el for searching multiple words with file as unit instead of lines

Here is the original post I write on ripgrep: BurntSushi/ripgrep#1110

(defun rg-direct (word)
  (format "rg %s" word))

(defun rg-files-with-matches-beginning (word dir)
  (format "rg --files-with-matches \"%s\" %s" word dir))

(defun rg-files-with-matches-middle (word)
  (format " | xargs rg --files-with-matches \"%s\"" word))

(defun rg-files-with-matches-end (word)
  (format " | xargs rg --heading \"%s\"" word))

(defun rg-files-construct-command (words dir)
  (case (length words)
    (1 (rg-direct (car words)))
    (2 (concat (rg-files-with-matches-beginning) (rg-files-with-matches-end)))
    (3 (concat (rg-files-with-matches-beginning (car words) dir)
               (rg-files-with-matches-middle (cadr words))
               (rg-files-with-matches-end (car (reverse words)))))
    (t (concat (rg-files-with-matches-beginning (car words) dir)
               ;; OPTIMIZE: Do I have to use (car (mapcan ...))?
               (car (mapcan
                     (lambda (word) (list (rg-files-with-matches-middle word)))
                     (delq (car (reverse words)) (cdr words))))
               (rg-files-with-matches-end (car (reverse words)))))))

;; (rg-files-construct-command
;;  (split-string "hello world stardiviner myself" " ")
;;  default-directory)

(defun rg-search-words-by-files (directory)
  "Search multiple words by file as unit instead of line.

rg --files-with-matches \"foo\" . | xargs rg --files-with-matches \"bar\" | ... | xargs rg --heading \"baz\"
"
  (interactive (list (completing-read "Dir: " `(,(expand-file-name org-directory)
                                                ,default-directory))))
  (let* ((words (split-string (read-from-minibuffer "Words: ") " "))
         (command (rg-files-construct-command words directory)))
    (compilation-start command 'rg-mode)))

I have some ideas about this code,

  • how to improve this code to fit rg.el style? (I wish to use rg.el's API functions like macro define-rg-search) I would like to hear your reviews. Thanks in advance.
  • Is it possible to integrated it into rg.el, If yes, I would like to send PR.

use smart case instead of ignore case

Please consider using rg's "smart case" mode (-S or --smart-case). It searches case-insensitively if the pattern is all-lowercase and case-sensitively if there's at least one upper-case letter in the pattern. Or make that configurable.

The advantage is not having to search multiple times if I know that I want exact case matching in advance.

At the moment I have to replace rg-set-case-sensitivity and rg-rerun-toggle-case. I cannot even use rg-command-line-flags because they're inserted before rg-toggle-command-line-flags, and therefore rg-toggle-command-line-flags (which includes -i) overrides my -S in rg-command-line-flags.

Smart case searching is the default in other similar implementations, notably ack-and-a-half from where I'm migrating.

Thanks for considering it.

Skip files confirmation?

Hi. First of all, thanks a lot for this package.

Is there any way to skip the files confirmation in rg-project and just always go with the default type alias instead? Basically, I'm looking for something like rg-dwim, but that will still allow me to enter a search pattern instead of just always using the thing at point. Is that possible?

path(s) to search should be part of command

rg optionally takes one or more path arguments (file or directory) to search, positionally at the end of the command. Currently, this package is limited to the default behavior of rg, which is to search the current directory. (command is simply run in default-directory without any path as part of the command) The dir argument could be a path name or a list of path names when calling rg-run programatically. Even a single path as part of the command would be an improvement as it would allow shell expansion.

rg-mode shouldn't bind C-n and C-p

I think rg-mode should stop binding C-n and C-p in the *rg* buffer.

The keymap is rg-mode-map which inherits from grep-mode-map which inherits from compilation-minor-mode-map which all seems reasonable.

compilation-minor-mode-map being a minor mode doesn't bind the most common keys. So it uses M-n and M-p for next and previous error and M-} and M-{ for next and previous file.

grep-mode-map being a map for major mode binds easier keys for these things. n and p are next and previous error and } and { are next and previous file and of course the parent bindings still work.

rg-mode-map has similar needs, needing motion by error (aka match) and by file, as well as forward and back in search history which are bound to C-c> and C-c< which is fine. It uses the inherited bindings for n and p for next and previous error which seems reasonable. Those are the most obvious keys for motion and moving by error is the most obvious motion.

But it also binds C-n and C-p to file motion commands rg-next-file and rg-previous-file. I tend to just use these keys for motion since they work everwhere else in emacs and having them skip over lines in *rg* buffers is jarring. Also unlike compilation-next-file and compilation-previous-file they don't move you to the first or last match in a file, but to the filename line itself (if rg-group-result is non-nil which is its default value).

As near as I can tell, when results are grouped, when point is on a file name line there don't seem to be useful key bindings. RET doesn't take you to the file, o doesn't display it in another window, etc. So I don't think the next and previous file commands should put you on those lines.

Also they don't seem to play well with the next and previous error commands. If I use n to move to say the 4th error of the 5th file and then use C-p to move up to the 2nd file; if I then hit n I move not to the first error of the 2nd file, but to the 5th error of the 5th file, as if I never hit C-p at all. Navigating with compilation-next-file and compilation-previous-file seem to have the same issue (I notice they don't move a bullet in the left gutter), even if results aren't grouped by files, but since they always leave me on an error, I can hit RET to move to that error and then n and p work. Using rg-next-file I end up on a file and then can't move to it's first error because C-n is bound to rg-next-file.

So I don't understand what rg-next-file and rg-previous-file are buying you over compilation-next-file and compilation-previous-file and regardless I don't think they should be bound to C-n and C-p.

rg-define-toggle command does not re-run rg

Hi,

I define w to toggle word-boundary searching using (rg-define-toggle "-w" "w"). However, when viewing rg results, pressing w has no effect on the command or the result. Pressing another predefined toggle, like c re-runs the rg command and also includes the -w flag.

The way I understand the documentation, defining custom toggles should behave just like pre-defined toggles, meaning the rg command is re-run with the flag set or unset.

rg version 20180522.1119

Cheers,
Martin

patterns starting with a dash are interpreted as options

If I call rg-the-Emacs-function with a pattern of e.g. --ui-language (because the program source code I want to search through should contain that string), rg-the-program will interpret that pattern as an option to rg. As rg-the-program doesn't know such an option, it stops with an error:

[0 mosu@sweet-chili (master) ~/prog/video/mkvtoolnix/src] rg --ui-language
error: Found argument '--ui-language' which wasn't expected, or isn't valid in this context
…

Fortunately rg-the-program knows the -e option which tells rg-the-program that the next command line argument is indeed the option:

[0 mosu@sweet-chili (master) ~/prog/video/mkvtoolnix/src] rg -e --ui-language
common/command_line.cpp
302:    if (args[i] == "--ui-language") {

Please adjust rg-the-Emacs-function (and its siblings) to add -e right before the pattern when calling rg-the-command. Thanks.

--glob overrides any other ignore logic

Hi!

I used * for Search in files to search in all but ignored files.

After dafd9e7 rg doesn't respect my ignore rules because, according to rg man, --glob option always overrides any other ignore logic.

I've tried create custom type alias like this:

(custom-set-variables
 '(rg-custom-type-aliases '(("not_ignored" . "*"))))

but searching using this type alias gives error:

/usr/local/bin/rg --color always --colors match:fg:red -n --type-add not_ignored\:\* --context 2 --follow -i --heading --column --type not_ignored -e foo
invalid definition (format is type:glob, e.g., html:*.html)

How can i search in all but ignored files?

More customizable rg-custom-type-aliases

Thank you for this well thought out and useful-by-default package.

I wanted to hear your thoughts on a feature I had in mind:

Add mechanism to alter custom type aliases "dynamically", e.g. based on current file, current project etc. This would mainly useful with the DWIM command that selects type alias based on current file.

I have a big project and often times identifiers stretch across file types. For example, in UI code, identifiers are shared between template files and javascript files. In backend code, there might be one java package that references a bunch of names that are tied to XML files. I can achieve cross-searching using the existing rg-custom-type-aliases, but that will always give the the cross searching. If I searched for something in other, non-XML related java code, it would still search all XML files, which might give me results I don't care about. Similarly, if I'm ripgreping through backend node.js code, I probably don't want to also search handlebars files.

I propose allowing lambdas in rg-custom-type-aliases. This way I can make my lambda change type aliases based on the current buffer, current project, etc. rg-dwim would become (more) context aware, allowing for different grouped type aliases based on where you are searching from.

Of course if you don't care for this change, I can always implement it w/ advice around the dwim command, so don't worry about my feelings.

Difficulty using rg with TRAMP

If I open a buffer whose default-directory is on a remote machine, and try to run M-x rg, I see that it tries to use the path to rg on my local machine, instead of on the remote machine.

It seems I could set the rg-command variable myself to get it to work on remote machines.

But would it be possible to update this package so that it automatically finds the rg executable on a remote machine?

*rg* buffer hangs when moderately long line is displayed

I have a line in an elisp file that's currently 624 characters long (the list of packages to install from init.el). When such a line is found by rg-the-program, rg-the-Emacs-mode hangs each time that line is currently visible with 100% CPU. I have to press C-g repeatedly to get back movement, and if I do anything inside that buffer that doesn't scroll that long line offscreen with that action, Emacs will hang again.

What happens in detail:

  • The *messages* buffer shows "rg finished (matches found)"
  • The *rg* buffer is shown with the following content with the mode line saying somthing about "compiling":
-*- mode: rg; default-directory: "~/tmp/" -*-
rg started at Sun Aug  6 14:54:28

rg --color always --colors match:fg:red -n --type all --no-heading --type-add gn\:\*.gn --type-add gn\:\*.gni --type-add gyp\:\*.gyp --type-add gyp\:\*.gypi -i ack-and-a-half .
  • When I press C-g repeatedly, I see messages such as Error during redisplay: (jit-lock-function 259) signaled (quit)
  • After pressing them repeatedly, the full content of the *rg* buffer including the matched line is shown normally.

I've confirmed that I can reproduce it with emacs -Q --eval '(package-initialize)' followed by rg'ing for ack-and-a-half in a directory where the only file present is the following one:

    (rg rhtml-mode rinari bbdb-vcard ht gh mu4e-maildirs-extension erlang use-package magit magit-popup magit-svn magithub modern-cpp-font-lock dired-single w3m yasnippet yari yaml-mode test-simple systemd rustfmt rtm projectile poporg paredit nsis-mode nrepl nginx-mode markdown-mode magit-gh-pulls lua-mode ldap-mode json-mode iedit ido-completing-read+ hide-lines graphviz-dot-mode go-mode gist flymake-yaml flymake flycheck-rust find-things-fast f expand-region dockerfile-mode dash-functional csv-mode color-theme clojure-test-mode cargo browse-kill-ring+ bbcode-mode apache-mode alchemist ack-and-a-half)))

This looks similar to #12, but in my case the folder contains a single file, the file is under 1 KB in size, but the single line it contains is long.

Where the match occurs doesn't matter. For example, I can rg for "rhtml-mode" (which is the second entry in the line), and rg-the-mode hangs just the same.

rg-the-program finishes its search pretty much instantly when executing the command shown in the *rg* buffer on the command line.

Wrong type argument: stringp, nil

When running the simple (rg-run "foo" "*.baz" default-directory) the error Wrong type argument: stringp, nil is emitted. This doesn't make much sense as the tests are littered with calls such as this one (rg-run "foo" "*.baz" (concat default-directory "dirlocals")). My local rg.el version is up to date with Melpa (not Melpa stable).


Debugger trace:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  string-match("[ \011\n\015]+\\'" nil)
  s-trim-right(nil)
  s-trim(nil)
  #f(compiled-function (type-alias) #<bytecode 0x16f6de1>)("")
  mapcar(#f(compiled-function (type-alias) #<bytecode 0x16f6de1>) ("" "agda: *.agda, *.lagda" "aidl: *.aidl" "amake: *.bp, *.mk" "asciidoc: *.adoc, *.asc, *.asciidoc" "asm: *.S, *.asm, *.s" "asp: *.ascx, *.ascx.cs, *.ascx.vb, *.aspx, *.aspx.cs, *.aspx.cs" "ats: *.ats, *.dats, *.hats, *.sats" "avro: *.avdl, *.avpr, *.avsc" "awk: *.awk" "bazel: *.bzl, BUILD, BUILD.bazel, WORKSPACE" "bitbake: *.bb, *.bbappend, *.bbclass, *.conf, *.inc" "brotli: *.br" "buildstream: *.bst" "bzip2: *.bz2, *.tbz2" "c: *.[chH], *.[chH].in, *.cats" "cabal: *.cabal" "cbor: *.cbor" "ceylon: *.ceylon" "clojure: *.clj, *.cljc, *.cljs, *.cljx" "cmake: *.cmake, CMakeLists.txt" "coffeescript: *.coffee" "config: *.cfg, *.conf, *.config, *.ini" "cpp: *.[ChH], *.[ChH].in, *.[ch]pp, *.[ch]pp.in, *.[ch]xx, *.[ch]xx.in, *.cc, *.cc.in, *.hh, *.hh.in, *.inl" "creole: *.creole" "crystal: *.cr, Projectfile" "cs: *.cs" "csharp: *.cs" "cshtml: *.cshtml" "css: *.css, *.scss" "csv: *.csv" "cython: *.pxd, *.pxi, *.pyx" "d: *.d" "dart: *.dart" "dhall: *.dhall" "docker: *Dockerfile*" "edn: *.edn" "elisp: *.el" "elixir: *.eex, *.ex, *.exs" "elm: *.elm" "erlang: *.erl, *.hrl" "fidl: *.fidl" "fish: *.fish" "fortran: *.F, *.F77, *.F90, *.F95, *.f, *.f77, *.f90, *.f95, *.pfo" "fsharp: *.fs, *.fsi, *.fsx" "gap: *.g, *.gap, *.gd, *.gi, *.tst" "gn: *.gn, *.gni" "go: *.go" "groovy: *.gradle, *.groovy" "gzip: *.gz, *.tgz" ...))
  rg-list-builtin-type-aliases()
  rg-get-type-aliases()
  rg-is-custom-file-pattern("*.baz")
  rg-build-command("foo" "*.baz" nil ("-i"))
  rg-run("foo" "*.baz" "/home/forloveofcats/Dotfiles/")
  nav/rg-project()
  (lambda nil (interactive) (nav/disable) (nav/rg-project))()
  funcall-interactively((lambda nil (interactive) (nav/disable) (nav/rg-project)))
  call-interactively((lambda nil (interactive) (nav/disable) (nav/rg-project)) nil nil)
  command-execute((lambda nil (interactive) (nav/disable) (nav/rg-project)))

Default "all" mode doesn't include same results as command-line default behavior

OS: macOS 10.13.5

When I invoke rg from zsh, the default behavior includes search results in ASCII data files having no suffix, but when I invoke it from Emacs using this package, with file type "all" (*), the search results do not include these files.

In particular, the files in question are ASCII-encoded data files containing text:

❯ file -I --apple ./deploy-scripts/env/stg
./deploy-scripts/env/stg: application/octet-stream; charset=us-ascii

❯ rg 'myBootstrapAction' .
<snip>
deploy-scripts/env/stg
27:myBootstrapAction=<snip>

Feature request: search file names

Some times, I want to search the specific file names in the folder or projects. I think "--files" flags is the answer. e.g.

rg -g '*.foo' --files

Would appreciate if the feature is added to the amazing tool.

rg-define-search with save

Thanks for rg.el, I've been using it for sometime now. But I just discovered rg-define-search macro and I've been using it to customize extensively. Is there a way to specify a name of the rg results buffer at the time this macro is run? I want to be able to provide the name as part of the args for the macro.

Please add a prefix to test-helper.el to avoid conflicts with 68 other packages

There exist at least 69 packages that contain a file named test-helper.el that also provides the feature test-helper.

This leads to issues for users who have at least two of these packages installed. It is unlikely that such a user would be able to run the tests of all of those packages. If the primary test file of one of those packages does (require 'test-helper), then it is undefined which of the various test-helper.el files gets loaded. Which it is, depends on the order of the load-path.

To avoid this conflicts, you should rename your test-helper.el to <your-package>-test-helper.el and adjust the feature and symbol prefixes accordingly.

Also don't forget to update the require form in your primary test file and/or update references to the library/feature elsewhere. Also, if your primary test file is named something like test.el, then please consider renaming that too (same for any other utility elisp files your repositoroy may contain).

Thanks!

PS: This issue is a bit generic because I had to open 69 issues.

Running a search replaces search buffer

If I run a search, and then another, the original search buffer is replaced. I would expect a new buffer to be created for each search.

I am aware of rg-back-history, but this doesn't help much for my very common use case:

  1. I'm doing some refactoring or checking, so I search for foo and go down the list of the results. Critically, every time I switch back to the search results buffer, my place in the buffer is remembered
  2. As part of fixing foo, I realize I also need to fix bar, and so start a search for that.
  3. After I finish fixing bar, I can carry on my place fixing foo

rg-back-history puts my cursor back at the top

Other tools e.g. ag-project-regexp from ag.el behaves ideally in this respect - it opens a new buffer for each search. When you are done with a search, you close the buffer and go back to your exact place in the previous search.

I've also tried the "saved search" functionality, but it's not very convenient. If I'm looking through a file, and want to do a search, I have to remember to use it. So before I do a search I have to first find the last search buffer, save it, then go back to where I was. I'm looking for something that will make rg.el always open a new search buffer - I can always close the ones I don't need any more, but if I lose one that I was half way through, I can't go back.

Thanks for your consideration!

Is it possible to override a build-in type alias?

I am working on a project that contains both .c and .cpp files. This makes it so that the result of rg-dwim is usually incomplete because either *.c *.h or *.cpp *.hpp files are searched depending on the current buffer.

I created a custom type alias that applies to both C and C++ files, but it is not selected by default over the built-in ones. Is there a way to change that?

Thanks

Default command line flags

It's better to remove "--no-ignore" from the default command line flags.
When searching in a project, lots of junk results pop up. Is there any way to change or set?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.