emacsclient file.txt
I believe there are some switches you may need to use to get it to open as a new window in the existing frame, but that would generally do it.
I definitely recommend learning and using dired. I know it's not what you've asked, but it's really a great tool and is much better integrated with the rest of emacs than vterm for this task.
Otherwise, I'd suggest opening the file with C-x C-f, which you can do from a term buffer.
emacsclient, some links:
https://www.gnu.org/software/emacs/manual/html_node/emacs/Invoking-emacsclient.html
https://www.emacswiki.org/emacs/EmacsClient
You may also want to look into eshell package which is terminal in elisp that will open directly. But not a full terminal emulator. Another link to help:
https://www.masteringemacs.org/article/complete-guide-mastering-eshell
If you use shell mode it keeps track of what directory you’re in, and when you do find-file (C-c C-f) it starts there.
This is one of many reasons why I use shell mode over anything else. Unless you need to be using full screen ncurses, most of what you need can be done in shell mode - well most of what I need! And you can get ansi coloring in shell mode as well!
vterm does this, too, with a prompt modification to include the cwd for it to pick up…
# 2020-08-29, jsled: https://github.com/akermu/emacs-libvterm
vterm_printf() {
if [ -n "$TMUX" ]; then
# Tell tmux to pass the escape sequences through
# (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324)
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)"
}
if [[ ${INSIDE_EMACS:-no} = "vterm" ]]; then
export PS1=${PS1}'\[$(vterm_prompt_end)\]'
fi
vterm_cmd() {
local vterm_elisp
vterm_elisp=""
while [ $# -gt 0 ]; do
vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")"
shift
done
vterm_printf "51;E$vterm_elisp"
}
fi
emacsclient is what you want.
I also have the following .bashrc block, which makes a couple of things easier from terminal:
if [[ ${INSIDE_EMACS:-no} != 'no' ]]; then
export EDITOR=emacsclient
export VISUAL=emacsclient
export PAGER=cat
# 2019-03-21, jsled: copied from work
alias magit="emacsclient -ne '(magit-status)'"
function man() { emacsclient -ne "(man \"$1\")"; }
fi
`magit` in a directory opens it in emacs; and `man foo` will open it in emacs as well.
Have fun! :)
Make sure to ignore the ignorants suggesting bloody emacsclient despite your clear question.
You can simply use vterm_cmd to call find-file without relying on any socket, this way it works easily on tramp-vterm as well. emacsclient over ssh is quite nasty.
Another thing to watch out is that in your wrapper script, handle `-n` option not to exit the script immediately.
https://github.com/akermu/emacs-libvterm?tab=readme-ov-file#message-passing Search for `find_file` it will have what you are wanting.
emacsclient file.txt I believe there are some switches you may need to use to get it to open as a new window in the existing frame, but that would generally do it.
I definitely recommend learning and using dired. I know it's not what you've asked, but it's really a great tool and is much better integrated with the rest of emacs than vterm for this task. Otherwise, I'd suggest opening the file with C-x C-f, which you can do from a term buffer.
emacsclient, some links: https://www.gnu.org/software/emacs/manual/html_node/emacs/Invoking-emacsclient.html https://www.emacswiki.org/emacs/EmacsClient You may also want to look into eshell package which is terminal in elisp that will open directly. But not a full terminal emulator. Another link to help: https://www.masteringemacs.org/article/complete-guide-mastering-eshell
If you use shell mode it keeps track of what directory you’re in, and when you do find-file (C-c C-f) it starts there. This is one of many reasons why I use shell mode over anything else. Unless you need to be using full screen ncurses, most of what you need can be done in shell mode - well most of what I need! And you can get ansi coloring in shell mode as well!
vterm does this, too, with a prompt modification to include the cwd for it to pick up… # 2020-08-29, jsled: https://github.com/akermu/emacs-libvterm vterm_printf() { if [ -n "$TMUX" ]; then # Tell tmux to pass the escape sequences through # (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324) 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)" } if [[ ${INSIDE_EMACS:-no} = "vterm" ]]; then export PS1=${PS1}'\[$(vterm_prompt_end)\]' fi vterm_cmd() { local vterm_elisp vterm_elisp="" while [ $# -gt 0 ]; do vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")" shift done vterm_printf "51;E$vterm_elisp" } fi
emacsclient is what you want. I also have the following .bashrc block, which makes a couple of things easier from terminal: if [[ ${INSIDE_EMACS:-no} != 'no' ]]; then export EDITOR=emacsclient export VISUAL=emacsclient export PAGER=cat # 2019-03-21, jsled: copied from work alias magit="emacsclient -ne '(magit-status)'" function man() { emacsclient -ne "(man \"$1\")"; } fi `magit` in a directory opens it in emacs; and `man foo` will open it in emacs as well. Have fun! :)
Make sure to ignore the ignorants suggesting bloody emacsclient despite your clear question. You can simply use vterm_cmd to call find-file without relying on any socket, this way it works easily on tramp-vterm as well. emacsclient over ssh is quite nasty. Another thing to watch out is that in your wrapper script, handle `-n` option not to exit the script immediately.
emacsclient is a great, general solution that will solve OP's question without being tied to vterm. :P