   )
 
 
+(defun jpw-phpBB-display-tag-analysis ()
+  "Show the results of `jpw-phpBB-tag-analysis' in the *Messages* buffer.
+{jpw: 09/2005}"
+  (interactive)
+  (message "%S" (jpw-phpBB-tag-analysis))
+  )
+
 ;;------------------------------------------------------------
 ;;
 ;; Bindings: Define Local Keymap

        :underline t :bold t)))
  "The face to use for URLs."
  :group 'phpBB)


;;------------------------------------------------------------

  )


;;
;; TODO:
;; Cache the analysis results, so we don't need to keep repeating them.
;;


(defun jpw-phpBB-tag-analysis ()
  "Search forward and backward from `point' to see what tags we're enclosed
in.  Returns a list of pairs.  Each pair is the position of the start tag and
end tag, respectively.  The list of pairs is built from the inside-out.

So, `\(car \(caadr \(jpw-phpBB-tag-analysis\)\)\)' would return the position of
the innermost start tag.

Returns nil if `point' is not enclosed in any phpBB tags.

The results of recent calls to this function are stored in the variable
`jpw-phpBB-tag-analysis-cache'.
{jpw: 09/2005}"
  (let* ((cached-inner-tagspec (car (reverse jpw-phpBB-tag-analysis-cache)))
         (cached-inner-startp (caadr cached-inner-tagspec))
         (cached-inner-endp (cadadr cached-inner-tagspec))
         (buffer-state (list (buffer-modified-p) (buffer-modified-tick)
                             (buffer-size)))
         current-tagspec
         );;end var defs

    ;; Clear the analysis cache if the buffer state has changed since last
    ;; call.
    (if (not (equal jpw-phpBB-tag-analysis-cache-last-update-buffer-state
                    buffer-state))
        (setq jpw-phpBB-tag-analysis-cache '())
      )
    (if (and (not (or (null cached-inner-startp)
                      (null cached-inner-endp)))
             (<= cached-inner-startp (point))
             (<= (point) cached-inner-endp))
        jpw-phpBB-tag-analysis-cache
      ;;else
      (save-excursion
        (setq current-tagspec (jpw-phpBB-tag-find-enclosing nil nil t)
              jpw-phpBB-tag-analysis-cache '()
              )
        (while (car current-tagspec)
          (setq jpw-phpBB-tag-analysis-cache 
                (cons current-tagspec jpw-phpBB-tag-analysis-cache))
          (setq current-tagspec 
                (jpw-phpBB-tag-find-enclosing (1- (caadr current-tagspec))
                                              (1+ (cadadr current-tagspec))
                                              t))
          )
        (setq 
         jpw-phpBB-tag-analysis-cache-last-update-buffer-state
         buffer-state)
        );;end excursion
      );;end if
    );;end let
  )


