`beginning/end-of-defun` doesn't work if point is in docstring or regex

未关闭
#115 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
emacs-lisp

调研方向

从 treesit-end-of-defun 和 treesit-beginning-of-defun 开始,在启用 markdown-inline 或 regex 嵌入式解析器的情况下重现该问题,并将 point 放在 docstring 或 regex 内部。完成的标准是,beginning/end-of-defun 能从这些位置到达外层的 Clojure defun,并且 CIDER 可以在那里求值 forms 而不会发生错误导航。

由索引模型根据 Issue 内容生成。

描述

bug

Expected behavior

Executing C-M-e (end-of-defun) or C-M-a (beginning-of-defun) from any place inside of a defun navigates to a proper position.

Actual behavior

Point is not moved or moved to some random place inside of a docstring or a regex.

Steps to reproduce the problem

The issue is reproducible only if any of the embedded parsers is enabled (either markdown-inline or regex). When end-of-defun is called Emacs delegates its execution to treesit-end-of-defun, which tries to operate on "things", but if parser at point is not clojure it tries to navigate to the end of defun of embedded parser.

It also affects CIDER: currently it's not possible to evaluate form if point is in a docstring, because CIDER uses end-of-defun internally.

Possible solutions

We can either defun custom clojure-ts-[beginning|end]-of-defun functions and remap treesit-* versions or we can add advice before treesit-* functions to jump out of an embedded node before using an actual navigation command:

(defun clojure-ts--ensure-not-embedded (&rest args)
  (when (and (derived-mode-p 'clojure-ts-mode)
             (not (equal (treesit-language-at (point)) 'clojure)))
    (backward-up-list 1 t)))

(advice-add 'treesit-end-of-defun :before #'clojure-ts--ensure-not-embedded)
(advice-add 'treesit-beginning-of-defun :before #'clojure--ts-ensure-not-embedded)

I tested both options locally, both work fine and solve the issue.

主要语言
Emacs Lisp
星标
192
派生
21
平均合并
2 天 14 小时
30 天内合并 PR
23

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

clojure-emacs/clojure-ts-mode 的其他 Issue

查看 clojure-emacs/clojure-ts-mode 的全部 Issue

相似的 Issue

更多 DevTools Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。