Function: mh-generate-sequence-font-lock

mh-generate-sequence-font-lock is a macro defined in mh-folder.el.gz.

Signature

(mh-generate-sequence-font-lock SEQ PREFIX FACE)

Documentation

Generate the appropriate code to fontify messages in SEQ.

PREFIX is used to generate unique names for the variables and functions defined by the macro. So a different prefix should be provided for every invocation. FACE is the font-lock face used to display the matching scan lines.

Source Code

;; Defined in /usr/src/emacs/lisp/mh-e/mh-folder.el.gz
;; Fontify unseen messages in bold.

(defmacro mh-generate-sequence-font-lock (seq prefix face)
  "Generate the appropriate code to fontify messages in SEQ.
PREFIX is used to generate unique names for the variables and
functions defined by the macro. So a different prefix should be
provided for every invocation.
FACE is the font-lock face used to display the matching scan lines."
  (let ((cache (intern (format "mh-folder-%s-seq-cache" prefix)))
        (func (intern (format "mh-folder-font-lock-%s" prefix))))
    `(progn
       (defvar-local ,cache nil
         "Internal cache variable used for font-lock in MH-E.
Should only be non-nil through font-lock stepping, and nil once
font-lock is done highlighting.")

       (defun ,func (limit)
         "Return unseen message lines to font-lock between point and LIMIT."
         (if (not ,cache) (setq ,cache (mh-seq-msgs (mh-find-seq ,seq))))
         (let ((cur-msg (mh-get-msg-num nil)))
           (cond ((not ,cache)
                  nil)
                 ((>= (point) limit)              ;Presumably at end of buffer
                  (setq ,cache nil)
                  nil)
                 ((member cur-msg ,cache)
                  (let ((bpoint (progn (beginning-of-line)(point)))
                        (epoint (progn (forward-line 1)(point))))
                    (if (<= limit (point)) (setq  ,cache nil))
                    (set-match-data (list bpoint epoint bpoint epoint))
                    t))
                 (t
                  ;; move forward one line at a time, checking each message
                  (while (and (= 0 (forward-line 1))
                              (> limit (point))
                              (not (member (mh-get-msg-num nil) ,cache))))
                  ;; Examine how we must have exited the loop...
                  (let ((cur-msg (mh-get-msg-num nil)))
                    (cond ((or (<= limit (point))
                               (not (member cur-msg ,cache)))
                           (setq ,cache nil)
                           nil)
                          ((member cur-msg ,cache)
                           (let ((bpoint (progn (beginning-of-line) (point)))
                                 (epoint (progn (forward-line 1) (point))))
                             (if (<= limit (point)) (setq ,cache nil))
                             (set-match-data
                              (list bpoint epoint bpoint epoint))
                             t))))))))

       (setq mh-folder-font-lock-keywords
             (append mh-folder-font-lock-keywords
                     (list (list ',func (list 1 '',face 'prepend t))))))))