Fork me on GitHub
#emacs
<
2022-02-25
>
Casey14:02:00

hi there folks. I'm looking for a mechanism to switch buffers/files by namespace rather than file. I use doom with ivy+projectile and use the projectile-find-file to hop around the codebase. But I'd much rather browse at the namespace level than the file. Any idea if there's some combo of cider/lsp that can make this happen? Or maybe let me open the question more: how do you browse around namespaces ?

2
ericdallo14:02:32

maybe you can use consult-lsp-symbols ?

ericdallo14:02:41

there is no such feature that return only namespaces though AFAIK

enn16:02:54

This isn’t quite what you are looking for, but I have a snippet that sets the names of Clojure buffers to the namespace, rather than the file:

(defun tc/rename-buffer-to-ns ()
  (interactive)
  (when (buffer-file-name)
    (let ((ns (clojure-expected-ns)))
      (when (not (string= "" ns))
        (rename-buffer ns)))))

(add-hook 'clojure-mode-hook 'tc/rename-buffer-to-ns)

enn16:02:17

Handy for navigating buffers once they’re open, but doesn’t really address the problem of finding files

practicalli-johnny17:02:45

helm-lsp-workspace-symbol looks very useful, lists namespaces and symbols in those namespaces (I assume this is similar to consult-lsp-symbols) Otherwise, I either jump to definition if the namespace or function is used in the current buffer (and easy to jump the cursor too) Mostly I use projectile find file - fuzzy matching of the pattern means _ characters can be skipped (as can most of the name), so narrowing by namespace name would be the same pattern as use with filenames anyway. cider-browse-ns could be used, although I believe it only lists loaded namespaces and requires navigating through a document popup that contains a link to the namespace file. Much more fiddly.

practicalli-johnny18:02:47

oh, and there is cider-find-ns which lists all loaded (evaluated) namespaces in the current project. This seems to be what the original ask was (assuming the namespaces are all loaded in the running REPL)

Casey08:02:58

consult-lsp-symbols is only available in doom when using vertico. But I'm using ivy.

Casey08:02:27

cider-find-ns is nice! But it doesn't prioritize "project" ns over ns from dependencies

Casey08:02:35

I'll play some more with these