Function: generic-set-comment-syntax

generic-set-comment-syntax is a byte-compiled function defined in generic.el.gz.

Signature

(generic-set-comment-syntax ST COMMENT-LIST)

Documentation

Set up comment functionality for generic mode.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/generic.el.gz
(defun generic-set-comment-syntax (st comment-list)
  "Set up comment functionality for generic mode."
  (let ((chars nil)
	(comstyles)
        (comment-start nil))

    ;; Go through all the comments.
    (pcase-dolist (`(,start . ,end) comment-list)
      (let ((comstyle
             ;; Reuse comstyles if necessary.
             (or (cdr (assoc start comstyles))
                 (cdr (assoc end comstyles))
                 ;; Otherwise, use a style not yet in use.
                 (if (not (rassoc "" comstyles)) "")
                 (if (not (rassoc "b" comstyles)) "b")
                 "c")))
       (push (cons start comstyle) comstyles)
       (push (cons end comstyle) comstyles)

	;; Setup the syntax table.
	(if (= (length start) 1)
	    (modify-syntax-entry (aref start 0)
				 (concat "< " comstyle) st)
	  (let ((c0 (aref start 0)) (c1 (aref start 1)))
	    ;; Store the relevant info but don't update yet.
	    (push (cons c0 (concat (cdr (assoc c0 chars)) "1")) chars)
	    (push (cons c1 (concat (cdr (assoc c1 chars))
				   (concat "2" comstyle)))
		  chars)))
	(if (= (length end) 1)
	    (modify-syntax-entry (aref end 0)
				 (concat ">" comstyle) st)
	  (let ((c0 (aref end 0)) (c1 (aref end 1)))
	    ;; Store the relevant info but don't update yet.
	    (push (cons c0 (concat (cdr (assoc c0 chars))
				   (concat "3" comstyle)))
		  chars)
	    (push (cons c1 (concat (cdr (assoc c1 chars)) "4")) chars)))))

    ;; Process the chars that were part of a 2-char comment marker
    (with-syntax-table st               ;For `char-syntax'.
    (dolist (cs (nreverse chars))
      (modify-syntax-entry (car cs)
			   (concat (char-to-string (char-syntax (car cs)))
				   " " (cdr cs))
                             st)))))