Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs started adding extra tabs in when I paste into it on OS X

Tags:

emacs

This always worked fine before, but all of a sudden when I paste into emacs from somewhere else on OS X (using cmd-c cmd-v), I get a bunch of extra spaces/tabs. Example, say I have the following YML:

- name: something
  hosts: some_host
  gather_facts: False

  tasks:

    - name: do something
      some_module:
        group: something

When I copy that and then paste it into emacs, it's suddenly formatted:

- name: something
    hosts: some_host
      gather_facts: False

        tasks:

              - name: do something
                      some_module:
                                  group: something

It looks like it's double the number of spaces on every line. I've tried this in both yaml-mode and fundamental mode. Everything used to work fine. What gives?

like image 618
Eli Avatar asked Jan 02 '15 00:01

Eli


People also ask

Does X Copy and paste work with Emacs?

X copy and paste support has historically been a mess. This is relevant, as Emacs supports the various aspects of this mess. Important for this discussion is the understanding that X generally distinguishes between two types of selection, the PRIMARY and the CLIPBOARD.

How do I copy and kill text in Emacs?

This is because in Emacs, when you cut or copy text, it is sent directly to the top of the kill-ring. The kill-ring is basically a list containing the previously killed (cut) blocks of text. To copy or kill text in Emacs, you must first select the text. This is done by using the selection command Ctrl + Space.

How do I indent with spaces instead of tabs in Emacs?

If you want to use spaces instead of tabs when indenting, put the following in your .emacs file: (setq-default indent-tabs-mode nil) You may also customize the ‘indent-tabs-mode’ variable instead, obviously. If you want to remove tabs in an existing file, mark the whole buffer using C-x h and use M-x untabify.

What is tab-width in Emacs?

Do not confuse this with tab-width, which is only good for displaying existing tabs in files! The tab-width variable tells Emacs how wide a tab is (more precisely, the distance between tab stops). You might want to set it to something other than 8 before calling M-x untabify.


1 Answers

OK, this is very weird. It looks like this happened because I updated emacs to 24.4 (I was updating a lot of stuff through homebrew and didn't notice). Turns out this is possibly somehow a "feature," though how is beyond me. You can disable it by adding (electric-indent-mode 0) to your .emacs. More info here.

like image 120
Eli Avatar answered Oct 19 '22 17:10

Eli