How can I disable emacs delete-selection-mode - emacs

Emacs's Delete-selection-mode, modern as it feels, makes it too easy to inadvertently delete code. Thus, I would like it disabled by default. Therefore, I added
(delete-selection-mode f)
to my init.el file but that had no effect. By which I mean, if I highlight a region and type something, the contents of the selection are replaced with the new typing. I also tried toggling the mode with M-x delete-selection-mode command, but that had no effect. I use Emacs 24.1.1 on Windows7, Mac and Linux. What am I missing, is there some other mode or variable that I should be enabling instead?

delete-selection-mode is set by default when CUA mode is enabled, but it can be disabled via M-x customize. CUA settings are a subgroup of the "Editing Basics" subgroup of the top-level "Editing" group. To disable delete-selection mode, use the Value Menu of the "Cua Delete Selection" item and change the setting to Disabled. This will place the following line among the custom-set-variables defined in your .emacs or init.el file: (cua-delete-selection nil). After this has been set, actions such as cut with C-w or pressing the delete key will continue to operate normally on regions.

Related

Emacs 24.5 , CUA mode. Not paste text in the minibuffer

In Windows 7 / Emacs 24.5
Copy text e.g. "example" in the kill-ring
M-x
C-y (yank)
Success show text "example" in the minibuffer
But if turn on CUA-mode, the text "example" not yank (paste) by 'C-v' in the minibuffer.
CUA mode makes C-v the yank/paste command.
If you start Emacs with :
emacs -Q
Then turn on CUA mode (M-x cua-mode) you'll see that C-v works as you expect.
Without knowing your setup it's difficult to be sure but it's likely you're using a package which modifies the behavior of M-x (E.g. smex, Ido, ivy, etc.)
It's likely CUA mode won't really have anything to do with this problem. You can verify this by trying to do C-y to yank in the minibuffer too.
Packages which enhance M-x may provide a way to allow you to drop out temporarily, so you can yank text in-place.
Update
From your comments we know you are using Helm, which overrides some bindings in the minibuffer, including C-v which is bound to page down.
Because bindings are applied at different mode (context) scopes, the minibuffer modemap (list of key bindings) will override anything that's applied at a more general context (such as cua mode)
To work around this you'd need to add a binding specifically for cua-paste in the affected mode map. It would need to be applied after Helm has loaded.

Why doesn't modifying the .emacs file change the behavior of GNU Emacs?

I'm running GNU Emacs 24.3.1 on Windows 7. As mentioned in this manual page, I can type
C-x d ~/ RET
to determine the location of my home directory. In my case, Emacs returns:
e:/EmacsDocs
which, according to Windows Explorer, indeed contains a file .emacs. When I open .emacs with Emacs, the file appears to be empty.
Now, I want to set Emacs so that it is in overwrite mode by default. According to this page, that can be done by adding the following to .emacs:
(setq-default overwrite-mode t)
But when I make this change to .emacs and close and reopen Emacs, Emacs does not overwrite when I select text and start typing. (Rather, it still operates in insertion mode, with new characters inserted before the cursor.)
I also tried, for example, adding this command to .emacs, which according to this page will disable cursor blinking:
(blink-cursor-mode 0)
but again, there is no change when I restart Emacs.
How can I tell if Emacs is actually reading the .emacs in the home directory (upon restarting Emacs)?
You are confusing what Emacs calls overwrite-mode with the requested behavior "overwrite when I select text and start typing".
In Emacs, the latter behavior is called delete-selection-mode, and overwrite-mode means that when you type text (without selecting anything), any existing text that follows the cursor is overwritten by what you type.
Most Emacs users do not turn on overwrite-mode by default, and they just hit the insert key (typically to the left of the home key) to toggle `overwrite-mode on/off when they need/want to.
One way to turn on delete-selection-mode by default is to put one of the following in your init file (.emacs):
(setq delete-selection-mode t)
or
(delete-selection-mode)
Another way is to customize the option delete-selection-mode using M-x customize-option RET delete-selection-mode RET and save the customized value.
Instead of editing the file outside of Emacs, just type
C-x C-f ~/.emacs
and add your configurations there. Save with
C-x C-s
and restart. This should work, since ~ in Emacs defaults to the home directory.

How can I adjust Emacs "Spc" mode?

I have a window whose mode line at the bottom says "(Text Spc Fill)", probably as a default for *.txt filenames. "Spc" seems to be a minor mode which attempts to preserve English text by, for example, collapsing two spaces to one after a word is removed. However, I don't want that in this buffer.
So, how can I turn off this minor mode?
I don't know the actual name of the mode. I tried M-x spc-mode and M-x space-mode, and I looked through a few help pages.
More generally, is there an easy way to get the list of modes which are active in the current buffer? Or to find out about a mode given its mode-line abbreviation? (These can be unpredictable; for example, M-x visual-line-mode corresponds to (WordWrap).)
This is Aquamacs, Emacs version 23.3.50.1.
To answer your second question, the command describe-mode (C-hm) will list
your major mode, along with
some documentation (usually including keybindings), and
all of the minor modes that are active
You might be surprised how many minor modes are active in a typical setup. Not all active modes have an "indicator."
in your .emacs file add the line
(remove-hook 'text-mode-hook 'turn-on-auto-fill)
Source

Disable auto indent globally in Emacs

How to disable auto indent in Emacs globally or only for some modes?
I have a number of packages installed for RubyOnRails (ruby, html, js, css).
Let's say I want to disable autoindent for css-mode.
For me, on emacs 24.x, M-xelectric-indent-mode toggled the behavior that I wanted to disable.
FWIW, the behavior was that RET was bound to the command newline which is defined in simple.el... Among other things, the behavior of that command is altered by electric-indent-mode.
You may want to look for variable names containing the word electric. (This is the common Emacs parlance for actions which occur automatically when particular visible characters are typed.)
In this instance, M-x apropos-variable RET electric RET shows me that there is a css-electric-keys variable containing a list of "Self inserting keys which should trigger re-indentation."
You could use M-x customize-variable RET css-electric-keys RET to set this list to nil, or add (setq css-electric-keys nil) to your init file.
Sometimes a minor mode is used to implement electric behaviours, so that you can switch them on and off more easily. Those would likely be found via M-x apropos-command RET electric RET, and you would probably use a major mode hook to ensure that the electric minor mode was disabled, in a similar fashion to this:
(add-hook 'MAJORMODE-mode-hook 'my-MAJORMODE-mode-hook)
(defun my-MAJORMODE-mode-hook ()
(ELECTRICMODE-mode 0))

Remove Emacs highlighting

I use the emacs command 'highlight-compare-buffers' to see the changes between two files. But I don't know how to turn the highlighting off. It seems like it should be really easy, but I can't seem to figure out how even with lots of googling and searching the emacs help files.
Try:
C-u -1 M-x highlight-compare-buffers
global-highlight-changes is an
interactive autoloaded Lisp function
in `hilit-chg'.
(global-highlight-changes &optional
arg)
Turn on or off global Highlight
Changes mode.
When called interactively:
if no prefix, toggle global Highlight Changes mode on or off
if called with a positive prefix (or just C-u) turn it on in active mode
if called with a zero prefix turn it on in passive mode
if called with a negative prefix turn it off
I don't have emacs installed on this box, so this is untested, but highlight-changes-toggle-visibility might work.