Emacs 变严格了?

每夜版已经不允许在包加载之前修改变量值了:

$ git log -1
commit e3f83a89aa7da460615064390273c87844bdb0dc (grafted, origin/master, origin/HEAD))
Author: Eric Abrahamsen <[email protected]>
Date:   Thu Dec 17 19:16:00 2020 -0800

    Fix regexp in IMAP search-string preparation

    * lisp/gnus/gnus-search.el (gnus-search-run-search): This was failing
    to catch all of X-GM-RAW.

$ src/emacs --batch --eval "
(let ((url-show-status t))
  (require 'package))"

Debugger entered--Lisp error: (error "Defining as dynamic an already lexical var")
  internal--define-uninitialized-variable(url-show-status "Whether to show a running total of bytes transferr...")
  custom-declare-variable(url-show-status (funcall #'#f(compiled-function () #<bytecode 0x1e0000153e5d>)) "Whether to show a running total of bytes transferr..." :type boolean :group url)
  byte-code("\300\301\302\303\304DD\305\306\307\310\311&\7\210\300\312\302\303\313DD\314\306\315\310\311&\7\207" [custom-declare-variable url-max-password-attempts funcall function #f(compiled-function () #<bytecode 0x1e0000153ec1>) "Maximum number of times a password will be prompte..." :type integer :group url url-show-status #f(compiled-function () #<bytecode 0x1e0000153e5d>) "Whether to show a running total of bytes transferr..." boolean] 8)
  require(url-vars)
  byte-code("\300\301!\210\300\302!\210\303\304\305\"\207" [require url-vars auth-source autoload url-scheme-get-property "url-methods"] 3)
  require(url-parse)
  require(url-handlers)
  byte-code("\301\302!\210\301\303!\210\301\304!\210\301\305!\210\301\306!\210\301\307!\210\310\311\312\313\314\315\316\317&\7\210\320\321\322\323\324DD\325\326\327\316\317&\7\210..." [package-user-dir require cl-lib seq tabulated-list macroexp url-handlers browse-url custom-declare-group package nil "Manager for Emacs Lisp packages." :group applications :version "24.1" custom-declare-variable package-enable-at-startup funcall function #f(compiled-function () #<bytecode 0x1e0000153e5d>) "Whether to make installed packages available when ..." :type boolean package-load-list #f(compiled-function () #<bytecode 0x1e00043e0601>) "List of packages for `package-initialize' to make ..." (repeat (choice (const all) (list :tag "Specific package" (symbol :tag "Package name") (choice :tag "Version" (const :tag "disable" nil) (const :tag "most recent" t) (string :tag "specific version"))))) :risky t package-archives #f(compiled-function () #<bytecode 0xac8dd99c5f0ac66>) "An alist of archives from which to fetch.\nThe defa..." (alist :key-type (string :tag "Archive name") :value-type (string :tag "URL or directory name")) "26.1" package-menu-hide-low-priority #f(compiled-function () #<bytecode 0x1feb7c170cf51>) "If non-nil, hide low priority packages from the pa..." (choice (const :tag "Don't hide anything" nil) (const :tag "Hide per package-archive-priorities" archive) (const :tag "Hide per archive and version number" t)) "25.1" package-archive-priorities #f(compiled-function () #<bytecode 0x1e0000153e91>) "An alist of priorities for packages.\n\nEach element..." (alist :key-type (string :tag "Archive name") :value-type (integer :tag "Priority (default is 0)")) package-pinned-packages #f(compiled-function () #<bytecode 0x1e0000153e91>) "An alist of packages that are pinned to specific a..." (alist :key-type (symbol :tag "Package") :value-type (string :tag "Archive name")) "24.4" #f(compiled-function () #<bytecode 0x1e00696c3c6e>) ...] 12)
  require(package)
  (let ((url-show-status t)) (require 'package))
  (progn (setq lexical-binding t) (let ((url-show-status t)) (require 'package)))
  eval((progn (setq lexical-binding t) (let ((url-show-status t)) (require 'package))) t)
  command-line-1(("--eval" "\n(progn\n  (setq lexical-binding t)\n  (let ((url-sh..."))
  command-line()
  normal-top-level()

修改如下可正常运行:

$ src/emacs --batch --eval "
(progn
  (require 'url-vars) ;; <<--
  (let ((url-show-status t))
    (require 'package)))"

有些变量必须在 require 之前修改(之后修改达不到预期效果)怎么办?


EDIT: 只是不允许 let 形式的修改,setq 不受限。

4 个赞

应该是因为 let 里面声明了一个 lexical scope 的 url-show-status, require 里面又用 custom-declare-variable 声明了一个 dynamic scope 的 url-show-status. 感觉这么写挺容易出问题的, 报个错也好.

1 个赞