Function: so-long-detected-long-line-p

so-long-detected-long-line-p is a byte-compiled function defined in so-long.el.gz.

Signature

(so-long-detected-long-line-p)

Documentation

Determine whether the current buffer contains long lines.

Following any initial comments and blank lines, the next N lines of the buffer will be tested for excessive length (where "excessive" means greater than so-long-threshold characters, and N is so-long-max-lines).

Returns non-nil if any such excessive-length line is detected.

If so-long-skip-leading-comments is nil then the N lines will be counted starting from the first line of the buffer. In this instance you will likely want to increase so-long-max-lines to allow for possible comments.

This is the default so-long-predicate function in Emacs versions < 28.1.
(Starting from 28.1, the default and recommended predicate function is
so-long-statistics-excessive-p, which is faster and sees the entire buffer.)

Probably introduced at or before Emacs version 28.1.

Source Code

;; Defined in /usr/src/emacs/lisp/so-long.el.gz
(defun so-long-detected-long-line-p ()
  "Determine whether the current buffer contains long lines.

Following any initial comments and blank lines, the next N lines of the buffer
will be tested for excessive length (where \"excessive\" means greater than
`so-long-threshold' characters, and N is `so-long-max-lines').

Returns non-nil if any such excessive-length line is detected.

If `so-long-skip-leading-comments' is nil then the N lines will be counted
starting from the first line of the buffer.  In this instance you will likely
want to increase `so-long-max-lines' to allow for possible comments.

This is the default `so-long-predicate' function in Emacs versions < 28.1.
\(Starting from 28.1, the default and recommended predicate function is
`so-long-statistics-excessive-p', which is faster and sees the entire buffer.)"
  (let ((count 0) start)
    (save-excursion
      (goto-char (point-min))
      (when (and so-long-skip-leading-comments
                 (or comment-use-syntax ;; Refer to `comment-forward'.
                     (and comment-start-skip comment-end-skip)))
        ;; Skip the shebang line, if any.  This is not necessarily comment
        ;; syntax, so we need to treat it specially.
        (when (looking-at "#!")
          (forward-line 1))
        ;; Move past any leading whitespace and/or comments.
        ;; We use narrowing to limit the amount of text being processed at any
        ;; given time, where possible, as this makes things more efficient.
        (setq start (point))
        (while (save-restriction
                 (narrow-to-region start (min (+ (point) so-long-threshold)
                                              (point-max)))
                 (goto-char start)
                 ;; Possibilities for `comment-forward' are:
                 ;; 0. No comment; no movement; return nil.
                 ;; 1. Comment is <= point-max; move end of comment; return t.
                 ;; 2. Comment is truncated; move point-max; return nil.
                 ;; 3. Only whitespace; move end of WS; return nil.
                 (prog1 (or (comment-forward 1) ;; Moved past a comment.
                            (and (eobp) ;; Truncated, or WS up to point-max.
                                 (progn ;; Widen and retry.
                                   (widen)
                                   (goto-char start)
                                   (comment-forward 1))))
                   ;; Otherwise there was no comment, and we return nil.
                   ;; If there was whitespace, we moved past it.
                   (setq start (point)))))
        ;; We're at the first non-comment line, but we may have moved past
        ;; indentation whitespace, so move back to the beginning of the line
        ;; unless we're at the end of the buffer (in which case there was no
        ;; non-comment/whitespace content in the buffer at all).
        (unless (eobp)
          (forward-line 0)))
      ;; Start looking for long lines.
      ;; `while' will ultimately return nil if we do not `throw' a result.
      (catch 'excessive
        (while (and (not (eobp))
                    (or (not so-long-max-lines)
                        (< count so-long-max-lines)))
          (setq start (point))
          (save-restriction
            (narrow-to-region start (min (+ start 1 so-long-threshold)
                                         (point-max)))
            (forward-line 1))
          ;; If point is not now at the beginning of a line, then the previous
          ;; line was long -- with the exception of when point is at the end of
          ;; the buffer (bearing in mind that we have widened again), in which
          ;; case there was a short final line with no newline.  There is an
          ;; edge case when such a final line is exactly (1+ so-long-threshold)
          ;; chars long, so if we're at (eobp) we need to verify the length in
          ;; order to be consistent.
          (unless (or (bolp)
                      (and (eobp) (<= (- (point) start)
                                      so-long-threshold)))
            (throw 'excessive t))
          (setq count (1+ count)))))))