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 {
62 if let clause = value("cl-loop ") { return String(localized: "cl-loop \(clause)", comment: comment) } 62 if let clause = value("cl-loop ") { return String(localized: "cl-loop \(clause)", comment: comment) }
63 if let names = value("condition-case on ") { return String(localized: "condition-case on \(names)", comment: comment) } 63 if let names = value("condition-case on ") { return String(localized: "condition-case on \(names)", comment: comment) }
64 if let pattern = value("pcase pattern ") { return String(localized: "pcase pattern \(pattern)", comment: comment) } 64 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") }
65 if let name = value("let-alist ") { return String(localized: "let-alist \(name)", comment: comment) } 66 if let name = value("let-alist ") { return String(localized: "let-alist \(name)", comment: comment) }
66 if let text = value("string-width of ") { return String(localized: "string-width of \(text)", comment: comment) } 67 if let text = value("string-width of ") { return String(localized: "string-width of \(text)", comment: comment) }
67 if let rest = value("regexp "), let parts = split(rest, " in ") { 68 if let rest = value("regexp "), let parts = split(rest, " in ") {
Sources/OrgCore/Config/Elisp.swift +4
@@ -46,6 +46,9 @@ public final class Elisp {
46 /// `lexical-binding`: lambdas close over the local frames, and only special variables 46 /// `lexical-binding`: lambdas close over the local frames, and only special variables
47 /// (the host's and `defvar`'s) are bound dynamically. 47 /// (the host's and `defvar`'s) are bound dynamically.
48 public var lexical = false 48 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
49 /// Variables bound dynamically when `lexical` is set. 52 /// Variables bound dynamically when `lexical` is set.
50 var specials: Set<String> = [] 53 var specials: Set<String> = []
51 /// Under lexical binding, running a lambda list, which Emacs evaluates with dynamic binding: 54 /// Under lexical binding, running a lambda list, which Emacs evaluates with dynamic binding:
@@ -112,6 +115,7 @@ public final class Elisp {
112 if v == Self.unknownError { throw Unsupported(what: "the data of this error") } 115 if v == Self.unknownError { throw Unsupported(what: "the data of this error") }
113 return v 116 return v
114 } 117 }
118 if unboundUnsupported { throw Unsupported(what: "variable \(name)") }
115 throw Signal(message: "Symbol’s value as variable is void: \(name)", data: [.symbol(name)]) 119 throw Signal(message: "Symbol’s value as variable is void: \(name)", data: [.symbol(name)])
116 } 120 }
117 121
Sources/OrgCore/Links/Links.swift +1
@@ -279,6 +279,7 @@ extension Links {
279 let lisp = Elisp() 279 let lisp = Elisp()
280 lisp.standardTime() 280 lisp.standardTime()
281 EmacsBuffer.defineLookups(lisp) 281 EmacsBuffer.defineLookups(lisp)
282 lisp.unboundUnsupported = true
282 do { 283 do {
283 let value = try lisp.eval(try LispReader.readFirst(form).sexp) 284 let value = try lisp.eval(try LispReader.readFirst(form).sexp)
284 if Elisp.containsClosure(value) { return "This link uses Emacs Lisp that runs only in Emacs." } 285 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 {
25 25
26 @Test func refusesWhatOnlyEmacsHas() { 26 @Test func refusesWhatOnlyEmacsHas() {
27 #expect(Links.evaluateElisp("(org-agenda nil \"a\")") == "This link uses Emacs Lisp that runs only in Emacs.") 27 #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")
28 // Emacs 31 prints a function made under dynamic binding as `#[nil (1) nil]`. 33 // Emacs 31 prints a function made under dynamic binding as `#[nil (1) nil]`.
29 for form in ["(let ((f (lambda () 1))) f)", "(prin1-to-string (lambda () 1))", "(format \"%S\" (lambda () 1))", "(car (lambda () 1))"] { 34 for form in ["(let ((f (lambda () 1))) f)", "(prin1-to-string (lambda () 1))", "(format \"%S\" (lambda () 1))", "(car (lambda () 1))"] {
30 #expect(Links.evaluateElisp(form) == "This link uses Emacs Lisp that runs only in Emacs.", "\(form)") 35 #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.
149 makes to the buffer or to files in Emacs's session are not kept. 149 makes to the buffer or to files in Emacs's session are not kept.
150- On iOS, in the Mac App Store version, and on the Mac without Emacs, the form runs in 150- On iOS, in the Mac App Store version, and on the Mac without Emacs, the form runs in
151 orgstar's Emacs Lisp interpreter, with the functions listed under Lisp formulas in 151 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
153 =This link uses Emacs Lisp that runs only in Emacs.= 154 =This link uses Emacs Lisp that runs only in Emacs.=
154 155
155A path that names a command, such as =elisp:org-agenda=, isn't run. The reader view on iOS 156A path that names a command, such as =elisp:org-agenda=, isn't run. The reader view on iOS