Skip to content

Instantly share code, notes, and snippets.

Last active September 20, 2020 06:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
(require 'ivy)
(require 'migemo)
(defun my/migemo-get-pattern-shyly (word)
(migemo-get-pattern word)))
(defun my/ivy--regex-migemo-pattern (word)
((string-match "\\(.*\\)\\(\\[[^\0]+\\]\\)" word)
(concat (my/migemo-get-pattern-shyly (match-string 1 word))
(match-string 2 word)))
((string-match "\\`\\\\([^\0]*\\\\)\\'" word)
(match-string 0 word))
(my/migemo-get-pattern-shyly word))))
(defun my/ivy--regex-migemo (str)
(when (string-match-p "\\(?:[^\\]\\|^\\)\\\\\\'" str)
(setq str (substring str 0 -1)))
(setq str (ivy--trim-trailing-re str))
(cdr (let ((subs (ivy--split str)))
(if (= (length subs) 1)
(setq ivy--subexps 0)
(if (string-match-p "\\`\\.[^.]" (car subs))
(concat "\\." (my/ivy--regex-migemo-pattern (substring (car subs) 1)))
(my/ivy--regex-migemo-pattern (car subs))))
(setq ivy--subexps (length subs))
"\\.\\*\\??\\\\( "
"\\( "
(lambda (x)
(if (string-match-p "\\`\\\\([^?][^\0]*\\\\)\\'" x)
(format "\\(%s\\)" (my/ivy--regex-migemo-pattern x))))
nil t))))))
(defun my/ivy--regex-migemo-plus (str)
(cl-letf (((symbol-function 'ivy--regex) #'my/ivy--regex-migemo))
(ivy--regex-plus str)))
;; for swiper
;; (setf (alist-get 'swiper ivy-re-builders-alist) #'my/ivy--regex-migemo-plus)
;; remove
;; (setf (alist-get 'swiper ivy-re-builders-alist nil 'remove) nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment