Commit e8bbc0d50c

e8bbc0d50ce6cc1c872974c5d053af68080c9a8f

parent: 95111c0832

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-21 11:50 UTC

Refuse elisp: links that read a variable the interpreter lacks

Layout: unified · split

Sources/OrgApp/TableReason.swift +1
@@ -62,6 +62,7 @@ public enum TableReason {
6262 if let clause = value("cl-loop ") { return String(localized: "cl-loop \(clause)", comment: comment) }
6363 if let names = value("condition-case on ") { return String(localized: "condition-case on \(names)", comment: comment) }
6464 if let pattern = value("pcase pattern ") { return String(localized: "pcase pattern \(pattern)", comment: comment) }
65 if let name = value("variable ") { return String(localized: "variable \(name)", comment: "Why a table needs Emacs: a Lisp variable with no value") }
6566 if let name = value("let-alist ") { return String(localized: "let-alist \(name)", comment: comment) }
6667 if let text = value("string-width of ") { return String(localized: "string-width of \(text)", comment: comment) }
6768 if let rest = value("regexp "), let parts = split(rest, " in ") {
Sources/OrgCore/Config/Elisp.swift +4
@@ -46,6 +46,9 @@ public final class Elisp {
4646 /// `lexical-binding`: lambdas close over the local frames, and only special variables
4747 /// (the host's and `defvar`'s) are bound dynamically.
4848 public var lexical = false
49 /// A variable with no value throws `Unsupported` rather than `void-variable`: Emacs may
50 /// give it one, such as `fill-column`.
51 public var unboundUnsupported = false
4952 /// Variables bound dynamically when `lexical` is set.
5053 var specials: Set<String> = []
5154 /// Under lexical binding, running a lambda list, which Emacs evaluates with dynamic binding:
@@ -112,6 +115,7 @@ public final class Elisp {
112115 if v == Self.unknownError { throw Unsupported(what: "the data of this error") }
113116 return v
114117 }
118 if unboundUnsupported { throw Unsupported(what: "variable \(name)") }
115119 throw Signal(message: "Symbol’s value as variable is void: \(name)", data: [.symbol(name)])
116120 }
117121
Sources/OrgCore/Links/Links.swift +1
@@ -279,6 +279,7 @@ extension Links {
279279 let lisp = Elisp()
280280 lisp.standardTime()
281281 EmacsBuffer.defineLookups(lisp)
282 lisp.unboundUnsupported = true
282283 do {
283284 let value = try lisp.eval(try LispReader.readFirst(form).sexp)
284285 if Elisp.containsClosure(value) { return "This link uses Emacs Lisp that runs only in Emacs." }
Tests/OrgCoreTests/ElispLinkTests.swift +5
@@ -25,6 +25,11 @@ struct ElispLinkTests {
2525
2626 @Test func refusesWhatOnlyEmacsHas() {
2727 #expect(Links.evaluateElisp("(org-agenda nil \"a\")") == "This link uses Emacs Lisp that runs only in Emacs.")
28 // Emacs has values for variables the interpreter doesn't define.
29 for form in ["(+ fill-column 1)", "most-positive-fixnum", "(concat user-full-name \"\")", "(condition-case nil org-directory (void-variable 0))"] {
30 #expect(Links.evaluateElisp(form) == "This link uses Emacs Lisp that runs only in Emacs.", "\(form)")
31 }
32 #expect(Links.evaluateElisp("(let ((x 2)) (+ x 1))") == "(let ((x 2)) (+ x 1)) => 3")
2833 // Emacs 31 prints a function made under dynamic binding as `#[nil (1) nil]`.
2934 for form in ["(let ((f (lambda () 1))) f)", "(prin1-to-string (lambda () 1))", "(format \"%S\" (lambda () 1))", "(car (lambda () 1))"] {
3035 #expect(Links.evaluateElisp(form) == "This link uses Emacs Lisp that runs only in Emacs.", "\(form)")
docs/manual/guide/09-links.org +2 −1
@@ -149,7 +149,8 @@ changes. The echo area then shows =(form) => value=, or the error's message.
149149 makes to the buffer or to files in Emacs's session are not kept.
150150- On iOS, in the Mac App Store version, and on the Mac without Emacs, the form runs in
151151 orgstar's Emacs Lisp interpreter, with the functions listed under Lisp formulas in
152 [[file:10-tables.org][Tables]]. A form that uses anything else shows
152 [[file:10-tables.org][Tables]]. A form that uses anything else, or a variable it doesn't
153 bind itself, such as =fill-column=, shows
153154 =This link uses Emacs Lisp that runs only in Emacs.=
154155
155156A path that names a command, such as =elisp:org-agenda=, isn't run. The reader view on iOS