4

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

Drew
  • 75,699
  • 9
  • 109
  • 225
built1n
  • 143
  • 4
  • 1
    You give very little input. So I can only guess that this is the [secondary selection](https://www.gnu.org/software/emacs/manual/html_node/emacs/Secondary-Selection.html). 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-`. – Tobias Dec 28 '19 at 05:26
  • 1
    I investigated that possibility, but `M-` does not seem to help. (My window manager might be interfering with that by intercepting Alt.) – built1n Dec 28 '19 at 06:05
  • 1
    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 06: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](https://www.gnu.org/software/emacs/manual/html_mono/semantic.html). – Tobias Dec 28 '19 at 06: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
  • 1.) It is still not fully clear how you got that selection in the first place if your Meta-modified mouse clicks are captured by your window manager. 2.) How can we make sure that you can easily delete the secondary selection? Should we define a command that just does `(delete-overlay mouse-secondary-overlay)`? The commands for the secondary selection defined in `mouse.el` all require a mouse event argument and are bound to some `M-`. So they seem not so appropriate for your case. – Tobias Dec 28 '19 at 21:09

1 Answers1

5

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>.

Tobias
  • 32,569
  • 1
  • 34
  • 75