In case this is an XY problem, what I'd like to do is always open Emacs visually as a background process, but still get tab completion and not have to append '&' manually. I'm in Tcsh, no way to change that. I don't know how or if it's possible to alias something to pass an input and append something to it - is this possible?


Yes, in tcsh this is possible (unlike Bourne-style shells where you'd need to use a function instead). You need to put !* in the alias text to substitute the parameters passed to the alias, and more stuff can go after that.

alias emacs 'emacs \!* &'

It's more useful to use its integrated server. Starting from Emacs 22 (IIRC), you can easily run emacsclient and make it start Emacs if it isn't started yet. (With earlier versions, emacsclient exists but is less useful.)

alias e 'emacsclient -a "" \!* &'

And if Emacs is running and you just want to open a new window, then there's no need to run emacsclient in the background: tell it to open the file in the existing Emacs instance and exit.

alias e 'emacsclient -a "" -c \!*'
  • Sorry if offtopic, but you can do that in bash or ksh93 too with alias e='_e=$(fc -nl -0); emacs ${_e#*e} & #'. There is a similar trick for zsh. Using an alias has the advantage that you can access the unexpanded command line eg. alias c='_c=$(fc -nl -0); bc -l <<<${_c#*c} #' then c 7.15 * (3.33 / 4). – mosvy Sep 5 '19 at 21:22
  • @mosvy That doesn't really work though. The alias has to be the sole command on the command line and the arguments can't include special characters. E.g. e "file with spaces.txt" or cd directory; e file.txt or e file.txt; ls – Gilles 'SO- stop being evil' Sep 6 '19 at 7:31
  • That could be fixed with a little imagination: alias e='_e=$(fc -nl -0); _e=" ${_e##*;}"; eval "${_e/ e /emacs } &" #'. This still won't work with e foo && e bar or e foo; echo done, but this wasn't intended as a demo of how to make aliases work exactly as functions. Again, sorry for bringing off-topic stuff in a csh-related answer. – mosvy Sep 6 '19 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.