From: Stephen Berman <stephen.berman@gmx.net>
To: help-gnu-emacs@gnu.org
Subject: Re: highlight region but not transient-mark-mode
Date: Thu, 14 Mar 2013 15:59:03 +0100 [thread overview]
Message-ID: <87sj3y81u0.fsf@rosalinde.fritz.box> (raw)
In-Reply-To: 51419FFA.2040802@mousecar.com
On Thu, 14 Mar 2013 06:01:30 -0400 ken <gebser@mousecar.com> wrote:
> Is there a way to make the region display as highlighted, but without being in
> transient-mark-mode?
If you want to manually do it, here's one way:
M-: (overlay-put (make-overlay (region-beginning) (region-end))
'face 'region)
But you probably also want to move the highlighting when the region
changes, so this would be better:
(defun kg-highlight-region ()
"Highlight the region without using Transient Mark mode."
(interactive)
(remove-overlays nil nil 'kg t)
(when (mark)
(let* ((beg (region-beginning))
(end (region-end))
(ovs (overlays-in beg end))
ov highlighted)
(while ovs
(setq ov (pop ovs))
(when (overlay-get ov 'kg)
(setq highlighted t)
(setq ovs nil)))
(if highlighted
(move-overlay ov beg end)
(setq ov (make-overlay beg end))
(overlay-put ov 'kg t)
(overlay-put ov 'face 'region)))))
If you want the highlighting to change automatically, you could then
evaluate this:
(add-hook 'post-command-hook 'kg-highlight-region)
If that starts driving you nuts, evaluate this:
(remove-hook 'post-command-hook 'kg-highlight-region)
and to then eliminate the remaining overlay, evaluate this:
(remove-overlays nil nil 'kg t)
Steve Berman
prev parent reply other threads:[~2013-03-14 14:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-14 10:01 highlight region but not transient-mark-mode ken
2013-03-14 14:59 ` Stephen Berman [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sj3y81u0.fsf@rosalinde.fritz.box \
--to=stephen.berman@gmx.net \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.