Fork me on GitHub
#emacs
<
2022-09-22
>
witek07:09:54

Hello, my eglot starts multiple lsp-servers. One for each major mode. When I open the first .clj file in my project, eglot starts a server:

[eglot] Connected! Server `EGLOT (clj/clojure-mode)' now managing `clojure-mode' buffers in project `clj'.
After that, when I open the first .cljc file, eglot starts another server:
[eglot] Connected! Server `EGLOT (clj/clojurec-mode)' now managing `clojurec-mode' buffers in project `clj'.
Same for .cljs files. Any ideas, how to configure eglot to use a single clojure-lsp server for all clojure modes (`clojure-mode`, clojurescript-mode, clojurec-mode,...) when files are opened in the same project?

ericdallo11:09:20

I don't know anything about eglot unfortunately, but the key is make sure eglot is sending the correct project root to clojure-lsp, lsp-mode has the workspace concept, eglot should have something similar

witek11:09:35

It does send the correct project root. Problem is that it sends the same project root to multiple clojure-lsp instances. One for each of clojure-mode, clojurec-mode and clojurescript-mod. 😞

ericdallo11:09:39

Oh, that's weird, never saw that with lsp-mode, so not sure why that is happening for eglot :(

witek11:09:39

I suspect, egot has a mapping of major mode to lsp server command. And since we are using multiple major modes for Clojure, this happens.

ericdallo12:09:17

lsp-mode does the same, it has a mapping that triggers lsp after entering in a major mode, this is correct, but what lsp-mode does is check if that buffer/file is associated to a running workspace

witek12:09:13

I will dive into Eglot code...

macrobartfast07:09:22

How can I see all the function names I have in a buffer at once? Or all the functions in a project? If I have a docstring in them would I be able to see those along with them (or other information about them)?

witek07:09:04

You can use consult-imenu to get a list of all functions in the current buffer and jump to them. And consult-imenu-multi for all functions for all buffers in the current project. This is just one way to do it.

macrobartfast16:09:33

Yay! Thank you.

oly09:09:39

anyone now how you can get cider to start shadow, I can get it to work with connect but would quite like the figwheel experience where I just connect, how ever with shadow I get this "error shadow-cljs has not been started yet!"

papachan16:09:27

Can we run some babashka tasks directly from M-x menu?

borkdude16:09:36

@papachan I guess you can write some elisp that shells out to bb right

🙌 1
papachan16:09:07

definitively but first have to ask if something have been already done. Was looking at cider recently which detect a bb.edn file.

borkdude16:09:11

Maybe ask in #babashka as well

teodorlu19:09:14

Here's a start, if you want to give it a shot yourself:

(let ((default-directory "~/dev/borkdude/blog")
      (options (s-split "\n"
                        (s-trim
                         (shell-command-to-string "bb tasks")))))
  (completing-read "which task?" options))
The strings need some cleaning, though :)

🎉 1
👀 1
papachan19:09:12

wow really cool !

❤️ 1
teodorlu19:09:15

Emacs sure is hackable 😁

teodorlu19:09:22

You might be interested in projectile-run-shell-command-in-root to list tasks relative to the current project root, rather than in a specific directory.

papachan21:09:59

Oh didnt know about projectile-run-shell-command-in-root

dakra10:09:03

There is also project-compile which is similar and built-in. And both commands project-/projectile-compile have autocomplete.

borkdude10:09:11

when you're done with this, feel free to post the elisp snippet to the babashka wiki

🙌 1
1
macrobartfast16:09:47

Is it possible to see a clj buffer in emacs in a ‘collapsed’ way… one line per defn or def and so on? I would be able to quickly see what’s in a buffer as well as the ordering is so.

dpsutton16:09:17

imenu is this

macrobartfast16:09:49

I see the list in the minibuffer in a different order… I would love to see them vertically stacked in a buffer in the order they actually appear (but maybe I’m using imenu differently).

dpsutton16:09:21

you can use occur and look for def

macrobartfast16:09:20

Oh yes! That’s perfect!

macrobartfast17:09:30

even shows the first line and args. I should be able to create something that would show the second line of each form, then, if I have docstrings, I’d be even more set.

dpsutton17:09:44

i think occur can take args of how much context to show

dpsutton17:09:05

check out m-x describe-function [ret] occur

teodorlu19:09:11

Hi! I want to use replace-regexp-in-region, but can't figure out how match a literal period in a regex. Help please? Specifically, I want to be able to mark a region around "desired input" below, and get "desired output":

Desired input:

Sentence one. Sentence two. Sentence three.

Desired output:

Sentence one.
Sentence two.
Sentence three.

teodorlu19:09:32

I tried this, which didn't do what I wanted:

(defun teod/tryit ()
  (interactive)
  (replace-regexp-in-region "\\.\ " ".\n"))

sw1nn20:09:37

M-x re-builder is useful for experimenting with regex in emacs. emacs regex syntax is slightly weird.

👀 1
👍 1
teodorlu20:09:34

re-builder is awesome! "\\. " might be what I want.

teodorlu20:09:06

I ended up going a different route:

(defun teod/one-line-per-sentence ()
  (interactive)
  (let* ((s (delete-and-extract-region (mark) (point)))
         (s2 (s-replace ". " ".\n" s)))
    (insert s2)))
I thought I had it working with replace-regexp-in-region, but it just behaved weirdly.

dakra10:09:19

Not relevant for your original question but you can check if the region is actually "active" instead of using (point) and (mark). I always use something like this in my functions that have to take a region:

(defun py2json (start end)
    "Read region in Python syntax and convert to json."
    (interactive
     (if (or (use-region-p) (not transient-mark-mode))
         (prog1 (list (region-beginning) (region-end))
           (deactivate-mark))
       (user-error "No region")))
    .... 

👍 1
👌 1
Benjamin11:09:52

(with-temp-buffer
  (insert "Sentence one. Sentence two. Sentence three.")
  (goto-char (point-min))
  (replace-regexp-in-region "\\." "\\&\n" (point-min) (point-max))
  (buffer-string))
;; =>
"Sentence one.
 Sentence two.
 Sentence three."

💯 1
teodorlu11:09:22

Nice, thanks!