redguardtoo / evil-matchit

Vim matchit ported into Emacs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jump to wrong line in ruby

leateng opened this issue · comments

class A
  def abc
    a = []

    # a.each do |x|     #  line 5
    a.each do |x| 
    end
  end # line 8, cursor here
end

when curosr on line 8, press %, jump to line 5

can't reproduce. make sure your are in ruby-mode or enh-ruby-mode.

Or else, add below line into your "~/.emacs",

  (evilmi-load-plugin-rules '(ruby-mode enh-ruby-mode your-rub-mode) '(simple ruby))

Thank you for your reply.
I found the problem. When I enable tree-sitter-hl-mode, evil-matchit does not work properly in some cases.
Is this a bug of Emacs tree-sitter or evil-machit ?
Or my configuration?

I use doom Emacs
just add a few lines config

;; enable tree sitter highlight
(global-tree-sitter-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)

;; enable evil-matchit
(global-evil-matchit-mode 1)

Only simple regex is used in ruby related code. Code should not be impacted by other plugins.

What's the major-mode in ruby file? Does M-x evilmi-jump-items work? Press C-h k %, what's output?

  1. major mode is ruby-mode
  2. M-x evilmi-jump-items works same as press % key
  3. c-h k % output
    image

I can't reproduce the issue. What's M-x evilmi-version, maybe you can try 2.4.4?

I have the similar problem with you. I couldn't jump appropriately in OCaml. And our configuration is exactly the same.

(global-tree-sitter-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)
(global-evil-matchit-mode 1)

@JohnsonLee-debug , could you give me more details? A sample ocaml file could help a lot

My environment:

> Executing 'doom info' with Emacs 28.1 at 2022-06-02 13:00:02
    generated    Jun 02, 2022 13:00:02
      system       Ubuntu 20.04.4 LTS Linux 5.10.102.1-microsoft-standard-WSL2 x86_64
      emacs        28.1 ~/.emacs.d/ -> ~/.emacs.d/
      doom         3.0.0-dev grafted, HEAD -> master, origin/master, origin/HEAD 1b8f46c 2022-05-27 03:13:00 +0200 ~/.config/doom/ -> ~/.config/doom/
      shell        /usr/bin/zsh
      features     ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB
      traits       batch server-running envvar-file custom-file
      modules      :completion (company +childfram +tng) (vertico +icons) :ui doom doom-dashboard hl-todo ligatures modeline ophints (popup +defaults) unicode vc-gutter vi-tilde-fringe workspaces :editor (evil +everywhere) file-templates fold snippets :emacs dired electric undo vc :term vterm :checkers syntax (spell +flyspell) grammar :tools (eval +overlay) lookup lsp magit :os tty :lang coq emacs-lisp (go +lsp) (haskell +lsp) json latex lean markdown (ocaml +lsp) org plantuml python sh web yaml :config (default +bindings +smartparens)
      packages     (tree-sitter) (tree-sitter-langs) (evil-matchit)

evilmi-version: 3.0.0
major-mode: tuareg-mode
Example OCaml file:
Behavior is described in the comment.

open Ordered

module type Heap = sig
  module Elt : Comparable

  type elt = Elt.t
  type t

  exception Empty

  val empty : t
  val is_empty : t -> bool
  val insert : elt -> t -> t
  val merge : t -> t -> t
  val find_min : t -> elt
  val delete_min : t -> t
end(* press '%' doesn't trigger any action *)

(* press '%' here, cursor is expected to jump to ')', but it jump to the end of 'module' *)
(*> LeftistHeaps <*)
module LeftistHeaps (Elt : Comparable) = struct
  module Elt = ExtendCompare (Elt)

  type elt = Elt.t

  type t =
    | E
    | T of int * elt * t * t

  exception Empty

  let rank = function
    | E -> 0
    | T (r, _, _, _) -> r
  ;;

  let rec merge a b =
    let makeT x a b =
      if rank a >= rank b then T (rank b + 1, x, a, b) else T (rank a + 1, x, b, a)
    in
    match a, b with
    | h, E -> h
    | E, h -> h
    | (T (_, x, l1, r1) as h1), (T (_, y, l2, r2) as h2) ->
      if Elt.leq x y then makeT x l1 (merge r1 h2) else makeT y l2 (merge r2 h1)
  ;;

  let is_empty = function
    | E -> true
    | T _ -> false
  ;;

  let empty = E
  let insert x h = merge (T (1, x, E, E)) h

  let find_min = function
    | E -> raise Empty
    | T (_, x, _, _) -> x
  ;;

  let delete_min = function
    | E -> raise Empty
    | T (_, _, a, b) -> merge a b
  ;;
end

Can't reproduce the issue. I've tried to toggle global-tree-sitter-mode or global-evil-matchit-mode several times.

ocaml algorithm was not written by me. But looks code is straight forward,
evilmi-ocaml-goto-word-beginning to get the beginning of the first keyword after the cursor, then jump.

Maybe it is caused by something in doom emacs. I use doom like @leateng did.

Please note I use tree-sitter-0.18.0 stable version. Emacs API scan-sexps is used to jump between {}, [], ().

If the api fails, it might be the bug of unstable tree-sitter or major mode.

+1 – I'm having the same issue as @leateng & @JohnsonLee-debug. Similarly, I am using Doom Emacs.

@redguardtoo I've tried the new evilmi-jump-hook as suggested but it did not resolve the issue.

Could you give me more details and some minimum example? evilmi version? Have you tested evil-matchit in vanllia emacs? Which package causes the issue? doom emacs version? I will download doomemacs and test.