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

Wrong indentation when opening a new line above the cursor in go #6520

Closed
en opened this issue Jul 6, 2016 · 14 comments
Closed

Wrong indentation when opening a new line above the cursor in go #6520

en opened this issue Jul 6, 2016 · 14 comments
Labels
- Bug tracker - Go stale marked as a stale issue/pr (usually by a bot)

Comments

@en
Copy link

en commented Jul 6, 2016

Description

Wrong indentation when opening a new line above the cursor in go

Reproduction guide

  • Start Emacs
  • Create a file named test.go
  • Insert "var ()", then back to normal mode, the cursor should now be on the ")"
  • Type the following sequence to start a new line between "()"
  • i RET C-[ O
    untitled

Observed behaviour:

the cursor is under "v"

var (
|
)

Expected behaviour:

var (
  |
)

It works by using vim.
I noticed a "auto trimmed 1 chars" at the bottom. This message can be found in clean-aindent-mode.
I'm not familiar with elisp yet, could somebody look into this?

System Info

  • OS: darwin
  • Emacs: 24.5.1
  • Spacemacs: 0.105.21
  • Spacemacs branch: master (rev. 0283f64)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(emacs-lisp go)

Backtrace

BACKTRACE IF RELEVANT
@TheBB
Copy link
Collaborator

TheBB commented Jul 11, 2016

Yeah, it's caused by clean-aindent-mode. Disabling it seems to fix this. I'm not sure why, it seems to work fine in e.g. C.

@chriskaukis
Copy link
Contributor

chriskaukis commented Oct 4, 2016

Just came across this issue after upgrading to Spacemacs 0.200 last night. Also using Go.

Exact same reproduction and expected behavior. Disabling clean-aindent-mode fixed it. Is there a fix besides calling this every time? I'm new to Emacs and Spacemacs, sorry.

System Info 💻

  • OS: darwin
  • Emacs: 25.1.1
  • Spacemacs: 0.200.0
  • Spacemacs branch: master (rev. e6357a5)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(javascript
 (auto-completion :variables auto-completion-enable-help-tooltip t auto-completion-return-key-behavior 'complete auto-completion-tab-key-behavior 'cycle)
 better-defaults emacs-lisp git markdown org ruby ruby-on-rails go osx sql react c-c++ spell-checking syntax-checking version-control
 (shell :variables shell-default-shell 'eshell shell-default-height 30 shell-default-position 'bottom))

@wilfreddenton
Copy link

I'm running into the same issue. I have very little experience with emacs and elisp and I'm wondering how I can disable clean-aindent-mode.

@db47h
Copy link
Contributor

db47h commented Jan 11, 2017

Looks like some hook on post-command-hook interferes with clean-aindent-mode's own hook. A fix would be to force clean-aindent-mode to be loaded last (or at least after the conflicting package). Since I don't know how to change the loading order (nor did I bother to identify the conflicting package), I went for the quick and dirty fix: remove then add again clean-aindent-mode's hook in dotspacemacs/user-config

In your ".spacemacs" file:

(defun dotspacemacs/user-config ()
  (remove-hook 'post-command-hook 'clean-aindent--check-last-point)
  (add-hook 'post-command-hook 'clean-aindent--check-last-point))

Further investigation is still needed though: what about that conflicting package? What side effects will this have on it?

jqmtor added a commit to jqmtor/dotfiles-legacy that referenced this issue Mar 8, 2017
The issue appears to be conflicting configurations between
clean-aindent-mode and a go-mode post-command hook. This is meant to be a
temporary solution and should be removed as soon as the underlying issue
is solved.

Issue: syl20bnr/spacemacs#6520
@dyxu
Copy link

dyxu commented Jun 5, 2017

@wilfreddenton add (clean-aindent-mode -1) to user-config to disable clean-aindent-mode:
(defun dotspacemacs/user-config () (clean-aindent-mode -1))

@chriskaukis
Copy link
Contributor

Won't @dyxu suggestion also affect other languages though? I also code a lot of C, Perl, Python, Ruby, Bash for example and I don't want to disrupt those settings.

Is there a plan to fix this issue or dive into it more? For now I'm using @db47h suggestion as it seems to work from what I have tested.

junhuihuang added a commit to junhuihuang/.spacemacs that referenced this issue Nov 20, 2017
Dummyc0m referenced this issue in Dummyc0m/dotfiles-old Jul 9, 2018
@igor-kupczynski
Copy link
Contributor

igor-kupczynski commented Dec 19, 2018

FWIIW I also have this issue

The following snippet does it for me:

(defun dotspacemacs/user-config ()
  ;; Workaround for https://github.com/syl20bnr/spacemacs/issues/6520
  ;;  seems that aindent mode conflicts with go-mode
  (defun disable-aindent()
      (clean-aindent-mode -1))
  (add-hook 'go-mode-hook 'disable-aindent)
  ;; (...)
)

It disables clean-aindent-mode only for go-mode buffers (or so I hope). Frankly I don't really understand what does clean-aindent-mode do and if I really need it anywhere else.

The suggestion around removing and adding 'clean-aindent--check-last-point doesn't work for me.

System Info 💻

  • OS: gnu/linux
  • Emacs: 26.1
  • Spacemacs: 0.300.0
  • Spacemacs branch: develop (rev. 5b2e969)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(helm asciidoc
      (auto-completion :variables auto-completion-enable-help-tooltip t :disabled-for markdown org)
      docker emacs-lisp epub git
      (go :variables godoc-at-point-function 'godoc-gogetdoc)
      html javascript lua markdown neotree
      (org :variables org-enable-github-support t)
      pdf python ranger
      (shell :variables shell-default-height 30 shell-default-position 'bottom)
      spacemacs-org spell-checking sql syntax-checking systemd theming version-control yaml)
  • System configuration features: XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 MODULES THREADS XWIDGETS LIBSYSTEMD LCMS2

@smile13241324
Copy link
Collaborator

I have tried to fix the related issue from xabbu42. For this I have made sure that the fix from db47h is applied when a mode is activated and if clean-aindent-mode is active.

However this does not fix the problem @en reported. Here I see a lot of strange behaviour i.e. when I reproduce the issue and leave insert mode at the ) then go up to ( in command mode and enter insert, then leave it again, set the cursor back to ) and then add one line above with C-o O it just works.

Here I am at my wits end, clean-aindent-mode is a global minor mode which does not allow to be disabled for go-mode only. Just changing the order of execution for post-command processing does not help either. Right now our best bet would be to either disable the package globally in the user-config or open a bug upstream.

@xshyne88
Copy link

xshyne88 commented Mar 4, 2020

I've had more success licking my elbow than I have turning this stupid mode off in golang mode. It's super frustrating.

  (add-hook 'go-mode 'clean-aindent-mode-hook)
  (clean-aindent-mode -1)

this was working and now randomly it stopped and I'm back to terrible indenting whenever I write a simple if err != nil statement which in golang is every 3rd line or whenever you blink, whichever comes first.

None of these solutions work for me - I've tried just about everything I can think of including loading the package in last and then trying to disable it. My favorite part about being frustrated by a spacemacs package is that when you delete it, spacemacs auto defaults to reinstalling it when you reload or the other bonus feature when you want a new package that isn't specifically listed in additional packages spacemacs courteously removes it for you.

TLDR -
Only possible solution is to add it to

   dotspacemacs-excluded-packages '(clean-aindent-mode)

@smile13241324
Copy link
Collaborator

@xshyne88 lol sounds like you had a real bad hair day :).

Let's see if I can help disabling the package this should be pretty easy, in your user-config just add (clean-aindent-mode -1) this will disable the mode globally.

Every other hack like adding hocks won't work due to the fact that this mode has been defined as global minor mode which literally means there is no event you can wait for to activate it in one and deactivate it in another mode. Having artificially added hocks for that mode will randomly activate it so please remove them from your config if they are there.

Anyway the good news is that mode is so old it should be pretty obsolete nowadays so disabling it globally should not have any negative side effects given your package is using a modern indentation model.

Btw: You can customise the default package clean up behaviour by setting dotspacemacs-install-packages 'used-but-keep-unused, this will prevent spacemacs from removing any package from your system which you have wildly installed. About excluding packages you are right, the only way to exclude a managed package is to put it in dotspacemacs-additional-packages.

Hope that helps.

@xshyne88
Copy link

@smile13241324
Thanks for your help, time and demonstrated patience.

As much as I dislike spacemacs and it keeps beating me up, I still can't switch or give it up like a bad domestic abuse relationship because I keep remembering all the good time and it's literally just the best editor.

@xshyne88 lol sounds like you had a real bad hair day :).

