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

How to stop auto indent? #4219

Closed
fuzihaofzh opened this issue Dec 18, 2015 · 22 comments
Closed

How to stop auto indent? #4219

fuzihaofzh opened this issue Dec 18, 2015 · 22 comments

Comments

@fuzihaofzh
Copy link

I want to copy a pice of python code into emacs. But emacs makes it automatically to indent to make my code a mess. How can I solve the problem?

@tuhdo
Copy link
Contributor

tuhdo commented Dec 18, 2015

You can use prefix argument by pressing C-u before pasting with C-y. If you are using evil-mode, pressing SPC u before pressing p.

@syl20bnr
Copy link
Owner

The auto-indent should not happen in python buffers so I suppose you are pasting in a buffer which is not a python buffer. Is it the case ? If yes then @tuhdo answer is the way to go, if no then we have a bug.

@fuzihaofzh
Copy link
Author

I use emacs in iterm to login in a remote client. so I just use command+v to paste in iterm.

@puffnfresh
Copy link

Auto-indenting is very annoying with Nix code. I've tried using SPC u p but it has never worked for me.

@magnetophon
Copy link
Contributor

SPC u p doesn't work in Nix code.

System Info

  • OS: gnu/linux
  • Emacs: 24.5.2
  • Spacemacs: 0.105.4
  • Spacemacs branch: master (rev. df8eb1b)
  • Distribution: spacemacs
  • Layers:
(auto-completion erc emacs-lisp extra-langs eyebrowse fasd git github markdown nixos org ranger search-engine spell-checking syntax-checking version-control)

@dlukes
Copy link

dlukes commented Feb 6, 2016

I use emacs in iterm to login in a remote client. so I just use command+v to paste in iterm.

+ 1, I experience the same behavior -- pasting in a Python buffer results in the contents of the clipboard being auto-indented beyond recognition.

@shakerlxxv
Copy link

+1 I'm pasting a bit of SQL into a SQL file and seeing similar "flattened" results after pasting. I'm in evil mode, trying SPC-u p doesn't change the result.

@aldanor
Copy link

aldanor commented Jun 23, 2016

How do I do a "raw paste" in prog-mode? (or any mode in general)

SPC-u p just results in Wrong type argument: number-of-marker-p, (4) error, or Wrong type argument: nump, (4).

Are the docs outdated / not working? It sure looks like it based on the replies here.

(latest develop branch, evil mode)

@laMudri
Copy link

laMudri commented Jul 2, 2016

I seem to have the same problem in Agda and Nix code. Any pasted lines are indented to the indentation level of the previous non-empty line. Python does no indentation (as wanted).

@aldanor
Copy link

aldanor commented Jul 4, 2016

Do any spacemacs gurus know the answer? 😉

@yashi
Copy link

yashi commented Jul 10, 2016

Just curious. I don't use spacemacs nor i-something, but are you all using spacemacs under some terminal emulator? And copy from something and past it on the terminal? If so, emacs can't distinguish pasted enter and key input enter and electric-indent kicks in.

What you can do is to disable electric indent with M-x electric-indent-mode. Past whatever you want, and do M-x electric-indent-mode again to re-enable it.

Hope this helps.

@laMudri
Copy link

laMudri commented Jul 10, 2016

@yashi, no, I'm using graphical Emacs (GNU/Linux). I'm also using Evil's paste, rather than sending keystrokes, so I would be surprised if that were the problem. The problem also occurs with electric-indent-mode disabled.

@aldanor
Copy link

aldanor commented Jul 11, 2016

I'm also using graphical Emacs (Mac). Can confirm, the problem occurs with electric indent disabled too.

@eskimor
Copy link

eskimor commented Jul 28, 2016

Same problem here, also GUI, disabling electric indent does not work. Switching to fundamental mode from nix-mode, does help though! :-) yeah!

@mosic
Copy link
Contributor

mosic commented Aug 23, 2016

I encountered this problem today when working in elixir-mode. I found the item in the docs which describes how to change the pasting behaviour: DOCUMENTATION.org#auto-indent-pasted-text

This is what I added to my .spacemacs file to make it work:

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

@clhodapp
Copy link

clhodapp commented Sep 9, 2016

(spacemacs|advise-commands

Spc-u 4 p actually does paste four times without autoindention. Fun.

@clhodapp
Copy link

clhodapp commented Sep 10, 2016

Proposal: replace both with a single working version:

(spacemacs|advise-commands
 "indent" (yank yank-pop evil-paste-before evil-paste-after) around
 "If current mode is not one of spacemacs-indent-sensitive-modes
 indent yanked text (with universal arg don't indent)."
 (let ((prefix (ad-get-arg 0)))
     (ad-set-arg 0 (unless (equal '(4) prefix) prefix))
     (evil-start-undo-step)
     ad-do-it
     (if (and (not (equal '(4) prefix))
                        (not (member major-mode spacemacs-indent-sensitive-modes))
                        (or (derived-mode-p 'prog-mode)
                                (member major-mode spacemacs-indent-sensitive-modes)))
             (let ((transient-mark-mode nil)
                         (save-undo buffer-undo-list))
                 (spacemacs/yank-advised-indent-function (region-beginning)
                                                                                                 (region-end))))
     (evil-end-undo-step)
     (ad-set-arg 0 prefix)))

@Blaisorblade
Copy link
Contributor

With SPC u p I also get the following warnings:

ad-Advice-evil-paste-after: Wrong type argument: number-or-marker-p, (4) [2 times]
evil-yank-line-handler: Wrong type argument: wholenump, (4)

@Blaisorblade
Copy link
Contributor

@clhodapp Since you seem to have found a solution, is there any chance you could send a pull request?

@aviggiano
Copy link

I'm still having this issue
@mosic Could you please post your dotfile with the appropriate code for the SQL layer? I tried to generalize your elixir piece of code but it didn't work

@henriquenj
Copy link
Contributor

@aviggiano You can disable auto-indent on p altogether using the spacemacs-indent-sensitive-modes variable. You can select this behaviour on a per-mode basis. If you think that is good for your workflow, here is the code for sql-mode:

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

Just put into your dotspacemacs/user-config

bet4it added a commit to bet4it/spacemacs that referenced this issue Sep 19, 2018
bet4it added a commit to bet4it/spacemacs that referenced this issue Oct 28, 2018
bet4it added a commit to bet4it/spacemacs that referenced this issue Oct 28, 2018
bet4it added a commit to bet4it/spacemacs that referenced this issue Nov 5, 2018
pritambaral added a commit to pritambaral/spacemacs that referenced this issue Jan 17, 2019
The auto-indent advice around evil-paste-{before,after} calls the advised funcs
without removing the universal argument. This results in errors like:

ad-Advice-evil-paste-before: Wrong type argument: number-or-marker-p, (4)

and, ultimately, in the paste failing.

This checks for the universal argument *before* calling the advised funcs,
adjusting the args to remove the universal argument.

Fixes syl20bnr#4219
Fixes syl20bnr#8897
duianto pushed a commit that referenced this issue Apr 25, 2019
@duianto
Copy link
Contributor

duianto commented Aug 8, 2019

This PR has been merged:
Check for universal argument before paste #11340

It superseeded this PR:
Fix pasting with universal argument #11858
which is marked as fixing this issue.

@duianto duianto closed this as completed Aug 8, 2019
stephanschubert pushed a commit to stephanschubert/spacemacs that referenced this issue Oct 23, 2019
sei40kr pushed a commit to sei40kr/spacemacs that referenced this issue Nov 11, 2019
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