Commit fa7dd01882

fa7dd01882a224af7e5797c7e8e1eaa9273d4c4f

parent: 47dd021371

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-20 22:34 UTC

Match Emacs in native Lisp: capitalize, closures, quoted lambdas, error data

capitalize follows the syntax table. Builtins refuse to look inside a
closure. A quoted lambda runs with dynamic binding under lexical binding.
condition-case binds the error symbol and data and matches specific
conditions. %F prints + for years past 9999. The reader reads \a, \b,
\d, \e, \f, \r, \v, \s and backslash-space as Emacs does.

Layout: unified · split

Sources/OrgApp/TableReason.swift +8
@@ -28,6 +28,8 @@ public enum TableReason {
2828 let comment: StaticString = "Why a table needs Emacs: something a Lisp formula does"
2929 switch what {
3030 case "integer size": return fixed(what)
31 case "a closure as a list": return String(localized: "a closure as a list", comment: comment)
32 case "capitalize past ASCII": return String(localized: "capitalize past ASCII", comment: comment)
3133 case "case folding past ASCII": return String(localized: "case folding past ASCII", comment: comment)
3234 case "cl-loop destructuring": return String(localized: "cl-loop destructuring", comment: comment)
3335 case "cl-loop with collect and sum": return String(localized: "cl-loop with collect and sum", comment: comment)
@@ -42,6 +44,7 @@ public enum TableReason {
4244 case "replace-regexp-in-string from the end": return String(localized: "replace-regexp-in-string from the end", comment: comment)
4345 case "seq-uniq with a test": return String(localized: "seq-uniq with a test", comment: comment)
4446 case "sort on a string": return String(localized: "sort on a string", comment: comment)
47 case "the data of this error": return String(localized: "the data of this error", comment: comment)
4548 default: break
4649 }
4750 func value(_ prefix: String) -> String? { what.hasPrefix(prefix) ? String(what.dropFirst(prefix.count)) : nil }
@@ -58,6 +61,7 @@ public enum TableReason {
5861 if let zone = value("format-time-string zone ") { return String(localized: "format-time-string zone \(zone)", comment: comment) }
5962 if let code = value("format-time-string ") { return String(localized: "format-time-string \(code)", comment: comment) }
6063 if let clause = value("cl-loop ") { return String(localized: "cl-loop \(clause)", comment: comment) }
64 if let names = value("condition-case on ") { return String(localized: "condition-case on \(names)", comment: comment) }
6165 if let pattern = value("pcase pattern ") { return String(localized: "pcase pattern \(pattern)", comment: comment) }
6266 if let name = value("let-alist ") { return String(localized: "let-alist \(name)", comment: comment) }
6367 if let text = value("string-width of ") { return String(localized: "string-width of \(text)", comment: comment) }
@@ -71,6 +75,10 @@ public enum TableReason {
7175 let name = String(what.dropLast(" on a place".count))
7276 return String(localized: "\(name) on a place", comment: "Why a table needs Emacs: a Lisp function used on a variable")
7377 }
78 if what.hasSuffix(" on a closure") {
79 let name = String(what.dropLast(" on a closure".count))
80 return String(localized: "\(name) on a closure", comment: "Why a table needs Emacs: a Lisp function that looks inside a closure")
81 }
7482 if what.hasSuffix(" on a list another value shares") {
7583 let name = String(what.dropLast(" on a list another value shares".count))
7684 return String(localized: "\(name) on a list another value shares", comment: "Why a table needs Emacs: a Lisp function that changes a shared list")
Sources/OrgCore/Config/Elisp.swift +103 −21
@@ -11,9 +11,28 @@ public final class Elisp {
1111
1212 public struct Signal: Error, Equatable, CustomStringConvertible {
1313 public let message: String
14 /// The error symbol, by default from the message, and its data when known: what
15 /// `condition-case` binds.
16 public let symbol: String?
17 public let data: [Sexp]?
1418 public var description: String { message }
19
20 public init(message: String, symbol: String? = nil, data: [Sexp]? = nil) {
21 self.message = message
22 self.symbol = symbol ?? Self.symbols.first(where: { message.hasPrefix($0.prefix) })?.symbol
23 self.data = data ?? (message == "Arithmetic error" ? [] : nil)
24 }
25
26 static let symbols: [(prefix: String, symbol: String)] = [
27 ("Arithmetic error", "arith-error"), ("Args out of range", "args-out-of-range"), ("Invalid function", "invalid-function"),
28 ("Symbol’s value as variable is void", "void-variable"), ("Wrong number of arguments", "wrong-number-of-arguments"),
29 ("Wrong type argument", "wrong-type-argument"),
30 ]
1531 }
1632
33 /// What `condition-case` binds its variable to for an error whose data isn't known.
34 static let unknownError = Sexp.symbol("\u{0}error")
35
1736 public typealias Builtin = (Elisp, [Sexp]) throws -> Sexp
1837
1938 /// A set of bindings, shared by the closures created while it is in scope.
@@ -29,6 +48,11 @@ public final class Elisp {
2948 public var lexical = false
3049 /// Variables bound dynamically when `lexical` is set.
3150 var specials: Set<String> = []
51 /// Under lexical binding, running a lambda list, which Emacs evaluates with dynamic binding:
52 /// every variable is bound dynamically and lambdas aren't closures.
53 private var dynamicOnly = false
54 /// The functions `defun` defined, which may take closures.
55 var defined: Set<String> = []
3256 /// Each closure's captured frames, by the id in its `(closure ID ARGS . BODY)` value.
3357 var closures: [[Frame]] = []
3458 /// The scopes of the callers of running closures, and the global values that dynamic
@@ -78,8 +102,12 @@ public final class Elisp {
78102 }
79103
80104 public func value(_ name: String) throws -> Sexp {
81 for scope in scopes.reversed() { if let v = scope.vars[name] { return v } }
82 throw Signal(message: "Symbol’s value as variable is void: \(name)")
105 for scope in scopes.reversed() {
106 guard let v = scope.vars[name] else { continue }
107 if v == Self.unknownError { throw Unsupported(what: "the data of this error") }
108 return v
109 }
110 throw Signal(message: "Symbol’s value as variable is void: \(name)", data: [.symbol(name)])
83111 }
84112
85113 /// Evaluates `body` with `bindings` added: in a new frame, or for special variables under
@@ -89,7 +117,7 @@ public final class Elisp {
89117 }
90118
91119 func binding<T>(_ frame: Frame, _ body: () throws -> T) rethrows -> T {
92 let dynamic = lexical ? frame.vars.keys.filter(specials.contains) : []
120 let dynamic = dynamicOnly ? Array(frame.vars.keys) : lexical ? frame.vars.keys.filter(specials.contains) : []
93121 var saved: [(String, Sexp?)] = []
94122 for name in dynamic {
95123 saved.append((name, scopes[0].vars[name]))
@@ -118,7 +146,7 @@ public final class Elisp {
118146 /// A lambda as `function` makes it: a closure over the local frames under lexical
119147 /// binding, else the list itself.
120148 func closure(_ lambda: Sexp) -> Sexp {
121 guard lexical, case .list(let items) = lambda, items.first == .symbol("lambda"), items.count >= 2 else { return lambda }
149 guard lexical, !dynamicOnly, case .list(let items) = lambda, items.first == .symbol("lambda"), items.count >= 2 else { return lambda }
122150 closures.append(Array(scopes.dropFirst()))
123151 return .list([.symbol("closure"), .integer(closures.count - 1)] + items.dropFirst())
124152 }
@@ -128,6 +156,29 @@ public final class Elisp {
128156 return false
129157 }
130158
159 /// Builtins that may take closures as arguments, from the given position on: those that
160 /// call them or only hold them. Emacs's closures aren't lists, as they are here.
161 static let closureArguments: [String: Int] = [
162 "funcall": 0, "apply": 0, "mapcar": 0, "mapc": 0, "mapconcat": 0, "seq-map": 0, "seq-filter": 0, "seq-remove": 0,
163 "seq-reduce": 0, "cl-reduce": 0, "cl-remove-if": 0, "cl-remove-if-not": 0, "cl-find": 1, "cl-position": 1, "sort": 0,
164 "replace-regexp-in-string": 1, "list": 0, "identity": 0, "ignore": 0, "null": 0, "not": 0,
165 ]
166 /// Builtins that compare or print what lists hold.
167 static let closureInspectors: Set<String> = [
168 "equal", "eq", "eql", "member", "memq", "memql", "assoc", "assq", "delete", "delq", "delete-dups", "seq-uniq",
169 "format", "format-message", "message", "error", "user-error", "prin1-to-string", "princ", "prin1", "print",
170 ]
171
172 /// Refuses a builtin call that would look inside a closure.
173 func refuseClosures(_ name: String, _ args: [Sexp]) throws {
174 guard !closures.isEmpty, !defined.contains(name) else { return }
175 for (i, arg) in args.enumerated() {
176 if Self.isClosure(arg) ? i < Self.closureArguments[name] ?? .max : Self.closureInspectors.contains(name) && Self.containsClosure(arg) {
177 throw Unsupported(what: "\(name) on a closure")
178 }
179 }
180 }
181
131182 /// Whether `v` contains a closure, which Emacs prints in a form this evaluator doesn't.
132183 static func containsClosure(_ v: Sexp) -> Bool {
133184 switch v {
@@ -199,25 +250,28 @@ public final class Elisp {
199250 }
200251
201252 static func car(_ v: Sexp) throws -> Sexp {
202 switch v {
253 if isClosure(v) { throw Unsupported(what: "car on a closure") }
254 return switch v {
203255 case .list(let items): items.first ?? .nil
204256 case .dotted(let items, _): items[0]
205257 case _ where isNil(v): .nil
206 default: throw Signal(message: "Wrong type argument: listp, \(v.description)")
258 default: throw Signal(message: "Wrong type argument: listp, \(v.description)", data: [.symbol("listp"), v])
207259 }
208260 }
209261
210262 static func cdr(_ v: Sexp) throws -> Sexp {
211 switch v {
263 if isClosure(v) { throw Unsupported(what: "cdr on a closure") }
264 return switch v {
212265 case .list(let items): list(Array(items.dropFirst()))
213266 case .dotted(let items, let last): items.count == 1 ? last : .dotted(Array(items.dropFirst()), last)
214267 case _ where isNil(v): .nil
215 default: throw Signal(message: "Wrong type argument: listp, \(v.description)")
268 default: throw Signal(message: "Wrong type argument: listp, \(v.description)", data: [.symbol("listp"), v])
216269 }
217270 }
218271
219272 /// A proper list's elements.
220273 static func elements(_ v: Sexp) throws -> [Sexp] {
274 if isClosure(v) { throw Unsupported(what: "a closure as a list") }
221275 if case .list(let items) = v { return items }
222276 if isNil(v) { return [] }
223277 throw Signal(message: "Wrong type argument: listp, \(v.description)")
@@ -328,6 +382,7 @@ public final class Elisp {
328382 defer { pending.removeLast() }
329383 for arg in args { pending[pending.count - 1].append(try eval(arg)) }
330384 let values = pending[pending.count - 1]
385 try refuseClosures(name, values)
331386 var variable: String?
332387 if case .symbol(let s)? = args.first, s != "nil", s != "t", !s.hasPrefix(":") { variable = s }
333388 inPlaceVariable = variable
@@ -440,6 +495,7 @@ public final class Elisp {
440495 assign(variable, try Self.cdr(list))
441496 return try Self.car(list)
442497 }
498 if Self.isClosure(list) { throw Unsupported(what: "push on a closure") }
443499 let pushed = Self.cons(try eval(args[0]), list)
444500 assign(variable, pushed)
445501 return pushed
@@ -481,12 +537,20 @@ public final class Elisp {
481537 do {
482538 return try eval(args[1])
483539 } catch let signal as Signal {
540 // Every error has the `error` condition as well as its own.
541 let conditions = ["error", "t"] + (signal.symbol.map { [$0] } ?? [])
484542 for handler in args.dropFirst(2) {
485543 let parts = try Self.elements(handler)
486544 guard let condition = parts.first else { continue }
487 let names = (try? Self.elements(condition)) ?? [condition]
488 guard names.contains(.symbol("error")) || names.contains(.symbol("t")) else { continue }
489 let bindings: [String: Sexp] = args[0].symbol.map { $0 == "nil" ? [:] : [$0: .list([.symbol("error"), .string(signal.message)])] } ?? [:]
545 let names = ((try? Self.elements(condition)) ?? [condition]).compactMap(\.symbol)
546 guard names.contains(where: conditions.contains) else {
547 if signal.symbol == nil, !names.isEmpty { throw Unsupported(what: "condition-case on \(names.joined(separator: " "))") }
548 continue
549 }
550 var bindings: [String: Sexp] = [:]
551 if let variable = args[0].symbol, variable != "nil" {
552 bindings[variable] = signal.symbol.flatMap { symbol in signal.data.map { .list([.symbol(symbol)] + $0) } } ?? Self.unknownError
553 }
490554 return try binding(bindings) { try progn(parts.dropFirst()) }
491555 }
492556 throw signal
@@ -501,10 +565,19 @@ public final class Elisp {
501565 switch function {
502566 case .symbol(let name): return try callNamed(name, args)
503567 case .list(let items) where Self.isClosure(function):
568 guard closures.indices.contains(items[1].integer!) else { throw Unsupported(what: "a closure as a list") }
569 let saved = dynamicOnly
570 dynamicOnly = false
571 defer { dynamicOnly = saved }
504572 return try apply(parameters: items[2], body: items.dropFirst(3), args, scope: closures[items[1].integer!])
505573 case .list(let items) where items.first == .symbol("lambda") && items.count >= 2:
506 // Under lexical binding, a lambda list runs outside the caller's local frames.
507 return try apply(parameters: items[1], body: items.dropFirst(2), args, scope: lexical ? [] : nil)
574 guard lexical else { return try apply(parameters: items[1], body: items.dropFirst(2), args, scope: nil) }
575 // Under lexical binding, a lambda list runs outside the caller's local frames, with
576 // dynamic binding.
577 let saved = dynamicOnly
578 dynamicOnly = true
579 defer { dynamicOnly = saved }
580 return try apply(parameters: items[1], body: items.dropFirst(2), args, scope: [])
508581 default:
509582 throw Signal(message: "Invalid function: \(function.description)")
510583 }
@@ -548,6 +621,7 @@ public final class Elisp {
548621
549622 func callNamed(_ name: String, _ args: [Sexp]) throws -> Sexp {
550623 guard let function = functions[name] else { throw Unsupported(what: "function \(name)") }
624 try refuseClosures(name, args)
551625 inPlaceVariable = nil
552626 return try function(self, args)
553627 }
@@ -831,12 +905,11 @@ public final class Elisp {
831905 try arity(args, 2...2, "delete")
832906 return list(try elements(args[1]).filter { normalized($0) != normalized(args[0]) })
833907 }
834 lisp.define("error") { _, args in
835 let message = args.isEmpty ? "" : try format(args)
836 throw Signal(message: message)
837 }
838 lisp.define("user-error") { _, args in
839 throw Signal(message: args.isEmpty ? "" : try format(args))
908 for name in ["error", "user-error"] {
909 lisp.define(name) { _, args in
910 let message = args.isEmpty ? "" : try format(args)
911 throw Signal(message: message, symbol: name, data: [.string(message)])
912 }
840913 }
841914
842915 // Printing.
@@ -890,9 +963,18 @@ public final class Elisp {
890963 if case .integer(let c) = args[0] { return .integer(Int(String(try scalar(c)).lowercased().unicodeScalars.first!.value)) }
891964 return .string(try string(args[0]).lowercased())
892965 }
893 lisp.define("capitalize") { _, args in
966 // A letter is upcased after a character without word syntax, downcased after one with it.
967 lisp.define("capitalize") { lisp, args in
894968 try arity(args, 1...1, "capitalize")
895 return .string(try string(args[0]).capitalized)
969 let s = try string(args[0])
970 guard s.unicodeScalars.allSatisfy(\.isASCII) else { throw Unsupported(what: "capitalize past ASCII") }
971 var inWord = false
972 var out = ""
973 for c in s.unicodeScalars {
974 out += inWord ? String(c).lowercased() : String(c).uppercased()
975 inWord = lisp.syntax.isWord(c)
976 }
977 return .string(out)
896978 }
897979 lisp.define("substring") { _, args in
898980 try arity(args, 1...3, "substring")
Sources/OrgCore/Config/ElispForms.swift +1
@@ -28,6 +28,7 @@ extension Elisp {
2828 while let head = body.first?.head, head == "declare" || head == "interactive" { body.removeFirst() }
2929 let function = closure(.list([.symbol("lambda"), args[1]] + body))
3030 define(name) { lisp, values in try lisp.call(function, values) }
31 defined.insert(name)
3132 return .symbol(name)
3233 }
3334
Sources/OrgCore/Config/ElispTime.swift +1 −1
@@ -157,7 +157,7 @@ extension Elisp {
157157 case "u": out += String(weekday == 0 ? 7 : weekday)
158158 case "w": out += String(weekday)
159159 case "j": out += String(format: "%03d", Days.absolute(year: year, month: month, day: day) - Days.absolute(year: year, month: 1, day: 0))
160 case "F": out += yearText + String(format: "-%02d-%02d", month, day)
160 case "F": out += (year > 9999 ? "+" : "") + yearText + String(format: "-%02d-%02d", month, day)
161161 case "D": out += String(format: "%02d/%02d/%02d", month, day, shortYear)
162162 case "R": out += String(format: "%02d:%02d", hour, minute)
163163 case "T": out += String(format: "%02d:%02d:%02d", hour, minute, second)
Sources/OrgCore/Config/Lisp.swift +6 −8
@@ -115,6 +115,9 @@ public enum LispReader {
115115
116116 func error(_ message: String) -> ReadError { ReadError(line: line, message: message) }
117117
118 /// What `\a` and the other one-letter escapes in strings and characters stand for.
119 static let escapes: [Unicode.Scalar: Unicode.Scalar] = ["a": "\u{7}", "b": "\u{8}", "d": "\u{7F}", "e": "\u{1B}", "f": "\u{C}", "n": "\n", "r": "\r", "s": " ", "t": "\t", "v": "\u{B}"]
120
118121 static let delimiters: Set<Unicode.Scalar> = ["(", ")", "[", "]", "\"", "'", "`", ",", ";"]
119122
120123 mutating func form() throws -> Sexp {
@@ -177,10 +180,8 @@ public enum LispReader {
177180 case "\\":
178181 guard let e = next() else { break }
179182 switch e {
180 case "n": out += "\n"
181 case "t": out += "\t"
182 case "\n": break
183 default: out.unicodeScalars.append(e)
183 case "\n", " ": break
184 default: out.unicodeScalars.append(Self.escapes[e] ?? e)
184185 }
185186 default:
186187 out.unicodeScalars.append(c)
@@ -194,10 +195,7 @@ public enum LispReader {
194195 guard c == "\\" else { return Int(c.value) }
195196 guard let e = next() else { throw error("bad character") }
196197 switch e {
197 case "n": return 10
198 case "t": return 9
199 case "s": return 32
200 case "e": return 27
198 case _ where Self.escapes[e] != nil: return Int(Self.escapes[e]!.value)
201199 case "C", "M", "S", "H", "A":
202200 if peek == "-" { _ = next(); return try character() }
203201 return Int(e.value)
Tests/OrgCoreTests/BabelTests.swift +23
@@ -310,6 +310,14 @@ struct BabelTests {
310310 "(let ((x 1)) (funcall '(lambda () x)))",
311311 "(let ((x 3)) (mapcar (lambda (y) (* x y)) '(1 2)))",
312312 "(let ((k 1)) (pcase 2 ((pred (lambda (v) (> v k))) 'big)))",
313 "(list (capitalize \"it's o'neil\") (capitalize \"o'neil x_y 3d\"))",
314 "(progn (defun h () y) (funcall '(lambda (y) (h)) 3))",
315 "(progn (defun h3 () zz) (mapcar '(lambda (zz) (h3)) '(1 2)))",
316 "(progn (defun h2 () yy) (let ((f '(lambda (yy) (h2)))) (funcall f 8)))",
317 "(progn (defun h4 () w) (funcall '(lambda () (let ((w 4)) (h4)))))",
318 "(let ((x 2)) (funcall '(lambda (f) (funcall f)) (lambda () x)))",
319 "(let ((f (lambda (x) (* 2 x)))) (list (funcall f 2) (apply f '(3)) (car (list 5 f)) (length (list f f))))",
320 "(let ((x 1)) (condition-case err (car x) (error (funcall (lambda () (list x (car err)))))))",
313321 ].map { "#+begin_src emacs-lisp\n\($0)\n#+end_src\n" }
314322
315323 /// Natively as with `emacs -Q --batch -l`, the way the app runs Emacs Lisp blocks.
@@ -333,6 +341,21 @@ struct BabelTests {
333341 }
334342 }
335343
344 /// Emacs's closures aren't lists: blocks that look inside one are refused.
345 @Test func refusesLookingInsideClosures() throws {
346 let folder = FileManager.default.temporaryDirectory
347 for form in [
348 "(listp (lambda () 1))", "(let ((f (lambda () 1))) (consp f))", "(car (lambda () 1))", "(equal (lambda () 1) (lambda () 1))",
349 "(functionp (lambda () 1))", "(let ((f (lambda () 1))) (eq f f))", "(let ((f (lambda () 1))) (length f))",
350 "(let ((f (lambda () 1))) (dolist (x f) x))", "(let ((f (lambda () 1))) (push 1 f) (length f))",
351 "(let ((f (lambda () 1))) (format \"%S\" (list f)))", "(let ((f (lambda () 1))) (and (memq f (list f)) t))",
352 "(funcall '(closure 99 () 1))",
353 ] {
354 let text = "#+begin_src emacs-lisp\n\(form)\n#+end_src\n"
355 #expect(throws: NativeUnsupported.self, "\(form)") { try TestBabelRunner.execute(text, caret: 2, directory: folder, native: true) }
356 }
357 }
358
336359 @Test func referencedQueryBlocksAskEveryTime() {
337360 let text = "#+begin_src sh :var x=gen\necho $x\n#+end_src\n\n#+NAME: gen\n#+begin_src sh :eval query\necho 1\n#+end_src\n"
338361 guard case .success(let job) = Babel.plan(EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [2..<2])) else {
Tests/OrgCoreTests/ElispTests.swift +10 −1
@@ -25,6 +25,12 @@ struct ElispTests {
2525 "(string-prefix-p \"ab\" \"abc\")", "(condition-case nil (/ 1 0) (error 'caught))", "(ignore-errors (car 1))", "(car 1)",
2626 "(let ((x 0)) (while (< x 5) (setq x (1+ x))) x)", "(elt [1 2 3] 1)", "(aref \"abc\" 1)", "(length [1 2])", "(nthcdr 1 '(1 2 3))",
2727 "(delq nil '(1 nil 2))", "(cadr '(1 2 3))", "(identity \"x\")", "(capitalize \"hello world\")", "(string-trim \" x \")",
28 "(capitalize \"it's o'neil x_y 3d foo-bar\")",
29 #"(aref "\f" 0)"#, #"(string-match "\\s-" "\f")"#, #"(append "\a\b\d\e\f\n\r\s\t\v\ x" nil)"#, #"(list ?\a ?\b ?\d ?\e ?\f ?\r ?\s ?\v)"#,
30 "(condition-case err (car 1) (error (car err)))", "(condition-case err (cdr 'a) (error err))", "(condition-case err (/ 1 0) (arith-error err))",
31 "(condition-case err void-orgstar-variable (void-variable err))", "(condition-case nil (car 1) (wrong-type-argument 'w) (error 'e))",
32 "(condition-case nil (car 1) (arith-error 'a))", #"(condition-case err (error "e %d" 1) (error err))"#,
33 #"(condition-case err (user-error "u") (user-error err))"#, "(condition-case nil (aref [1] 5) (args-out-of-range 'r))",
2834 ]
2935
3036 static func ours(_ form: String) -> String {
@@ -141,6 +147,9 @@ struct ElispTests {
141147 "(let* ((a (list 3 1 2)) (b (list a))) (sort a '<) b)", "(let* ((a (list 1 2 3)) (b a)) (nreverse a) b)",
142148 "(let* ((a (list 1 1 2)) (b a)) (delete-dups a) b)", "(let ((a (list 3 1 2))) (list a (sort a '<)))",
143149 "(let* ((a (list 3 1 2)) (b a)) (funcall #'sort a '<) b)", "(let ((a (list 3 1 2))) (prog1 a (sort a '<)))",
150 // Errors whose data, or whose symbol, isn't known here.
151 "(condition-case err (aref [1] 5) (error err))", "(condition-case nil (number-sequence 1 2 0) (wrong-type-argument 1))",
152 #"(capitalize "café")"#,
144153 ]
145154
146155 static func strict(_ form: String) -> String {
@@ -211,7 +220,7 @@ struct ElispTests {
211220 #"(format-time-string "%F %a" (date-to-time "1500-01-01"))"#, #"(format-time-string "%F" -15000000000)"#,
212221 #"(format-time-string "%Y" -100000000000)"#, #"(format-time-string "%Y %y %D %F %j %a" -62200000000)"#,
213222 #"(format-time-string "%Y %F" -62135596800)"#, "(time-to-days -100000000000)", #"(time-to-days (date-to-time "1500-01-01"))"#,
214 #"(days-between "1500-01-01" "1600-01-01")"#,
223 #"(days-between "1500-01-01" "1600-01-01")"#, #"(format-time-string "%Y %F" 300000000000 t)"#,
215224 ]
216225
217226 static let unsupportedTime = [
docs/manual/guide/10-tables.org +7 −1
@@ -498,7 +498,13 @@ Regular expressions use Emacs's syntax and the syntax table of an Org buffer, an
498498=case-fold-search= is on unless the formula binds it to =nil=. These need Emacs:
499499numbered groups =\\(?N:=, categories =\\c=, syntax classes and character classes
500500such as =\\w=, =\\b= or =[[:alpha:]]= against text with characters past ASCII,
501and case folding of a letter past ASCII. =format-time-string= takes =%Y=, =%y=, =%m=,
501and case folding of a letter past ASCII, including =capitalize=. =condition-case=
502binds its variable to the error symbol and data, such as =(wrong-type-argument listp 1)=;
503reading that variable for an error whose data orgstar doesn't know, such as
504=args-out-of-range=, needs Emacs, as does a handler that names a specific condition
505when the error isn't one of =wrong-type-argument=, =args-out-of-range=, =arith-error=,
506=void-variable=, =invalid-function=, =wrong-number-of-arguments=, =error= and
507=user-error=. =format-time-string= takes =%Y=, =%y=, =%m=,
502508=%d=, =%e=, =%H=, =%k=, =%I=, =%l=, =%M=, =%S=, =%p=, =%a=, =%A=, =%b=, =%h=, =%B=, =%u=,
503509=%w=, =%j=, =%F=, =%D=, =%R=, =%T=, =%s=, =%z=, =%n=, =%t= and =%%=, without flags or
504510widths; other codes need Emacs, as do float times in =time-add= and =time-subtract=. =date-to-time= and =days-between= read dates as
docs/manual/guide/11-code-blocks.org +1 −1
@@ -620,7 +620,7 @@ An inline call, =call_double(n=6)=, has the same parts as a =#+CALL:= line: =cal
620620
621621On the Mac, an =emacs-lisp= or =elisp= block runs in a new =emacs -Q --batch= for each run, with lexical binding on. =-Q= means your init file and packages are not loaded, and nothing carries over between runs. orgstar looks for Emacs at =ORGSTAR_EMACS=, then =/opt/homebrew/bin/emacs=, =/usr/local/bin/emacs=, =/Applications/Emacs.app/Contents/MacOS/Emacs=, =/run/current-system/sw/bin/emacs= and =/usr/bin/emacs=. Without Emacs, the block runs in orgstar's own Emacs Lisp interpreter, and a block that uses something the interpreter does not have fails with "This block uses Emacs Lisp that runs only in Emacs, and Emacs isn't installed."
622622
623On iOS, Emacs Lisp blocks run in orgstar's own Emacs Lisp interpreter. It has the forms and functions listed under Lisp formulas in [[file:10-tables.org][Tables]]: list, string, number and control forms, regular expressions on strings, =defun=, =pcase=, =cl-loop=, the =seq-= and =cl-= sequence functions, time functions, =princ= and =message=. Like =emacs -Q --batch=, it uses lexical binding, with dynamic binding for variables declared with =defvar=, and the syntax table of Emacs Lisp mode for regular expressions. It has no buffers. A block that uses something the interpreter does not have fails with "This block uses Emacs Lisp that runs only in Emacs, on the Mac." A Lisp error fails the run, as it does in Emacs.
623On iOS, Emacs Lisp blocks run in orgstar's own Emacs Lisp interpreter. It has the forms and functions listed under Lisp formulas in [[file:10-tables.org][Tables]]: list, string, number and control forms, regular expressions on strings, =defun=, =pcase=, =cl-loop=, the =seq-= and =cl-= sequence functions, time functions, =princ= and =message=. Like =emacs -Q --batch=, it uses lexical binding, with dynamic binding for variables declared with =defvar=, and the syntax table of Emacs Lisp mode for regular expressions and =capitalize=. A quoted lambda, ='(lambda ...)=, runs with dynamic binding, as in Emacs. A closure can be called, stored and passed to functions such as =mapcar=; a block that takes one apart as a list, compares it or prints it needs Emacs. It has no buffers. A block that uses something the interpreter does not have fails with "This block uses Emacs Lisp that runs only in Emacs, on the Mac." A Lisp error fails the run, as it does in Emacs.
624624
625625In the [[file:../install.org][Mac App Store version]], Emacs Lisp blocks run in the same interpreter as on iOS. A block that uses something it does not have fails with "This block uses Emacs Lisp that runs only in Emacs."
626626