Function: expreg--comment

expreg--comment is a natively compiled function defined in expreg.el.

Signature

(expreg--comment)

Documentation

Return a list of regions containing comment.

Source Code

;; Defined in /nix/store/29cdhkmkqv2bgp3p30khhf35kkbgx1ya-emacs-packages-deps/share/emacs/site-lisp/elpa/expreg-1.4.1/expreg.el
(defun expreg--comment ()
  "Return a list of regions containing comment."
  (let ((orig (point))
        (beg (point))
        (end (point))
        result forward-succeeded trailing-comment-p)

    ;; Go backward to the beginning of a comment (if exists).
    (while (expreg--inside-comment-p)
      (backward-char))

    ;; Now we are either at the beginning of a comment, or not on a
    ;; comment at all. (When there are multiple lines of comment,
    ;; each line is an individual comment.)
    (while (and (save-excursion
                  (expreg--inside-comment-p
                   (min (point-max) (1+ (point)))))
                (forward-comment 1))
      (setq end (point))
      (setq forward-succeeded t))
    (while (and (save-excursion
                  (expreg--inside-comment-p
                   (max (point-min) (1- (point)))))
                (forward-comment -1))
      (setq beg (point)))

    (goto-char beg)
    (setq trailing-comment-p
          (not (looking-back (rx bol (* whitespace))
                             (line-beginning-position))))
    (when (not trailing-comment-p)
      ;; Move BEG to BOL.
      (skip-chars-backward " \t")
      (setq beg (point))

      ;; Move END to BOL.
      (goto-char end)
      (skip-chars-backward " \t")
      (setq end (point)))

    (when (and forward-succeeded
               ;; If we are at the BOL of the line below a comment,
               ;; don’t include this comment. (END will be at the
               ;; BOL of the line after the comment.)
               (< orig end))
      (push `(comment . ,(cons beg end)) result))
    result))