nim-lang / nim-mode

An emacs major mode for the Nim programming language
138 stars 46 forks source link

Prevent using interactive command line-move-visual if possible? #189

Open kaushalmodi opened 6 years ago

kaushalmodi commented 6 years ago

Conforming Bugs

Please tell us below:

And describe your problem:

Use of visual-line-move in nim-mode exposed an emacs bug and causes crashes when doing org-comment-dwim in a nim SRC_BLOCK in an Org file (debbugs # 29326).

The Lisp backtrace explains the interaction between org-mode and nim-mode:

Lisp Backtrace:
"line-number-display-width" (0xffff37e0)
"line-move-visual" (0xffff4030)
"line-move" (0xffff4780)
"let" (0xffff4b80)
"condition-case" (0xffff4e70)
"nim-line-move" (0xffff5030)
"not" (0xffff5300)
"if" (0xffff54a0)
"progn" (0xffff5640)
"if" (0xffff57e0)
"save-excursion" (0xffff59c0)
"catch" (0xffff5be0)
"nim-line-empty-p" (0xffff5da0)
"or" (0xffff60c0)
"if" (0xffff6260)
"let" (0xffff64f0)
"save-excursion" (0xffff66d0)
"nim-get-empty-line-indent" (0xffff6890)
"cons" (0xffff6b50)
"list" (0xffff6ce0)
"setq" (0xffff6ed0)
"nim-smie-indent-calculate" (0xffff7090)
"and" (0xffff73a0)
"let*" (0xffff7590)
"nim-indent-calculate-indentation" (0xffff7750)
"and" (0xffff7a70)
"let*" (0xffff7c60)
"save-excursion" (0xffff7e40)
"let" (0xffff80d0)
"nim--indent-line-core" (0xffff8290)
"nim-indent-line" (0xffff8650)
"indent-according-to-mode" (0xffff8da0)
"comment-dwim" (0xffff9640)
"funcall-interactively" (0xffff9638)
"call-interactively" (0xffff9af8)
"org-comment-dwim" (0xffffa360)
"funcall-interactively" (0xffffa358)
"call-interactively" (0xffffa840)
"command-execute" (0xffffb028)

While the emacs bug was clearly present (and later fixed in emacs-26/90add182), Eli had these comments:

The trigger was the call to line-move-visual in nim-mode. So you need to do something that causes that function to be called by nim-mode, when Org does the indent thing. I think this doesn't happen frequently because most modes used in source snippets in Org buffers don't call line-move-visual (why would they? that function is for interactively moving cursor vertically).

yuutayamada commented 6 years ago

Thank you for conforming the bug. I'm assuming line-move function calls the line-move-visual function in nim-mode and I think it could be changed line-move-1 instead. I'll check when I have time. (indent stuff is kinda vulnerable part in nim-mode and may take some time to fix indentation test)