How to force a syntax-highlighting refresh in emacs? - emacs

In emacs, especially when ssh'ed into a remote machine, there's a delay between when I type a closing quotation mark and when emacs updates the syntax-highlighting to reflect that change. For a few seconds, all of the text after my quotation is highlighted as if it were part of the quotation. Usually this is fine, but sometimes I'd rather not wait. Is there a way to tell emacs to "re-highlight everything right now"?

Yes. The emacs command is M-x font-lock-fontify-buffer if I recall it right. You can bind it to a key sequence if it's not already bound in your mode.

Related

Text being highlighted in emacs even when the mark is deactivated

I am a beginner user of emacs. Even after I have deactivated the mark by pressing ctrl+spc still the text gets highlighted when I move across the text. Emacs works fine before I set mark for the first time while editing a file. Once I use the mark this problem begins.
Why do you think that you have "deactivated the mark by pressing C-SPC"?
Do you have transient-mark-mode enabled? (It is enabled by default in Emacs 23 and later.) If so, the you do not see highlighting by default - the mark and region are not active, and if you hit C-SPC once then you see highlighting when point is moved away from the mark that C-SPC just set - the mark and region are active.
When the region is active, you can hit C-g to inactivate it, removing the region highlighting.
If this is not the behavior you see then probably something in your init file is causing the problem. In that case, try starting Emacs without your init file: emacs -Q. If the problem goes away with emacs -Q then recursively bisect your init file to find the problem.

set-mark-command not working emacs with C-SPC

I am not able to set the mark at the current point by C-SPC (both when emacs loads the init file and when it doesn't). However, when I do M-x set-mark-command, the mark is well set and I am able to select the region by moving the cursor. When I do M-x apropos set-mark-command, it shows two bindings C-# and C-SPC, but only the first one works. Any suggestions will be appreciated.
I am running emacs 24.3 on a GUI on Kubuntu 14.04.
Ubuntu 14.04 has an open bug affecting some desktop environments (at least KDE, LXDE and i3, but not Unity).
The default IBus key binding for "next input method" is Ctrl+Space, which prevents this key combination from reaching Emacs (or any other userspace program). To resolve the issue, run ibus-setup and change the key binding for "next input method" to something else (or delete it entirely by clicking the "..." button and then the "Delete" button).
Note that running ibus-setup from Unity, where C-SPC works already, shows a preferences window that does not include the key binding option that needs to be changed.
The "next input method" command cycles through your configured inputs, e.g. perhaps from English to French.
So I tracked down a similar issue to this on macOS. It seems that at some point C-SPC became bound to "Select the previous input source":
I just had the same issue today which I never had before. I am on Windows 7. As it turns out the Ctrl+SPC is bound to the OS's language switch. So the keystrokes are not sent to emacs at all.
But one thing that is even more weird is that I have never installed new languages/keyboards, yet the 'CH PRC' shows up in my language bar as a language/keyboard today. It turns out to be a Windows 7 bug and all I had to do to fix was:
Add 'CH PRC' in the language bar then Save.
Remove the language then Save again.
I know you are not on Windows, so the fix may not be the same as mine, but it is very likely Ctrl+SPC is bound to your OS's language switch as well.

emacs delete-selection-mode disables itself

In my .emacs file I have (delete-selection-mode t) to enable the delete-selection-mode globally. Currently I'm working on a TeX file with AUXTeX, so it might be related to AUCTeX, but I don't know.
At first, after visiting a file foo.tex everything works fine, and typing over a marked text replaces the marked text with the one I type. However, after some time, during which I compile the document, add TeX macros, etc. the functionality of the delete-selection-mode doesn't work any more.
I don't know which action of mine is the one which causes the problem - it would be hard to trace it.
Note that although the functionality of the delete-selection-mode fails, when I try to enable it (M-x delete-selection-mode) I get a message that the mode was disabled! That is it was not disabled before - it just didn't work... I I then enable it (M-x delete-selection-mode again), then it is enabled and working again. Till the next fail...
Under the hood, the mode use pre-command-hook, which allows commands to run things right before every command. Emacs is known to clear this variable in the event of an error (just to make sure that Emacs don't hang). This mean that the function used by delete-selection-mode, or any other mode that use this hook, triggered an error.
How to fix it? Find what caused the error, wrap the function in a ignore-errors block, or run a timer re-adding the function every ten seconds or so.

emacs xterm-mouse-mode double click to highlight word

I have to use xterm-mouse-mode to support mouse when using emacs via ssh, but i found it will not highlight the whole word when i double click on a character of the word. Instead it only highlight the character under the mouse. How can i fix it?
C-h f xterm-mouse-mode says:
...works for simple uses of the mouse. Basically, only non-modified
single clicks are supported. When turned on, the normal xterm...
So, I'm afraid double clicks are known not to work (they are seen by Emacs as 2 normal clicks).
EDIT 2014-Aug-29: This limitation has been recently lifted in Emacs's trunk (i.e. not in the upcoming 24.4 but in the next version instead).
Highlighting does not work in the non-windowed version of emacs (emacs run in a terminal window). It's hard to tell whether things are being highlighted which is why I recommend using C-space (Mark-set) to highlight things instead as it gives you a little more control rather than enabling xterm-mouse-mode as sometimes you may not double click correctly.

Why does C+[up,down,left,right]arrow return [A,B,C,D] in emacs -nw (terminal a.k.a. "special interface") mode? and how can I get it to stop?

When I open an emacs buffer in the terminal using
emacs -nw
C+arrow does not move me around like I would like it to.
Is there a way to change this behavior?
There are two steps to fix this.
First find out what your terminal is sending emacs. This can be done right inside emacs by hitting C-q then the combination you want to see, say C-⇒ or something.
Then in your .emacs, you can bind the combination to whatever you want. For example, if you want C-⇒ to go to the next word, you can use (global-set-key "<your combination here>" 'forward-word). Do the same for the other bindings.
I have that sometimes in combination with screen. I run emacs as a daemon -- just disconnect that screen 'window' (or is it called panel or session?) and reconnect and you should be fine.
No idea what upsets the terminal settings.