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

オープン
#115 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
emacs-lisp

調査の方向性

treesit-end-of-defun と treesit-beginning-of-defun から始め、markdown-inline または regex の埋め込みパーサーを有効にした状態で問題を再現し、docstring または regex の内部に point を置きます。完了の条件は、beginning/end-of-defun がそれらの位置から外側の Clojure defun に到達し、CIDER が誤ったナビゲーションなしにそこでフォームを評価できることです。

索引モデルが 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時間
マージ済み PR(30日)
23

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

clojure-emacs/clojure-ts-mode のほかの issue

clojure-emacs/clojure-ts-mode の issue をすべて見る

似ている issue

DevTools の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。