Part of my post is a rant but also self deprecating humor which I always thought developers loved. However I did mention in my post above that (clean-aindent-mode -1) is clearly not working for me.

Anyway the good news is that mode is so old it should be pretty obsolete nowadays so disabling it globally should not have any negative side effects given your package is using a modern indentation model.

The point was also to mention I'm sad to do this, I want to use solid packages like these in other modes. I'm sure it serves a good purpose, but right now I'm a golang developer and that's what I'm trying to figure out how to optimize. My short term > My long term, that's probably why I can't stop eating these free doughnuts at the office in the morning.

Every other hack like adding hocks won't work due to the fact that this mode has been defined as global minor mode which literally means there is no event you can wait for to activate it in one and deactivate it in another mode. Having artificially added hocks for that mode will randomly activate it so please remove them from your config if they are there

Global minor mode was not inside my brain until just now, maybe I should have combed the docs a little better.

Btw: You can customise the default package clean up behaviour by setting dotspacemacs-install-packages 'used-but-keep-unused, this will prevent spacemacs from removing any package from your system which you have wildly installed. About excluding packages you are right, the only way to exclude a managed package is to put it in dotspacemacs-additional-packages.

I did know about the dotspacemacs-install-packages 'used-but-keep-unused I had alluded to it above but only found it after hours of pain and torture.

Let me know if there's anyway I can help or contribute.

@smile13241324
Copy link
Collaborator

smile13241324 commented Mar 13, 2020 via email

@smile13241324
Copy link
Collaborator

@xshyne88 I have added a new setting to the dotfile dotspacemacs-use-clean-aindent-mode which when set to nil will remove clean-aindent-mode entirely.

Please sync your dotfile and give it a try.
If this finally solves your issue please close this one.

@smile13241324 smile13241324 removed their assignment Mar 13, 2020
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Bug tracker - Go stale marked as a stale issue/pr (usually by a bot)
Projects
None yet
Development

No branches or pull requests

10 participants