bash - $INSIDE_EMACS 对 bash 有什么作用

标签 bash command-line emacs

我看到了here bash 4.4 会查找变量 $INSIDE_EMACS 来确定它是否在 comint 模式缓冲区中运行。但是我似乎找不到这对 bash 行为有何改变。 $INSIDE_EMACS 进行了哪些更改?

最佳答案

根据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.

查看了 bash 的 source code并且没有什么魔力:

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     }

更新:

刚刚找到 bash 处理 INSIDE_EMACS 的原始请求(在 bug-bash 邮件列表中):Bash should look at INSIDE_EMACS not just EMACS

关于bash - $INSIDE_EMACS 对 bash 有什么作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47062370/

相关文章:

bash - 在 bash 中,如何在不停止脚本的情况下捕获和处理 SIGINT?

bash - X 分钟后脚本重复自身

git - 使用 Git 创建跟踪分支的简洁方法

python - 如何执行程序或批处理文件?

C++代码突然不再编译

emacs - 在 Emacs 组织模式中,如何重新归档组织标题下突出显示的文本?

linux - 如何从脚本运行 grep 并将输出存储在 bash 脚本的目标目录中的文件中

linux - 如何使用 linux 命令获取非常大的 csv 文件的第二列?

emacs - Emacs 中的方案打破了配色方案

Ruby 程序在终端中无法正常运行