【问题标题】:Breaking out of .emacs script突破 .emacs 脚本
【发布时间】:2011-01-07 21:15:58
【问题描述】:

我在我的 Mac 上使用了两个 emacs(Aquamcs 和基于文本的 emacs)。 我通常使用基于文本的 emacs 只是编辑一些东西,所以我不想用它加载任何东西。

我想出的是让 .emacs 中的检查代码退出/中断,如果它是基于文本的 emacs(darwin 系统但不是 aquamacs)。

 (when (and (equal system-type 'darwin) (not (boundp 'aquamacs-version)))
     (exit) ??? (break) ????
 )

它似乎工作,但我不知道如何突破 .emacs。该怎么做?

添加

我只是想加快在我的 mac 上加载基于文本的 emacs 的速度,并且我考虑将其作为一种解决方案。根据有用的答案,我想出了以下代码,仅当它不是基于文本的 emacs 时才运行 .emacs。

(setq inhibit-splash-screen t)
(unless (null window-system)

【问题讨论】:

  • 非 elisp 解决方案始终有效; alias emacs="/usr/bin/emacs -nw --no-init"。但实际上,为什么不直接使用emacsclient -t 从终端连接到正在运行的 emacs?
  • 非常好!我认为这几乎就是 Gareth Rees 的建议,所以如果你有时间,最好将他的答案标记为正确。
  • 我也有同样的问题,但是我没有找到任何命令,比如 break 或 exit of C。

标签: emacs


【解决方案1】:

我不知道有什么方法可以完全按照您的意愿行事。一些解决方法:

  1. 您可以通过评估 (error "message") 来停止评估您的 .emacs,但这有点令人不快。

  2. 您可以重新排序 .emacs,以便在整个文件周围有一个 (unless (CONDITION) ...)

  3. 您可以在命令行中运行emacs -Q FILE

为什么要这样做?您是否担心加载.emacs 所需的时间?如果是这样,您可以考虑改用 Emacs 客户端/服务器。

【讨论】:

    【解决方案2】:

    我也不确定如何退出,但是.....我宁愿为您的 init 文件建议另一种逻辑,而不是具有所有不同配置的平面文件。

    以你的 ~/.emacs(或者更好的 ~/.emacs.d/init.el)作为你的控制器和文件,比如 ~/.emacs.d/aquamacs.el 或 ~/.emacs.d/textmode .el 作为您的个人配置文件。

    That would make your init having something like this :
    (defun my-short-hostname() 
      (string-match "[0-9A-Za-z]+" system-name)
      (substring system-name (match-beginning 0) (match-end 0))
      )
    
    ;Load different config file in text mode or gui mode.
    (if (null window-system)
        (load-file "~/.emacs.d/texmode-emacs.el")
      (load-file "~/.emacs.d/gui.el"))
    
    ;Load configuration for this host only, ie ~/.emacs.d/myhostname.el if exist
    (if (file-exists-p 
         (downcase (concat "~/.emacs.d/" (my-short-hostname) ".el")))
        (load-file (downcase "~/.emacs.d/" (my-short-hostname) ".el"))))
    

    【讨论】:

      【解决方案3】:

      我建议有条件地从您的 .emacs 加载特定的不同文件,一个用于一种设置,另一个用于另一种设置。

      或者,只需将每个设置的代码包装在 progn 中,并在 .emacs 本身中执行适当的条件。

      【讨论】:

        猜你喜欢
        • 2016-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-28
        • 2016-04-01
        • 1970-01-01
        相关资源
        最近更新 更多