How to kill text when overwriting in delete-selection-mode - emacs

I would like to change the default behaviour of delete-selection-mode so that overwritten selections get killed rather than deleted. This is the case with a fresh Emacs 24.2:
Emacs -Q
(delete-selection-mode)
Looking through delsel.el I got close to the behaviour I want:
(put 'self-insert-command 'delete-selection 'kill)
but this doesn't actually insert the key I type to overwrite the selected text. And it doesn't cater for 'org-self-insert-command (as an example of unforeseen consequences).
Am I missing something basic?

Related

Reftex-toc prevent vsplit on goto

I am currently using spacemacs with auctex. When I use reftex-toc and goto an item then it performs a vsplit and shows the content in the right window. How do I prevent this splitting behaviour? I would like it to open in the current buffer from which the command was issued.
It is related to reftex-toc.el.
I added this hook to maximize the newly opened window:
(add-hook 'reftex-toc-mode-hook 'spacemacs/toggle-maximize-buffer)
but it is a suboptimal solution, as it influences other splits I might have made.
What you describe could be related to the way you select an item.
In normal Emacs (not Spacemacs), I see that SPC is bound to reftex-toc-view-line which behaves just how you describe it. But RET is bound to reftex-toc-goto-line-and-hide which seems to do what you want.
Maybe you just need to find out where that function is on your keymap.

Why does Emacs sometimes overwrite characters when I insert or delete?

This happens for me all the time. Upon insertion/deletion, the positions of other characters in the buffer are not shifted.
For example, with buffer contents this is important content, inserting very before important results in the two words very and important appearing overlapped, like this: this is veryrtant content instead of this is very important content
How can I fix this?
Killing the buffer and reopening of course works.
It sounds like you have accidentally turned on overwrite-mode.
That command is a toggle. It is bound by default to the keys <insertchar> and <insert>. Typically one of those keys in a keyboard key labeled Insert.
But perhaps your keyboard is sending that key when you do something else.
Does the overwriting ever turn off? If so, that would suggest that you accidentally hit the toggle key a second time.
If not, then perhaps your keyboard or terminal is itself somehow locked in an overwriting mode. Do you see the same behavior outside of Emacs?

Shift selection in Emacs 24 does not highlight text

I must be stupid, but I just switched to Emacs 24, and holding Shift while moving the point no longer highlights text. Mouse selection works as before. What am I missing? Did I turn it off by chance? Or has Shift selection been deemed unergonomical so we have some other, better keyboard-based selection at hand?
Shift selection is enabled by default in Emacs 24.
You can always run emacs -Q to disable your init file and any other default libraries, in order to determine what Emacs' default behaviour is.
You can also run emacs -q which will disable only your init file (other system-wide init files can be loaded).
If the feature works without your init file and does not work with it, you can then start to narrow down what part of your init file is at fault (often by commenting out functionality until the feature starts working as expected -- note Drew's comment).
In this case I suggest that you firstly verify (using C-hv) that the shift-select-mode variable is non-nil (when running with your normal configuration), as a nil value means that shift selection is disabled.
I also found it useful to look at load-path variable, C-h v load-path, which directed me to the culprits, old elpa packages.

New to Emacs. When I type ", \" is automatically inserted

As the title states, I'm relatively new to Emacs. I tried out several starter kits but went with Prelude and changed a lot of things around.
Anyway, I've been getting a good handle on everything...until this morning I was working and I typed double-quotes. Normally Emacs would insert a second double quotes right after ("") due to the auto-completion, but I must have accidentally changed something with a keystroke and now when I type ", I get \"\".
Thoughts?
Thank you.
This seems to be an issue with smartparens which prelude installs by default (see the file prelude-programming.el. This behavior is described in detail on smartparens wiki. To ensure that smartparens is causing problems you can can do C-h k" this would print about the command acutally run when " is pressed, if the command is sp--self-insert-command then the following should work
Paste this (setq sp-autoescape-string-quote nil) to your *scratch* buffer, go to the closing parenthesis and do C-xC-e, this will disable the behavior for current emacs session.
To disable the behavior for all future emacs session, assuming that you are using prelude, you will need to add the following to your personal config (basically some file inside /path/to/prelude/personal/).
(setq sp-autoescape-string-quote nil)
This will disable the auto-escaping of the string quotes, completely. If you like this behavior and do not want to disable it completely you can do what #steckerhalter suggests C-q" will insert just one parenthesis.
If the above does not solve the issue then try providing following info in your question which may help us debug the issue,
1) The list minor modes active (this can be obtained by doing C-hm).
2) Output of C-hk"
Hope that helps
this sounds a lot like smartparens (https://github.com/Fuco1/smartparens) which is included in Prelude. usually when you are inside "" then it will escape the quotes:
"hahah \"\" bah"
if you want to get a normal " inside quotes you have to use C-q " or disable smartparens with M-x smartparens-mode
If, as you say in a comment, " is bound to self-insert-command, then when you type " what happens is that a (single, unescaped) " character is inserted.
However, I suspect you have some mode turned on that does something additional whenever a " char is inserted. You mention automatic insertion of a second ", for example. That kind of behavior comes from a mode such as is provided by library smart-parens or electric-pair.
And you mention Prelude.
To find out what part of your init file (~/.emacs) is causing the behavior you see, bisect your init file recursively (first comment-out half, to see which half is responsible, then 3/4, to see which quarter is responsible,...). Then, if you still have a question about the responsible code, ask here, providing that info.
When you describe your problem here, it is important to be specific: what Emacs version, what mode(s), what libraries have you loaded,... Whatever might be pertinent. But first narrow down the problem by bisecting your init file to find the culprit.

Why isn't return bound to newline-and-indent by default on emacs

I have tried emacs on and off for a while now and every time I start emacs, I go through the same routine. Customizing. The first one is binding return to newline-and-indent. (g)Vim does this by default. Showing matching parenthesis is also done by default on (g)Vim. It is grea that I can customize emacs to my heart's content but why doesn't emacs have nice and easy defaults? For reference, I am now using Emacs 23 on a RHEL5 box.
Probably because RMS didn't want it, that and because changing long-standing defaults is just an issue of politics. Like vi, Emacs has a hard-core following and basic changes like these are minefields.
Note: if you saved your customizations, then you wouldn't have to re-do them every time...
To have those nice and easy defaults, install Emacs Starter Kit. It enables by default a bunch of useful and convenient features make even the advanced Emacs users more productive.
Otherwise, as TJ pointed out, Emacs Customization Mode (type M-x customize) allows you to save permanently any of the settings. You can even store them in a separate file from your dotemacs―(setq custom-file "~/.emacs-custom.el")―so you can use it in every computer you work on.
The title of your question doesn't really reflect what your question is (and has been answered by Trey and Torok), but I'll tell you why I like it being bound to just newline: useless whitespace. Say you are nested inside a conditional in a function etc. and hit return a couple times to leave a blank line. The blank line now has a bunch of space chars on it. Yes, you can (and I do) remove trailing whitespace before saving, but I also have visual whitespace mode on and I can see it there taunting me.