home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / emacs / help / 5149 < prev    next >
Encoding:
Text File  |  1992-12-22  |  1.9 KB  |  60 lines

  1. Newsgroups: gnu.emacs.help
  2. Path: sparky!uunet!spool.mu.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!math.ep.utexas.EDU!jerry
  3. From: jerry@math.ep.utexas.EDU (Jerry)
  4. Subject: Re: WANTED: highlight-region code
  5. Message-ID: <9212212345.AA18533@banach>
  6. Sender: daemon@cis.ohio-state.edu
  7. Organization: Department of Mathematical Sciences--University of Texas at El Paso
  8. References: <RATINOX.92Dec12102156@splinter.coe.northeastern.edu>
  9. Date: Mon, 21 Dec 1992 23:45:49 GMT
  10. Lines: 48
  11.  
  12. This code was fleshed out on the net some months ago.  It has the
  13. advantage of not using delete-region which messes up undo history.  It
  14. should also work under X, which the ispell version had some difficulty
  15. with on certain machines ("you may have to rewrite this..." in the
  16. comment).  Hope this helps.
  17.  
  18. -Jerry
  19.  
  20.  
  21. ;; ---------------- highlight-region.el ----------------------------
  22.  
  23. (defun highlight-region (p1 p2)
  24.   "Highlight the current region in reverse video."
  25.   (interactive "r")
  26.   (highlight-region-internal p1 p2 t))
  27.  
  28. (defun unhighlight-region (p1 p2)
  29.   "Unhighlight the current region.  If region is displayed in reverse
  30. video, then it no longer will be."
  31.   (interactive "r")
  32.   (highlight-region-internal p1 p2 nil))
  33.  
  34. (defun highlight-region-internal (p1 p2 highlight)
  35.   "Highlight/unhighlight the region between P1 and P2.  HIGHLIGHT set to T
  36. means do highlight, NIL means don't."
  37.   (save-excursion
  38.     (save-restriction
  39.       (let ((screen-start (progn (move-to-window-line 0)
  40.                  (point)))
  41.         (screen-end (progn (move-to-window-line -1)
  42.                    (end-of-line 1)
  43.                    (point)))
  44.         (region-start (min p1 p2))
  45.         (region-end (max p1 p2)))
  46.  
  47.     (setq region-start (max region-start screen-start))
  48.     (setq region-end (min region-end screen-end))
  49.               
  50.     (goto-char region-start)
  51.     (narrow-to-region screen-start region-start)
  52.     (sit-for 0)
  53.  
  54.     (let ((inverse-video highlight))
  55.       (goto-char screen-start)
  56.       (widen)
  57.       (narrow-to-region screen-start region-end)
  58.       (sit-for 0)
  59.       )))))
  60.