# Calling emacsclient from ansi-term makes emacsclient hang, how do I get around this?

Emacs Asked on October 7, 2020

Sometimes I use ansi-term in emacsclient instead of directly using my shell. When I do this, it is not an infrequent occurrence that I forget where I am and call emacsclient someFile, which freezes the terminal window and doesn’t let me start a new emacsclient process. Is there a way to make invocations of emacsclient in ansi-term instead open the file? Or some other way to unfreeze this? The only solution I have found is to kill the server process.

You don't have to display an error when using emacsclient from inside term : you can make it use your current Emacs instance.

For shell-mode, there is a package called "shx", which provides useful shell commands like :e (to edit a file), :diff (to ediff 2 files ), :find (run find command and open files in clickable output) etc.

Edit : and yes, you never need to kill the server process too. On unixes, just send it a USR2 signal and Emacs would drop whatever it was doing and unfreeze from most situations including this one.

" killall -USR2 emacs"

Answered by Jeeves on October 7, 2020

It looks like ansi-term sets the TERM environment variable to eterm, possibly extended to eterm-color or similar. You can use this to define emacs to an appropriate alias whenever you're already in ansi-term inside emacs. Something like this in your .bashrc:

case "$TERM" in eterm*) alias emacs=emacsclient ;; *) ## code to run for non-eterm shells ;; esac  If that doesn't work, another option is the environment variable INSIDE_EMACS, which is set to <emacs version>,term<term version>. Note that shell-mode sets this to <emacs version>,comint, so if you use both you'll want to distinguish between them with your test: case "$INSIDE_EMACS" in
*term*)
alias emacs=emacsclient
;;
*comint*)
## code to run for shell-mode
;;
*)
## code for non-emacs shells
esac


Answered by Tyler on October 7, 2020

## Related Questions

### Match undone in sparse tree

2  Asked on February 9, 2021 by ivan-perez

### Force one window when opening multiple files

1  Asked on February 7, 2021

### Different fill-column for comments than code in programming modes

1  Asked on February 5, 2021 by daniel-doherty

### How can I get a ruler at column 80?

8  Asked on February 3, 2021 by jorgen-schfer

### Relationship between Skeleton and Tempo

1  Asked on February 2, 2021

### keybinding behavior and smartparens

0  Asked on January 30, 2021 by andi

### Emacs keeps overwriting files in Haskell mode

1  Asked on January 30, 2021 by ashesh

### Continuously redirect debugging information (e.g. *Messages*) to file

0  Asked on January 29, 2021 by alexey-shiklomanov

### how do I customize spacemacs default buffer

3  Asked on January 28, 2021 by fangxing

### How to set org-mode category icon on per file basis?

0  Asked on January 26, 2021 by klorax

### Open PDF files with pdf-tools does not work

0  Asked on January 23, 2021 by infinitelooper

### org-mode document structure / templates

1  Asked on January 22, 2021 by mr-hasquestions

### Why does emacs use both propertly lists and association lists?

2  Asked on January 17, 2021 by kdb

### use-package and package-initialize problem with emacs27

1  Asked on January 15, 2021 by chakravarthy-raghunandan

### Package for live inline rendering for markdown/org mode text with css styling?

1  Asked on January 10, 2021

### Recentf list not updated

0  Asked on January 9, 2021 by gub

### Aggregate tag lists for completion in orgmode

0  Asked on January 8, 2021 by user1683620

### How to get org-mode fully support Arabic language for export?

1  Asked on January 8, 2021 by doctorate

### shell-mode alias keyword is not recognized as font-lock-builtin-face type

1  Asked on January 6, 2021 by alper

### How to use ‘glossaries’ package in aquamacs, or I mean how could I run makeglossaries in aquatics

1  Asked on January 5, 2021 by raymond