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

nim layer: indentation is broken on paste #13470

Closed
yglukhov opened this issue Apr 10, 2020 · 4 comments
Closed

nim layer: indentation is broken on paste #13470

yglukhov opened this issue Apr 10, 2020 · 4 comments

Comments

@yglukhov
Copy link

Description :octocat:

nim layer: indentation is broken on paste

Reproduction guide 🪲

  • Start Emacs
  • Open any test.nim file
  • Type in the following
proc foo() =
  echo "foo"
proc bar() =
  echo "bar"
  • Press gg to go to start and press y3j to yank
  • Press 3j to to go to start of line 4
  • Press p to paste. Observe the result.

Observed behaviour: 👀 💔

proc foo() =
  echo "foo"
proc bar() =
  echo "bar"
  proc foo() =
    echo "foo"
    proc bar() =
      echo "bar"

Expected behaviour: ❤️ 😄

proc foo() =
  echo "foo"
proc bar() =
  echo "bar"
proc foo() =
  echo "foo"
proc bar() =
  echo "bar"

System Info 💻

  • OS: gnu/linux
  • Emacs: 26.3
  • Spacemacs: 0.300.0
  • Spacemacs branch: develop (rev. c3f13d0)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(helm auto-completion emacs-lisp org nim python git shell html restructuredtext)
  • System configuration features: XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS GLIB NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD LCMS2

Backtrace 🐾

<<BACKTRACE IF RELEVANT>>
@duianto
Copy link
Collaborator

duianto commented Apr 17, 2020

Confirmed.
After pasting: p, then the minibuffer shows:

Indenting region...done

Cause

By default Spacemacs advices the yank and evil-paste functions to call spacemacs//yank-indent-region:

(dolist (func '(yank yank-pop evil-paste-before evil-paste-after))
(advice-add func :around #'spacemacs//yank-indent-region))

Solution

The docstring for spacemacs//yank-indent-region says:

(defun spacemacs//yank-indent-region (yank-func &rest args)
"If current mode is not one of spacemacs-indent-sensitive-modes
indent yanked text (with universal arg don't indent)."

Which means that if nim-mode is added to the spacemacs-indent-sensitive-modes variable, then it will be excluded from being indented when pasting.

It can be done now from the dotspacemacs/user-config section with:

(add-to-list 'spacemacs-indent-sensitive-modes 'nim-mode)

or if the nim layer shouldn't indent by default, then that line can be added in a PR to the
nim/init-nim-mode functions :init section:

(defun nim/init-nim-mode ()
(use-package nim-mode
:defer t
:init
(progn
(add-hook 'nim-mode-hook 'nimsuggest-mode)
(add-to-list 'spacemacs-jump-handlers-nim-mode 'nimsuggest-find-definition))

Currently spacemacs-indent-sensitive-modes contains these modes:

(asm-mode coffee-mode elm-mode haml-mode haskell-mode slim-mode makefile-mode makefile-bsdmake-mode makefile-gmake-mode makefile-imake-mode python-mode yaml-mode)

The docstring for the spacemacs//yank-indent-region function also says:

(with universal arg don't indent)

which means that if one only want to stop the automatic indentation sometimes when pasting, then one can press: SPC u p

Result

The expected behavior is observed when either:

  • nim-mode is added to the spacemacs-indent-sensitive-modes variable
  • or when pasting with SPC u p
proc foo() =
  echo "foo"
proc bar() =
  echo "bar"
proc foo() =
  echo "foo"
proc bar() =
  echo "bar"
Windows 1903
#### System Info :computer:
- OS: windows-nt
- Emacs: 26.3
- Spacemacs: 0.300.0
- Spacemacs branch: develop (rev. 0a7ab7873)
- Graphic display: t
- Distribution: spacemacs
- Editing style: vim
- Completion: helm
- Layers:
```elisp
(autohotkey
 (auto-completion :variables auto-completion-enable-help-tooltip t auto-completion-enable-snippets-in-popup t)
 command-log dap emacs-lisp git helm helpful html imenu-list javascript
 (markdown :variables markdown-live-preview-engine 'vmd markdown-command "vmd")
 multiple-cursors nim
 (org :variables org-agenda-files
      '("~/org/notes.org"))
 (shell :variables shell-default-shell 'shell shell-default-height 30 shell-default-position 'bottom)
 spell-checking
 (syntax-checking :variables syntax-checking-enable-by-default nil)
 treemacs version-control)
```
- System configuration features: XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS THREADS LCMS2

@yglukhov
Copy link
Author

Which means that if nim-mode is added to the spacemacs-indent-sensitive-modes variable, then it will be excluded from being indented when pasting.

Imho it makes sense to do this by default. But I'm just a newbie with spacemacs, so don't quote me.

@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 Apr 17, 2021
@lebensterben lebensterben reopened this Aug 23, 2021
@lebensterben lebensterben removed the stale marked as a stale issue/pr (usually by a bot) label Aug 23, 2021
@lebensterben
Copy link
Collaborator

I applied the fix of @duianto in the last commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants