通过配置文件实现终端Emacs鼠标点击定位光标
终端Emacs鼠标点击移动光标配置方案
你直接在.emacs里写(mouse-set-point 'mouse-1)不会生效,原因有两个:一是这只是单次调用函数,没有把光标移动行为绑定到鼠标左键点击事件上;二是终端环境下的Emacs默认可能未开启鼠标支持。
以下是正确的配置步骤:
先开启终端鼠标支持,并绑定左键点击动作:
适配Emacs 28+的写法:(when (not window-system) (xterm-mouse-mode 1) (global-set-key [mouse-1] 'mouse-set-point))如果你用的是Emacs 27及更早版本,可以用这个兼容写法:
(when (not window-system) (mouse-wheel-mode 1) (global-set-key [mouse-1] 'mouse-set-point))配置说明:
(not window-system)用于判断当前是否处于终端环境,避免影响图形界面的Emacs配置。xterm-mouse-mode(或旧版的mouse-wheel-mode)是开启终端Emacs鼠标事件支持的关键,没有这一步,鼠标点击不会被Emacs识别。global-set-key [mouse-1] 'mouse-set-point才是把鼠标左键点击和光标移动动作绑定起来,每次点击左键时,Emacs会调用mouse-set-point将光标移到点击位置。
生效验证:
保存配置后重启终端Emacs,或者在Emacs内执行M-x eval-buffer加载当前配置文件。另外要确保你的终端支持鼠标事件(现代终端如iTerm2、GNOME Terminal等都默认支持,老旧终端可能需要手动开启鼠标报告功能)。
内容的提问来源于stack exchange,提问作者theheretic
相关产品推荐
相关产品推荐

