Function: claude-code-ide--assign-window-slot

claude-code-ide--assign-window-slot is a natively compiled function defined in claude-code-ide.el.

Signature

(claude-code-ide--assign-window-slot PROJECT-DIR)

Documentation

Return a side-window slot for a new instance of PROJECT-DIR.

Each project owns a block of claude-code-ide--window-slot-block slots, so windows sort as emacs, emacs, src, src rather than by creation order. Within the block the smallest slot not used by any live session is picked (the global check also keeps legacy out-of-block slots collision-free).

Source Code

;; Defined in /nix/store/yjvbhwl7p6zrbw9xlnni7y4hra8sa3pl-emacs-packages-deps/share/emacs/site-lisp/claude-code-ide.el
(defun claude-code-ide--assign-window-slot (project-dir)
  "Return a side-window slot for a new instance of PROJECT-DIR.
Each project owns a block of `claude-code-ide--window-slot-block'
slots, so windows sort as emacs, emacs, src, src rather than by
creation order.  Within the block the smallest slot not used by any
live session is picked (the global check also keeps legacy
out-of-block slots collision-free)."
  (let* ((block claude-code-ide--window-slot-block)
         (siblings (cl-remove-if-not #'claude-code-ide-mcp-session-window-slot
                                     (claude-code-ide-mcp--sessions-for-project project-dir)))
         (all-slots (cl-remove nil
                               (mapcar #'claude-code-ide-mcp-session-window-slot
                                       (claude-code-ide-mcp--active-sessions)))))
    (cl-flet ((free-block-base ()
                (let ((used-bases (mapcar (lambda (slot) (floor slot block))
                                          all-slots))
                      (b 0))
                  (while (memq b used-bases)
                    (cl-incf b))
                  (* block b))))
      (let* ((base (if siblings
                       ;; Join the project's existing block
                       (* block (floor (claude-code-ide-mcp-session-window-slot
                                        (car siblings))
                                       block))
                     ;; New project: smallest block no live session occupies
                     (free-block-base)))
             (slot base))
        (while (and (< slot (+ base block))
                    (memq slot all-slots))
          (cl-incf slot))
        ;; Block exhausted: overflow into a fresh block rather than
        ;; spilling into a neighboring project's block
        (when (>= slot (+ base block))
          (setq slot (free-block-base)))
        slot))))