Fork me on GitHub
#emacs
<
2023-11-16
>
vemv07:11:39

Anyway knows an ideal way of opening a file with emacsclient, evaluating some sexprs once it's loaded as provided in advance from the CLI? It works to emacsclient foo.clj in an iTerm tab and then emacsclient --eval "(cider-connect-clj)" in another tab - this way you can effectively script the already-open emacsclient. A cheap approach is, from a script, to open the file first, and in the background, wait 1.5 seconds and then perform the eval. But it's not ideal 🙂

vemv07:11:16

Possible approach: dump the instructions to a file with a special extension (e.g. .lisp_eval), create a mode for it which simply evals its contents when it's open

Ed10:11:14

can you construct it something like

emacsclient -c -nw -e '(progn (find-file "foo.clj") (cider-connect-clj))'
? Maybe with a shell function? I have this in my zshrc:
emacs-pipe() {
    local TMP;
    if [[ "$1" == "-" ]]; then
        TMP="$(mktemp /tmp/emacsstdinXXX)";
        cat >"$TMP";
        if ! emacsclient -s ${EMACS_SOCKET_NAME} --alternate-editor /usr/bin/false --create-frame --tty --eval "(let ((b (create-file-buffer \"*stdin*\"))) (switch-to-buffer b) (insert-file-contents \"${TMP}\") (delete-file \"${TMP}\"))" \
 > /dev/null 2>&1; then
            # emacs --eval "(let ((b (create-file-buffer \"*stdin*\"))) (switch-to-buffer b) (insert-file-contents \"${TMP}\") (delete-file \"${TMP}\"))" &                                                                                    
        fi;
    else
        emacsclient -s ${EMACS_SOCKET_NAME} --alternate-editor /usr/bin/false --create-frame --tty --no-wait "$@" > /dev/null 2>&1 &
    fi;
}
zle -N emacs-pipe
which might contain enough hacks?

👀 1
Ed16:11:23

did you get this sorted? https://www.masteringemacs.org/article/fuzzy-finding-emacs-instead-of-fzf ... this might have more ideas?

vemv16:11:54

I tried the first approach you laid out but it didn't appear to work - emacs opened for a glimpse, then closed. will check the other one + the article soon!

Ed16:11:03

weird ... when I run this emacsclient -s ${EMACS_SOCKET_NAME} -c -nw -e '(progn (find-file "src/scratch.clj") (cider-connect-clj))' I get this

Ed16:11:46

and when I hit enter twice and y to agree to connecting to the repl again I end up with

Ed16:11:48

I'm running GNU Emacs 28.3 (build 1, x86_64-redhat-linux-gnu, X toolkit, cairo version 1.17.8, Xaw3d scroll bars) of 2023-09-24

Ed17:11:40

ah ... but if I put it in a shell function, it exits, as you say

Ed17:11:34

huh .... no, it doesn't ... it's not because it's in a function, it works if I've already connected to cider and I'm connecting a new repl, but not if it's connecting for the first time

Ed17:11:35

I think it's to do with cider-connect-clj returning an error if it can't connect

vemv18:11:00

Will let you know if I have interesting progress! Some useful hints there, thanks 🍻

👍 1
Ed18:11:24

function thnig { emacsclient -s ${EMACS_SOCKET_NAME} --alternate-editor /usr/bin/false --create-frame --tty --eval "(progn (find-file \"$1\") (ignore-errors (cider-connect-clj)) )" }
thnig src/scratch.clj works on my machine

Ed18:11:28

even if it can't connect to a repl ...

Matti Uusitalo08:11:47

At some point, Cider (I presume) has started to put application error log messages to the minibuffer. How can I turn this off? It is very noisy

vemv08:11:59

I had a similar report but it didn't provide further details. It's not the intended behavior, certainly. What logging solution do you use?

vemv08:11:22

Also, please post a screenshot. Let's take it to GH directly

Matti Uusitalo08:11:12

We are using taoensso timbre. Moment, I have to scrub some sensitive things from the screenshot

lassemaatta08:11:32

yeah, I noticed this too with timbre + midje tests

vemv08:11:58

Does it happen at any point, or only while running tests?

Matti Uusitalo08:11:48

This is what it looks like in the minibuffer. The minibuffer keeps resizing too

Matti Uusitalo08:11:42

Not sure if tests trigger this, but at the moment there are no tests running and that happens.

Matti Uusitalo08:11:18

I restart the repl and try to get it to log an error and see if it happens without running tests

vemv08:11:01

Thanks. (setq inhibit-message t) might work as a patch in the meantime

Matti Uusitalo08:11:28

for what it's worth we aren't using midje

Matti Uusitalo09:11:58

That inhibit message does seem to remove the issue

🙌 1
Roma08:02:38

Nice! Thank you @U45T93RA6!

vemv08:02:51

To you cider

🍻 2