关于增强swiper的代码

各位大佬好: 下面是增强swiper的一段代码,我是从别人那里拷贝过来的,但是我不熟悉elisp语法,所以不太清楚这是什么意思,请各位大佬赐教:

defun my-swiper-search § (interactive “P”) (let ((current-prefix-arg nil)) (call-interactively (if p #'spacemacs/swiper-region-or-symbol #'swiper)))

我只隐约知道这个函数应该既可以是swiper的默认行为,也同时可以抓取光标下的symbol去搜索,但是我不太清楚如何该触发后一种,于是我查了interactive的相关参数 p – Prefix arg converted to number. Does not do I/O. P – Prefix arg in raw form. Does not do I/O. 还是不了解该怎么操作,谢谢各位大佬了,

%E6%B7%B1%E5%BA%A6%E6%88%AA%E5%9B%BE_%E9%80%89%E6%8B%A9%E5%8C%BA%E5%9F%9F_20190422104003 这个是有格式的代码

Ctrl - u

大佬好: 我是这样按键的,my-swiper-search 绑定了C-s. 按键顺序是: C-s C-u 但是没有什么效果啊?

fanguolai

大佬好: 是这样的啊: C-u已经绑定了这个函数,是向上翻页的吧? 然后就没有效果了

我不懂 evil

sorry

还是谢谢大佬了,我是小白,非常感谢

在 Emacs 中,命令的行为可以被 prefix argument 改变。你这个函数的定义是说如果有 prefix argument,就用 spacemacs/swiper-region-of-symbol,没有的话就用 swiper。我认为前者不一定是你说的作用,具体要自己查它的文档,Spacemacs 里好像是 SPC h f 之类的按键。

要传 prefix argument 给函数,本来确实是按 C-u,但 spacemacs 给改了:

Spacemacs binds C-u to scroll-up and changes the universal argument binding to SPC u.

不过 C-u 在 emacs state 中应该还是可用的。根据你的设置,或许在 insert state 中也是可用的。

非常感谢大佬。 确实如同您所说。 在emac state 和 insert state 下, C-u C-s 是可以抓取光标下的symbol搜索的, 但是在normal state 下, 由于 C-u 被绑定其他东西了,所以就不能用了。 十分感谢

C-u 绑定的是 (universal-argument) 这个函数,你可以查这个函数在你的配置里绑定的是哪个键。在spacemacs 的 normal state 下,我猜测是 SPC-u

还真是的:+1:

:+1: 还真是的

Swiper 后按 M-n 搜光标下的 symbol,这是 ivy 的通用快捷键。

1 个赞