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

spacemacs/toggle-whitespace-cleanup cannot locally disable whitespace cleanup #8221

Closed
jakemcarthur opened this issue Jan 20, 2017 · 20 comments · Fixed by #16551
Closed

spacemacs/toggle-whitespace-cleanup cannot locally disable whitespace cleanup #8221

jakemcarthur opened this issue Jan 20, 2017 · 20 comments · Fixed by #16551

Comments

@jakemcarthur
Copy link

jakemcarthur commented Jan 20, 2017

Description :octocat:

spacemacs/toggle-whitespace-cleanup cannot locally disable whitespace cleanup

Reproduction guide 🪲

  • Set dotspacemacs-whitespace-cleanup to all and reload.
  • Open a file and add some trailing whitespace.
  • spacemacs/toggle-whitespace-cleanup-off
  • save-buffer

Observed behaviour: 👀 💔
The trailing whitespace is removed.

Expected behaviour: ❤️ 😄
The trailing whitespace is not removed.

System Info 💻

  • OS: gnu/linux
  • Emacs: 25.1.2
  • Spacemacs: 0.200.7
  • Spacemacs branch: master (rev. c2774bc)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
((auto-completion :variables auto-completion-enable-help-tooltip t auto-completion-enable-sort-by-usage t)
 colors csv emacs-lisp
 (haskell :variables haskell-completion-backend 'intero)
 helm
 (ibuffer :variables ibuffer-group-buffers-by 'projects)
 javascript markdown ranger
 (shell :variables shell-default-shell 'eshell shell-default-height 30 shell-default-position 'bottom)
 sql syntax-checking
 (version-control :variables version-control-diff-tool 'diff-hl)
 yaml)
  • System configuration features: XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11 MODULES
@nixmaniack
Copy link
Contributor

nixmaniack commented Jan 21, 2017

Well - it is expected behaviour based on value of dotspacemacs-whitespace-cleanup.
If it's nil, even if you enable whitespace-cleanup locally for the buffer - the cleanup function doesn't know how to cleanup trailing whitespace i.e. whether to cleanup all, trailing or just changed and hence it doesn't cleanup anything.

What you can do currently is: set dotspacemacs-whitespace-cleanup to your expected behaviour i.e. all, trailing or changed and then toggle it (off) globally with SPC t C-S-w [(spacemacs/toggle-global-whitespace-cleanup)] and then you can turn on/off for individual buffers.


May be we can improve this by having default local/global value specified in case the value is nil so that if user invokes this functionality we're able to set it up appropriately. Open to discussion.

@jakemcarthur
Copy link
Author

jakemcarthur commented Jan 23, 2017

My desire is for it to be on by default and off for specific buffers. It seems wrong that I can't toggle it off per-buffer when I set it to all. I accept that I would have to follow the procedure you outlined to do the opposite (off by default and on for specific buffers), so that part of my original bug report should probably be removed (edit: I just did this).

@jakemcarthur jakemcarthur changed the title spacemacs/toggle-whitespace-cleanup does not work spacemacs/toggle-whitespace-cleanup cannot locally disable whitespace cleanup Jan 23, 2017
@nixmaniack
Copy link
Contributor

This looks like an issue then. I might look into it if I find some time later this weekend.

@liweitianux
Copy link

Hello,

I can reproduce this issue. I have dotspacemacs-whitespace-cleanup set to trailing, which adds the delete-trailing-whitespace to the global hook before-save-hook. For example, my Spacemacs has before-save-hook: (delet-trailing-whitespace spacemacs//python-sort-imports).

Then, when I try to locally disable the whitespace cleanup for a buffer by SPC t W (i.e., spacemacs/toggle-whitespace-cleanup), which basically executes (remove-hook 'before-save-hook 'delete-trailing-whitespace t). However, this fails because there is NO local hook before-save-hook from which to remove the function delete-trailing-whitespace.

Cheers,
Aly

@asok
Copy link
Contributor

asok commented Jun 7, 2017

I have a similar issue on develop. I have the variable dotspacemacs-whitespace-cleanup set to 'trailing.
In the markdown mode I'm unable to have double space at the end of a line (which is a line break in markdown).

After doing M-x eval-expression RET (remove-hook 'before-save-hook 'delete-trailing-whitespace) RET I'm able to save the trailing whitespaces. But after doing some edits to the buffer and saving those spaces get deleted again (funny enough before-save-hook does not hold delete-trailing-whitespace anymore).

@planigan
Copy link
Contributor

planigan commented Aug 1, 2017

I've been struggling to figure out how to stop suppressing trailing whitespace in markdown in spacemacs. Turns out that I had set up editorconfig to do this before I found the option in the spacemacs config. I set dotspacemacs-whitespace-cleanup nil and am just letting editorconfig handle it now. The following basic ~/.editorconfig will clean up trailing whitespace everywhere other than markdown files if you add the editorconfig package in your config.

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

@KMontag42
Copy link

I am still having this issue. Is there any update on it being fixed?

@chshersh
Copy link

I'm observing this issue as well. Toggling any of whitespace-cleanup hooks/actions/variables doesn't work. I'm editing code from another editor when I don't want to introduce whitespace changes.

@treymerkley
Copy link
Contributor

can confirm this issue is still present.

@usq
Copy link

usq commented Dec 17, 2019

same issue here, have to switch to vim for whitespace changes 😢

@lestercheung
Copy link

I've been struggling to figure out how to stop suppressing trailing whitespace in markdown in spacemacs. Turns out that I had set up editorconfig to do this before I found the option in the spacemacs config. I set dotspacemacs-whitespace-cleanup nil and am just letting editorconfig handle it now. The following basic ~/.editorconfig will clean up trailing whitespace everywhere other than markdown files if you add the editorconfig package in your config.

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

Came here to say this - It was editorconfig for me as well. 😆

catesandrew added a commit to catesandrew/dotemacs that referenced this issue Dec 7, 2020
syl20bnr/spacemacs#8221

toggle-whitespace-cleanup cannot locally disable whitespace cleanup

When I had `dotspacemacs-whitespace-cleanup` set to `trailing`, it would add the
`delete-trailing-whitespace` to the **global** hook `before-save-hook`. For
example, my Spacemacs has `before-save-hook`: `(delet-trailing-whitespace
spacemacs//python-sort-imports)`.

Then, when I try to **locally** disable the whitespace cleanup for a buffer by
`SPC t W` (i.e., `spacemacs/toggle-whitespace-cleanup`), which basically
executes `(remove-hook 'before-save-hook 'delete-trailing-whitespace t)`.
However, this fails because there is NO **local** hook `before-save-hook` from
which to remove the function `delete-trailing-whitespace`.
@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 Oct 17, 2021
@GiovanH
Copy link

GiovanH commented Dec 31, 2021

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!

I don't see any reason to think this issue has been fixed.

@lebensterben
Copy link
Collaborator

@GiovanH
Is this still an issue on develop?

@practicalli-johnny
Copy link
Contributor

I can confirm this issue on the latest commit of Spacemacs (as of today - 6ccbbcc7d develop origin/develop gnux: fix which-key prefix bug)

I add a whitespace at the end of a line in a yasnippet file I created.
SPC SPC spacemacs/toggle-whitespace-cleanup
SPC f s to save the file which then removes all whitespace from end of lines in the snippet buffer

The following seems to have no effect, as whitespace was still deleted

M-x eval-expression RET (remove-hook 'before-save-hook 'delete-trailing-whitespace) 
Spacemacs configuration SPC h d s

System Info 💻

  • OS: gnu/linux
  • Emacs: 27.1
  • Spacemacs: 0.999.0
  • Spacemacs branch: develop (rev. 6ccbbcc)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(asciidoc
 (auto-completion :variables auto-completion-enable-help-tooltip t auto-completion-enable-snippets-in-popup t auto-completion-enable-sort-by-usage t auto-completion-use-company-box t)
 (clojure :variables cider-repl-display-help-banner nil cider-pprint-fn 'fipp clojure-indent-style 'align-arguments clojure-align-forms-automatically t clojure-toplevel-inside-comment-form t cider-overlays-use-font-lock t cider-repl-buffer-size-limit 100 clojure-enable-kaocha-runner t)
 colors command-log csv emacs-lisp emoji
 (git :variables git-magit-status-fullscreen t magit-diff-refine-hunk t git-enable-magit-todos-plugin t)
 github graphviz
 (helm :variables helm-follow-mode-persistent t)
 html javascript
 (json :variables js-indent-level 2 json-backend 'lsp)
 (lsp :variables lsp-enable-on-type-formatting t lsp-enable-indentation t lsp-enable-snippet nil lsp-enable-symbol-highlighting t lsp-ui-doc-enable t lsp-ui-doc-show-with-cursor nil lsp-ui-doc-show-with-mouse nil lsp-ui-doc-delay 1 lsp-ui-doc-include-signature t lsp-ui-sideline-enable nil lsp-ui-sideline-show-code-actions nil lsp-lens-enable t treemacs-space-between-root-nodes nil lsp-file-watch-threshold 10000 lsp-log-io nil)
 (markdown :variables markdown-live-preview-engine 'vmd)
 multiple-cursors
 (org :variables org-enable-github-support t org-enable-bootstrap-support t org-enable-reveal-js-support t org-want-todo-bindings t org-enable-org-journal-support t org-journal-dir "~/projects/journal/" org-journal-file-format "%Y-%m-%d" org-journal-date-prefix "#+TITLE: " org-journal-date-format "%A, %B %d %Y" org-journal-time-prefix "* " org-journal-time-format "" org-journal-carryover-items "TODO=\"TODO\"|TODO=\"DOING\"|TODO=\"BLOCKED\"|TODO=\"REVIEW\"")
 (ranger :variables ranger-show-preview t ranger-show-hidden t ranger-cleanup-eagerly t ranger-cleanup-on-disable t ranger-ignored-extensions
         '("mkv" "flv" "iso" "mp4"))
 (shell :variables shell-default-shell 'eshell shell-default-height 30 shell-default-position 'bottom)
 (spacemacs-layouts :variables spacemacs-layouts-restrict-spc-tab t persp-autokill-buffer-on-remove 'kill-weak)
 (spacemacs-modeline :variables doom-modeline-height 12 doom-modeline-major-mode-color-icon t doom-modeline-buffer-file-name-style 'relative-to-project doom-modeline-display-default-persp-name t doom-modeline-minor-modes nil doom-modeline-modal-icon nil)
 spell-checking
 (syntax-checking :variables syntax-checking-use-original-bitmaps t)
 (treemacs :variables treemacs-indentation 1 treemacs-use-git-mode 'simple)
 theming
 (unicode-fonts :variables unicode-fonts-enable-ligatures t unicode-fonts-ligature-modes
                '(prog-mode))
 (version-control :variables version-control-diff-tool 'diff-hl version-control-global-margin t)
 yaml)
  • System configuration features: XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY INOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD JSON PDUMPER LCMS2 GMP

@lebensterben lebensterben added Help wanted and removed stale marked as a stale issue/pr (usually by a bot) labels Jan 19, 2022
@borup3
Copy link

borup3 commented Mar 24, 2022

How does this go unresolved for 5 years?

@lebensterben lebensterben self-assigned this Mar 24, 2022
Copy link

github-actions bot commented May 1, 2024

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 May 1, 2024
@dwang20151005
Copy link
Contributor

dwang20151005 commented May 1, 2024 via email

@github-actions github-actions bot removed the stale marked as a stale issue/pr (usually by a bot) label May 1, 2024
@johbo
Copy link

johbo commented Aug 19, 2024

Just did bump into this as well I think. Did want to switch off the removal of trailing whitespace for a specific butter, but without success. My dotspacemacs-whitespace-cleanup is set to trailing.

In my case I've not found a way (yet) to disable the whitespace removal at all. Both spacemacs/toggle-gobal-whitespace-cleanup-off and spacemacs/toggle-whitespace-cleanup-off do not seem to have an effect.

@fnussbaum
Copy link
Contributor

I will fix this.

fnussbaum added a commit to fnussbaum/spacemacs that referenced this issue Sep 2, 2024
Fixes syl20bnr#8221.

The previous implementation had a non-standard structure that made it difficult
to correctly implement toggling the minor mode locally and globally. Hence this
commit rewrites the enabling/disabling mechanisms of the minor mode. Both local
and global toggling with `SPC t W` and `SPC t C-S-w` should now work correctly.

As `ws-butler-global-mode` is not used anymore, users that customized
`ws-butler-global-exempt-modes` need to customize
`global-spacemacs-whitespace-cleanup-modes` instead. The default values are
equivalent: `markdown-mode` is excluded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.