How can I get mouse-track-delete-and-insert in emacs? - emacs

One of my favourite xemacs features is the ability to zap chunks of text from one place to another with a mere gesture: mouse-track-delete-and-insert. Is it possible to do the same in emacs?
This is the help entry:
C-Sh-button1 runs `mouse-track-delete-and-insert'
`mouse-track-delete-and-insert' is an interactive compiled Lisp
function -- loaded from
"c:\XEmacsBuild\xemacs-21.4.22\lisp\mouse.elc"
(mouse-track-delete-and-insert EVENT)
Documentation: Make a selection with the mouse and insert it at point.
This is exactly the same as the `mouse-track' command on button1,
except that point is not moved; the selected text is immediately
inserted after being selected; and the text of the selection is
deleted.

Related

Change default EMACS mouse highlight behaviour

In EMACS the default seems to be to 'copy' any text highlighted with the mouse. I'm attempting to replicate the functionality of modern text editors, where I can highlight a section of text and press 'paste' to replace it. I have so far added
(delete-selection-mode 1)
to my init.el
The problem is, if I copy something, then highlight to paste in its place, I end up pasting what I had just highlighted, changing nothing.
What do I need to change to fix that behaviour?
The most powerful element of emacs is its introspection features, lets have a look at how we can use them to try and solve this problem. We must use the power of the source.
One of the most important tools for introspection in emacs is the describe-key command which is bound to C-h k. It brings up the documentation of whatever keystroke is called after it. So in our case if we press C-h k and then click and drag we will see the documentation for <down-mouse-1> and more importantly for <drag-mouse-1>. The documentation states that "<drag-mouse-1> at that spot runs the command mouse-set-region". Below it then gives some documentation for this command. It says
Set the region to the text dragged over, and copy to kill ring.
This should be bound to a mouse drag event.
See the ‘mouse-drag-copy-region’ variable to control whether this
command alters the kill ring or not.
Now we know that somehow mouse-drag-copy-region controls whether or not the highlighted text is copied.
If we follow the link of that variable it tells us the default value and some documentation:
If non-nil, copy to kill-ring upon mouse adjustments of the region.
Now all we have to do is set the variable to be nil to get the effect that you want. Place the following code at the end of your init file and you should be all set
(setq mouse-drag-copy-region nil)
I hope that this helps you with this problem and that more importantly it helps you with further issues.
By default, selecting a region with the mouse does not copy the text to the kill ring. If your Emacs does this, you probably have set the variable mouse-drag-copy-region.
In a fresh Emacs (24.5 started using -Q), you can do the following:
Start delete-selection-mode.
Mark a region using the mouse. Copy it using M-w.
Mark a second region. Replace it with the first using C-y.
I see two alternatives, neither of which does exactly what you request. (For both, yes, turn on delete-selection-mode.)
Use the secondary selection for the text to copy, and use the primary selection (the region) for the text to be replaced.
You copy text into the secondary selection using the Meta key plus the mouse - for example, press and hold Meta (the Alt key, usually) while dragging or double-clicking mouse-1.
You paste the secondary selection using Meta plus mouse-2.
Select text with the mouse, then copy it to the kill-ring using M-w. Then select the text to replace with the mouse and use C-y to paste the copied text to replace it.

Wrapping already typed text in Emacs

I have a text that I already typed in a text editor, but when I open it in Emacs, so I can keep working o Emacs (Org-Mode), it appears it is not wrapping the lines propperly. The paragraph (or what it is supposed to be a paragraph) appears in a single line, instead of having a line break when reaching the screen limit.
Do you guys know how to reformat these line breaks?
Emacs has a built-in variable called word-wrap, which has a default value of nil. When word-wrap is nil, long lines are wrapped indiscriminately at the window-edge without consideration as to whether a whole word is visually broken up -- i.e., part of a word may be at the end of the visually wrapped line and part of the word may be at the beginning of the subsequent visually wrapped line.
The most common method of enabling word-wrap is to use the built-in visual-line-mode: http://www.gnu.org/software/emacs/manual/html_node/emacs/Visual-Line-Mode.html Visual line mode includes a few other goodies, like remapping certain keyboard shortcuts and pretty bitmap images in the fringes if they are visible in the window. Enabling visual-line-mode can be accomplished a number of ways -- one example is manually: M-x visual-line-mode

How to force emacs's pasting to behave like in other apps

I am new emacs user and one of the things that irritates me is that when I want to replace current selected text with the one from clipboard I need to delete it first. Every other application that I know replaces pasted text with the current selection by default.
Here's a little bit more detailed description:
Select some block of text
Paste text from clipboard
Emacs just pastes text where the cursor was and previously selected text it is still there. I want that selected text was deleted first.
As artscan wrote in a comment, you can get this functionaly for the normal yank (paste) operations by adding:
(delete-selection-mode 1)
to your configuration.
If you want yank by mouse to also delete the current selection, you can add:
(put 'mouse-yank-primary 'delete-selection 'yank)
in your configuration as well.

show repeated selected text in emacs

I don't know which text editor have it but when you select text it show up where the same text appear in text with a box. It's usefull when you select variable and it show up where it's use in the code.
The text can show up with different backgorund when I copy the text and then call the function and dissapear when position of the cursor change.
Is it possible to do this in Emacs (probably is but how)?
Yes, Emacs has that (highlight matches of a given symbol or other pattern). Sounds like any of these correspond to what you are looking for:
Incremental search (aka isearch): C-s or C-M-s, then type what you want to match (or use C-w... to pick it up from the buffer).
Library highlight-symbol.
Library highlight, command hlt-highlight-symbol. (And see option `hlt-auto-faces-flag.) Does what library highlight-symbol does, and more.
Emacs 24.4 (i.e., current development snapshot), command hi-lock-face-symbol-at-point.
If you use library mouse3.el then right-clicking the mouse gives you the last two alternatives for the symbol under the mouse pointer.
You can maybe try to use cedet with ECB on Emacs.
You can install it with Meta+x list-packages or you can try another IDE like Kdevelop.

Turn off selection mode after I-searching for the word that was found

After searching for a word using an I-search, the selection mode remains enabled and pressing the escape button just once does not turn it off.
Is it possible to search for a word (forwards / backwards) and quickly go on about my business without pressing a bunch of keys to exit out of the select mode?
Also, the selection mode looks useful -- is there any way to turn it on / off without first performing a search?
Thanks.
You probably have transient-mark-mode enabled, which is now the default Emacs behavior. (It was not enabled by default in older versions of Emacs). If you're not familiar with it you may want to read about it in the Emacs manual.
You can set the mark (begin selection) using Control-space (C-SPC, the default key binding for set-mark-command). Then you can use other navigation keys to extend the selected region before you operate on it. For example: C-SPC to set the mark, M-f M-f to extend the selection forward two words, C-w to delete the selected region.
If you set the mark before beginning an incremental search, the search acts as a navigation command and extends the selected region. Exiting the search will leave the entire region selected from the place where you set the mark to the place where you exited the search. Note that this is not the default behavior for isearch-forward however.
just press ENTER to end the search.
if you mean that the selection area is displayed, you can unmark it with Ctrl-Space.
but I am not sure this answers your question.
--dmg