Function: table--generate-source-scan-lines

table--generate-source-scan-lines is a byte-compiled function defined in table.el.gz.

Signature

(table--generate-source-scan-lines DEST-BUFFER LANGUAGE ORIGIN-CELL TAIL-CELL COL-LIST ROW-LIST)

Documentation

Scan the table line by line.

Currently this method is for LaTeX only.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/table.el.gz
(defun table--generate-source-scan-lines (dest-buffer _language origin-cell tail-cell col-list row-list)
  "Scan the table line by line.
Currently this method is for LaTeX only."
  (let* ((lu-coord (table--get-coordinate (car origin-cell)))
	 (rb-coord (table--get-coordinate (cdr tail-cell)))
	 (x0 (car lu-coord))
	 (x1 (car rb-coord))
	 (y  (cdr lu-coord))
	 (y1 (cdr rb-coord)))
    (while (<= y y1)
      (let* ((border-p (memq (1+ y) row-list))
	     (border-char-list
	      (mapcar (lambda (x)
			(if border-p (char-after (table--goto-coordinate (cons x y)))
			  (char-before (table--goto-coordinate (cons x y)))))
		      col-list))
	     start i c)
	(if border-p
	    ;; horizontal cell border processing
	    (if (and (table--cell-horizontal-char-p (car border-char-list))
		     (table--uniform-list-p border-char-list))
		(with-current-buffer dest-buffer
		  (insert "\\hline\n"))
	      (setq i 0)
	      (while (setq c (nth i border-char-list))
		(if (and start (not (table--cell-horizontal-char-p c)))
		    (progn
		      (with-current-buffer dest-buffer
			(insert (format "\\cline{%d-%d}\n" (1+ start) i)))
		      (setq start nil)))
		(if (and (not start) (table--cell-horizontal-char-p c))
		    (setq start i))
		(setq i (1+ i)))
	      (if start
		  (with-current-buffer dest-buffer
		    (insert (format "\\cline{%d-%d}\n" (1+ start) i)))))
	  ;; horizontal cell contents processing
	  (let* ((span 1) ;; spanning length
		 (first-p t) ;; first in a row
		 (insert-column ;; a function that processes one column/multicolumn
                  (lambda (from to)
                    (let ((line (table--buffer-substring-and-trim
                                 (table--goto-coordinate (cons from y))
                                 (table--goto-coordinate (cons to y)))))
                      ;; escape special characters
                      (with-temp-buffer
                        (insert line)
                        (goto-char (point-min))
                        (while (re-search-forward "\\([#$~_^%{}&]\\)\\|\\(\\\\\\)\\|\\([<>|]\\)" nil t)
                          (if (match-beginning 1)
                              (save-excursion
                                (goto-char (match-beginning 1))
                                (insert  "\\"))
                            (if (match-beginning 2)
                                (replace-match "$\\backslash$" t t)
                              (replace-match (concat "$" (match-string 3) "$")) t t)))
                        (setq line (buffer-substring (point-min) (point-max))))
                      ;; insert a column separator and column/multicolumn contents
                      (with-current-buffer dest-buffer
                        (unless first-p
                          (insert (if (eq (char-before) ?\s) "" " ") "& "))
                        (if (> span 1)
                            (insert (format "\\multicolumn{%d}{%sl|}{%s}" span (if first-p "|" "") line))
                          (insert line)))
                      (setq first-p nil)
                      (setq span 1)
                      (setq start (nth i col-list))))))
	    (setq start x0)
	    (setq i 1)
	    (while (setq c (nth i border-char-list))
	      (if (eq c table-cell-vertical-char)
		  (funcall insert-column start (1- (nth i col-list)))
		(setq span (1+ span)))
	      (setq i (1+ i)))
	    (funcall insert-column start x1))
	  (with-current-buffer dest-buffer
	    (insert (if (eq (char-before) ?\s) "" " ") "\\\\\n"))))
      (setq y (1+ y)))
    (with-current-buffer dest-buffer
      (insert "\\hline\n"))
    ))