Function: hif-token-concatenation

hif-token-concatenation is a byte-compiled function defined in hideif.el.gz.

Signature

(hif-token-concatenation L)

Documentation

Scan token list for hif-token-concat ('##') token and concatenate tokens.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/hideif.el.gz
(defun hif-token-concatenation (l)
  "Scan token list for `hif-token-concat' ('##') token and concatenate tokens."
  (if (memq 'hif-token-concat l)
      ;; Notice that after some substitutions, there could be more than
      ;; one `hif-space' in a list.
      (let ((items nil)
            (tk nil)
            (count 0) ; count of `##'
            result)
        (setq l (hif-keep-single l 'hif-space))
        (while (setq tk (car l))
          (if (not (eq tk 'hif-token-concat))
              ;; In reverse order so that we don't have to use `last' or
              ;; `butlast'
              (progn
                (push tk result)
                (setq l (cdr l)))
            ;; First `##' met, start `##' sequence
            ;; We only drop `hif-space' when doing token concatenation
            (setq items nil
                  count 0)
            (setq tk (pop result))
            (if (or (null tk)
                    (and (eq tk 'hif-space)
                         (null (setq tk (pop result)))))
                (error "No token before `##' to concatenate")
              (push tk items) ; first item, in reverse order
              (setq tk 'hif-token-concat))
            (while (eq tk 'hif-token-concat)
              (incf count)
              ;; 2+ item
              (setq l (cdr l)
                    tk (car l))
              ;; only one 'hif-space could appear here
              (if (eq tk 'hif-space) ; ignore it
                  (setq l (cdr l)
                        tk (car l)))
              (if (or (null tk)
                      (eq tk 'hif-token-concat))
                  (error
                   "No token after the %d-th `##' to concatenate at line %d"
                   count (line-number-at-pos))
                (push tk items)
                (setq l (cdr l)
                      tk (car l))))
            ;; `##' sequence ended, concat them, then push into result
            (push (hif-token-concat (nreverse items)) result)))
        (nreverse result))
    ;; no need to reassemble the list if no `##' presents
    l))