[net.emacs] highlight region

ray (05/10/83)

The following piece of Mlisp implements a rather crude visible mark mechanism
that I use in conjunction with other functions to extend the marking
and killing facilities.
When a mark is set, its position is highlighted in reverse video.
The routines depend on the use of a VT100, i.e. the control sequences
sent to the terminal set and unset the VT100 reverse-video attribute.

The two useful functions are "set-my-mark" and "exchange-my-mark" which I 
have bound to keys.

The problems with the mechanism are two-fold, because it is only on the
physical screen, emacs knows nothing about the highlight:-

	1) If the mark goes off-screen, it does not get re-highlighted
	   when it comes back on screen. Similarly if the position of the
	   mark is redrawn on the screen.
	2) Because of the screen update optimisation (?!) in emacs, sometimes
	   when the mark moves on the screen its old position is not
	   overwritten and the old highlight remains. This is particularly so
	   when the highlight is on indentation spaces or tabs.

I find the mechanism better than nothing however, and calling
"exchange-my-mark" twice, will often fix up the highlight.

A similar technique could be used to implement a "show-mark" function which
would highlight the mark for a fraction of a second for-instance, but in fact
the exchange-dot-and-mark function really gives you all you need!

					Ray Dunn. Micom. Montreal
					philabs!micomvax!ray

;NOTE: Escape is shown as the two characters ^ and [

(declare-buffer-specific my-mark MK)

(defun
  (set-dsp-mark c
    (sit-for 0)
    (send-string-to-terminal "^[[7m")
    (setq c (following-char))
    (send-string-to-terminal (if (|(= 9 c)(= 10 c)) " " (char-to-string c)))
    (send-string-to-terminal "^[[m^[[1D")
    (set-mark)
  )

  (clr-dsp-mark c
    (if (dot-is-visible)
      (progn
	(sit-for 0)
	(setq c (following-char))
	(send-string-to-terminal
	  (if (|(= 9 c)(= 10 c)) " " (char-to-string c)))
	(send-string-to-terminal "^[[1D"))
    )
  )

  (set-my-mark
    (if MK (save-excursion (goto-character my-mark)(clr-dsp-mark)))
    (setq my-mark (dot))
    (set-dsp-mark)
    (setq MK 1)
  )

  (exchange-my-mark m
    (if (! MK)(error-message "No mark set"))
    (setq m my-mark)(setq my-mark (dot))(set-dsp-mark)
    (goto-character m)(clr-dsp-mark)
  )
)