Skip to content

haskell-cabal-add-dependency messes up cabal file if tabs are not turned off. #474

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

Closed
rabipelais opened this issue Feb 20, 2015 · 7 comments

Comments

@rabipelais
Copy link
Contributor

I am attempting to add a dependency automatically to a cabal file. However, after the insertion, the cabal file is completely broken. This happens if indent-tabs-mode is set to true, even if it is set to false for haskell-cabal mode.

Steps to reproduce

Start with default auto-generated minimal cabal file.
With that file in the current buffer run:
(setq-default indent-tabs-mode t)
(haskell-cabal-add-dependency "foo" "3" nil nil)
Answer yes to prompts

Expected result

name:                test
version:             0.1.0.0
license-file:        LICENSE
build-type:          Simple
cabal-version:       >=1.10

executable test
  main-is:             Main.hs
  build-depends:  foo >= 3
                 , base >=4.7 && <4.8
  default-language:    Haskell2010

Actual result

name:                test
version:             0.1.0.0
license-file:        LICENSE
build-type:          Simple
cabal-version:       >=1.10

executable test
  main-is:             Main.hs
  build-depends:                           foo >= 3
                     , 4.8
  default-language:    Haskell2010

Note that the weird indentation and lack of base is verbatim copied from my editor. The whitespace between build-depends: and foo is tabs, not spaces.

Notes

As mentioned above, this happens if tabs are turned on, even if they are turned off for all haskell related modes. Adding more dependencies after this only makes the file wonkier.
If I undo the (haskell-cabal-add-dependency "foo" "3" nil nil) command, set indent-tabs-mode to nil, and re-add the dependency, it is inserted correctly this time.

@gracjan
Copy link
Contributor

gracjan commented Feb 22, 2015

@rabipelais: Is this the same as #376?

@rabipelais
Copy link
Contributor Author

@gracjan

haskell-cabal-mode explicitly does (setq indent-tabs-mode nil) so I guess a TAB in cabal file will
happen never again.

That solution doesn't work for me in this case, because that (setq indent-tabs-mode nil) applies only to haskell-cabal-mode.
In the use-case where a global indent-tabs-mode is not nil (for example for me, as I use tabs for C/C++ dev), the problem arises when haskell-cabal-add-dependency calls haskell-cabal-with-subsection, which in turn uses the with-temp-buffer macro to temporarily format the new entries. The buffer that with-temp-buffer opens starts in the default major-mode, which is fundamental-mode in the default case.
Here the indent-tabs-mode from the haskell-cabal-mode has no effect, hence the tabs, which are copied verbatim to the cabal file.

I will test if changing indent-tabs-mode inside the with-temp-buffer macro solves the issue.

@rabipelais
Copy link
Contributor Author

Yes, apparently setting indent-tabs-mode to nil inside with-temp-buffer (and recompiling) solves the issue, with no side-effects.

--- #<buffer haskell-cabal.el>
***************
*** 464,469 ****
--- 464,470 ----
         (save-excursion
           (prog1
               (with-temp-buffer
+                (setq indent-tabs-mode nil)
                 (indent-to ,start-col)
                 (insert ,section-data)
                 (goto-char (point-min))

should I submit a pull request? Or is the change way too small?

@gracjan
Copy link
Contributor

gracjan commented Feb 23, 2015

@rabipelais: Change looks good to me and was already discussed in #376.

A pull request would be greatly appreciated.

rabipelais added a commit to rabipelais/haskell-mode that referenced this issue Feb 25, 2015
This prevents the insertion of unwanted tabs in the cabal file when
auto-inserting dependencies, regardless of the user value for
`indent-tabs-mode` in the default mode (default is fundamental mode).
Solves issues haskell#379 and haskell#474.
@gracjan
Copy link
Contributor

gracjan commented Feb 25, 2015

@rabipelais: Is this working for you now? Can we close?

@rabipelais
Copy link
Contributor Author

Yes, working. It can be closed, thank you.

@gracjan
Copy link
Contributor

gracjan commented Feb 27, 2015

@rabipelais: You can close this issue yourself as you are the one reporting it!

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

2 participants