Function: cider--sesman-friendly-session-p
cider--sesman-friendly-session-p is a byte-compiled function defined
in cider-session.el.
Signature
(cider--sesman-friendly-session-p SESSION &optional DEBUG)
Documentation
Check if SESSION is a friendly session, DEBUG optionally.
A session is friendly to the current buffer when the buffer's file lives under the session's project directory. The checking is done as follows:
* If cider-default-session is set and the named session still
exists, only that session is considered friendly (it serves every
buffer, regardless of project context). When the named session has
been quit/killed, fall through to the normal matching logic.
* Consider if the buffer belongs to cider-ancillary-buffers.
* Consider the buffer's filename, strip any Docker/TRAMP details from it.
* Check whether that filename lives under the connection's project
directory.
Buffers associated with their originating session explicitly through
cider--pinned-repl-buffer (e.g. popups, or a dependency's source
jumped to via cider-find-var) resolve via that pin and don't rely on
this matcher.
The project directory is cached at connection time by
cider--cache-session-project-dir, so this function does not block on
any nREPL requests.
Source Code
;; Defined in ~/.emacs.d/elpa/cider-20260822.1520/cider-session.el
(defun cider--sesman-friendly-session-p (session &optional debug)
"Check if SESSION is a friendly session, DEBUG optionally.
A session is friendly to the current buffer when the buffer's file lives
under the session's project directory. The checking is done as follows:
* If `cider-default-session' is set and the named session still
exists, only that session is considered friendly (it serves every
buffer, regardless of project context). When the named session has
been quit/killed, fall through to the normal matching logic.
* Consider if the buffer belongs to `cider-ancillary-buffers'.
* Consider the buffer's filename, strip any Docker/TRAMP details from it.
* Check whether that filename lives under the connection's project
directory.
Buffers associated with their originating session explicitly through
`cider--pinned-repl-buffer' (e.g. popups, or a dependency's source
jumped to via `cider-find-var') resolve via that pin and don't rely on
this matcher.
The project directory is cached at connection time by
`cider--cache-session-project-dir', so this function does not block on
any nREPL requests."
(setcdr session (seq-filter #'buffer-live-p (cdr session)))
(when-let* ((repl (cadr session)))
(cond
;; If a default session is set and still exists, only that session is
;; friendly. If the named session no longer exists we fall through to
;; the normal matching logic, matching `cider-repls' behavior.
((cider--default-session)
(equal (car session) cider-default-session))
((member (buffer-name) cider-ancillary-buffers)
t)
(t
(when-let* ((proc (get-buffer-process repl))
(file (file-truename (or (buffer-file-name) default-directory))))
(when-let* ((tp (cider-tramp-prefix (current-buffer))))
(setq file (string-remove-prefix tp file)))
(when (process-live-p proc)
(let ((proj-dir (or (process-get proc :cached-project-dir)
(when-let* ((pd (buffer-local-value 'nrepl-project-dir repl)))
(file-name-as-directory (file-truename pd))))))
;; The project dir is cached as a truename-resolved directory (with
;; a trailing slash), so a plain `string-prefix-p' is both a correct
;; directory-boundary check and cheap enough for the redisplay hot
;; path. `file' is already resolved via `file-truename' above.
(or (and proj-dir (string-prefix-p proj-dir file))
;; For remote (TRAMP/Docker) sessions the project dir is a remote
;; path; translate the local file and match against it.
(when-let* ((cider-path-translations (cider--all-path-translations))
(translated (cider--translate-path file 'to-nrepl :return-all)))
(and proj-dir
(seq-find (lambda (tp) (string-prefix-p proj-dir (file-truename tp)))
translated)))
(when debug
(list file
"was not determined to belong to project-dir:" proj-dir))))))))))