Function: hfy-parse-tags-buffer

hfy-parse-tags-buffer is a byte-compiled function defined in htmlfontify.el.gz.

Signature

(hfy-parse-tags-buffer SRCDIR BUFFER)

Documentation

Parse a BUFFER containing etags formatted output, loading the hfy-tags-cache and hfy-tags-sortl entries for SRCDIR.

Source Code

;; Defined in /usr/src/emacs/lisp/htmlfontify.el.gz
;; break this out from `hfy-load-tags-cache' to make the tar file
;; functionality easier to implement.
;; ( tar file functionality not merged here because it requires a
;;   hacked copy of etags capable of tagging stdin: if Francesco
;;   Potortì accepts a patch, or otherwise implements stdin tagging,
;;   then I will provide a `htmlfontify-tar-file' defun )
(defun hfy-parse-tags-buffer (srcdir buffer)
  "Parse a BUFFER containing etags formatted output, loading the
`hfy-tags-cache' and `hfy-tags-sortl' entries for SRCDIR."
  (let ((cache-entry     (assoc srcdir    hfy-tags-cache))
        (tlist-cache     (assoc srcdir    hfy-tags-sortl))
        (trmap-cache     (assoc srcdir    hfy-tags-rmap ))
        (cache-hash nil) (trmap-hash nil) (tags-list  nil)
        (hash-entry nil) (tag-string nil) (tag-line   nil)
        (tag-point  nil) (new-entry  nil) (etags-file nil))

    ;; (re)initialize the tag reverse map:
    (if trmap-cache (setq trmap-hash (cadr trmap-cache))
      (setq trmap-hash (make-hash-table :test 'equal))
      (setq hfy-tags-rmap (list (list srcdir trmap-hash) hfy-tags-rmap)))
    (clrhash trmap-hash)

    ;; (re)initialize the tag cache:
    (if cache-entry (setq cache-hash (cadr cache-entry))
      (setq cache-hash (make-hash-table :test 'equal))
      (setq hfy-tags-cache (list (list srcdir cache-hash) hfy-tags-cache)))
    (clrhash cache-hash)

    ;; cache the TAG => ((file line point) (file line point) ... ) entries:
    (with-current-buffer buffer
      (goto-char (point-min))

      (while (and (looking-at "^\x0c") (= 0 (forward-line 1)))
        ;;(message "^L boundary")
        (if (and (looking-at "^\\(.+\\),\\([0-9]+\\)$")
                 (= 0 (forward-line 1)))
            (progn
              (setq etags-file (match-string 1))
              ;;(message "TAGS for file: %s" etags-file)
              (while (and (looking-at hfy-etag-regex) (= 0 (forward-line 1)))
                (setq tag-string (match-string 1))
                (if (= 0 (length tag-string)) nil ;; noop
                  (setq tag-line   (round (string-to-number (match-string 2))))
                  (setq tag-point  (round (string-to-number (match-string 3))))
                  (setq hash-entry (gethash tag-string  cache-hash))
                  (setq new-entry  (list etags-file tag-line tag-point))
                  (push new-entry hash-entry)
                  ;;(message "HASH-ENTRY %s %S" tag-string new-entry)
                  (puthash tag-string hash-entry cache-hash)))) )))

    ;; cache a list of tags in descending length order:
    (maphash (lambda (K _V) (push K tags-list)) cache-hash)
    (setq tags-list (sort tags-list (lambda (A B) (< (length B) (length A)))))

    ;; put the tag list into the cache:
    (if tlist-cache (setcar (cdr tlist-cache) tags-list)
      (push (list srcdir tags-list) hfy-tags-sortl))

    ;; return the number of tags found:
    (length tags-list) ))