Closed tkf closed 11 years ago
When no emacs server is running I get the following error message and one new emacs instance with lots of file buffers named after source provided to emacsclient instead:
emacsclient: can't find socket; have you started the server? To start the server in Emacs, type "M-x server-start". /home/a00001/.bin/editor: line 13: [: too many arguments chdir to
Maybe it's worth fixing
Ive modified it a bit
Now it looks like this::
# Go to currently active project root in Emacs
cdp() {
local EMACS_CWP=$(emacsclient -a false -e "
(let ((current-buffer
(nth 1 (assoc 'buffer-list
(nth 1 (nth 1 (current-frame-configuration)))))))
(or (ignore-errors (eproject-root current-buffer))
(with-current-buffer current-buffer
(let ((filename (buffer-file-name)))
(if filename
(file-name-directory filename)
default-directory)))))
" 2>/dev/null | sed 's/^"\(.*\)"$/\1/')
if [ -d "$EMACS_CWP" ]; then
cd "$EMACS_CWP"
else
return 1
fi
}
Thanks for the review! I agree with your points except for hiding errors from Emacs. Why not just show them?
Can you send a pull request to my shell-utils branch? That way your change will show up here. I just don't want to take your credit. :)
ok., lets show the errors. i'll make the pull req.
Merged https://github.com/tkf/eproject/pull/1. Thanks.
This is clever and will probably prove quite useful.
I'd prefer if that Lisp code was in a .el file, however, so it's easier to edit and tweak. The shell script should then look like: emacsclient -a false -e "(eproject-print-current-project-working-directory)"
or something like that.
I'll merge this for now, however, as it's not a really big problem :smile:
This pull request adds
cdp
(cd to project) shell function. In your terminal, you can type this command to go to the root of the project you are opening now. Needs emacsclient.