all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* highlight region but not transient-mark-mode
@ 2013-03-14 10:01 ken
  2013-03-14 14:59 ` Stephen Berman
  0 siblings, 1 reply; 2+ messages in thread
From: ken @ 2013-03-14 10:01 UTC (permalink / raw)
  To: help-gnu-emacs

Is there a way to make the region display as highlighted, but without 
being in transient-mark-mode?

Thanks.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: highlight region but not transient-mark-mode
  2013-03-14 10:01 highlight region but not transient-mark-mode ken
@ 2013-03-14 14:59 ` Stephen Berman
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Berman @ 2013-03-14 14:59 UTC (permalink / raw)
  To: help-gnu-emacs

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-14 14:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-14 10:01 highlight region but not transient-mark-mode ken
2013-03-14 14:59 ` Stephen Berman

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.