在评估.emacs时未启用词法绑定

时间:2016-02-23 18:15:22

标签: emacs elisp lexical-scope

以下是我.emacs的一些摘录:

(setq lexical-binding t)
;; .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.
 '(diff-switches "-u")
 '(tab-always-indent (quote complete)))

;...    

(require 'dired)

;...    

(dotimes (i 12) (define-key dired-mode-map (kbd (concat "<f" (number-to-string (1+ i)) ">"))
          (lambda ()
            (interactive)
            (goto-char (point-min))
            (forward-line (+ 4 i)))))

这应该将f1中的密钥f12绑定到dired-mode中的.到跳转到文件列表中的特定文件的命令(忽略..forward-line: Symbol's value as variable is void: i) 。但是,最初,在启动emacs后,这些键不起作用 - 我收到错误消息.emacs。但是,当我转到dotimes的顶行并按Cx Ce来评估该行时,然后转到上面引用的最后一行并按Cx Ce来评估python3 -m ensurepip 表达式,这些函数钥匙开始工作!

为什么?

顺便说一句,如果我评估整个缓冲区,它也不起作用。

1 个答案:

答案 0 :(得分:2)

事实证明有必要更换

(setq lexical-binding t)

;; -*- lexical-binding: t -*-

手册提示暗示这一点,但实际上并没有这么说。