help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: highlight region but not transient-mark-mode


From: Stephen Berman
Subject: Re: highlight region but not transient-mark-mode
Date: Thu, 14 Mar 2013 15:59:03 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]