AnswerBun.com

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.

2 Answers

See "with-editor" : https://github.com/magit/with-editor/blob/master/README.md

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

Add your own answers!

Related Questions

Blank menus with Athena / Lucid

1  Asked on December 31, 2020 by tastytea

   

How to clear the eshell

6  Asked on December 24, 2020 by startec

 

org-agenda not showing any todos

1  Asked on December 20, 2020 by stevenmurray

   

Configuring emacs gdb behavior

0  Asked on December 17, 2020 by onye

 

Where find good json formater and validation?

1  Asked on December 17, 2020 by a_subscriber

   

Enlarge pictures in image-dired

1  Asked on December 16, 2020 by calculus

 

Coloured active mode line only when many windows

1  Asked on December 14, 2020 by toothrot

   

Copy-text-to-clipboard-link

1  Asked on December 12, 2020 by jens-lange

   

How to get “:size” from font-spec

1  Asked on December 11, 2020 by enze-chi

 

Getting w3 to work

0  Asked on December 10, 2020 by 0x1a4

 

Wish to define specific defcustom entries

0  Asked on December 9, 2020 by jean-louis

   

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP