Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting polymode with lsp, makes the cursor to jump to the end of buffer #316

Open
maikol-solis opened this issue Apr 28, 2022 · 10 comments

Comments

@maikol-solis
Copy link

maikol-solis commented Apr 28, 2022

I have this problem when I try to edit Rmd files.

In the video happens several things:

  1. A fresh opened file (test.Rmd) works as expected. I typed the letters abc several times without problem.
  2. Around the second 0:23 I started polymode and execute the fenced code. Here LSP is also activated.
  3. After that (second 0:50), every time I type a character the cursor jumps to the end of the buffer and operations like delete-char, backward-char, etc., become unreliable.
pm.mov

My undesirable workaround for the moment is disabling polymode completely, edit my Rmd in Emacs and run everything in Rstudio.

The pm-debug-relevant-variables


================== test.Rmd ===================
((:change
  (before-change-functions polymode-before-change whitespace-buffer-changed t sp--reset-memoization)
  (after-change-functions polymode-flush-syntax-ppss-cache poly-lock-after-change flycheck-handle-change flyspell-lazy-after-change-function flyspell-after-change-function t markdown-gfm-checkbox-after-change-function polymode-after-change))
 (:command
  (pre-command-hook polymode-pre-command eldoc-pre-command-refresh-echo-area evil--jump-hook company-pre-command t)
  (post-command-hook evil-normal-post-command hl-line-highlight whitespace-post-command-hook eldoc-schedule-timer evil--jump-handle-buffer-crossing yas--post-command-handler company-post-command flycheck-perform-deferred-syntax-check flycheck-error-list-update-source flycheck-error-list-highlight-errors flycheck-maybe-display-error-at-point-soon flycheck-hide-error-buffer jit-lock--antiblink-post-command t polymode-post-command))
 (:font-lock
  (fontification-functions poly-lock-function)
  (font-lock-function . poly-lock-mode)
  (font-lock-flush-function . poly-lock-flush)
  (font-lock-ensure-function . poly-lock-fontify-now)
  (font-lock-fontify-region-function . font-lock-default-fontify-region)
  (font-lock-fontify-buffer-function . poly-lock-flush)
  (font-lock-unfontify-region-function . font-lock-default-unfontify-region)
  (font-lock-unfontify-buffer-function . font-lock-default-unfontify-buffer)
  (jit-lock-after-change-extend-region-functions font-lock-extend-jit-lock-region-after-change t markdown-font-lock-extend-region-function)
  (jit-lock-functions font-lock-fontify-region t adaptive-wrap-prefix-function)
  (poly-lock-defer-after-change . t))
 (:search
  (parse-sexp-lookup-properties . t)
  (parse-sexp-ignore-comments)
  (case-fold-search . t))
 (:indent
  (indent-line-function . pm-indent-line-dispatcher)
  (indent-region-function . pm-indent-region)
  (pm--indent-line-function-original . markdown-indent-line))
 (:revert
  (revert-buffer-function . revert-buffer--default)
  (before-revert-hook flycheck-teardown t)
  (after-revert-hook solaire-mode--restore))
 (:save
  (after-save-hook polymode-after-save +vc-gutter-init-maybe-h flycheck-handle-save t markdown-live-preview-if-markdown)
  (before-save-hook polymode-before-save t)
  (write-contents-functions)
  (local-write-file-hooks)
  (write-file-functions whitespace-write-file-hook t))
 (:syntax
  (syntax-propertize-function . polymode-syntax-propertize)
  (syntax-propertize-extend-region-functions markdown-syntax-propertize-extend-region syntax-propertize-wholelines)
  (pm--syntax-propertize-function-original . markdown-syntax-propertize)))

My session info:

