From xemacs-m  Fri Sep 19 03:21:46 1997
Received: from frege.math.ethz.ch (root@frege-d-math-north-g-west.math.ethz.ch [129.132.145.3])
	by xemacs.org (8.8.5/8.8.5) with SMTP id DAA28793
	for <xemacs-beta@xemacs.org>; Fri, 19 Sep 1997 03:21:45 -0500 (CDT)
Received: from midget (vroonhof@midget [129.132.145.4]) by frege.math.ethz.ch (8.6.12/Main-STAT-mailer) with ESMTP id KAA29734 for <xemacs-beta@xemacs.org>; Fri, 19 Sep 1997 10:21:40 +0200
Received: (vroonhof@localhost) by midget (SMI-8.6/D-MATH-client) id KAA29933; Fri, 19 Sep 1997 10:21:40 +0200
To: xemacs-beta@xemacs.org
Subject: lazy-shot.el
Mime-Version: 1.0 (generated by tm-edit 7.106)
Content-Type: multipart/mixed;
 boundary="Multipart_Fri_Sep_19_10:21:40_1997-1"
Content-Transfer-Encoding: 7bit
From: Jan Vroonhof <vroonhof@math.ethz.ch>
Date: 19 Sep 1997 10:21:40 +0200
Message-ID: <byraalogrv.fsf@midget.math.ethz.ch>
Lines: 133
X-Mailer: Gnus v5.4.55/XEmacs 19.15

--Multipart_Fri_Sep_19_10:21:40_1997-1
Content-Type: text/plain; charset=US-ASCII


We have exmans to correct the next weeks so I don't have the time to
work on this. Here is a basic working version of lazy-shot.el



--Multipart_Fri_Sep_19_10:21:40_1997-1
Content-Type: application/octet-stream; type=emacs-lisp
Content-Disposition: attachment; filename="lazy-hot.el"
Content-Transfer-Encoding: 7bit

;; Jan Vroonhof <vroonhof@math.ethz.ch>
;; This file is part of XEmacs
;; and falls under the GNU Public Licence Version 2
;; or later 
;; 
;; This versions has basic demand lock functionality. Somebody please
;; sync further with lazy-lock v2 from FSF add proper comments header,
;; customize etc.
;;
;;
;; Idea for the stealth lock function:
;;
;;
;; On an Idle itimer
;;    Loop over all buffers with lazy-lock set
;;       mapcar-extent in the region  (point) point-max for
;;                      one-shot-function property
;;         If not found do the same for [point-min,point]
;;         font-lock the found region and delete the extent



(require 'font-lock)

(defvar lazy-lock-mode nil)


(defvar lazy-lock-step-size (* 1 124)) ;; Please test diffent sizes

;;;###autoload
(defun lazy-lock-mode (&optional arg)
  "Toggle Lazy Lock mode.
With arg, turn Lazy Lock mode on if and only if arg is positive."
  (interactive "P")
  (set (make-local-variable 'lazy-lock-mode)
       (and (if arg (> (prefix-numeric-value arg) 0) (not lazy-lock-mode))))
  (cond ((and lazy-lock-mode (not font-lock-mode))
	 ;; Turned on `lazy-lock-mode' rather than `font-lock-mode'.
	 (let ((font-lock-support-mode 'lazy-lock-mode))
	   (font-lock-mode t)))
	(lazy-lock-mode
	 ;; Turn ourselves on.
	 (lazy-lock-install))
	(t
	 ;; Turn ourselves off.
	 (lazy-lock-unstall))))

;;;###autoload
(defun turn-on-lazy-lock ()
  "Unconditionally turn on Lazy Lock mode."
  (lazy-lock-mode t))


(defun lazy-lock-shot-function (extent)
   "Lazy lock the extent when it has become visisble"
   (let ((start (extent-start-position extent))
         (end   (extent-end-position extent))
	 (buffer (extent-buffer extent)))
     (delete-extent extent)
     (save-excursion 
       ;; This magic should really go into font-lock-fonity-region
       (goto-char start)
       (unless (bolp)
	 (beginning-of-line)
	 (setq start (point)))
       (goto-char end)
       (unless (bolp)
	 (forward-line)
	 (setq end (point)))
       (message "Lazy-shot fontifying from %s to %s in %s" start end buffer)
       (save-match-data
	   (font-lock-fontify-region start end)))))

(defun lazy-lock-install-extent (spos epos &optional buffer)
  "Make an extent that will lazy-lock if it is displayed"
     (let ((extent (make-extent spos epos buffer)))
       (when extent
         (set-extent-one-shot-function extent
                       'lazy-lock-shot-function))
       extent))

(defun lazy-lock-install-extents (fontifying)
  ;;
  ;; Add hook if lazy-lock.el is deferring or is fontifying on scrolling.
     (when fontifying
     (let ((start  (point-min)))
      (while (< start (point-max))
         (lazy-lock-install-extent start
           (min (point-max) (+ start lazy-lock-step-size)))
         (setq start (+ start lazy-lock-step-size))))))

(defun lazy-lock-install ()
  (make-local-variable 'font-lock-fontified)
  (setq font-lock-fontified t)
  (lazy-lock-install-extents font-lock-fontified))

(defun lazy-lock-unstall ()
  ;;
  ;; Remove the extents.
  (map-extents 
     (lambda (e arg) (delete-extent e) nil) 
     nil nil nil nil nil 'one-shot-function 'lazy-lock-shot-function)
  ;;
  ;; Remove the fontification hooks.
  (remove-hook 'after-change-functions 'lazy-lock-defer-after-change t)
  ;;
  ;; If Font Lock mode is still enabled, reinstall its hook.
  (when font-lock-mode
    (add-hook 'after-change-functions 'font-lock-after-change-function nil t)))


(provide 'lazy-lock)

--Multipart_Fri_Sep_19_10:21:40_1997-1
Content-Type: text/plain; charset=US-ASCII



--Multipart_Fri_Sep_19_10:21:40_1997-1--

