Function: combobulate--navigate-sequence

combobulate--navigate-sequence is a natively compiled function defined in combobulate-navigation.el.

Signature

(combobulate--navigate-sequence DIRECTION)

Documentation

Navigate to the next node in the sequence in DIRECTION.

If there is no node in the sequence in DIRECTION, raise an error.

If the command is re-issued after an error is raised, the search will continue by scanning in DIRECTION for any other contextual node (as per context-nodes) that has the same text.

Source Code

;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-navigation.el
(defun combobulate--navigate-sequence (direction)
  "Navigate to the next node in the sequence in DIRECTION.

If there is no node in the sequence in DIRECTION, raise an error.

If the command is re-issued after an error is raised, the search will
continue by scanning in DIRECTION for any other contextual node (as per
`context-nodes') that has the same text."
  (let* ((thing (thing-at-point 'symbol))
         (node (combobulate--get-nearest-navigable-node))
         (node-text (or (with-navigation-nodes (:procedures (combobulate-read context-nodes))
                          ;; we must explicitly get the nearest
                          ;; navigable node again as we have changed
                          ;; the context.
                          (combobulate-node-text (combobulate--get-nearest-navigable-node)))
                        ;; fall back to the thing at point if this
                        ;; function is triggered in a comment, string,
                        ;; or other ex-node context.
                        thing))
         (seq-nodes (ignore-errors (combobulate-procedure-start-matches node))))
    (cond
     ;; This is the 'fallback scan' in case there are no sequences
     ;; available at/near point. It can only trigger if:
     ;;
     ;; 1. There are no sequences available at/near point.  2. The
     ;; last command was a sequence scan, indicating continuity (i.e.,
     ;; the user has requested multiple scans in a row and we should
     ;; just proceed accordingly.)
     ((or (null seq-nodes)
          (eq last-command 'combobulate-navigation-sequence-scan))
      (unless thing (error "No valid symbol at point"))
      (setq this-command 'combobulate-navigation-sequence-scan)
      (combobulate--navigate-scan
       ;; Use the last term if we have one, otherwise use the symbol
       ;; at point.
       (if (not (eq last-command 'combobulate-navigation-sequence-scan))
           (progn (push-mark)
                  (setq combobulate--navigate-term thing))
         combobulate--navigate-term)
       direction))
     ;; This is the 'normal' case where we have sequences available
     ;; at/near point.
     ((member this-command '(combobulate-navigate-sequence-next
                             combobulate-navigate-sequence-previous))
      ;; Find the following node in the direction we are told to look
      ;; and return it if there is such a node.
      (if-let (following-node (if (eq direction 'next)
                                  (seq-find #'combobulate-node-after-point-p seq-nodes)
                                (seq-find #'combobulate-node-before-point-p (reverse seq-nodes))))
          following-node
        ;; Hack this/last command so it thinks we're doing a sequence
        ;; scan. This is probably the simplest way of passing state
        ;; between commands without having to build an elaborate state
        ;; machine and ensure it does not go out of sync if myriad of
        ;; conditions cause it to do so.
        (setq last-command 'combobulate-navigation-sequence-scan
              this-command 'combobulate-navigation-sequence-scan)
        ;; Capture the current symbol at point.
        (setq combobulate--navigate-term thing)
        ;; Throw an error so the user knows there is no node that
        ;; follows in DIRECTION.
        (user-error
         (format "%s (repeat command to scan for `%s')"
                 (if (eq direction 'next)
                     "No next node in sequence"
                   "No previous node in sequence")
                 node-text)))))))