4

When I copy some text into a buffer in Fundamental mode, from some website opened in Firefox, there are always some unnecessary indents.

For example, from https://github.com/hakimel/reveal.js/, I selected and copied some text by Ctrl+c, and pasted it into a buffer in emacs running in a terminal.

PDF Export

Presentations can be exported to PDF via a special print stylesheet. This feature requires that you use Google Chrome. Here's an example of an exported presentation that's been uploaded to SlideShare: http://www.slideshare.net/hakimel/revealjs-300.

    Open your presentation with print-pdf included anywhere in the query string. This triggers the default index HTML to load the PDF print stylesheet (css/print/pdf.css). You can test this with lab.hakim.se/reveal-js?print-pdf.
    Open the in-browser print dialog (CMD+P).
    Change the Destination setting to Save as PDF.
    Change the Layout to Landscape.
    Change the Margins to None.
    Click Save.

The text in the buffer becomes:

PDF Export

Presentations can be exported to PDF via a special print stylesheet. This feature requires that you use Google Chrome. Here's an example of an exported presentation that's been uploaded to SlideShare: http://www.slideshare.net/hakimel/revealjs-300.

    Open your presentation with print-pdf included anywhere in the query string. This triggers the default index HTML to load the PDF print stylesheet (css/print/pdf.css). You can test this with lab.hakim.se/reveal-js?print-pdf.
        Open the in-browser print dialog (CMD+P).
            Change the Destination setting to Save as PDF.
                Change the Layout to Landscape.
                    Change the Margins to None.
                        Click Save.

How can I avoid the unnessary indents? Thanks.

I installed GNU Emacs 24.4.1 from its official site, a few days ago, without having made any change to personal configuration. The mode is Fundamental. I don't know it uses some minor mode.

enter image description here


When I copy from a website opened in Chrome:

Presentations can be exported to PDF via a special print stylesheet. This feature requires that you use Google Chrome. Here's an example of an exported presentation that's been uploaded to SlideShare: http://www.slideshare.net/hakimel/revealjs-300.

Open your presentation with print-pdf included anywhere in the query string. This triggers the default index HTML to load the PDF print stylesheet (css/print/pdf.css). You can test this with lab.hakim.se/reveal-js?print-pdf.

Open the in-browser print dialog (CMD+P).
Change the Destination setting to Save as PDF.
Change the Layout to Landscape.
Change the Margins to None.
Click Save.

enter image description here


I agree the problem is browser dependent (notice how different the selected regions are in the two browsers, see the pictures), but it is also emacs dependent, since emacs can't handle tab without inheriting tabs from previous line.

Tim
  • 4,987
  • 7
  • 31
  • 60
  • I don't have an answer but a reason why: "Pasting" in a terminal is not like pasting normally, it is actually more like executing a keyboard macro. In this case newlines are autoindenting like they would if you were typing, and then the tabs are beings inserted in already indented lines. You might also notice this if you use key-chords, ie. if you have a `ea` key-chord, then pasting the word `each` will execute it. Because of this, I use my own paste function in terminal that just runs: `(insert (shell-command-to-string "pbpaste -Prefer txt")))` which works on my osx system. – Jordon Biondo Mar 16 '15 at 00:47
  • What happens if you just press return in a buffer with newline mode? If it indents then, you might have been hit by a bug. Check the value of indent-line-function. – Meaningful Username Mar 16 '15 at 11:21
  • the next line will inherit the indent of the current line. @MeaningfulUsername. Don't know how to check the value of indent-line-function. – Tim Mar 16 '15 at 12:09
  • C-h v indent-line-function. It doesn't seem you're hit by the bug I was thinking of, since then it would keep on indenting. It was the stair like appearance of your example I recognized. – Meaningful Username Mar 16 '15 at 12:21
  • its value is indent-relative. @MeaningfulUsername. Does it explain my problem? – Tim Mar 16 '15 at 12:29
  • No, that's what it should be. – Meaningful Username Mar 16 '15 at 14:14
  • what does indent-relative mean? @Meaning – Tim Mar 16 '15 at 14:16
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/21985/discussion-between-meaningful-username-and-tim). – Meaningful Username Mar 16 '15 at 16:09
  • See also https://emacs.stackexchange.com/questions/28008/how-do-i-paste-code-without-auto-indentation – Max Ghenis Dec 23 '19 at 04:57

2 Answers2

3

From https://emacs.stackexchange.com/a/14307/120

Emacs ≥24.4

In Emacs 24.4, Electric Indent mode is switched on by default. It's a global minor mode, so you can turn it off everywhere by calling (electric-indent-mode 0) and you can toggle it interactively with M-x electric-indent-mode RET.

You can find this information in the manual, or by looking at the documentation of the command invoked by pressing Return (press C-h k RET).

You can turn it on in a specific buffer with electric-indent-local-mode. Some programming modes (especially third-party ones) may have their own automatic indentation features that don't follow the settings of Electric Indent mode.

Tim
  • 4,987
  • 7
  • 31
  • 60
  • 1
    Disabling electric indent mode also stops indenting when hitting Enter from a given line. Is there a way to preserve auto-indentation from a line, while keeping indentation as-is when pasting? – Max Ghenis Dec 19 '19 at 06:38
1

Well, it's not happening with my emacs (GNU Emacs 23.4.1, started with emacs -q -nw, emacs -q, or for that matter, emacs).

But I remember running into that one. Either with an older version or with some minor mode or variable. I just can't remember which ...

Does it act the same if you start with emacs -q -nw? (If so, what's your emacs version?) If not, it's time to check your configs.

ETA: Hang on, I've managed to reproduce it. Or something like it. If I copy a text with two leading tabs on consecutive lines, I get the jigsaw. The text you indicated, didn't copy that way from my Firefox.

Browser dependent issue, or a different issue with similar symptoms? That is, are you seeing double tabs being copied?

Though, looking at your pasted text, it looks like a single tab all the way. And if "the next line will inherit the indent of the current line" after just a newline, it sure behaves differently from mine.

Perhaps I should shut up until I find a version 24.4.1 to try …

The Sidhekin
  • 111
  • 1
  • 1
  • 3