Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does $INSIDE_EMACS do for bash

I saw here that bash 4.4 looks for the variable $INSIDE_EMACS to determine if it is running in a comint mode buffer. However I can't seem to find what this changes about bash behavior. What changes does $INSIDE_EMACS make?

like image 855
Prgrm.celeritas Avatar asked Jun 23 '26 05:06

Prgrm.celeritas


1 Answers

According to emacs doc:

Emacs sets the environment variable INSIDE_EMACS in the subshell to version,comint, where version is the Emacs version (e.g., 24.1). Programs can check this variable to determine whether they are running inside an Emacs subshell.

Took a look at bash's source code and there's no much magic:

575   /*
576    * M-x term -> TERM=eterm-color INSIDE_EMACS='251,term:0.96' (eterm)
577    * M-x shell -> TERM='dumb' INSIDE_EMACS='25.1,comint' (no line editing)
578    *
579    * Older versions of Emacs may set EMACS to 't' or to something like
580    * '22.1 (term:0.96)' instead of (or in addition to) setting INSIDE_EMACS.
581    * They may set TERM to 'eterm' instead of 'eterm-color'.  They may have
582    * a now-obsolete command that sets neither EMACS nor INSIDE_EMACS:
583    * M-x terminal -> TERM='emacs-em7955' (line editing)
584    */
585   if (interactive_shell)
586     {
587       char *term, *emacs, *inside_emacs;;
588       int emacs_term, in_emacs;
589
590       term = get_string_value ("TERM");
591       emacs = get_string_value ("EMACS");
592       inside_emacs = get_string_value ("INSIDE_EMACS");
593
594       if (inside_emacs)
595         {
596           emacs_term = strstr (inside_emacs, ",term:") != 0;
597           in_emacs = 1;
598         }
599       else if (emacs)
600         {
601           /* Infer whether we are in an older Emacs. */
602           emacs_term = strstr (emacs, " (term:") != 0;
603           in_emacs = emacs_term || STREQ (emacs, "t");
604         }
605       else
606         in_emacs = emacs_term = 0;
607
608       /* Not sure any emacs terminal emulator sets TERM=emacs any more */
609       no_line_editing |= STREQ (term, "emacs");
610       no_line_editing |= in_emacs && STREQ (term, "dumb");
611
612       /* running_under_emacs == 2 for `eterm' */
613       running_under_emacs = in_emacs || STREQN (term, "emacs", 5);
614       running_under_emacs += emacs_term && STREQN (term, "eterm", 5);
615
616       if (running_under_emacs)
617         gnu_error_format = 1;
618     }

UPDATE:

Just found the original request (in bug-bash mailing list) for bash to deal with INSIDE_EMACS: Bash should look at INSIDE_EMACS not just EMACS

like image 111
pynexj Avatar answered Jun 25 '26 21:06

pynexj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!