emacs及evil正则表达式转义字符能否模拟Vim的简化规则?

貌似只能在使用/和?搜索替换时生效,在swiper中用\v或\d之类还都是直接搜索v d的字母,如果能在swiper实现就更好啦,我是不是太贪心了 :joy:

:dog:

swiper毕竟和evil没有关系,目测实现有难度

求人不如求己。

所谓支持 very magic,只不过是把 \d[[:digit:]] 做了映射,送给 Emacs 执行的还是后者:

(car (evil-ex-make-search-pattern "\\d")) ;; => "[[:digit:]]"

你可以修改 swiper,按照同样的方式处理:

\d --> Swiper --> [[:digit:]] --> Emacs
2 个赞

中间这行会导致 evil-ex-start-word-search 搜索错误:

image

evil-ex-make-pattern 函数里的这两句把 "\\_<pattern\\_>" 变成了 "\\_\\<pattern\\_\\>":

    (if evil-ex-search-vim-style-regexp
        (setq re (evil-transform-vim-style-regexp re))

重现代码:

$ emacsq.sh -P evil -M evil-mode -nw --eval "
(progn
  (toggle-debug-on-error)
  (setq evil-magic 'very-magic)
  (setq evil-ex-search-vim-style-regexp t)
  (evil-select-search-module 'evil-search-module 'evil-search)
  (with-current-buffer \"*scratch*\"
    (erase-buffer)
    (insert \"foo bar\nfoo bar\nfoo bar\nfoo bar\nfoo bar\nfoo bar\n\")
    (insert \"\nReproduce: \n\n  Press / and RET to repeat the last search.\")
    (goto-char (point-min))
    (evil-ex-start-word-search nil 'forward 1 t)
    (evil-ex-nohighlight)))
"

EDIT: 已提交补丁 emacs-evil/evil#pr1591

3 个赞

虽然补丁合并了,但还有其它问题 ,不建议开启该特性。

very magic,
very buggy。

1 个赞