【问题标题】:why my frame-title-format does not work?为什么我的框架标题格式不起作用?
【发布时间】:2014-10-25 10:18:33
【问题描述】:

我的 emacs 版本:GNU Emacs 24.3.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.10.9) of 2014-05-21 on buildvm-07.phx2.fedoraproject.org

我希望 Emacs 的标题显示当前文件的绝对路径。我写了以下内容(来自互联网):

;;;Emacs title bar to reflect file name
(defun frame-title-string ()
   "Return the file name of current buffer, using ~ if under home directory"
(let
  ((fname (or
             (buffer-file-name (current-buffer))
             (buffer-name))))
 ;;let body
  (when (string-match (getenv "HOME") fname)
    (setq fname (replace-match "~" t t fname))        )
  fname))

 ;;; Title = 'system-name File: foo.bar'
(setq frame-title-format '("" system-name "  File: "(:eval (frame-title-string))))

在重装FC20+Emacs之前,以上内容可以正常使用。现在除了我手动打开 .emacs 和 eval frame-title-format 之外它不起作用,我不知道为什么我必须手动评估它?

【问题讨论】:

  • 如果代码在您手动评估时有效,则问题很可能出在其他地方。启动 Emacs 时是否出现错误?您的 init 文件中是否有其他代码可能导致这种情况?找到问题的一个好方法是将您的 init 文件减少到最低限度。如果可行,则将其延长直到问题再次出现,这样您就可以缩小问题的范围。
  • 启动 Emacs 时没有任何错误。为了排除其他代码的影响,我的.emacs现在只有上面的代码,但我得到了相同的结果。
  • 你确定初始化文件被读取了吗? (您可以将(message "I'm here") 添加到其中,然后检查*Messages* 缓冲区。此外,系统上可能安装了一个系统初始化文件,它会覆盖您的设置?
  • 是的,我在 (setq frame-title-format ...) 之后添加了 (message "come here here"),它出现在 *Messages* 中。现在我想在 .emacs 中强制 eval (setq frame-title-format ...),我该怎么办?谢谢
  • 我还没有找到为什么它不起作用,但是这个answer 起作用了!

标签: emacs centos elisp fedora redhat


【解决方案1】:

听起来您正在加载的其他一些代码正在设置框架名称。来自frame-title-format的文档字符串的注释:

它仅用于框架 没有设置明确的名称(参见 `modify-frame-parameters')。

要找到执行此操作的代码,请递归地一分为二。

【讨论】:

    【解决方案2】:

    我也受到了同样的问题的影响。在 CentOS 7 和 Fedora 21 系统上,我发现 /usr/share/emacs/site-lisp/default.el 覆盖了 frame-title-format(仅此而已)。大概 Fedora 20 也有同样的问题。同一个文件包含禁用此功能的说明(“在~/.emacs 中设置inhibit-default-init non-nil”)对我有用。

    @abelard20008 所指的答案也是如此。

    【讨论】:

      【解决方案3】:

      我通过将其添加到我的 .emacs 来解决它:

      (add-hook 'after-init-hook (lambda ()
                       (setq frame-title-format "%b")
      ))
      

      【讨论】:

        【解决方案4】:

        升级到GNU Emacs 29.0.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0) of 2021-12-07后遇到同样的问题

        解决方案是也设置icon-title-format

        ;; No hostname in frame title
        ;; Without setting the `icon-title-format`. The window title will revert
        ;; back to its original value after loosing its focus.
        (setq frame-title-format '("" invocation-name " - " "%b"))
        (setq icon-title-format '("" invocation-name " - " "%b"))
        

        信用:https://stackoverflow.com/a/17532502/6000005

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2022-12-06
          • 2015-02-28
          • 2023-04-06
          • 1970-01-01
          • 1970-01-01
          • 2016-01-14
          • 1970-01-01
          相关资源
          最近更新 更多