generated    Apr 28, 2022 15:42:16
system       MacOS 11.6.5 Darwin 20.6.0 x86_64 ns
emacs        28.1 HEAD c2fb07fdb ~/.emacs.d/ -> ~/.emacs.d/
doom         3.0.0-dev HEAD -> master 6bf725837 2022-04-26 03:58:14 +0200 ~/.doom.d/ -> ~/dotfiles/.doom.d/
shell        /bin/zsh
features     ACL DBUS GIF GLIB GMP GNUTLS JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP NOTIFY KQUEUE NS PDUMPER PNG RSVG THREADS TIFF TOOLKIT_SCROLL_BARS XIM XWIDGETS ZLIB
traits       gui server-running envvar-file custom-file
custom       interaction-log-mode x-underline-at-descent-line widget-image-enable
modules      :completion (company +tng) (vertico +icons) :ui deft doom (&nopath fill-column) hl-todo hydra minimap modeline nav-flash ophints (popup +all +defaults) treemacs vc-gutter vi-tilde-fringe (window-select +numbers) workspaces zen :editor (evil +everywhere) file-templates fold format multiple-cursors snippets word-wrap :emacs (dired +icons) electric (ibuffer +icons) (undo +tree) vc :checkers syntax (spell +flyspell +everywhere) grammar :tools biblio ein (eval +overlay) (lookup +dictionary +offline +docsets) (lsp +peek) (magit +forge) pdf :os (tty +osc) macos :lang emacs-lisp (ess +lsp) (latex +latexmk +cdlatex +fold +lsp) (markdown +grip) (org +pomodoro +dragndrop +jupyter +present +noter +pandoc +pretty +roam2) (python +lsp) sh (yaml +lsp) :email (mu4e +org +gmail) :app calendar everywhere :config literate (default +bindings +smartparens)
packages     (nano-theme) (nano-agenda) (mu4e-alert :disable t) (outline-minor-faces) (bicycle) (google-translate) (plantuml-mode) (graphviz-dot-mode) (org-super-agenda) (org-ql) (org-pomodoro-third-time :recipe (:host github :repo telotortium/org-pomodoro-third-time)) (org-alert) (org-fragtog) (laas) (real-auto-save) (git-auto-commit-mode) (org-roam-ui) (citar) (helm-bibtex) (org-ref) (org-transclusion) (zetteldesk :recipe (:host github :repo Vidianos-Giannitsis/zetteldesk.el)) (pretty-hydra) (oxr :recipe (:host github :repo bdarcus/oxr)) (ess-view-data) (move-dup) (academic-phrases) (company-tabnine) (consult-yasnippet) (company-wordfreq) (el-secretario :recipe (:repo https://git.sr.ht/~zetagon/el-secretario :files (*))) (org-gtd) (org-edna) (org-agenda-property) (keypression) (good-scroll) (org-graph-view :recipe (:host github :repo alphapapa/org-graph-view)) (mini-modeline) (minions) (org-inline-pdf) (interaction-log)
unpin        org-roam org-roam-bibtex company org-gcal
@gdkrmr
Copy link

gdkrmr commented May 18, 2022

I can confirm this, it basically makes it impossible to edit the file

@jrgant
Copy link

jrgant commented Jul 20, 2022

I'm also experiencing similar behavior. I basically can't work with Rmd files while in polymode.

@gdkrmr
Copy link

gdkrmr commented Jul 28, 2022

I think the culprit is lsp-managed-mode if you navigate inside of a code chunk and disable lsp-managed-mode there, the jumping stops. I havent' tested this extensively yet.

@lebensterben
Copy link

@yyoncho

Please help.

@AlexDaniel
Copy link

It used to work OK, but now after upgrading something it indeed became unusable. :(

@AlexDaniel
Copy link

Alright, I found this commit: 2094c92#diff-7a892d2433cc77b44621c3724f45b25815a7c3c98ad7fa9b6531ca252f927ff3R308

So I went to the source code of the package and changed t to nil. Now the cursor no longer jumps. I have no idea what it means for lsp, I use it but not as much. Probably it breaks lsp, but at least polymode itself works.

@AlexDaniel
Copy link

Now more than one month later, I updated emacs and all related packages, and my hotfix to the file was reverted. This immediately brought the problem back. I edited the file again and the workaround is still working.

@jrgant
Copy link

jrgant commented Oct 26, 2022

@AlexDaniel Thank you for this sleuthing. Seems to be working for me too.

I decided to set polymode-lsp-integration in my config.el for each language mode I use regularly in polymode, which should avoid having to reset this variable in the polymode source every time the package gets updated.

I use Doom Emacs, so you might have to set the hooks differently if you don't, but here's what I'm doing now:

(setq-hook! ess-r-mode polymode-lsp-integration nil)
(setq-hook! sh-mode polymode-lsp-integration nil)
(setq-hook! yaml-mode polymode-lsp-integration nil)
(setq-hook! markdown-mode polymode-lsp-integration nil)
(setq-hook! python-mode polymode-lsp-integration nil)

@maikol-solis
Copy link
Author

I have a (setq-default polymode-lsp-integration nil) as a drastic alternative.

@kchanqvq
Copy link
Contributor

(setq-default polymode-lsp-integration nil) doesn't remove the jumping for me QAQ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants