(define-error(引用gv-invalid-place)“%S不是有效的地方表达式”)

时间:2016-02-18 20:18:44

标签: emacs windows-7 elisp windows-10

当我加载emacs时,在添加cl-lib.el之后使用--debug-init给出了这个错误:

Debugger entered--Lisp error: (void-function gv-define-simple-setter)
  (gv-define-simple-setter buffer-file-name set-visited-file-name t)
  eval-buffer(#<buffer  *load*<2>> nil "d:/Tools/Emacs-24.3/cl-lib/cl-lib.el" nil t)  ; Reading at buffer position 23391
  load-with-code-conversion("d:/Tools/Emacs-24.3/cl-lib/cl-lib.el" "d:/Tools/Emacs-24.3/cl-lib/cl-lib.el" nil nil)
  load("d:/Tools/Emacs-24.3/cl-lib/cl-lib.el")
  mapc(load ("d:/Tools/Emacs-24.3/cl-lib/cl-lib.el"))
  eval-buffer(#<buffer  *load*> nil "c:/Users/Psalm3_3/.emacs" nil t)  ; Reading at buffer position 76
  load-with-code-conversion("c:/Users/Psalm3_3/.emacs" "c:/Users/Psalm3_3/.emacs" t t)
  load("~/.emacs" t t)
  #[0 "\205\262

这是我正在使用的gv.el文件:

https://github.com/emacs-mirror/emacs/blob/master/lisp/emacs-lisp/gv.el

有没有人有任何建议? TIA。

更新

以下是我遇到的原始错误:

Debugger entered--Lisp error: (file-error "Cannot open load file" "cl-lib")
  require(cl-lib)
  eval-buffer(#<buffer  *load*<2>> nil "d:/Tools/emacs-24.3/site-lisp/desktop.el" nil t)  ; Reading at buffer position 5870
  load-with-code-conversion("d:/Tools/emacs-24.3/site-lisp/desktop.el" "d:/Tools/emacs-24.3/site-lisp/desktop.el" nil nil)
  load("d:/Tools/emacs-24.3/site-lisp/desktop.el")
  mapc(load ("d:/Tools/emacs-24.3/site-lisp/desktop.el"))
  eval-buffer(#<buffer  *load*> nil "c:/Users/Psalm3_3/.emacs" nil t)  ; Reading at buffer position 549
  load-with-code-conversion("c:/Users/Psalm3_3/.emacs" "c:/Users/Psalm3_3/.emacs" t t)
  load("~/.emacs" t t)
  #[0 "\205\262

这是我的.emacs文件:

(mapc 'load (file-expand-wildcards "D:/Tools/Emacs-24.3/cl-lib/cl-lib.el"))

;; Require Common Lisp. (cl in <=24.2, cl-lib in >=24.3.)
(if (require 'cl-lib nil t)
  (progn
    (defalias 'cl-block-wrapper 'identity)
    (defalias 'member* 'cl-member)
    (defalias 'adjoin 'cl-adjoin))
  ;; Else we're on an older version so require cl.
  (require 'cl))

;; Load lisp files on start
(mapc 'load (file-expand-wildcards "D:/Tools/emacs-24.3/site-lisp/flymake.el"))
(mapc 'load (file-expand-wildcards "D:/Tools/emacs-24.3/site-lisp/csharp-mode.el"))
(mapc 'load (file-expand-wildcards "D:/Tools/emacs-24.3/site-lisp/desktop.el"))
(mapc 'load (file-expand-wildcards "D:/Tools/emacs-24.3/site-lisp/session.el"))

;; setup load-path
(add-to-list 'load-path "D:/Tools/emacs-24.3/site-lisp")

;; TABS for C
(setq-default c-indent-tabs-mode t     ; Pressing TAB should cause indentation
                c-indent-level 4         ; A TAB is equivilent to four spaces
                c-argdecl-indent 0       ; Do not indent argument decl's extra
                c-tab-always-indent t
                backward-delete-function nil) ; DO NOT expand tabs when deleting
  (c-add-style "my-c-style" '((c-continued-statement-offset 4))) ; If a statement continues on the next line, indent the continuation by 4
  (defun my-c-mode-hook ()
    (c-set-style "my-c-style")
    (c-set-offset 'substatement-open '0) ; brackets should be at same indentation level as the statements they open
    (c-set-offset 'inline-open '+)
    (c-set-offset 'block-open '+)
    (c-set-offset 'brace-list-open '+)   ; all "opens" should be indented by the c-indent-level
    (c-set-offset 'case-label '+))       ; indent case labels by c-indent-level, too
(require 'csharp-mode)
(setq auto-mode-alist
      (append '(("\\.cs$" . csharp-mode)) auto-mode-alist))
(defun my-csharp-mode-fn ()
  "function that runs when csharp-mode is initialized for a buffer."
  (setq default-tab-width 4)
  ; Set indentation level to 4 spaces (instead of 2)
  (setq c-basic-offset 4)
  ; Set the extra indentation before a substatement (e.g. the opening brace in
  ; the consequent block of an if statement) to 0 (instead of '+)
  (c-set-offset 'substatement-open 0)
  (setq-default c-basic-offset 4)
)
(add-hook  'csharp-mode-hook 'my-csharp-mode-fn t)
(add-hook 'c-mode-hook 'my-c-mode-hook)
(add-hook 'c++-mode-hook 'my-c-mode-hook)

(global-set-key "\C-cg" 'goto-line)
(global-set-key "\C-cy" '(lambda ()
                         (interactive)
                         (popup-menu 'yank-menu)))
(put 'upcase-region 'disabled nil)
;; Always use spaces instead of tabs
(setq-default indent-tabs-mode nil)

(defun FindNextDbl ()
  "move to next doubled word, ignoring <...> tags" (interactive)
  (re-search-forward "\\<\\([z-z]+\\)\\([\\n \\t]\\|<[^>]+>\\)+\\1\\?"))

(define-key global-map "\C-x\C-d" 'FindNextDbl)

;; Search all open buffers
(defun my-multi-occur-in-matching-buffers (regexp &optional allbufs)
  "Show all lines matching REGEXP in all buffers."
  (interactive (occur-read-primary-args))
  (multi-occur-in-matching-buffers ".*" regexp))
(global-set-key (kbd "M-s /") 'my-multi-occur-in-matching-buffers)

(setq x-select-enable-clipboard t)

;; Copy list of all open buffers to clipboard: see http://stackoverflow.com/questions/10537265/emacs-save-current-buffer-list-to-a-text-file
(defun copy-open-files ()
  "Add paths to all open files to kill ring"
  (interactive)
  (kill-new (mapconcat 'identity
                       (delq nil (mapcar 'buffer-file-name (buffer-list)))
                       "\n"))
  (message "List of files copied to kill ring"))

;; save my desktop
(desktop-save-mode 1)

;; auto-reload modified files
(global-auto-revert-mode t)

;; put save files in back dir (see http://www.emacswiki.org/emacs/BackupDirectory)
(setq
   backup-by-copying t      ; don't clobber symlinks
   backup-directory-alist
    '(("." . "~/.saves"))    ; don't litter my fs tree
   delete-old-versions t
   kept-new-versions 6
   kept-old-versions 2
   version-control t)       ; use versioned backups

;; move to window based on arrow keys
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)

;; incremental completion
(require 'helm-config)
(helm-mode 1)

;; http://stackoverflow.com/questions/275842/is-there-a-repeat-last-command-in-emacs
(defun describe-last-function()
  (interactive)
  (describe-function last-command))

;; get path of present buffer, see http://stackoverflow.com/questions/3669511/the-function-to-show-current-files-full-path-in-mini-buffer
(defun show-file-name ()
  "Show the full path file name in the minibuffer."
  (interactive)
  (message (buffer-file-name)))

(global-set-key [C-f1] 'show-file-name) ; Or any other key you want

;; generate guids
(require 'guid)

更新2:

感谢优秀的帖子@Thomas。这就是我将.emacs文件的开头更新为:

;; setup load-path
(add-to-list 'load-path "C:/Tools/emacs-24.3/site-lisp/gv.el")
(require 'gv)
(add-to-list 'load-path "D:/Tools/Emacs-24.3/cl-lib")
(add-to-list 'load-path "C:/Tools/emacs-24.3/site-lisp")

;; Load lisp files on start
(mapc 'load (file-expand-wildcards "C:/Tools/emacs-24.3/site-lisp/flymake.el"))
(mapc 'load (file-expand-wildcards "C:/Tools/emacs-24.3/site-lisp/csharp-mode.el"))
(mapc 'load (file-expand-wildcards "C:/Tools/emacs-24.3/site-lisp/desktop.el"))
(mapc 'load (file-expand-wildcards "C:/Tools/emacs-24.3/site-lisp/session.el"))

现在这是我得到的错误:

Debugger entered--Lisp error: (void-variable defun-declarations-alist)
  (assq (quote gv-expander) defun-declarations-alist)
  (or (assq (quote gv-expander) defun-declarations-alist) (let ((x (\` (gv-expander (\, (apply-partially ... ...)))))) (push x macro-declarations-alist) (push x defun-declarations-alist)))
  eval-buffer(#<buffer  *load*<2>> nil "d:/Tools/Emacs-24.3/site-lisp/gv.el" nil t)  ; Reading at buffer position 8332
  load-with-code-conversion("d:/Tools/Emacs-24.3/site-lisp/gv.el" "d:/Tools/Emacs-24.3/site-lisp/gv.el" nil t)
  require(gv)
  eval-buffer(#<buffer  *load*> nil "c:/Users/Psalm3_3/.emacs" nil t)  ; Reading at buffer position 96
  load-with-code-conversion("c:/Users/Psalm3_3/.emacs" "c:/Users/Psalm3_3/.emacs" t t)
  load("~/.emacs" t t)
  #[0 "\205\262

对不起,我在LISP很新。

2 个答案:

答案 0 :(得分:1)

错误源于Emacs无法加载正确的文件。你试图在这里手动加载一堆单个文件。但是,这不是底层软件包应该加载的方式。

通常,软件包附带安装说明,通常要求您在init文件中添加一些行:修改加载路径,在加载软件包时为设置条件,以及添加命令如何加载包。几乎没有任何一个涉及直接调用load函数,这个函数非常低级。

如果查看原始错误,堆栈跟踪会告诉您(require cl-lib)抛出它。 require是Emacs在必要时加载文件的机制之一。要使其正常工作,您无需直接加载有问题的文件。您所要做的就是设置加载路径,以便Emacs可以找到所引用的文件。

例如,对于您的cl-lib.el文件,您可以这样做:

(add-to-list 'load-path "D:/Tools/Emacs-24.3/cl-lib")

您将此行添加到您的init文件中(当然,在 Emacs尝试加载cl-lib之前的点)。

require的反对部分为provide。如果您查看gv.el的源代码并一直滚动到底部,您将找到最后一行:

(provide 'gv)

这意味着他的文件提供了“功能”gv,每当您编写(require 'gv)时,您都会告诉Emacs您需要该功能。如果Emacs已经知道它,一切都很好,花花公子;如果没有,Emacs将尝试加载该功能。因此,要加载gv.el文件的内容,您只需将以下内容添加到init文件中:

(add-to-list 'load-path "/path/to/directory/containing/gv.el")
(require 'gv)

有关requireprovide的详情,请参阅Emacs Manual

但是,让我重申上面的一点:通常,软件包附带特定的安装说明,通常在源代码文件顶部的长注释部分中“隐藏”。因此,每当您想要手动将软件包添加到设置中时,请务必检查此类说明。

旁注:

(mapc 'load <something>)

只有在<something>扩展为文件的列表时才真正有意义。如果,就像你的情况一样,<something>只是一个文件,你也可以写一下:

(load <something>)

但同样,load是一个低级功能,你几乎不需要作为最终用户。

答案 1 :(得分:1)

你对cl-lib的代码看起来很奇怪。如果你有Emacs≥24.3那么你已经有了cl-lib内置。如果你有更旧的东西那么你就不能使用Emacs-24.3的cl-lib(你必须使用GNU ELPA的cl-lib,但是如果它已经足够老了你也不会内置GNU ELPA支持,所以所有总之,你最好将你的Emacs升级到最近的24.3或更高。

如果您的Emacs是24,1或24.2,那么我建议您只需通过M-x package-install RET安装cl-lib然后添加

(package-initialize)

~/.emacs的开头,它将为您通过package.el安装的软件包(例如上面的cl-lib)正确设置自动加载。

(if (require 'cl-lib ...) ...)开头的块看起来像是一个丑陋的黑客,可以解决您错误理解的问题。只需删除它。

此外,从您的flymake.el中删除desktop.elsite-lisp,Emacs附带的版本可能更新。