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

Aperta
#115 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
emacs-lisp

Direzione di ricerca

Inizia con treesit-end-of-defun e treesit-beginning-of-defun, riproduci il problema con il parser incorporato markdown-inline o regex abilitato e posiziona il point all’interno di un docstring o di una regex. Il lavoro è completato quando beginning/end-of-defun raggiunge il defun Clojure contenitore da quelle posizioni e CIDER può valutare le forme in quel punto senza navigare in modo errato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Emacs Lisp
Stelle
192
Fork
21
Merge medio
2g 14h
PR unite (30g)
23

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di clojure-emacs/clojure-ts-mode

Tutte le issue di clojure-emacs/clojure-ts-mode

Issue simili

Altre issue su DevTools

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.