【问题标题】:Unable to edit and save .emacs file. Error; Symbol’s function definition is void: auto-update-file-header无法编辑和保存 .emacs 文件。错误; Symbol 的函数定义为 void:auto-update-file-header
【发布时间】:2017-12-13 21:03:05
【问题描述】:

我正在处理我的 .emacs 文件时,突然发生了一些事情。我无法编辑 .emacs 文件。每次我尝试修改文件然后保存时,它都会给我这个错误:

Symbol 的函数定义为 void:auto-update-file-header。

我试图删除 .emacs 文件本身,但每次我再次启动 emacs 时它都会回来。

这是我的 .emacs 文件包含的内容:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(ansi-color-names-vector
   ["#212526" "#ff4b4b" "#b4fa70" "#fce94f" "#729fcf" "#e090d7" "#8cc4ff" "#eeeeec"])
 '(custom-enabled-themes (quote (manoj-dark)))
 '(package-selected-packages (quote (color-identifiers-mode flycheck))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
(require 'package)

(add-to-list 'package-archives
             '("MELPA Stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-refresh-contents)
(add-hook 'after-init-hook #'global-flycheck-mode)
(add-hook 'after-init-hook 'global-color-identifiers-mode)
(add-to-list 'custom-theme-load-path "/Users/kjr132/.emacs.d/themes")
(set-cursor-color "#0a9dff")
(provide 'init-themes)
(add-to-list 'load-path' "~/.emacs.d/")
(package-install 'color-identifiers-mode)
(autoload 'auto-make-header "header2")     
(add-hook 'write-file-hooks 'auto-update-file-header)     
(add-hook 'emacs-lisp-mode-hook 'auto-make-header)     
(add-hook 'c-mode-common-hook 'auto-make-header)     
(add-hook 'tex-mode-hook 'auto-make-header)
(add-to-list 'load-path "~/.emacs.d")
(defun my-compilation-hook ()
  (when (not (get-buffer-window "*compilation*"))
    (save-selected-window
      (save-excursion
        (let* ((w (split-window-vertically))
               (h (window-height w)))
          (select-window w)
          (switch-to-buffer "*compilation*")
          (shrink-window (- h compilation-window-height)))))))
(add-hook 'compilation-mode-hook 'my-compilation-hook)

【问题讨论】:

  • 那是emacs需要的文件,否则它不会重新创建自己。我认为你注定要失败;D

标签: macos emacs ide


【解决方案1】:

实际的错误是您显然未定义从write-file-hooks 运行的auto-update-file-header。所以每次你试图写东西到磁盘时,Emacs 都会抛出一个错误。

也许从其他编辑器中删除.emacs 文件中的write-file-hooks 行,或使用emacs -Q。或者,如果你很勇敢,试试吧

(remove-hook 'write-file-hooks 'auto-update-file-header)

在你正在运行的 Emacs 中,看看你是否可以恢复。

【讨论】:

  • 我试图用谷歌搜索这个名字的函数,但结果是空白,所以我猜这是你的本地添加。
  • 叫我疯了,但我什至更喜欢vi 而不是nano。在现代vi 中,箭头键应该可以工作,您可以删除带有d d 的行。 (u 撤消,如果你删除了错误的!)用 Esc 退出 :wq 或者不写任何东西就退出(也许重新开始而不保存):q!
  • 我尝试使用另一个编辑器删除该行,但它又回来了,我没有对其进行任何更改。
  • Emacs 本身不应该这样做,您是否还有其他正在运行的 Emacs 进程仍然处于活动状态并且可能以某种方式被操纵以自动保存?
  • 是的,我想通了,我修改了 .emacs 文件然后加载它,然后我保存了它。知道为什么我无法修改和保存。
【解决方案2】:

信息是说明性的。

Symbol’s function definition is void: auto-update-file-header

这样的消息表明了 Emacs lisp 中符号的性质,因为它们有 4 个单独的组件或单元格,如 here 所述。

问题不在于这段代码,而是无法为这个符号解析 lambda 表达式。请参阅 this 了解符号函数间接在 Emacs 中的工作原理。

如果有一个可以通过符号访问的函数,我宁愿只添加钩子,否则什么都不做[带有该效果的消息]。

(if (symbol-function 'auto-update-file-header)
  (add-hook 'write-file-hooks 'auto-update-file-header)
 (message "Symbol 'auto-update-file-header has void function definition.
Maybe define one?"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多