Skip to content

momomo5717/avy-migemo

Repository files navigation

https://melpa.org/packages/avy-migemo-badge.svg https://stable.melpa.org/packages/avy-migemo-badge.svg

avy-migemo

This package is a minor mode of avy for using migemo.

The following functions are provided:

  • avy-migemo-goto-char
  • avy-migemo-goto-char-2
  • avy-migemo-goto-char-in-line
  • avy-migemo-goto-char-timer
  • avy-migemo-goto-subword-1
  • avy-migemo-goto-word-1
  • avy-migemo-isearch
  • avy-migemo-org-goto-heading-timer
  • avy-migemo--overlay-at
  • avy-migemo--overlay-at-full
  • avy-migemo--read-candidates

These are the same as avy’s predefined functions except for adding candidates via migemo (simply using migemo instead of regexp-quote).

The following extensions are available:

  • avy-migemo-e.g.zzz-to-char.el
  • avy-migemo-e.g.ivy.el
  • avy-migemo-e.g.swiper.el
  • avy-migemo-e.g.counsel.el

image/image.gif

Table of contents

Requirements

  • GNU Emacs 24.4 or later
  • avy 0.4 or later
  • migemo 1.9 or later

Setup

(add-to-list 'load-path "/path/to/avy-migemo")
(require 'avy-migemo)
;; `avy-migemo-mode' overrides avy's predefined functions using `advice-add'.
(avy-migemo-mode 1)
(global-set-key (kbd "M-g m m") 'avy-migemo-mode)

Customization

User Option: avy-migemo-lighter

Lighter for avy-migemo-mode. Default value is nil.

User Option: avy-migemo-get-function

Its type is function which takes a string and returns a regular expression.

Default value is migemo-get-pattern.

;; e.g. Using non-capturing group
(custom-set-variables
 '(avy-migemo-get-function 'avy-migemo-get-pattern-non-capturing)
 '(avy-migemo-regex-concat-use-non-capturing t))

User Option: avy-migemo-regex-concat-use-non-capturing

If non-nil, avy-migemo-regex-concat / avy-migemo-regex-quote-concat will use non-capturing group.

Default value is nil.

Using non-capturing group will affect counsel-grep-function-migemo which uses counsel-grep-base-command-migemo , since grep with -E option can not work with it.

User Option: avy-migemo-function-names

Its value is a list of avy-migemo’s function names. (orig-fn where advice-fn) like args of advice-add is also available.

Default value has all avy-migemo’s function names which can be used as advice.

Instead of using setq, custom-set-variables is recommended for changing its value. If you would like to override only avy-goto-char-timer, you can use custom-set-variables as below.

;; Override only `avy-goto-char-timer' when `avy-migemo-mode' is enabled.
(custom-set-variables
 '(avy-migemo-function-names
   '(avy-migemo-goto-char-timer)))

Function: avy-migemo-remove-names &rest names

This function removes names from avy-migemo-function-names.

;; Remove only `avy-migemo-goto-char' from `avy-migemo-function-names'.
(avy-migemo-remove-names 'avy-migemo-goto-char)

Function: avy-migemo-add-names &rest names

This function adds names to avy-migemo-function-names.

User Option: avy-migemo-use-isearch-search-fun

If non-nil, avy-migemo-isearch uses isearch-search-fun for collecting candidates.

Default value is nil.

It would be useful for migemo-isearch-toggle-migemo or isearch symbol/word.

User Option: avy-migemo-at-full-max

If its value is an integer, the length of displayed keys will be restricted to the maximum number.

Default value is nil.

This feature depends on avy-migemo--overlay-at-full.

(custom-set-variables '(avy-migemo-at-full-max 2))

User Option: avy-migemo-regex-cache-clear-hook

This normal hook is run at the end of avy-migemo-regex-cache-clear.

An example config for zzz-to-char ( zzz-to-char--base )

You can add a function which uses avy by adapting it for migemo.

avy-migemo-e.g.zzz-to-char.el provides the example.

;; If you use zzz-to-char (which can be installed from MELPA or El-Get),
;; you can adapt it for migemo.
(require 'zzz-to-char)

;; Adding "-migemo" to the original name is needed.
(defun zzz-to-char--base-migemo (char n-shift)
  "The same as `zzz-to-char--base' except for using migemo."
  (let ((p (point))
        (avy-all-windows nil))
    (avy-with zzz-to-char
      (avy--generic-jump
       (if (= 13 char)
           "\n"
         ;; Adapt for migemo
         (avy-migemo-regex-quote-concat (string char)))
       nil
       avy-style
       (- p zzz-to-char-reach)
       (+ p zzz-to-char-reach)))
    (let ((n (point)))
      (when (/= n p)
        (cl-destructuring-bind (beg . end)
            (if (> n p)
                (cons p (- (1+ n) n-shift))
              (cons (+ n n-shift) p))
          (goto-char end)
          (kill-region beg end))))))

(avy-migemo-add-names 'zzz-to-char--base-migemo)

An example config for ivy

avy-migemo-e.g.ivy.el is a config file for ivy.el.

(require 'avy-migemo-e.g.ivy)

The following functions will be used as advice.

  • ivy--regex-migemo-around
  • ivy--regex-ignore-order-migemo-around
  • ivy--regex-plus-migemo-around
  • ivy--highlight-default-migemo
  • ivy-occur-revert-buffer-migemo
  • ivy-occur-press-migemo

User Option: ivy-migemo-get-function

Its type is function which takes a string and returns a regular expression.

Default value is avy-migemo-regex-concat-nnl.

This function takes a string and returns a regular expression.

User Option: ivy-migemo-ignore-functions

List of function names. If it has ivy-state-caller or ivy-state-collection, ivy--regex-*-migemo-around will not use migemo.

Default value is nil. ( avy-migemo-e.g.counsel.el will add counsel commands to this list. )

User Option: ivy-migemo-ignore-prompts

List of regexps. If one of it matches ivy-state-prompt, ivy--regex-*-migemo-around will not use migemo.

Default value is (list (regexp-opt '("symbol" "function" "variable" "binding" "face"))).

This variable can be used for ivy/counsel commands which do not have ivy-state-caller.

User Option: ivy-migemo-preferred-functions

List of function names. If it has ivy-state-caller or ivy-state-collection, ivy--regex-*-migemo-around will use migemo. If non-nil, ivy-migemo-ignore-functions / ivy-migemo-ignore-prompts will be ignored.

Default value is nil.

;; e.g. Using only swiper with migemo.
(add-to-list 'ivy-migemo-preferred-functions 'swiper)

An example config for swiper

avy-migemo-e.g.swiper.el is a config file for swiper.el.

(require 'avy-migemo-e.g.swiper)

The following functions will be used as advice.

  • swiper--add-overlays-migemo
  • swiper--re-builder-migemo-around

User Option: swiper-migemo-min-highlight

Default value is 2.

swiper--add-overlays-migemo will highlight matches if an input string is at least this long.

If nil, swiper-min-highlight will be used.

An example config for counsel

avy-migemo-e.g.counsel.el is a config file for counsel.el.

(require 'avy-migemo-e.g.counsel)

The following functions will be used as advice.

  • counsel-grep-migemo-around
  • counsel-grep-function-migemo
  • counsel-grep-occur-migemo
  • counsel-git-occur-migemo-around
  • counsel-find-file-occur-migemo-around
  • avy-migemo-disable-around for counsel-clj

The following functions will be added to ivy-migemo-ignore-functions.

counsel-ag, counsel-rg, counsel-git-grep, counsel-locate counsel-describe-variable, counsel-fzf, counsel-describe-function, counsel-descbinds, counsel-M-x ,counsel-dpkg, counsel-rpm, counsel-irony

The following commands are provided.

  • counsel-pt-migemo
  • counsel-rg-migemo

User Option: counsel-grep-base-command-migemo

Format string for counsel-grep-function-migemo. Default value is counsel-grep-base-command.

When avy-migemo-regex-concat-use-non-capturing is non-nil, grep with -E option can not work. -P option can work with non-capturing group.

;; e.g. grep with -P option
(custom-set-variables
 '(counsel-grep-base-command-migemo "grep -nP %s %s"))
;; e.g. ripgrep
(custom-set-variables
 '(counsel-grep-base-command-migemo "rg --color never --no-heading -ni %s %s"))

User Option: counsel-pt-migemo-base-command

Format string for counsel-pt-migemo. Default value is counsel-pt-base-command.

User Option: counsel-rg-migemo-base-command

Format string for counsel-rg-migemo. Default value is counsel-rg-base-command.

User Option: counsel-cmd-to-dired-migemo-grep-command

Format string of grep part for an arg of counsel-cmd-to-dired. Default value is “grep %s -i -P %s”.

User Option: counsel-cmd-to-dired-migemo-grep-invert-matching

The --invert-matching option of grep. This will be inserted into the first format specification of counsel-cmd-to-dired-migemo-grep-command. Default value is “-v”

User Option: counsel-find-file-occur-migemo-ls-cmd

Command string as ls command part of counsel-find-file-occur-cmd. Default value is “ls -a”.

User Option: counsel-find-file-occur-migemo-ls-xargs-cmd

Command string as xargs command part of counsel-find-file-occur-cmd. Default value is “xargs -d ‘\n’ ls -d –group-directories-first”.

User Option: counsel-find-file-occur-migemo-find-cmd

Command string as find command part of counsel--occur-cmd-find. Default value is “find . -maxdepth 1”.

User Option: counsel-find-file-occur-migemo-find-xargs-cmd

Command string as xargs command part of counsel--occur-cmd-find. Default value is “xargs -I {} find {} -maxdepth 0 -ls”.

User Option: counsel-unquote-regex-parens-migemo-function

Its type is function which takes a string ivy--regex will return and returns a regular expression.

counsel-unquote-regex-parens-migemo will use this internally.

Default value is counsel-unquote-regex-parens-migemo-default which will replace “\\|” with “|” after counsel-unquote-regex-parens.