home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.emacs.help
- 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
- From: jerry@math.ep.utexas.EDU (Jerry)
- Subject: Re: Wanted: el code for highlighting region
- Message-ID: <9208260114.AA11374@banach.math.ep.utexas.edu>
- Sender: daemon@cis.ohio-state.edu
- Organization: Department of Mathematical Sciences, University of Texas at El Paso
- References: <KONKAR.92Aug24111100@sunrise.stanford.edu>
- Date: Wed, 26 Aug 1992 01:14:04 GMT
- Lines: 71
-
- Ranjit Konkar on August 92 wrote:
- -> I am sure this must have been addressed umpteen times before, but I am
- -> new to this newsgroup, so pl pardon this if it is a repetition. Does
- -> anyone have code to hightlight region in gnu emacs? If so could s/he
- -> post it or mail it to me? Thanks.
- ->
- -> Ranjit
-
- May not work on your machine, but here's what I use:
-
- ;; Emacs highlight-region (modified from ispell.el)
- ;; Usual GNU copyleft applies
- ;; Look at the file $EMACSDIR/etc/COPYING of your Emacs distribution
- ;; or email gnu@prep.ai.mit.edu for more information
-
- (defun highlight-region (p1 p2)
- "Highlight the current region in reverse video. Although the buffer will
- not be marked modified unless it already was, the affected region will be
- deleted and reinserted which changes undo history."
- (interactive "r")
- (let ((s (buffer-substring p1 p2))
- (inverse-video t)
- (was-mod (buffer-modified-p)))
- (delete-region p1 p2)
- (sit-for 0)
- (insert s)
- (sit-for 0)
- (if (not was-mod) (set-buffer-modified-p nil))))
-
-
- (defun unhighlight-region (p1 p2)
- "Unhighlight the current region. See highlight-region."
- (interactive "r")
- (let ((s (buffer-substring p1 p2))
- (inverse-video nil)
- (was-mod (buffer-modified-p)))
- (delete-region p1 p2)
- (sit-for 0)
- (insert s)
- (sit-for 0)
- (if (not was-mod) (set-buffer-modified-p nil))))
-
- ;; Epoch highlight-region
-
- (defun highlight-region (p1 p2)
- "Highlight the current region in reverse video."
- (interactive "r")
- (let ((highlight-style (make-style)))
- (set-style-foreground highlight-style (background))
- (set-style-background highlight-style (foreground))
- (epoch::add-zone p1 p2 highlight-style)))
-
-
- (defun unhighlight-region (p1 p2)
- "Unhighlight the current region (if in reverse video)."
- (interactive "r")
- (let ((highlight-style (make-style)))
- (set-style-foreground highlight-style (foreground))
- (set-style-background highlight-style (background))
- (epoch::add-zone p1 p2 highlight-style)))
-
- ;; then to highlight misspelled words in ispell
-
- (setq ispell-highlight t)
-
- ;; then bind to mnemonic keys
-
- (define-key esc-map "+" 'highlight-region)
- (define-key esc-map "_" 'unhighlight-region)
-
- ;; -Jerry
-