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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With