【问题标题】:Start Emacs in shell when started form shell从 shell 启动时在 shell 中启动 Emacs
【发布时间】:2013-08-23 06:20:13
【问题描述】:

我最近开始使用 Emacs 作为我的主要编辑器。有一件事情困扰着我: 当我在我的 shell 中启动 Emacs 时,它会在一个新窗口中启动 Emacs。如果它被 shell 调用,我希望它在 shell 中启动,当它从工作区调用时,我希望它在新窗口中启动。

这可以通过我错过的一些配置来实现,还是任何一种 lisp?

我将 Manjaro 与 Xfce 和 fish-shell 一起使用 (http://fishshell.com/)

问候, 罗宾

【问题讨论】:

  • 你的意思是像emacs -nw
  • 谢谢 jlahd,我不知道'emacs -nw'。有没有办法在 shell 中启动时使用 -nw 自动调用 emacs?
  • 你应该在你的 shell 中为它创建一个别名,例如alias em "emacs -nw"。之后,在 shell 中说 em 运行 emacs -nw

标签: shell emacs fish


【解决方案1】:

所以有别名解决方案,但我遇到的一个问题是我有时使用 Ctrl-z 让 emacs 进入睡眠状态,然后我忘记了我启动了一个 emacs 会话,所以我再次使用我的别名,最后我得到了两个 emacs终端,这让我很恼火。 所以我使用了一个函数来检查 emacs 是否已经在运行:

cemacs () {
if (ps|grep emacs); then
   echo  "Hey, emacs is already running";       
   fg %emacs
else 
    emacs -nw $@
fi
}

快捷方式

我定义了一个方便的快捷方式来恢复休眠的 emacs:

bind -x '"\C-x\C-e":fg %emacs' 

Emacs 服务器

所以这就是我使用了很长时间的方法,但它并不完美。我无法启动正常的 emacs 和我的功能,除非我使用 emacs 服务器:http://wikemacs.org/index.php/Emacs_server

只需为 emacsclient -t 创建一个别名。

和外壳模式

但是现在,我更喜欢在 emacs 中使用终端(在 shell 的缓冲区中移动、不使用鼠标进行复制粘贴、查找字符串、转到输出的开头非常方便,使用 dired,...) 操作文件。

【讨论】:

    【解决方案2】:

    好主意!

    我刚刚更新了我的 .bashrc :

    edit_file_in_emacs_console() {
        emacsclient -t $@ || emacs -q -nw $@
    }
    
    if [ "$PS1" ]; then
        alias emacs=edit_file_in_emacs_console
    fi
    

    因此,如果可用,我会使用当前的 emacs 服务器,或者使用简单的 emacs 控制台 (-q) 以加快启动速度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 2011-09-07
      相关资源
      最近更新 更多