File: configuration.org

package info (click to toggle)
rg-el 2.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 700 kB
  • sloc: lisp: 3,746; python: 167; makefile: 106
file content (643 lines) | stat: -rw-r--r-- 20,612 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
#+TITLE: Configuration
#+AUTHOR: David Landell
#+EMAIL: david.landell@sunnyhill.email
#+DATE: 2019
#+LANGUAGE: en
#+OPTIONS: broken-links:auto, toc:nil, email:nil, num:nil, ^:nil, author:nil, date:nil

#+INCLUDE: "utils.org"

* Customization
  :PROPERTIES:
  :CUSTOM_ID: customization
  :END:
  Customization is done via the Emacs customization system. The group
  =rg= is the main group of the package.
  #+BEGIN_SRC elisp
  M-x customize-group [RET] rg [RET]
  #+END_SRC
  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-executable '(executable-find "rg"))
  #+END_SRC

  The /ripgrep/ executable to use. Could be an absolute path or just the
  base name if the executable is in the path. The default is using
  =executable-find= to locate the command. If you want to use this
  package with tramp it might be better to set it to just "rg" in
  order to let the OS find the binary where it's invoked.
  From Emacs 27.1, the tramp use case is by default handled
  automatically. See [[opt:rg-executable-per-connection]] for details.
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-executable-per-connection)
  #+END_SRC

  This setting only has effect in Emacs 27.1 or later.
  Handle the [[opt:rg-executable]] automatically for different hosts if used
  with tramp. =executable-find= for "rg" binary will be invoked on
  remote hosts to determine the path to ripgrep. The result is stored
  per connection.
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-custom-type-aliases)
  #+END_SRC

  An association list that maps file type aliases to a space
  delimited string with file globs. These are combined with the
  /ripgrep/ builtin file aliases.

  Example:
  #+BEGIN_SRC elisp
    (setq rg-custom-type-aliases
      '(("foo" .    "*.foo *.bar")
        ("baz" .    "*.baz *.qux")))
  #+END_SRC

  You may also add lambdas to =rg-custom-type-aliases= to add aliases
  dynamically based on mode, directory, project, etc.

  #+BEGIN_SRC elisp
     (add-to-list
      'rg-custom-type-aliases
      (lambda ()
        (when (in-frontend-app)
          (cons "ui" "*.js *.hbs *.json"))))
  #+END_SRC
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-prioritized-type-aliases)
  #+END_SRC

  A list of aliases that are prioritized among ripgrep's builtin
  aliases when selecting the alias based on the buffer file name. This
  list contains only the alias names and the order between the items
  does not matter.

  Example:
  #+BEGIN_SRC elisp
    (setq rg-custom-type-aliases
      '("cpp" "puppet"))
  #+END_SRC
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-default-alias-fallback)
  #+END_SRC

  This setting controls the default alias used when no alias can be
  recognized for the current buffer. =all= or =everything= are
  reasonable values for this variable.
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-command-line-flags)
  #+END_SRC

  A list of command line flags that will be appended to the
  /ripgrep/ command line. Must either be a list of flags or a function
  that returns a list of flags.
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-group-result)
  #+END_SRC


  Controls the layout of the results buffer. If non =nil=, each file name
  is displayed once and matches are grouped under that filename instead of
  repeating the filename on each match. This is essentially the layout of
  the =--no-heading= /ripgrep/ command line flag.
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-show-columns)
  #+END_SRC


  Controls if column numbers are used in the search result.
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-ignore-case)
  #+END_SRC

  Setting that controls if case sensitive search is made or not. It
  can essentially be *on*, *off* or *smart*. The *smart* setting will
  trigger an analyze of the search string and if it's all lower case,
  the search will be case /insensitive/, otherwise it will be case
  /sensitive/. The following values are valid:

  - *case-fold-search* - A non nil value of =case-fold-search= will trigger smart case behavior.
  - *smart* - Smart case behavior.
  - *force* - Always ignore case.
  - *nil* - Always consider case.
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-hide-command)
  #+END_SRC

  Hide most of command line by default. This is enabled by default and can
  be set to =nil= to show full command line.
  This can be toggled in the results buffer by clicking on the command line.
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-keymap-prefix)
  #+END_SRC

  This variable sets the default prefix used for the global key bindings.
  Note that =rg-enable-default-bindings= needs to be invoked for the
  bindings to be enabled.
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-use-transient-menu)
  #+END_SRC

  Controls whether =rg-menu= will be used by default or not. It's also
  possible to enable the menu explicitly with
  #+BEGIN_SRC elisp
  (rg-enable-menu)
  #+END_SRC
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-show-header)
  #+END_SRC

  Controls if the search info header is shown in the result buffer. This
  is enabled by default but can be disabled by setting this variable to
  =nil=.
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-buffer-name)
  #+END_SRC

  Controls the name of the results buffer. It may be /string/ or /function/.
  This name will be surrounded by  =*= to yield the final buffer name
  so if this setting is =foo= the buffer name will be =*foo*=.
  One useful case of using it is to have separate result buffers per project.
  One can set this variable in `dir-locals` file or set it to function.

  Example, this function will set results buffer name based on `project-current`:
  #+BEGIN_SRC elisp
    (defun my-rg-buffer-name ()
      (let ((p (project-current)))
        (if p
            (format "rg %s" (abbreviate-file-name (cdr p)))
          "rg")))
  #+END_SRC
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-ignore-ripgreprc)
  #+END_SRC

  Controls if the [[https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#configuration-file][ripgreprc]] file should be ignored or not. If =nil=,
  the config file will be used, otherwise it will be ignored. The
  default is to ignore this file in order to avoid that conflicting
  settings have impact on this package's behavior. Setting this to =nil=
  may affect core functionality of this package. Especially changing
  colors can affect parsing of the output and result in a broken
  results buffer.
  :END:

*** Position numbers alignment
    :PROPERTIES:
    :CUSTOM_ID: position-numbers-alignment
    :END:

    When operating /rg/ in grouped output mode ([[opt:rg-group-result]] is non
    nil), it's possible to control how the line and column numbers are
    displayed in the result buffer.

    Example settings:

    #+BEGIN_SRC elisp
    (setq rg-align-position-numbers t)
    (setq rg-align-line-number-field-length 3)
    (setq rg-align-column-number-field-length 3)
    (setq rg-align-line-column-separator "#")
    (setq rg-align-position-content-separator "|")
    #+END_SRC

    Will yield the following format:

    #+BEGIN_EXAMPLE
    File: matched_file.foo
      1#  2|match1
    888# 10|match2
    #+END_EXAMPLE

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
    (rg-custom-info 'rg-align-position-numbers)
    #+END_SRC

    Setting this to =t= will align line and column numbers in columns padded
    with white space.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
    (rg-custom-info 'rg-align-line-number-field-length)
    #+END_SRC


    Defines the length of the line number field.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
    (rg-custom-info 'rg-align-column-number-field-length)
    #+END_SRC


    Defines the length of the column number field.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
    (rg-custom-info 'rg-align-line-column-separator)
    #+END_SRC


    Separator string used between line and column numbers. =nil= means
    use default separator from /ripgrep/.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
    (rg-custom-info 'rg-align-position-content-separator)
    #+END_SRC

    Separator string used between the position numbers and matched content. =nil= means
    use default separator from /ripgrep/.
    :END:

* Faces
  All faces are in the subgroup =rg-face= of the main group =rg=.
  #+BEGIN_SRC elisp
  M-x customize-group [RET] rg-face [RET]
  #+END_SRC
*** Results buffer
    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
  (rg-face-info 'rg-match-face)
    #+END_SRC
    Face used to highlight matches in result.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
  (rg-face-info 'rg-error-face)
    #+END_SRC
    Face used to highlight errors when invoking /ripgrep/.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
  (rg-face-info 'rg-context-face)
    #+END_SRC
    Face used to highlight context lines in /ripgrep/ output when
    =--context-lines= flag is used.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
  (rg-face-info 'rg-info-face)
    #+END_SRC
    Face used to highlight general info in results buffer. For instance
    the number of matches found.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
  (rg-face-info 'rg-warning-face)
    #+END_SRC
    Face used to highlight warnings in the /ripgrep/ output.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
  (rg-face-info 'rg-filename-face)
    #+END_SRC
    Face used to highlight filenames in the output.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
  (rg-face-info 'rg-file-tag-face)
    #+END_SRC
    Face used for the =File:= tag in grouped results output.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
  (rg-face-info 'rg-line-number-face)
    #+END_SRC
    Face used on line numbers.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
  (rg-face-info 'rg-column-number-face)
    #+END_SRC
    Face used on column numbers.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
  (rg-face-info 'rg-match-position-face)
    #+END_SRC
    Face added to file positions. This is the start of a matching line
    and depending on configuration may be, file name, column number and
    line number.
    :END:


*** Header line
    :PROPERTIES:
    :CUSTOM_ID: header_line_config
    :END:
    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
    (rg-face-info 'rg-toggle-on-face)
    #+END_SRC
    Face used for flags that are toggled =on=.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
   (rg-face-info 'rg-toggle-off-face)
    #+END_SRC
    Face used for flags that are toggled =off=.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
    (rg-face-info 'rg-literal-face)
    #+END_SRC
    Face used the on the =literal= marker in the header line.
    :END:

    :OPTION:
    #+BEGIN_SRC elisp :results value raw :exports results
    (rg-face-info 'rg-regexp-face)
    #+END_SRC
    Face used the on the =regexp= marker in the header line.
    :END:

* Configuration functions
  :PROPERTIES:
  :CUSTOM_ID: configuration_functions
  :END:

  :FUNCTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-function-info 'rg-enable-default-bindings)
  #+END_SRC
  Enable the default keyboard bindings for the package with prefix
  key. If [[opt:rg-use-transient-menu]] is on this will enable the menu
  instead of activating the global bindings. If =prefix= is not
  provided [[opt:rg-keymap-prefix]] will be used.
  :END:

  :FUNCTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-function-info 'rg-enable-menu)
  #+END_SRC
  Enable the [[file:usage.org::#the_menu][rg-menu]] with prefix key. This bypass
  [[opt:rg-use-transient-menu]] setting. If =prefix= is not provided
  [[opt:rg-keymap-prefix]] will be used.
  :END:

  :FUNCTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-function-info 'rg-use-old-defaults)
  #+END_SRC
  This function is provided to keep backwards compatibility with
  versions older than 2.0.0. In this version default settings as well
  as key bindings changed and to bring back the old defaults call this
  function in your init file.
  :END:

* Hooks
  :PROPERTIES:
  :CUSTOM_ID: hooks
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-finish-functions)
  #+END_SRC
  Functions to call when a ripgrep search is finished.

  Each function is called with two arguments: the compilation buffer,
  and a string describing how the process finished.
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-filter-hook)
  #+END_SRC
  Hook run after new content has been inserted in in the rg buffer.
  This hook is called every time the rg buffer has been updated with
  new content and filtered internally by the package.
  :END:

  :OPTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-custom-info 'rg-mode-hook)
  #+END_SRC
  Hook run after entering rg mode.
  :END:

* Configuration macros
  :PROPERTIES:
  :CUSTOM_ID: configuration_macros
  :END:

  :FUNCTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-function-info 'rg-define-toggle)
  #+END_SRC

  This is a macro that can be used to define custom /ripgrep/ flag
  toggling functions in the result buffer. The macro takes the flag
  (and potential value) as an argument and optionally binds the toggle
  function to a key. If =default= is non nil the flag is used by default.

  The function defined by this macro will be named as the flag name
  stripped with leading dashes and prefixed with =rg-custom-toggle-flag-=.

  #+BEGIN_SRC elisp
    (rg-define-toggle "-uu" "I" t)
  #+END_SRC

  Creates a function named =rg-custom-toggle-flag-uu= that is on by
  default and bound to =I= in /rg/ result
  buffer.

  #+BEGIN_SRC elisp
    (rg-define-toggle "--context 3" (kbd "C-c c"))
  #+END_SRC

  Creates a function named =rg-custom-toggle-flag-context= that is off by
  default and bound to =C-c c= in /rg/ result
  buffer.
  :END:

  :FUNCTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-function-info 'rg-define-search)
  #+END_SRC

  This macro can be used to define custom search functions in a
  declarative style. Default implementations for common behavior is
  available and custom forms can also be used.

  It optionally starts with a string that is used as the docstring for
  the defined function.  The rest of the arguments contain key value pairs
  according to the specification below.  All keys are optional with
  specified default if left out.

  - *:query* - Method for retrieving the search string.  Allowed values are
    =point= which means extract thing at point and =ask= which means
    prompt the user for a string.  Any form that evaluates to a string
    is allowed. Default is =ask=.
  - *:format* - Specifies if =:query= is interpreted literally
    (=literal=) or as a regexp (=regexp=). If it is a form, eg.
    =(not current-prefix-arg)=, and is non-nil the =:query= is interpreted
    literally, otherwise as a regexp. Default is =regexp=.
  - *:files* - Form that evaluates to a file alias or custom file
    glob. =current= means extract alias from current buffer file name,
    =ask= will prompt the user. Default is =ask=.
  - *:dir* - Root search directory.  Allowed values are =ask= for user
    prompt, =current= for current dir and =project= for project
    root.  Any form that evaluates to a directory string is also allowed.
    Default is =ask=.
  - *:confirm* - =never=, =always=, or =prefix= are allowed values.  Specifies
    if the the final search command line string can be modified
    and confirmed the user. Default is =never=.
  - *:flags* - =ask= or a list of command line flags that will be used when
    invoking the search.
  - *:menu* - Bind the command into =rg-menu=.  Must be a list with three
    items in it.  The first item is the description of the
    group in which the new command will appear.  If the group
    does not exist a new will be created.  The second item is
    the key binding for this new command (ether a key vector
    or a key description string) and the third item is the
    description of the command that will appear in the menu.

  Examples:
  #+BEGIN_SRC elisp
    (rg-define-search search-everything-at-home
      "Search files including hidden in home directory"
      :query ask
      :format literal
      :files "everything"
      :flags ("--hidden")
      :dir (getenv "HOME")
      :menu ("Search" "h" "Home"))

    (rg-define-search rg-emacs
      "Search the emacs lisp source code."
      :dir "/usr/share/emacs/25.2/lisp/"
      :flags '("-z")
      :files "*.{el,el.gz}"
      :menu ("Custom" "L" "lisp"))
  #+END_SRC
  :END:

* Use with evil-mode
  Some key bindings clash with /evil-mode/. Recommendation is to use
  evil /motion/ state for the results buffer and then switch to
  evil /normal/ mode when editing in /wgrep-mode/. Some adjustments
  need to be done to avoid the clashes though.

  This is a start of a configuration. This let /rg-mode/'s key bindings
  override the motion state map bindings based on that these motion
  keys are not important in an /rg/ results buffer.
  Adjust this to your preferred use case:
  #+begin_src elisp
    (with-eval-after-load 'rg
      (advice-add 'wgrep-change-to-wgrep-mode :after
                  #'evil-normal-state)
      (advice-add 'wgrep-to-original-mode :after
                  #'evil-motion-state)
      (defvar rg-mode-map)
      (add-to-list 'evil-motion-state-modes 'rg-mode)
      (evil-add-hjkl-bindings rg-mode-map 'motion
        "e" #'wgrep-change-to-wgrep-mode
        "g" #'rg-recompile
        "t" #'rg-rerun-change-literal))
  #+end_src

* Customizing the menu
  :PROPERTIES:
  :CUSTOM_ID: customizing_the_menu
  :END:
  The menu can be modified from the emacs configuration file.

  To add a new *switch* before the option triggered by =-n= at suffix
  level 3:
  #+BEGIN_SRC elisp
    (transient-insert-suffix 'rg-menu "-n" '(3 "-o" "Only print matches" "--only-matching"))
  #+END_SRC
  To add a new *option* before the option triggered by =-g= at suffix
  level 4:
  #+BEGIN_SRC elisp
    (transient-insert-suffix 'rg-menu "-g" '(4 "-f" "Pattern file" "--file="))
  #+END_SRC
  The === in =--file== triggers argument input for the flag.

  To remove an item from the menu specify the trigger key in the
  transient remove command.
  For example, to remove the =Search hidden files= switch use the following:
  #+BEGIN_SRC elisp
    (transient-remove-suffix 'rg-menu "-h")
  #+END_SRC

  Please refer to the [[https://magit.vc/manual/transient/Modifying-Existing-Transients.html#Modifying-Existing-Transients][transient]] documentation for details on customizing the menu.

  This package also adds a convenience function for appending new
  *commands* to the menu in the groups at the bottom.

  :FUNCTION:
  #+BEGIN_SRC elisp :results value raw :exports results
  (rg-function-info 'rg-menu-transient-insert)
  #+END_SRC
  This inserts a new command under =group= if it exists, otherwise a
  new group is created. =key=, =description= and =command= is as for
  the =transient-insert-suffix= function.

  For example to insert a new command under =Search= group:
  #+BEGIN_SRC elisp
    (rg-menu-transient-insert "Search" "m" "My search" 'my-search-command)
  #+END_SRC

  It's usually better to use the =:menu= key of the [[func:rg-define-search]]
  macro to define a search function and adding it to the menu in one go.
  :END: