Emacs shift selection hook? - emacs

I've set up activate-mark-hook and deactivate-mark-hook, but they work only when selecting text by dragging mouse, not by using shift-selection. How do I hook into shift selection?
I'm using Aquamacs 24 on Mac OS X 10.6.6.

Just peeked into the Emacs source to see what happens, this is what I found:
For every command that has been shift-translated, the function "handle-shift-selection" is called. This function will activate or deactivate the selection by using the "transient-mark-mode" variable, and by calling "push-mark" and "deactivate-mark", respectively. If I do the math correctly, this means that your deactivate hook will be called, but not you activation hook.
One way to solve this is to add your own code to "push-mark" using "defadvice".

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.

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.

Stop emacs auto complete from flashing cursor in other windows

When I'm typing in an emacs window and auto complete isn't giving me an auto complete suggestion the cursor blinks on both the window I'm typing in and all other windows. I've found the manual which seems like it should be what I need but I can't figure out a correct configuration to stop the blinking. How can I disable the cursor from blinking?
The behavior you observe is fuzzy matching in action read about it here. Basically whenever auto-complete cannot complete at point it tries to complete using fuzzy match, if completion succeeds it turns the cursor red momentarily. You can disable fuzzy matching completely by adding the following to your init file (see manual)
(setq ac-use-fuzzy nil)
OR
If you want to keep fuzzy matching and just disable the blink you can add the following to your init file
(setq ac-fuzzy-cursor-color nil)

Configure pointer focus properties of Matlab's command window

I'm running Matlab 2013a, under Linux, using Xmonad (using the XMonad.Config.Xfce package).
This problem occurs whether the command window is docked or not.
The command window prompt does not get the keyboard focus unless the pointer is located
over the command window.
Is there a way to get the Matlab command window to have focus behaviour just like other normal windows, like a terminal?
Most important: I'd like to have the keyboard focus follow the window focus,
and not require any special positioning of the pointer, so that I can just "Alt-Tab" around my windows and have the command window get the keyboard focus. All of the resources I've found so far relate to programmatic control of focus; I'm just trying to improve my user experience in an interactive session.
To get keyboard focus on the Command Window, include the following in your xmonad.hs
import XMonad.Hooks.SetWMName
import XMonad.Hooks.ManageHelpers
and configure your ManageHook as follows
myManageHook = composeAll . concat $
[ [appName =? a --> doCenterFloat | a <- myFloatAS ]
, (your other hooks)
] where
myFloatAS = ["MATLAB"]
Finally, include setWMName "LG3D" in your startupHook. See here for a full xmonad.hs configuration which uses this (this is where I found the solution). If you have other Java apps that don't get focus as they should you can add them to the myFloatAS list.
It's a problem in the built-in java.
If i run:
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre
matlab -desktop
Matlab works as expected.
I ran into this problem, running MATLAB2014a. I set up setWMName "LG3D" but still i couldn't get focus on my window. I had to click on the focused window to get the cursor, and sometimes the situation was even worse and I had to click on random places till i get my cursor back. This wouldn't happen on MATLAB2010. What worked for me was to use the native version of java as describe above.
In the end, i used the following bash script to start matlab8:
#!/bin/bash
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk-amd64/jre/
/usr/local/bin/matlab8 -desktop -nosplash

emacs shift arrow selection selects only 1st char/line

This question is linked to my previous one: Shift arrow selection in emacs
It was solved but partially only.
For now I have another problem:
when I'm pressing shift-right 2 times - only last selection will be present. So. It is not extended (as it should be according my achivements) but always overwritten...
f.e. I have 1 word "window" only. And my cursor at position 0. I want to copy "wi" only. I've pressed shift-right 2 times. But only "i" was selected.
How I can fix this?
den#playground:~/.emacs.den$ cat -v
^[[1;2C^[[1;2C
M-x version
GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0) of 2010-12-11 on raven, modified by Debian
I'm running my emacs on a remote machine via screen
den#playground:~/.emacs.den$ echo $TERM
screen
Without screen
den#playground:~$ echo $TERM
xterm
Behavior the same as under screen.
As I have understood the problem. Emacs after each shift-right click overwrites selection instead of expanding it...
So. Without screen and without my scripts (emacs -q).
Shift-right, shift-left, shift-down - working. shift-up - doing nothing. So. cursor is not moved after shift-up is pressed. Also shift-home, shift-end are working. shift-pgdown, shift-pgup - does not.
With screen and without my scripts (emacs -q).
Nothing.
Why do you press Shift-right 2 times, and not press on 'w' C-SPACERightRight
This selects the wi. Now you press M-w, and you copied it.
Probably I understood wrong the problem ?