Function: cider-xref--ns-context
cider-xref--ns-context is a byte-compiled function defined in
cider-xref-source.el.
Signature
(cider-xref--ns-context TARGET-NS NAME)
Documentation
Parse the current buffer to learn how TARGET-NS and NAME are brought in.
Return a plist with :this-ns (the file's own namespace), :alias (this file's
alias for TARGET-NS, or nil), :referred (non-nil when NAME can be used
unqualified in this file), and :ns-beg/:ns-end (the bounds of the (ns ...)
form, so its own require declarations can be excluded from matches). When
TARGET-NS is nil only bare matching applies, so :referred is forced on.
Source Code
;; Defined in ~/.emacs.d/elpa/cider-20260822.1520/cider-xref-source.el
(defun cider-xref--ns-context (target-ns name)
"Parse the current buffer to learn how TARGET-NS and NAME are brought in.
Return a plist with `:this-ns' (the file's own namespace), `:alias' (this file's
alias for TARGET-NS, or nil), `:referred' (non-nil when NAME can be used
unqualified in this file), and `:ns-beg'/`:ns-end' (the bounds of the `(ns ...)'
form, so its own require declarations can be excluded from matches). When
TARGET-NS is nil only bare matching applies, so `:referred' is forced on."
(save-excursion
(goto-char (point-min))
(let (this-ns alias referred ns-beg ns-end)
;; Locate the `(ns ...)' form and the file's own namespace.
(when (re-search-forward (concat "(ns\\(?:" cider-xref--ws "\\|$\\)") nil t)
(goto-char (match-beginning 0))
(setq ns-beg (point))
(ignore-errors (forward-sexp))
(setq ns-end (point))
(goto-char ns-beg)
(when (re-search-forward
(concat "(ns" cider-xref--ws "+"
"\\(?:\\^[^ \t\r\n\f]+" cider-xref--ws "+\\)*" ; skip metadata
"\\([^ \t\r\n\f()]+\\)")
ns-end t)
(setq this-ns (match-string-no-properties 1))))
;; Within the ns form, find the libspec for TARGET-NS and read off its
;; `:as'/`:as-alias' alias and any `:refer'. (These run on the extracted
;; libspec string, where `[:space:]' behaves normally.)
(when (and target-ns ns-beg ns-end)
(goto-char ns-beg)
(when (re-search-forward
(concat "\\_<" (regexp-quote target-ns) "\\_>") ns-end t)
(when-let* ((libspec (cider-xref--enclosing-libspec
(match-beginning 0) ns-end)))
(when (string-match
":as\\(?:-alias\\)?[[:space:]]+\\([^][[:space:](){}]+\\)" libspec)
(setq alias (match-string 1 libspec)))
(when (or (string-match-p ":refer[[:space:]]+:all" libspec)
(and (string-match ":refer[[:space:]]+\\[\\([^]]*\\)\\]" libspec)
(member name (split-string (match-string 1 libspec)
"[[:space:]]+" t))))
(setq referred t)))))
;; A var defined in this namespace is naturally used unqualified here.
(when (and target-ns (equal this-ns target-ns))
(setq referred t))
(unless target-ns
(setq referred t))
(list :this-ns this-ns :alias alias :referred referred
:ns-beg ns-beg :ns-end ns-end))))