reddit / emacs

libvterm directory tracking not working?

Zeta611 · 2022-12-21 10:51
Hi, I'v been using vterm for a while now, and I just discovered what "directory tracking" is. How I understood is that Emacs should be aware of what directory I'm currently inside in vterm, so `<c-x> <c-f>` should by default show the files in the current directory---but it's not working! I've followed the steps shown in the [README](https://github.com/akermu/emacs-libvterm): ```sh vterm_printf() { if [ -n "$TMUX" ] && ([ "${TERM%%-*}" = "tmux" ] || [ "${TERM%%-*}" = "screen" ]); then # Tell tmux to pass the escape sequences through printf "\ePtmux;\e\e]%s\007\e\\" "$1" elif [ "${TERM%%-*}" = "screen" ]; then # GNU screen (screen, screen-256color, screen-256color-bce) printf "\eP\e]%s\007\e\\" "$1" else printf "\e]%s\e\\" "$1" fi } vterm_prompt_end() { vterm_printf "51;A$(whoami)@$(hostname):$(pwd)" } setopt PROMPT_SUBST PROMPT=$PROMPT'%{$(vterm_prompt_end)%}' ``` I have the above at the end of my `.zshrc`; but it is simply not working. Do I need some additional setup in the Emacs side, or did I correctly understand what "directory tracking" and it is not working for me? While writing this post, I began to suspect that maybe ivy is messing things up? Thanks!
anaumann · 2022-12-21 12:50
Those steps in the README have been put into a shell snippet for your convenience and can be included like this: if [[ "$INSIDE_EMACS" == 'vterm' ]] \ && [[ -n ${EMACS_VTERM_PATH} ]] \ && [[ -f ${EMACS_VTERM_PATH}/etc/emacs-vterm-zsh.sh ]]; then source ${EMACS_VTERM_PATH}/etc/emacs-vterm-zsh.sh fi But for me, it's most probably oh-my-zsh that's mangling the added logic int he prompt and I chose to ignore it and rely on my emacsclient alias some more.. I just run "edit -n filename" from vterm and get a new buffer with that file in the same emacs frame.. that's good enough for me..
Zeta611 · 2022-12-21 16:10
Oh, I never knew about `emacsclient -n [filenmae]`... How does it work inside vterm? `-n` says `Don't wait for the server to return` in the usage but I don't understand it.
anaumann · 2022-12-21 16:17
Normally, emacsclient will stay in the foreground, blocking your terminal window while the buffer with the file is open... -n lets you continue to use that terminal.. much like an `&` would. But there's a little more to it: I basically have [this](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/emacs/emacsclient.sh) aliased to an "edit" command that will either start an emacs instance or reuse an existing one and I can even call it from a vterm to kind of do what I mean.. So, vterm or not, emacs running or not, I usually run "edit filename" all of the time and throw in a `-n` when I'm planning to keep the file open for a while(eg. editing a configuration file while using the terminal to rerun a command using that configuration over and over again).
Zeta611 · 2022-12-22 07:21
Thank you for the detailed explanation! It helped a lot :)
anaumann · 2022-12-22 08:55
You're very welcome.. I quite like the way it behaves, so I like to share it :) And I just sourced that zsh-snippet that comes with vterm.. It's definitely oh-my-zsh that's killing the directory following.. If I source the file from the shell prompt(ie. after oh-my-zsh has finished configuring everything), `C-x C-f` will try to open files in the folder I'm currently in in vterm.. I now put it after the oh-my-zsh include and it seems to work just fine. Even my RPROMPTs are back :D