jcollard / elm-mode

Elm mode for emacs
GNU General Public License v3.0
373 stars 67 forks source link

Corrupted file after elm-format-on-save #156

Closed rofrol closed 5 years ago

rofrol commented 5 years ago

Last good commit for me is 57104f0d7e98bfa6aeaec5854d933291d19aedb4.

This:

module Mapdid.App exposing (main)

import Animation
import Browser
import Browser.Dom
import Browser.Events
import Browser.Navigation as Nav
import Element exposing (Element)
import Element.Background
import Element.Border

formats to this:

module Mapdid.App exposing (maimn)

import Animation
import Browser
import Browser.Dom
import Brr
iopowser.EvenrtDs

import tr Bserrovwnts
impser.Navigation as Nav
import
iElement emxptosing (Element)
import Element.Background
import orElement.B.orrder

This is my config https://github.com/rofrol/.emacs.d/blob/df81ad4c5958072fda5cf413b8838b6a2482cef0/lisp/rofrol-elm.el

rofrol commented 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.

rofrol commented 5 years ago

Also I am using this for formatting on save:

(add-hook 'before-save-hook #'elm-mode-format-buffer)

purcell commented 5 years ago

Hmm. Are you on Emacs 26.1? And which version of the reformatter package do you have?

purcell commented 5 years ago

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 ...))

purcell commented 5 years ago

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.

purcell commented 5 years ago

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.

rofrol commented 5 years ago

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
rofrol commented 5 years ago

Works after fix.

purcell commented 5 years ago

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.