Doom-emacs: Scroll Position Jumps after formatter runs

Created on 26 Feb 2020  路  3Comments  路  Source: hlissner/doom-emacs

When saving a file (js2-mode or elm-mode) and the formatter (prettier.js or elm-format) has to change the file (eg remove empty line) the scroll position...

What did you expect to happen?
...stays almost the same.

What actually happened?
...jumps to the end of the visible buffer but the cursor stays on the current line where it was before saving the file. Like pressing SPC f s and then z b.

Additional details:
out

Reformatted!
Wrote xxxxxxxxxx/.emacs.d/.local/cache/undo-tree-hist/.!xxxx!xxxx!xxxxxxxxxxxxx!xxxxxxxx!xxxxx!miToMu!src!Main.elm.~undo-tree~
Wrote xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/miToMu/src/Main.elm
"miToMu/src/Main.elm" 154L, 3480C written

Steps to reproduce:

  1. open this file in emacs https://github.com/ni-ko-o-kin/elm-meetups/blob/master/20191204/set-card-game/src/Main.elm
  2. go to line 100
  3. press z z to center the cursor position to the middle (so you can actually see the bug)
  4. add an empty line (o)
  5. save the file
  6. the scroll position now jumps to the end (like pressing z b after spc f s)

System information:

emacs   version    26.1
        features   XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 THREADS LIBSYSTEMD LCMS2
        build      Apr 11, 2019
        buildopts  (--build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/26.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.1/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/26.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.1/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars 'CFLAGS=-g -O2 -fdebug-prefix-map=/build/emacs-cQxEw2/emacs-26.1+1=. -fstack-protector-strong -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro')
        windowsys  x
        daemonp    server-running
doom    version    2.0.9
        build      HEAD -> develop, origin/develop, origin/HEAD 51d71ee7e 2020-02-12 20:40:34 -0500
        dir        ~/.doom.d/
system  type       gnu/linux
        config     x86_64-pc-linux-gnu
        shell      /bin/zsh
        uname      Linux 5.0.0-38-generic #41-Ubuntu SMP Tue Dec 3 00:27:35 UTC 2019 x86_64
        path       (~/.nvm/versions/node/v12.6.0/bin ~/.local/bin ~/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games /snap/bin /usr/lib/emacs/26.1/x86_64-linux-gnu/)
config  envfile    envvar-file
        elc-files  0
        modules    (:completion company ivy :ui doom doom-dashboard hl-todo modeline nav-flash ophints (popup +all +defaults) treemacs vc-gutter vi-tilde-fringe window-select workspaces :editor (evil +everywhere) file-templates fold (format +onsave) multiple-cursors rotate-text snippets :emacs dired electric vc :tools eval :checkers syntax :tools (lookup +docsets) lsp magit :lang data (elm +lsp) emacs-lisp (javascript +lsp) markdown org sh :config (default +bindings +smartparens))
        packages   (n/a)
        elpa       (n/a)
        unpin      (n/a)

:editor format bug update resolved

All 3 comments

I'm aware of the issue. It appears to be an issue with Doom's layer of hacks over format-all. I haven't had time to revisit this and bring it up to speed yet. I'll let you know once I have.

As of https://github.com/hlissner/doom-emacs/commit/c2a0ac8b3e69fc362d222f108ddd3a01e46f1574 this issue should be resolved. Let me know if that isn't the case and I'll reopen it. Thanks for bringing it to my attention!

Thank you so much! It works!

Was this page helpful?
0 / 5 - 0 ratings