# emacsclient function



## NapoleonWils0n (Nov 28, 2018)

You can set up emacs as an edit server so instead of starting a new instance of emacs,
it “listens” for external edit requests

so you can use emacsclient -t somefile.txt to open the file in the terminal
but thats too much too type so i created a simple function called e that accepts multiple files and opens them in emacsclient in the terminal

add the following code to your ~/.emacs config to start the emacs server when you open emacs


```
; emacs server start for emacsclient
(server-start)
```

set emacs as your editor in your ~/.bashrc


```
# set emacslient as editor
ALTERNATE_EDITOR=""; export ALTERNATE_EDITOR
EDITOR="/usr/local/bin/emacsclient -t"; export EDITOR
VISUAL="/usr/local/bin/emacsclient -c -a emacs"; export VISUAL
```

add the function to your ~/.bashrc


```
# emacsclient function e
function e {
/usr/local/bin/emacsclient -t "$@"
}
```

source your ~/.bashrc to pick up the changes


```
. ~/.bashrc
```

now you can edit files with emacsclient by typing


```
e somefile.txt
```

you can also pass multiple files to the function which will open the files in different buffers in emacsclient


```
e somefile.txt somefile2.txt somefile3.txt
```

we use $@ in the function which accepts multiple files as arguments
instead of $1 which only accepts 1 file

its better to use a function instead of an aliases
as i have found that pressing tab to autocomplete the file name doesnt work with an alias
unless you expand the alias first and then press tab


----------

