Commit db6552840c

db6552840cdd0fb192d32f24cf13e8eed79877df

parent: f8dc91d0e6

Verified · cmc

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

Run Emacs Lisp natively when Emacs is missing; translate the new Lisp reasons

Layout: unified · split

Sources/OrgApp/TableReason.swift +43 −1
@@ -25,15 +25,57 @@ public enum TableReason {
25 25
26 /// `Elisp.Unsupported`'s reasons. 26 /// `Elisp.Unsupported`'s reasons.
27 static func lisp(_ what: String) -> String? { 27 static func lisp(_ what: String) -> String? {
28 if what == "integer size" { return fixed(what) } 28 let comment: StaticString = "Why a table needs Emacs: something a Lisp formula does"
29 switch what {
30 case "integer size": return fixed(what)
31 case "case folding past ASCII": return String(localized: "case folding past ASCII", comment: comment)
32 case "cl-loop destructuring": return String(localized: "cl-loop destructuring", comment: comment)
33 case "cl-loop with collect and sum": return String(localized: "cl-loop with collect and sum", comment: comment)
34 case "cl-loop without for": return String(localized: "cl-loop without for", comment: comment)
35 case "float times": return String(localized: "float times", comment: comment)
36 case "float-time of picoseconds": return String(localized: "float-time of picoseconds", comment: comment)
37 case "org-time-string-to-absolute with a day": return String(localized: "org-time-string-to-absolute with a day", comment: comment)
38 case "random with a seed": return String(localized: "random with a seed", comment: comment)
39 case "regexp classes on text past ASCII": return String(localized: "regexp classes on text past ASCII", comment: comment)
40 case "replace-match case past ASCII": return String(localized: "replace-match case past ASCII", comment: comment)
41 case "replace-match in a buffer": return String(localized: "replace-match in a buffer", comment: comment)
42 case "replace-regexp-in-string from the end": return String(localized: "replace-regexp-in-string from the end", comment: comment)
43 case "seq-uniq with a test": return String(localized: "seq-uniq with a test", comment: comment)
44 case "sort on a string": return String(localized: "sort on a string", comment: comment)
45 default: break
46 }
29 func value(_ prefix: String) -> String? { what.hasPrefix(prefix) ? String(what.dropFirst(prefix.count)) : nil } 47 func value(_ prefix: String) -> String? { what.hasPrefix(prefix) ? String(what.dropFirst(prefix.count)) : nil }
48 func split(_ text: String, _ separator: String) -> (String, String)? {
49 guard let range = text.range(of: separator) else { return nil }
50 return (String(text[..<range.lowerBound]), String(text[range.upperBound...]))
51 }
30 if let name = value("function ") { return String(localized: "function \(name)", comment: "Why a table needs Emacs: a Calc function") } 52 if let name = value("function ") { return String(localized: "function \(name)", comment: "Why a table needs Emacs: a Calc function") }
31 if let time = value("time value ") { return String(localized: "time value \(time)", comment: "Why a table needs Emacs: a Lisp time value") } 53 if let time = value("time value ") { return String(localized: "time value \(time)", comment: "Why a table needs Emacs: a Lisp time value") }
32 if let number = value("date number ") { return String(localized: "date number \(number)", comment: "Why a table needs Emacs: a Lisp date number") } 54 if let number = value("date number ") { return String(localized: "date number \(number)", comment: "Why a table needs Emacs: a Lisp date number") }
55 if let text = value("date-to-time of ") { return String(localized: "date-to-time of \(text)", comment: comment) }
56 if let parts = value("date ") { return String(localized: "date \(parts)", comment: comment) }
57 if let text = value("time string ") { return String(localized: "time string \(text)", comment: comment) }
58 if let zone = value("format-time-string zone ") { return String(localized: "format-time-string zone \(zone)", comment: comment) }
59 if let code = value("format-time-string ") { return String(localized: "format-time-string \(code)", comment: comment) }
60 if let clause = value("cl-loop ") { return String(localized: "cl-loop \(clause)", comment: comment) }
61 if let pattern = value("pcase pattern ") { return String(localized: "pcase pattern \(pattern)", comment: comment) }
62 if let name = value("let-alist ") { return String(localized: "let-alist \(name)", comment: comment) }
63 if let text = value("string-width of ") { return String(localized: "string-width of \(text)", comment: comment) }
64 if let rest = value("regexp "), let parts = split(rest, " in ") {
65 return String(localized: "regexp \(parts.0) in \(parts.1)", comment: "Why a table needs Emacs: part of a Lisp regular expression")
66 }
67 if let rest = value("value< on "), let parts = split(rest, " and ") {
68 return String(localized: "value< on \(parts.0) and \(parts.1)", comment: comment)
69 }
33 if what.hasSuffix(" on a place") { 70 if what.hasSuffix(" on a place") {
34 let name = String(what.dropLast(" on a place".count)) 71 let name = String(what.dropLast(" on a place".count))
35 return String(localized: "\(name) on a place", comment: "Why a table needs Emacs: a Lisp function used on a variable") 72 return String(localized: "\(name) on a place", comment: "Why a table needs Emacs: a Lisp function used on a variable")
36 } 73 }
74 if what.hasSuffix(" in a buffer") {
75 let name = String(what.dropLast(" in a buffer".count))
76 return String(localized: "\(name) in a buffer", comment: comment)
77 }
78 if let parts = split(what, " with ") { return String(localized: "\(parts.0) with \(parts.1)", comment: comment) }
37 return nil 79 return nil
38 } 80 }
39 81
Sources/OrgCore/Config/Elisp.swift +6 −1
@@ -600,7 +600,12 @@ public final class Elisp {
600 guard let last = args.last else { return .nil } 600 guard let last = args.last else { return .nil }
601 var items: [Sexp] = [] 601 var items: [Sexp] = []
602 for arg in args.dropLast() { items += try sequence(arg) } 602 for arg in args.dropLast() { items += try sequence(arg) }
603 return items.reversed().reduce(last) { cons($1, $0) } 603 switch last {
604 case .list(let rest): return .list(items + rest)
605 case .dotted(let rest, let tail): return .dotted(items + rest, tail)
606 case _ where isNil(last): return list(items)
607 default: return items.isEmpty ? last : .dotted(items, last)
608 }
604 } 609 }
605 lisp.define("length") { _, args in 610 lisp.define("length") { _, args in
606 try arity(args, 1...1, "length") 611 try arity(args, 1...1, "length")
Sources/OrgCore/Config/ElispLibrary.swift +17 −6
@@ -102,6 +102,7 @@ extension Elisp {
102 let s = try string(args[0]) 102 let s = try string(args[0])
103 let pad = try int(args[1]) - s.unicodeScalars.count 103 let pad = try int(args[1]) - s.unicodeScalars.count
104 guard pad > 0 else { return .string(s) } 104 guard pad > 0 else { return .string(s) }
105 guard pad <= lengthLimit else { throw Signal(message: "Too long for string-pad") }
105 let padding = String(repeating: String(try scalar(args.count > 2 && !isNil(args[2]) ? try int(args[2]) : 32)), count: pad) 106 let padding = String(repeating: String(try scalar(args.count > 2 && !isNil(args[2]) ? try int(args[2]) : 32)), count: pad)
106 return .string(args.count > 3 && !isNil(args[3]) ? padding + s : s + padding) 107 return .string(args.count > 3 && !isNil(args[3]) ? padding + s : s + padding)
107 } 108 }
@@ -181,6 +182,20 @@ extension Elisp {
181 } 182 }
182 } 183 }
183 184
185 /// The first of each run of `equal` items, in order.
186 static func uniqueEqual(_ items: [Sexp]) -> [Sexp] {
187 var seen: [String: [Sexp]] = [:]
188 var kept: [Sexp] = []
189 for item in items {
190 let value = normalized(item)
191 let key = printed(value, escape: true)
192 guard !(seen[key]?.contains(value) ?? false) else { continue }
193 seen[key, default: []].append(value)
194 kept.append(item)
195 }
196 return kept
197 }
198
184 /// A stable merge sort with a predicate that may throw. 199 /// A stable merge sort with a predicate that may throw.
185 static func stableSort(_ items: [Sexp], _ less: (Sexp, Sexp) throws -> Bool) throws -> [Sexp] { 200 static func stableSort(_ items: [Sexp], _ less: (Sexp, Sexp) throws -> Bool) throws -> [Sexp] {
186 guard items.count > 1 else { return items } 201 guard items.count > 1 else { return items }
@@ -229,9 +244,7 @@ extension Elisp {
229 } 244 }
230 lisp.define("delete-dups") { _, args in 245 lisp.define("delete-dups") { _, args in
231 try arity(args, 1...1, "delete-dups") 246 try arity(args, 1...1, "delete-dups")
232 var kept: [Sexp] = [] 247 return list(uniqueEqual(try elements(args[0])))
233 for item in try elements(args[0]) where !kept.contains(where: { normalized($0) == normalized(item) }) { kept.append(item) }
234 return list(kept)
235 } 248 }
236 lisp.define("nreverse") { _, args in 249 lisp.define("nreverse") { _, args in
237 try arity(args, 1...1, "nreverse") 250 try arity(args, 1...1, "nreverse")
@@ -291,9 +304,7 @@ extension Elisp {
291 lisp.define("seq-uniq") { _, args in 304 lisp.define("seq-uniq") { _, args in
292 try arity(args, 1...2, "seq-uniq") 305 try arity(args, 1...2, "seq-uniq")
293 guard args.count == 1 || isNil(args[1]) else { throw Unsupported(what: "seq-uniq with a test") } 306 guard args.count == 1 || isNil(args[1]) else { throw Unsupported(what: "seq-uniq with a test") }
294 var kept: [Sexp] = [] 307 return list(uniqueEqual(try sequence(args[0])))
295 for item in try sequence(args[0]) where !kept.contains(where: { normalized($0) == normalized(item) }) { kept.append(item) }
296 return list(kept)
297 } 308 }
298 lisp.define("cl-reduce") { lisp, args in 309 lisp.define("cl-reduce") { lisp, args in
299 try arity(args, 2...Int.max, "cl-reduce") 310 try arity(args, 2...Int.max, "cl-reduce")
Sources/OrgPrograms/Programs.swift +13 −2
@@ -5,7 +5,12 @@ import OrgCore
5 5
6/// Babel and Emacs as processes, for `DocumentSession.programs`. 6/// Babel and Emacs as processes, for `DocumentSession.programs`.
7public struct Programs: ProgramRunning { 7public struct Programs: ProgramRunning {
8 public init() {} 8 /// Where Emacs is, or nil when it isn't installed.
9 let emacs: @Sendable () -> URL?
10
11 public init(emacs: @escaping @Sendable () -> URL? = { EmacsRunner.executable() }) {
12 self.emacs = emacs
13 }
9 14
10 public func runBabel(_ job: BabelJob, fileDirectory: URL) async throws -> BabelOutput { 15 public func runBabel(_ job: BabelJob, fileDirectory: URL) async throws -> BabelOutput {
11 // js in JavaScriptCore when node (or `:cmd`) isn't installed. A `:cmd` with arguments runs 16 // js in JavaScriptCore when node (or `:cmd`) isn't installed. A `:cmd` with arguments runs
@@ -14,7 +19,13 @@ public struct Programs: ProgramRunning {
14 case .process(let executable, _), .session(_, let executable, _): 19 case .process(let executable, _), .session(_, let executable, _):
15 if !executable.contains(where: \.isWhitespace), !BabelRunner.installed(executable), let output = try await JavaScriptBlocks.run(job, directory: fileDirectory) { return output } 20 if !executable.contains(where: \.isWhitespace), !BabelRunner.installed(executable), let output = try await JavaScriptBlocks.run(job, directory: fileDirectory) { return output }
16 case .emacs: 21 case .emacs:
17 break 22 // Emacs Lisp in `Elisp` when Emacs isn't installed.
23 if emacs() == nil {
24 guard let output = try Babel.evaluateNatively(job) else {
25 throw BabelRunner.Failure(description: "This block uses Emacs Lisp that runs only in Emacs, and Emacs isn't installed.")
26 }
27 return output
28 }
18 } 29 }
19 return try await BabelRunner.run(job, fileDirectory: fileDirectory) 30 return try await BabelRunner.run(job, fileDirectory: fileDirectory)
20 } 31 }
Sources/Orgstar/ContentView.swift +3
@@ -1053,6 +1053,9 @@ struct ContentView: View {
1053 commands.show(String(localized: "This table's formulas can't be calculated here: \(TableReason.localized(reason)).", comment: "Table formulas orgstar can't calculate")) 1053 commands.show(String(localized: "This table's formulas can't be calculated here: \(TableReason.localized(reason)).", comment: "Table formulas orgstar can't calculate"))
1054 #else 1054 #else
1055 case .emacsTable(let table, let point, let form, let reason, let lisp): 1055 case .emacsTable(let table, let point, let form, let reason, let lisp):
1056 guard EmacsRunner.executable() != nil else {
1057 return commands.show(String(localized: "This table's formulas can't be calculated here: \(TableReason.localized(reason)).", comment: "Table formulas orgstar can't calculate"))
1058 }
1056 let run = { 1059 let run = {
1057 commands.show(String(localized: "Recalculating in Emacs (\(TableReason.localized(reason)))…", comment: "Table formulas sent to Emacs, and why")) 1060 commands.show(String(localized: "Recalculating in Emacs (\(TableReason.localized(reason)))…", comment: "Table formulas sent to Emacs, and why"))
1058 commands.runInEmacs { commands.show(await session.recalculateInEmacs(table: table, point: point, form: form)) } 1061 commands.runInEmacs { commands.show(await session.recalculateInEmacs(table: table, point: point, form: form)) }
Tests/OrgAppTests/TableReasonTests.swift +18 −1
@@ -12,7 +12,24 @@ struct TableReasonTests {
12 for file in files where file.hasSuffix(".swift") { 12 for file in files where file.hasSuffix(".swift") {
13 let text = try String(contentsOf: Self.root.appendingPathComponent("Sources/OrgCore/" + file), encoding: .utf8) 13 let text = try String(contentsOf: Self.root.appendingPathComponent("Sources/OrgCore/" + file), encoding: .utf8)
14 // An interpolated value stands as "x", as it would read at run time. 14 // An interpolated value stands as "x", as it would read at run time.
15 func sample(_ literal: Substring) -> String { String(literal).replacing(/\\\(.*\)/, with: "x") } 15 func sample(_ literal: Substring) -> String {
16 var out = "", depth = 0, chars = Array(literal), i = 0
17 while i < chars.count {
18 if depth == 0, chars[i] == "\\", i + 1 < chars.count, chars[i + 1] == "(" {
19 out += "x"
20 depth = 1
21 i += 2
22 continue
23 }
24 if depth > 0 {
25 if chars[i] == "(" { depth += 1 } else if chars[i] == ")" { depth -= 1 }
26 } else {
27 out.append(chars[i])
28 }
29 i += 1
30 }
31 return out
32 }
16 reasons += text.matches(of: /Unsupported\("((?:[^"\\]|\\\([^)]*\)+)*)"/).map { sample($0.1) } 33 reasons += text.matches(of: /Unsupported\("((?:[^"\\]|\\\([^)]*\)+)*)"/).map { sample($0.1) }
17 lisp += text.matches(of: /Unsupported\(what: "((?:[^"\\]|\\\([^)]*\)+)*)"/).map { sample($0.1) } 34 lisp += text.matches(of: /Unsupported\(what: "((?:[^"\\]|\\\([^)]*\)+)*)"/).map { sample($0.1) }
18 } 35 }
Tests/OrgCoreTests/ElispTests.swift +4 −1
@@ -231,11 +231,14 @@ struct HostileInputTests {
231 "(% -9223372036854775808 -1)", "(mod -9223372036854775808 -1)", "(/ -9223372036854775808 -1)", 231 "(% -9223372036854775808 -1)", "(mod -9223372036854775808 -1)", "(/ -9223372036854775808 -1)",
232 "(upcase -1)", "(downcase -1)", "(concat (list -1))", "(format \"%c\" -1)", "(format \"%c\" 99999999)", 232 "(upcase -1)", "(downcase -1)", "(concat (list -1))", "(format \"%c\" -1)", "(format \"%c\" 99999999)",
233 "(funcall (lambda (f) (funcall f f)) (lambda (f) (funcall f f)))", 233 "(funcall (lambda (f) (funcall f f)) (lambda (f) (funcall f f)))",
234 "(dotimes (i 10000000000) nil)", "(number-sequence 1 10000000000)", 234 "(dotimes (i 10000000000) nil)", "(number-sequence 1 10000000000)", #"(string-pad "a" 10000000000)"#,
235 "(cl-loop for i from 1 to 10000000000 sum i)", "(cl-loop for i from 1 collect i)", "(expt 7 10000000000)",
235 ] 236 ]
236 237
237 @Test func evaluatorRefusesWithoutCrashing() { 238 @Test func evaluatorRefusesWithoutCrashing() {
238 for form in Self.forms { #expect(ElispTests.ours(form) == "error", "\(form)") } 239 for form in Self.forms { #expect(ElispTests.ours(form) == "error", "\(form)") }
240 // Long lists lose duplicates without comparing every pair.
241 #expect(ElispTests.ours("(length (seq-uniq (append (number-sequence 1 50000) (number-sequence 1 50000))))") == "50000")
239 } 242 }
240 243
241 /// On a stack the size of a background task's, deep recursion stops with an error. 244 /// On a stack the size of a background task's, deep recursion stops with an error.
Tests/OrgProgramsTests/ProgramsTests.swift +20
@@ -200,3 +200,23 @@ struct JavaScriptFallbackTests {
200 #expect(try await run("#+begin_src js :results output\nconsole.log(typeof require('fs').readFileSync)\n#+end_src\n").stdout == "function\n") 200 #expect(try await run("#+begin_src js :results output\nconsole.log(typeof require('fs').readFileSync)\n#+end_src\n").stdout == "function\n")
201 } 201 }
202} 202}
203
204/// Emacs Lisp runs in `Elisp` when Emacs isn't installed.
205struct EmacsLispFallbackTests {
206 func run(_ text: String) async throws -> BabelOutput {
207 let context = EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [2..<2])
208 guard case .success(let job) = Babel.plan(context) else { throw Babel.Failure.message("not planned") }
209 return try await Programs(emacs: { nil }).runBabel(job, fileDirectory: FileManager.default.temporaryDirectory)
210 }
211
212 @Test func runsWithoutEmacs() async throws {
213 #expect(try await run("#+begin_src emacs-lisp\n(cl-loop for i from 1 to 4 sum i)\n#+end_src\n").stdout.contains("\"s\":\"10\""))
214 }
215
216 @Test func refusesWhatOnlyEmacsRuns() async throws {
217 let error = await #expect(throws: BabelRunner.Failure.self) {
218 try await run("#+begin_src emacs-lisp\n(with-temp-buffer (insert \"x\") (buffer-string))\n#+end_src\n")
219 }
220 #expect(error?.description == "This block uses Emacs Lisp that runs only in Emacs, and Emacs isn't installed.")
221 }
222}
docs/manual/guide/08-capture.org +1 −1
@@ -215,7 +215,7 @@ From the Mac capture window, =%a= links to the heading at the cursor in the open
215 215
216=%[file]= is replaced by the file's contents before anything else, as in Org, so escapes and prompts in the file work, and so does a =%[…]= in it. A relative path is relative to the configuration folder (the one with =capture.toml=), and =~= is your home folder. The file name runs to the last =]= on the line. A file that can't be read leaves =%![could not insert …]= in the text. 216=%[file]= is replaced by the file's contents before anything else, as in Org, so escapes and prompts in the file work, and so does a =%[…]= in it. A relative path is relative to the configuration folder (the one with =capture.toml=), and =~= is your home folder. The file name runs to the last =]= on the line. A file that can't be read leaves =%![could not insert …]= in the text.
217 217
218=%(sexp)= evaluates the form after the other escapes are expanded, as Org does, and inserts its value: a string as it is, nothing for =nil=; any other value is an error. Escapes inside the form, such as =%i= or =%:link= in a string, are expanded with backslashes and quotes escaped. orgstar evaluates the form with its own Lisp, not Emacs: =concat=, =format=, =upcase=, =substring=, =mapconcat=, =if=, =let= and the other basic functions, plus =format-time-string= (the codes =%<…>= takes, at the capture's time or a =current-time= value), =current-time=, =user-full-name= and =read-string=. =read-string= is asked as a question before the template's =%^= prompts. A form that calls anything else stops the capture with a message naming the function. 218=%(sexp)= evaluates the form after the other escapes are expanded, as Org does, and inserts its value: a string as it is, nothing for =nil=; any other value is an error. Escapes inside the form, such as =%i= or =%:link= in a string, are expanded with backslashes and quotes escaped. orgstar evaluates the form with its own Lisp, not Emacs: =concat=, =format=, =upcase=, =substring=, =mapconcat=, =if=, =let= and the other functions listed under Lisp formulas in [[file:10-tables.org][Tables]], with =current-time= and =format-time-string= at the capture's time, plus =user-full-name= and =read-string=. =read-string= is asked as a question before the template's =%^= prompts. A form that calls anything else stops the capture with a message naming the function.
219 219
220=%:name= inserts a property of the link being captured. From org-protocol these are =%:link=, =%:description= (the page title), =%:type= (the link's scheme, such as =https=), =%:annotation= (the same as =%a=) and =%:initial= (the same as =%i=). Without org-protocol, =%:annotation= and =%:initial= still work and other names insert nothing. 220=%:name= inserts a property of the link being captured. From org-protocol these are =%:link=, =%:description= (the page title), =%:type= (the link's scheme, such as =https=), =%:annotation= (the same as =%a=) and =%:initial= (the same as =%i=). Without org-protocol, =%:annotation= and =%:initial= still work and other names insert nothing.
221 221
docs/manual/guide/10-tables.org +40 −8
@@ -455,25 +455,56 @@ The evaluator supports:
455 455
456- special forms: =quote=, =function=, =lambda=, =progn=, =prog1=, =if=, =when=, 456- special forms: =quote=, =function=, =lambda=, =progn=, =prog1=, =if=, =when=,
457 =unless=, =cond=, =and=, =or=, =let=, =let*=, =setq=, =push=, =pop=, =while=, 457 =unless=, =cond=, =and=, =or=, =let=, =let*=, =setq=, =push=, =pop=, =while=,
458 =dolist=, =dotimes=, =with-output-to-string=, =ignore-errors=, =condition-case=; 458 =dolist=, =dotimes=, =with-output-to-string=, =ignore-errors=, =condition-case=,
459 =save-match-data=, =defun=, =defvar=, =defconst=, =let-alist=, =cl-incf= and =cl-decf=
460 on a variable;
461- =pcase= with literal, symbol, quoted, backquoted and =pred= patterns, where =pred=
462 takes a function name or a lambda;
463- =cl-loop= with =for VAR in LIST=, =for VAR from START to END=, and one kind of
464 =collect= or =sum=, with =do=;
459- arithmetic: =+=, =-=, =*=, =/=, =%=, =mod=, =1+=, =1-=, =abs=, =max=, =min=, =float=, 465- arithmetic: =+=, =-=, =*=, =/=, =%=, =mod=, =1+=, =1-=, =abs=, =max=, =min=, =float=,
460 =floor=, =ceiling=, =round=, =truncate=, ~=~, =<=, =>=, ~<=~, ~>=~, ~/=~, =zerop=; 466 =floor=, =ceiling=, =round=, =truncate=, ~=~, =<=, =>=, ~<=~, ~>=~, ~/=~, =zerop=,
467 =expt=, =sqrt=, =exp=, =log=, =sin=, =cos=, =tan=, =asin=, =acos=, =atan=, =isnan=,
468 =random=, =logand=, =logior=, =logxor=, =ash=, and the variables =float-pi=, =pi= and
469 =float-e=;
461- predicates: =not=, =null=, =eq=, =eql=, =equal=, =numberp=, =integerp=, =floatp=, 470- predicates: =not=, =null=, =eq=, =eql=, =equal=, =numberp=, =integerp=, =floatp=,
462 =stringp=, =listp=, =consp=, =symbolp=; 471 =stringp=, =listp=, =consp=, =symbolp=;
463- lists: =car=, =cdr=, =cadr=, =cddr=, =cons=, =list=, =nth=, =nthcdr=, =elt=, =aref=, 472- lists: =car=, =cdr=, =cadr=, =cddr=, =cons=, =list=, =nth=, =nthcdr=, =elt=, =aref=,
464 =append=, =length=, =reverse=, =number-sequence=, =memq=, =member=, =memql=, =assoc=, 473 =append=, =length=, =reverse=, =number-sequence=, =memq=, =member=, =memql=, =assoc=,
465 =assq=, =delq=, =delete=, =mapcar=, =mapc=, =mapconcat=, =funcall=, =apply=, 474 =assq=, =delq=, =delete=, =mapcar=, =mapc=, =mapconcat=, =funcall=, =apply=,
466 =identity=, =ignore=; 475 =identity=, =ignore=, =last=, =butlast=, =delete-dups=, =nreverse=, =sort= (both
476 calling conventions), =seq-reduce=, =seq-filter=, =seq-remove=, =seq-map=, =seq-uniq=,
477 =cl-reduce= (with =:initial-value=), =cl-remove-if=, =cl-remove-if-not=, =cl-find= and
478 =cl-position= (with =:test=);
467- strings: =concat=, =format=, =format-message=, ~string=~, =string-equal=, =string<=, 479- strings: =concat=, =format=, =format-message=, ~string=~, =string-equal=, =string<=,
468 =string-lessp=, =upcase=, =downcase=, =capitalize=, =substring=, =string-to-number=, 480 =string-lessp=, =upcase=, =downcase=, =capitalize=, =substring=, =string-to-number=,
469 =number-to-string=, =int-to-string=, =string-prefix-p=, =string-suffix-p=, 481 =number-to-string=, =int-to-string=, =string-prefix-p=, =string-suffix-p=,
470 =string-empty-p=, =string-trim=, =split-string=, =prin1-to-string=; 482 =string-empty-p=, =string-trim=, =split-string=, =prin1-to-string=, =string-join=,
483 =string-to-char=, =char-to-string=, =string-pad=, =string-width=, =string-search=,
484 =string-replace=;
485- regular expressions: =string-match=, =string-match-p=, =match-beginning=, =match-end=,
486 =match-string=, =replace-match= and =replace-regexp-in-string= on strings, and
487 =regexp-quote=;
488- time: =current-time=, =format-time-string=, =float-time=, =time-add=, =time-subtract=,
489 =time-to-days=, =date-to-time=, =days-between=, =org-time-string-to-time=,
490 =org-time-string-to-absolute= and the =calendar-= functions that diary sexps use, in
491 the local time zone;
471- output and errors: =princ=, =prin1=, =print=, =terpri=, =message=, =error=, 492- output and errors: =princ=, =prin1=, =print=, =terpri=, =message=, =error=,
472 =user-error=; 493 =user-error=;
473- Org's lookup functions =org-lookup-first=, =org-lookup-last= and =org-lookup-all=. 494- Org's lookup functions =org-lookup-first=, =org-lookup-last= and =org-lookup-all=.
474 495
475Any other function needs Emacs. An error inside a Lisp formula writes =#ERROR= in the 496Regular expressions use Emacs's syntax and the syntax table of an Org buffer, and
476field, as does a Calc error. 497=case-fold-search= is on unless the formula binds it to =nil=. These need Emacs:
498numbered groups =\\(?N:=, categories =\\c=, syntax classes and character classes
499such as =\\w=, =\\b= or =[[:alpha:]]= against text with characters past ASCII,
500and case folding of a letter past ASCII. =format-time-string= takes =%Y=, =%y=, =%m=,
501=%d=, =%e=, =%H=, =%k=, =%I=, =%l=, =%M=, =%S=, =%p=, =%a=, =%A=, =%b=, =%h=, =%B=, =%u=,
502=%w=, =%j=, =%F=, =%D=, =%R=, =%T=, =%s=, =%z=, =%n=, =%t= and =%%=, without flags or
503widths; other codes need Emacs, as do float times in =time-add= and =time-subtract=. =date-to-time= and =days-between= read dates as
504=YYYY-MM-DD=, with an optional =HH:MM= or =HH:MM:SS=.
505
506Any other function, or a macro not listed, needs Emacs. An error inside a Lisp formula
507writes =#ERROR= in the field, as does a Calc error.
477 508
478* Entering formulas 509* Entering formulas
479 510
@@ -555,8 +586,9 @@ packages and customizations are not loaded, then replaces the table with Emacs's
555result. It looks for Emacs at the path in the =ORGSTAR_EMACS= environment variable, 586result. It looks for Emacs at the path in the =ORGSTAR_EMACS= environment variable,
556then =/opt/homebrew/bin/emacs=, =/usr/local/bin/emacs=, 587then =/opt/homebrew/bin/emacs=, =/usr/local/bin/emacs=,
557=/Applications/Emacs.app/Contents/MacOS/Emacs=, =/run/current-system/sw/bin/emacs= and 588=/Applications/Emacs.app/Contents/MacOS/Emacs=, =/run/current-system/sw/bin/emacs= and
558=/usr/bin/emacs=. If none is found, the echo area says Emacs isn't installed and the 589=/usr/bin/emacs=. If none is found, the echo area shows the reason, as
559table is unchanged. Emacs gets your =PATH= with =/opt/homebrew/bin=, =/usr/local/bin=, 590=This table's formulas can't be calculated here: reason.=, and the table is unchanged.
591Emacs gets your =PATH= with =/opt/homebrew/bin=, =/usr/local/bin=,
560=/Library/TeX/texbin=, =/usr/bin= and =/bin= added, as code blocks and export do, so 592=/Library/TeX/texbin=, =/usr/bin= and =/bin= added, as code blocks and export do, so
561programs a formula starts are found when orgstar was opened from the Dock. The run 593programs a formula starts are found when orgstar was opened from the Dock. The run
562stops after 60 seconds. If you edit the table while Emacs is working, its result is 594stops after 60 seconds. If you edit the table while Emacs is working, its result is
docs/manual/guide/11-code-blocks.org +3 −3
@@ -89,7 +89,7 @@ On the Mac, orgstar starts each interpreter through =/usr/bin/env=. Because an a
89| =sh=, =bash=, =zsh=, =fish=, =ksh=, =dash=, =ash=, =csh=, =mksh=, =posh= | The shell of that name | 89| =sh=, =bash=, =zsh=, =fish=, =ksh=, =dash=, =ash=, =csh=, =mksh=, =posh= | The shell of that name |
90| =shell= | The shell in =SHELL=, or =/bin/sh= | 90| =shell= | The shell in =SHELL=, or =/bin/sh= |
91| =python= | =python3=, or the program in =:python= | 91| =python= | =python3=, or the program in =:python= |
92| =emacs-lisp=, =elisp= | =emacs -Q --batch=; see Emacs Lisp blocks below | 92| =emacs-lisp=, =elisp= | =emacs -Q --batch=, or the interpreter; see below |
93| =ruby= | =ruby=, or the program in =:ruby= | 93| =ruby= | =ruby=, or the program in =:ruby= |
94| =js=, =javascript= | =node=, or JavaScriptCore without it; see below | 94| =js=, =javascript= | =node=, or JavaScriptCore without it; see below |
95| =R= | =Rscript -= | 95| =R= | =Rscript -= |
@@ -618,9 +618,9 @@ An inline call, =call_double(n=6)=, has the same parts as a =#+CALL:= line: =cal
618 618
619* Emacs Lisp blocks 619* Emacs Lisp blocks
620 620
621On 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 fails with "Emacs isn't installed, so Emacs Lisp blocks can't run." 621On 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."
622 622
623On iOS, Emacs Lisp blocks run in orgstar's own Emacs Lisp interpreter. It covers ordinary list, string, number and control forms, =princ= and =message=. 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=. It binds variables dynamically, and 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.
624 624
625In 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." 625In 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."
626 626
docs/manual/install.org +1 −1
@@ -54,7 +54,7 @@ App Store version.
54 54
55| Feature | Mac App Store version | Download version | 55| Feature | Mac App Store version | Download version |
56|----------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------| 56|----------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------|
57| Code blocks | Emacs Lisp in orgstar's own interpreter, JavaScript in JavaScriptCore | Every language installed; Emacs Lisp in Emacs; JavaScript in node, or JavaScriptCore without it | 57| Code blocks | Emacs Lisp in orgstar's own interpreter, JavaScript in JavaScriptCore | Every language installed; Emacs Lisp in Emacs and JavaScript in node, or built in without them |
58| Sessions, graphics | JavaScript sessions; no graphics | Yes | 58| Sessions, graphics | JavaScript sessions; no graphics | Yes |
59| Tangling | Yes | Yes | 59| Tangling | Yes | Yes |
60| Table formulas | Those orgstar computes itself | The rest in Emacs as well | 60| Table formulas | Those orgstar computes itself | The rest in Emacs as well |