clearloop / leetcode-cli

May the code be with you 👻
MIT License
308 stars 49 forks source link

`emacsclient` doesn't works. #75

Closed samyakbardiya closed 2 years ago

samyakbardiya commented 2 years ago

I am trying to open via leetcode edit <ID> command, it is working fine with vim, nvim & even emacs but does not open the file with emacsclient it gives error:

$ leetcode edit 1
error: No such file or directory (os error 2), please try again

here's my leetcode.toml

[code]
editor = "emacsclient -n -s doom"             # "nvim" and "emacs" works fine
lang = "cpp"
pick = "${fid}.${slug}"
submission = "${fid}.${slug}.${sid}.${ac}"

Note: emacsclient is the command to use emacs in daemon-client mode.

clearloop commented 2 years ago

what about just using emacsclient? I'm an emacs user also

samyakbardiya commented 2 years ago

@clearloop, then this error comes up:

$ leetcode edit 1
emacsclient: can't find socket; have you started the server?
emacsclient: To start the server in Emacs, type "M-x server-start".
emacsclient: No socket or alternate editor.  Please use:

        --socket-name
        --server-file      (or environment variable EMACS_SERVER_FILE)
        --alternate-editor (or environment variable ALTERNATE_EDITOR)

that's why -s doom is important, it solves this error.

I have tried every other options but all them gave the same error, the previous one.

I have tried -c, -nw & -nc along with -s doom; but no success.

clearloop commented 2 years ago

that's why -s doom is important, it solves this error.

hi @samyak039 !, have you run emacs --daemon before emacsclient?

samyakbardiya commented 2 years ago

yeah of cource. it's in my xinit file.

edit: I forgot to mention, if I open the file manually it working fine.

$ emacsclient -n -s doom <file>
clearloop commented 2 years ago

hmmm, my editor config is just emacsclient

[code]
editor = 'emacsclient'
lang = 'rust'
pick = '${fid}.${slug}'
submission = '${fid}.${slug}.${sid}.${ac}'

and it works fine...the code of using editor is here https://github.com/clearloop/leetcode-cli/blob/2b373c0eee7824d96f13353cbe7ff53828db5815/src/cmds/edit.rs#L102, not sure if this could help

samyakbardiya commented 2 years ago

maybe I found the issue, it is that your editor command is unable to deal with the options given to it.

I tested it:

hence the issue is that the rust command is unable to parse the option given in the editor command.

PS. I cannot open any file if I don't give -s doom along with the command, ig this is happening because I am using chemacs2

clearloop commented 2 years ago

maybe I found the issue, it is that your editor command is unable to deal with the options given to it.

exactly, and we mb can update the command to sth like

let editor_with_args = conf.code.editor.split(" ");

// do some checking stuffs

let mut editor_args = editor_with_args[0..];
editor_args.push(file_name);

std::process::Command::new(editor_with_args[0]).args(editor_args);
samyakbardiya commented 2 years ago

sorry I don't know any rust :)

clearloop commented 2 years ago

sorry I don't know any rust :)

nevermind, I can fix this on this weekend

samyakbardiya commented 2 years ago

thanks @clearloop :)

clearloop commented 2 years ago

This update haven't applied to the latest version yet since there are some bugs in 0.3.12