;;; -*-Emacs-Lisp-*-

;;; Addition to .emacs file
;;; Block highlight on cursor movement in Scheme-mode 
;;
;; Hrvoje Blazevic <hrvoje.blazevic@ri.tel.hr>

;; Insert the code below to your .emacs file

(set-face-foreground 'bold-italic "Blue")
(add-hook 'scheme-mode-hook (function font-lock-mode))
(add-hook 'scheme-mode-hook
	  (lambda ()
	    (add-hook 'post-command-hook
		      'scheme-post-command-highlight-function)))

(defun scheme-post-command-highlight-function ()
  "Flash matching opening paren after cursor movement commands."
  (and
   (memq this-command
	 '(backward-char forward-char previous-line next-line
			 backward-delete-char-untabify))
   (memq (preceding-char) '(93 41 125))
   (unwind-protect
       ;; Bind temporarily matching delay to 2 seconds & face to bold
       ;; Change 2 to whatever - delay is broken on first user action
       (let ((blink-matching-delay 2)
	     (region-face 5))
	 (push-mark nil t)
	 ;; Show the region
	 ;; This is very cheap, but will have to do - for now.
	 (setq transient-mark-mode t)
	 (blink-matching-open))
     (pop-mark)
     ;; We're back to normal
     (setq transient-mark-mode nil))))

