Article View: gnu.emacs.help
Article #1869Re: WANTED: highlight-region code
From: Jerry
Date: Mon, 21 Dec 1992 23:45
Date: Mon, 21 Dec 1992 23:45
48 lines
2047 bytes
2047 bytes
This code was fleshed out on the net some months ago. It has the
advantage of not using delete-region which messes up undo history. It
should also work under X, which the ispell version had some difficulty
with on certain machines ("you may have to rewrite this..." in the
comment). Hope this helps.
-Jerry
;; ---------------- highlight-region.el ----------------------------
(defun highlight-region (p1 p2)
"Highlight the current region in reverse video."
(interactive "r")
(highlight-region-internal p1 p2 t))
(defun unhighlight-region (p1 p2)
"Unhighlight the current region. If region is displayed in reverse
video, then it no longer will be."
(interactive "r")
(highlight-region-internal p1 p2 nil))
(defun highlight-region-internal (p1 p2 highlight)
"Highlight/unhighlight the region between P1 and P2. HIGHLIGHT set to T
means do highlight, NIL means don't."
(save-excursion
(save-restriction
(let ((screen-start (progn (move-to-window-line 0)
(point)))
(screen-end (progn (move-to-window-line -1)
(end-of-line 1)
(point)))
(region-start (min p1 p2))
(region-end (max p1 p2)))
(setq region-start (max region-start screen-start))
(setq region-end (min region-end screen-end))
(goto-char region-start)
(narrow-to-region screen-start region-start)
(sit-for 0)
(let ((inverse-video highlight))
(goto-char screen-start)
(widen)
(narrow-to-region screen-start region-end)
(sit-for 0)
)))))
Technical Details
Message-ID:
<9212212345.AA18533@banach>Path:
arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!math.ep.utexas.EDU!jerryReferences:
<RATINOX.92Dec12102156@splinter.coe.northeastern.edu>Show Full Headers
Complete Article Headers
Newsgroups: gnu.emacs.help Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!math.ep.utexas.EDU!jerry From: jerry@math.ep.utexas.EDU (Jerry) Subject: Re: WANTED: highlight-region code Message-ID: <9212212345.AA18533@banach> Sender: daemon@cis.ohio-state.edu Organization: Department of Mathematical Sciences--University of Texas at El Paso References: <RATINOX.92Dec12102156@splinter.coe.northeastern.edu> Date: Mon, 21 Dec 1992 23:45:49 GMT Lines: 48