Function: combobulate--get-sibling

combobulate--get-sibling is a natively compiled function defined in combobulate-navigation.el.

Signature

(combobulate--get-sibling NODE DIRECTION)

Documentation

Returns the sibling node of NODE in the specified DIRECTION.

The sibling node is determined by the value of DIRECTION, which can be either backward or forward. If DIRECTION is backward, the previous sibling of NODE is returned.

If DIRECTION is forward, the next sibling of NODE is returned.

If DIRECTION is self, then NODE is resolved to the closes self-like sibling node.

The function will aggressively try to search through the parents of the current node if the direction if forward. This is done to try and prevent point from getting stuck at the end of a node that technically has another immediate parent.

Source Code

;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-navigation.el
(defun combobulate--get-sibling (node direction)
  "Returns the sibling node of NODE in the specified DIRECTION.

The sibling node is determined by the value of DIRECTION, which
can be either `backward' or `forward'. If DIRECTION is
`backward', the previous sibling of NODE is returned.

If DIRECTION is `forward', the next sibling of NODE is
returned.

If DIRECTION is `self', then NODE is resolved to the closes
self-like sibling node.

The function will aggressively try to search through the parents
of the current node if the direction if `forward'. This is done
to try and prevent point from getting stuck at the end of a node
that technically has another immediate parent."
  (when node
    (save-excursion
      (combobulate--goto-node node)
      (let* ((siblings (combobulate-nav-get-siblings node)))
        (cond
         ((eq direction 'forward)
          (car (seq-filter #'combobulate-node-after-point-p siblings)))
         ((eq direction 'backward)
          (car (last (seq-filter #'combobulate-node-before-point-p siblings))))
         ((eq direction 'self)
          (or (car (seq-filter #'combobulate-point-at-beginning-of-node-p siblings))
              (when (combobulate-point-at-beginning-of-node-p node) node))))))))