Function: logview--forward-section

logview--forward-section is a natively compiled function defined in logview.el.

Signature

(logview--forward-section N &optional GO-TO-END)

Source Code

;; Defined in /nix/store/3zkn9hgpv447zb8nrg55d9x2ynmmrk40-emacs-packages-deps/share/emacs/site-lisp/elpa/logview-20260218.2013/logview.el
(defun logview--forward-section (n &optional go-to-end)
  (logview--locate-current-entry last-valid-entry last-valid-start
    ;; The logic of this code is pretty much impossible to follow.  Just trust it as long
    ;; as it passes the tests.
    (let* ((forward         (or (> n 0) (and (= n 0) go-to-end)))
           (limit           (if forward (logview--point-max) (logview--point-min)))
           (section-thread  (when (logview-sections-thread-bound-p)
                              (logview--entry-group last-valid-entry last-valid-start logview--thread-group)))
           (header-filter   (cdr logview--section-header-filter))
           ;; Current section is always visible.
           (visible-section t)
           (callback        (lambda (entry start)
                              ;; See comment above iterating calls.
                              (and (if forward (<= start limit) (> (logview--entry-end entry start) limit))
                                   ;; Ignore entries belonging to a "wrong" thread and continue.
                                   (or (and section-thread (not (string= (logview--entry-group entry start logview--thread-group) section-thread)))
                                       (let ((header (funcall header-filter entry start)))
                                         (if (and (= n 0) forward go-to-end header)
                                             nil
                                           (let ((invisible (invisible-p start)))
                                             (when header
                                               (unless (or invisible forward)
                                                 (setf visible-section t))
                                               (when visible-section
                                                 (setf n (if forward (1- n) (1+ n))))
                                               (when forward
                                                 (setf visible-section nil)))
                                             (or invisible
                                                 (progn
                                                   (setf last-valid-entry entry
                                                         last-valid-start start)
                                                   (when (or forward (not header))
                                                     (setf visible-section t))
                                                   (or (if forward
                                                           (or (> n 0) go-to-end)
                                                         (when (if go-to-end
                                                                   (or (< n 0) header)
                                                                 (or (<= n 0) (not header)))
                                                           (when header
                                                             (setf visible-section nil))
                                                           t))
                                                       (progn (setf n 0) nil))))))))))))
      ;; We don't skip invisible entries, since we need to detect section bounds even if
      ;; the headers are filtered out.  Therefore, the callback needs to take narrowing
      ;; into account explicitly.
      (if forward
          (logview--iterate-entries-forward last-valid-start callback nil nil t)
        (logview--iterate-entries-backward  last-valid-start callback))
      (goto-char (logview--entry-message-start last-valid-entry last-valid-start))
      (unless visible-section
        (setf n (if forward (1+ n) (1- n))))
      n)))