Closed rofrol closed 5 years ago
Looks like this works https://github.com/jcollard/elm-mode/commit/dc5ce009b18c07e5235d1974691b372fc0cacace
But not autoformat with saving but manually running elm-mode-format-buffer
.
Also I am using this for formatting on save:
(add-hook 'before-save-hook #'elm-mode-format-buffer)
Hmm. Are you on Emacs 26.1? And which version of the reformatter
package do you have?
BTW your config is quite broken. You add an after-save-hooks
function at the top level but you pass the "local" flag, so you're still modifying the global version of after-save-hooks
. What you instead want is to add that hook locally inside the elm-mode buffer, e.g. in a function added to elm-mode-hook
. (You can then safely skip checking whether major-mode
is elm-mode
... and in any case, prefer derived-mode-p
to (eq major-mode ...)
)
My guess at what's happening here is that you have an old snapshot version of Emacs which nonetheless looks newer than 26.1, and is getting hit by the emacs version check here, so that your reformatting is messed up by the core replace-buffer-contents
function being broken.
old snapshot version of Emacs which nonetheless looks newer than 26.1,
In case this is the problem, I've pushed a fix in https://github.com/purcell/reformatter.el/commit/0da7241ca20df4d3e5f4ccbd03227816d8d5f698.
I am using remacs.
~/.emacs.d/straight/repos/reformatter.el (master)$ emacs --version
GNU Emacs 27.0.50
Copyright (C) 2018 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
~/.emacs.d/straight/repos/reformatter.el (master)$ git --no-pager log | head
commit 7e41f1a397e0d19d122695b835f0cd6cb3f7363a
Author: Steve Purcell <steve@sanityinc.com>
Date: Fri May 17 16:42:06 2019 +1200
Use replace-buffer-contents when available and not broken
Fixes #10
Works after fix.
I am using remacs.
Then that version of remacs must have the bug that was subsequently fixed in Emacs.
Works after fix.
Cool, thanks for confirming.
Last good commit for me is 57104f0d7e98bfa6aeaec5854d933291d19aedb4.
This:
formats to this:
This is my config https://github.com/rofrol/.emacs.d/blob/df81ad4c5958072fda5cf413b8838b6a2482cef0/lisp/rofrol-elm.el