评估 .emacs 时未启用词法绑定
lexical-binding not being enabled when evaluating .emacs
以下是我的一些摘录 .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)))))
这应该将 dired-mode
中的键 f1
绑定到 f12
到跳转到文件列表中特定文件的命令(忽略 .
和 ..
).但是,最初,在启动 emacs 后,这些键不起作用 - 我收到一条错误消息 forward-line: Symbol's value as variable is void: i
。但是,当我转到 .emacs
的第一行并按 C-x C-e 来计算该行,然后转到上面引用的最后一行并按 C-x C-e 来计算 dotimes
表达式时,那些函数按键开始工作!
这是为什么?
顺便说一句,如果我评估整个缓冲区,它也不起作用。
原来是需要更换
(setq lexical-binding t)
和
;; -*- lexical-binding: t -*-
手册暗示性地暗示了这一点,但实际上并没有直截了当地说。
以下是我的一些摘录 .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)))))
这应该将 dired-mode
中的键 f1
绑定到 f12
到跳转到文件列表中特定文件的命令(忽略 .
和 ..
).但是,最初,在启动 emacs 后,这些键不起作用 - 我收到一条错误消息 forward-line: Symbol's value as variable is void: i
。但是,当我转到 .emacs
的第一行并按 C-x C-e 来计算该行,然后转到上面引用的最后一行并按 C-x C-e 来计算 dotimes
表达式时,那些函数按键开始工作!
这是为什么?
顺便说一句,如果我评估整个缓冲区,它也不起作用。
原来是需要更换
(setq lexical-binding t)
和
;; -*- lexical-binding: t -*-
手册暗示性地暗示了这一点,但实际上并没有直截了当地说。