home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / gnu / emacs / help / 3844 < prev    next >
Encoding:
Text File  |  1992-08-25  |  2.7 KB  |  83 lines

  1. Newsgroups: gnu.emacs.help
  2. Path: sparky!uunet!stanford.edu!ames!haven.umd.edu!darwin.sura.net!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: el code for highlighting region
  5. Message-ID: <9208260114.AA11374@banach.math.ep.utexas.edu>
  6. Sender: daemon@cis.ohio-state.edu
  7. Organization: Department of Mathematical Sciences, University of Texas at El Paso
  8. References: <KONKAR.92Aug24111100@sunrise.stanford.edu>
  9. Date: Wed, 26 Aug 1992 01:14:04 GMT
  10. Lines: 71
  11.  
  12. Ranjit Konkar on August 92 wrote:
  13. -> I am sure this must have been addressed umpteen times before, but I am
  14. -> new to this newsgroup, so pl pardon this if it is a repetition. Does
  15. -> anyone have code to hightlight region in gnu emacs? If so could s/he
  16. -> post it or mail it to me? Thanks.
  17. -> 
  18. -> Ranjit
  19.  
  20. May not work on your machine, but here's what I use:
  21.  
  22. ;; Emacs highlight-region (modified from ispell.el)
  23. ;; Usual GNU copyleft applies
  24. ;; Look at the file $EMACSDIR/etc/COPYING of your Emacs distribution
  25. ;; or email gnu@prep.ai.mit.edu for more information
  26.  
  27. (defun highlight-region (p1 p2)
  28.    "Highlight the current region in reverse video.  Although the buffer will
  29. not be marked modified unless it already was, the affected region will be
  30. deleted and reinserted which changes undo history."
  31.    (interactive "r")
  32.    (let ((s (buffer-substring p1 p2))
  33.          (inverse-video t)
  34.      (was-mod (buffer-modified-p)))
  35.       (delete-region p1 p2)
  36.       (sit-for 0)
  37.       (insert s)
  38.       (sit-for 0)
  39.       (if (not was-mod)    (set-buffer-modified-p nil))))
  40.  
  41.  
  42. (defun unhighlight-region (p1 p2)
  43.    "Unhighlight the current region.  See highlight-region."
  44.    (interactive "r")
  45.    (let ((s (buffer-substring p1 p2))
  46.          (inverse-video nil)
  47.      (was-mod (buffer-modified-p)))
  48.       (delete-region p1 p2)
  49.       (sit-for 0)
  50.       (insert s)
  51.       (sit-for 0)
  52.       (if (not was-mod)    (set-buffer-modified-p nil))))
  53.  
  54. ;; Epoch highlight-region
  55.  
  56. (defun highlight-region (p1 p2)
  57.    "Highlight the current region in reverse video."
  58.    (interactive "r")
  59.    (let ((highlight-style (make-style)))
  60.      (set-style-foreground highlight-style (background))
  61.      (set-style-background highlight-style (foreground))
  62.      (epoch::add-zone p1 p2  highlight-style)))
  63.  
  64.  
  65. (defun unhighlight-region (p1 p2)
  66.    "Unhighlight the current region (if in reverse video)."
  67.    (interactive "r")
  68.    (let ((highlight-style (make-style)))
  69.      (set-style-foreground highlight-style (foreground))
  70.      (set-style-background highlight-style (background))
  71.      (epoch::add-zone p1 p2  highlight-style)))
  72.  
  73. ;; then to highlight misspelled words in ispell
  74.  
  75. (setq ispell-highlight t)
  76.  
  77. ;; then bind to mnemonic keys
  78.  
  79. (define-key esc-map "+" 'highlight-region)
  80. (define-key esc-map "_" 'unhighlight-region)
  81.  
  82. ;; -Jerry
  83.