3

I accidentally pressed some keys in a buffer and created the permanently highlighted region shown below. What is this region called, and how can I get rid of it?

highlighted region

6
  • 1
    You give very little input. So I can only guess that this is the secondary selection. You get it if you press the Meta-key (i.e., the Alt-key) while selecting and you get rid of it by a click on M-<mouse-1>. – Tobias Dec 28 '19 at 5:26
  • 1
    I investigated that possibility, but M-<mouse 1> does not seem to help. (My window manager might be interfering with that by intercepting Alt.) – built1n Dec 28 '19 at 6:05
  • If you think that your window manager could be interfering you can try M-: (delete-overlay mouse-secondary-overlay) to kill the secondary selection. In this case you can trigger the event M-: by clicking once the Escape button and afterwards the : button. – Tobias Dec 28 '19 at 6:17
  • 3
    If my guess is not right we definitively need more information. Go to the middle of the blue area and call M-x describe-char. Include the information emitted by describe-char in your question. BTW it looks like the method render_dots is marked. Could be some C++ helper mode like semantic. – Tobias Dec 28 '19 at 6:26
  • 1
    @Tobias You're correct - describe-char shows that it's part of a secondary-selection overlay, and (delete-overlay mouse-secondary-overlay) successfully removed it. Must've been my window manager, then. Feel free to write this up as an answer. – built1n Dec 28 '19 at 17:00
4

That permanently highlighted region is the secondary selection.

We deduced this in the comments to your question by putting point in the middle of the highlighted region and by calling M-x describe-char RET. You get something like the following in the opening *Help* buffer:

There is an overlay here:  
 From 316781 to 316796  
  face                 secondary-selection  

You also mentioned in one of your comments that your window manager hides mouse-1 events from Emacs.

One possible solution to that problem could be to define the following key bindings:

(global-set-key [?\e mouse-1] 'mouse-start-secondary)
(global-set-key [?\e drag-mouse-1] 'mouse-set-secondary)
(global-set-key [?\e down-mouse-1] 'mouse-drag-secondary)
(global-set-key [?\e mouse-3] 'mouse-secondary-save-then-kill)
(global-set-key [?\e mouse-2] 'mouse-yank-secondary)

These are the secondary selection bindings of mouse.el with M- replaced by ?\e, the escape key.

So whenever you are asked to use the Meta modifier for a secondary selection command you can press the ESC key before the unmodified key sequence instead.

For an example, press ESC <mouse-1> instead of M-<mouse-1> to get rid of the "strange" highlighting by deleting the secondary selection overlay.

Note, that the secondary selection can become handy when you want to temporarily remember stuff in a selection while using the primary selection as usual. For an example you can mark some stretch of text by the secondary selection, mark and delete some other stretch of text with the primary selection and insert the stuff from the secondary selection with ESC <mouse-2>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.