Commit 0dbf01d3bc

0dbf01d3bc8b68b775dfc3a8385b84bd682b85dd

parent: c8b76a7f6a

Verified · cmc

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

Describe calc and sqlite blocks in the manual

Layout: unified · split

docs/manual/guide/11-code-blocks.org +52 −3
@@ -94,6 +94,8 @@ On the Mac, orgstar starts each interpreter outside a =:session= through =/bin/s
94| =js=, =javascript= | =node FILE=, the program written to a file, or JavaScriptCore without node; see below | 94| =js=, =javascript= | =node FILE=, the program written to a file, or JavaScriptCore without node; see below |
95| =R= | =Rscript -= | 95| =R= | =Rscript -= |
96| =awk= | =awk -f=, the program written to a file | 96| =awk= | =awk -f=, the program written to a file |
97| =calc= | orgstar's Calc, or =emacs -Q --batch=; see below |
98| =sqlite= | =sqlite3=, or the SQLite library without it; see below |
97| =dot=, =plantuml=, =mermaid= | =dot=, =plantuml=, =mmdc=; see Graphics below | 99| =dot=, =plantuml=, =mermaid= | =dot=, =plantuml=, =mmdc=; see Graphics below |
98| =C=, =C++=, =cpp=, =D=, =java=, =fortran=, =clojure= | A compiler, or =bb= or =clojure=; see Compiled languages below | 100| =C=, =C++=, =cpp=, =D=, =java=, =fortran=, =clojure= | A compiler, or =bb= or =clojure=; see Compiled languages below |
99 101
@@ -103,7 +105,7 @@ Any other language is refused with "No way to run /language/ blocks yet."
103 105
104A run that takes longer than five minutes is stopped. Runs in a =:session= have no time limit, except in JavaScriptCore. 106A run that takes longer than five minutes is stopped. Runs in a =:session= have no time limit, except in JavaScriptCore.
105 107
106The [[file:../install.org][Mac App Store version]] starts no programs, so only Emacs Lisp and JavaScript blocks run there; see /In the Mac App Store version/ below. 108The [[file:../install.org][Mac App Store version]] starts no programs, so only Emacs Lisp, JavaScript, calc and sqlite blocks run there; see /In the Mac App Store version/ below.
107 109
108** JavaScript in JavaScriptCore 110** JavaScript in JavaScriptCore
109 111
@@ -626,6 +628,53 @@ In the [[file:../install.org][Mac App Store version]], Emacs Lisp blocks run in
626 628
627Variables are bound with =let= around the body. =:results output= collects what the block prints with =princ=, =prin1=, =print= and =terpri=. 629Variables are bound with =let= around the body. =:results output= collects what the block prints with =princ=, =prin1=, =print= and =terpri=.
628 630
631* calc blocks
632
633A =calc= block runs as ob-calc runs it in =emacs -Q=, with orgstar's Calc, the one table formulas use. Each line of the body is trimmed and handled in turn; blank lines are skipped:
634
635- A line that is the name of a =:var= puts its value on the stack.
636- A line that starts with ='= runs a stack key on the stack: ='+=, ='-=, ='*=, ='/=, ='^=, ='%= (modulo), ='\= (integer division), ='n= (negate), ='&= (inverse), ='Q= (square root) and ='A= (absolute value).
637- Any other line is a formula. Its value goes on the stack; if it isn't a number, the formula is evaluated again with the block's variables put in, and that goes on the stack as text, as ob-calc does.
638
639The result is the top of the stack, shown with Calc's own settings in =emacs -Q=: 12 significant digits, all of them shown (=1/3= gives =0.333333333333=). A vector is written as a table row and a matrix as a table, unless =:results= asks for a string. =:prologue= and =:epilogue= add lines before and after the body.
640
641Each run starts with an empty stack. In Emacs the Calculator's stack carries over from one block to the next, so a block that relies on what an earlier block left there gives a different result in orgstar.
642
643=:var= values can be numbers, and lists and tables of integers; a table of one row is a vector. Errors that Emacs reports, such as "Too few elements on stack" or a stack key on a formula ("Invalid data object encountered"), fail the run without writing a result.
644
645What orgstar's Calc doesn't do as Emacs's Calc does is refused rather than given a different result: functions and forms table formulas also refuse, stack keys other than those above, dates, string variables, variables named like Calc's constants (=e=, =pi=, =i=) or with characters other than letters and digits, lists with fractional numbers, and a =:prologue= or =:epilogue= that is a bare number. The message is "This calc block can't be calculated here:" with the reason. The download version then runs the block in =emacs -Q --batch= when Emacs is installed.
646
647* sqlite blocks
648
649A =sqlite= block runs as ob-sqlite runs it: the body goes to =sqlite3= on standard input, with the options the header arguments name, and the output becomes the result. The download version runs =sqlite3= (macOS has one in =/usr/bin=) and uses the SQLite library only when it isn't installed. The Mac App Store version and iOS run the block in the SQLite library, writing the output as macOS's =sqlite3= writes it.
650
651| Header argument | Effect |
652|-----------------------------+----------------------------------------------------------------------------|
653| =:db file= | The database, relative to the file's folder or =:dir=; without it, an in-memory one |
654| =:readonly yes= | Opens the database read-only |
655| =:csv=, =:list=, =:column=, =:html=, =:line= | The output mode; without one or =:separator=, =csv= |
656| =:separator s=, =:nullvalue s= | The column separator and the text for NULL, in list mode |
657| =:colnames yes= | The first row of the result becomes the table's header |
658| =:header=, =:echo=, =:bail= | Pass =-header=, =-echo= and =-bail= to =sqlite3= |
659
660As in Emacs, a mode option resets the header, separator and NULL text to that mode's, so =:header= has an effect only with =:separator= alone.
661
662=:var= values replace =$name= in the body, in any case. A table becomes a CSV file and =$name= its path, for =.import=:
663
664#+begin_src org
665,#+begin_src sqlite :var t=prices :db shop.db
666create table if not exists prices(item text, price real);
667.import --csv $t prices
668select item, price * 2 from prices;
669,#+end_src
670#+end_src
671
672The output is read as a table the way ob-sqlite reads it, with =org-table-convert-region=; a single value becomes a scalar. In =csv= mode =sqlite3= ends lines with CR LF and Emacs keeps the CR, so the last column of each row ends with a CR, which shows as =^M=; orgstar writes the same.
673
674In the Mac App Store version, =:db= must be in a folder orgstar has access to: a folder in the sidebar, or one you granted access to.
675
676Without =sqlite3=, these dot-commands run: =.headers= (=.header=), =.mode= with =list=, =csv=, =column=, =html= or =line=, =.separator= and =.nullvalue= with one plain argument, and =.import FILE TABLE= (with =--csv= or not) into a table that exists, of rows that fit it. Anything else is refused with "This sqlite block can't run here:" and the reason: other dot-commands, header values with characters the shell would read differently (spaces, quotes, =~=, =;=, =|=), BLOB values, control characters other than tab and newline in values, text other than ASCII or values on several lines in =column= mode and in =line= mode's column names, =EXPLAIN= statements, and text that isn't UTF-8. When the refused value comes after other statements, those statements have already run, and the message says so.
677
629* Graphics 678* Graphics
630 679
631=dot= (Graphviz), =plantuml= and =mermaid= blocks draw a picture into =:file=, and the result is a link to it. =:file= is required: "/language/ code blocks need a :file header argument". The file's extension picks the output format; with none, =png= is used. 680=dot= (Graphviz), =plantuml= and =mermaid= blocks draw a picture into =:file=, and the result is a link to it. =:file= is required: "/language/ code blocks need a :file header argument". The file's extension picks the output format; with none, =png= is used.
@@ -748,7 +797,7 @@ Tangling stops, writes nothing and says why when:
748 797
749* On iOS 798* On iOS
750 799
751- Only Emacs Lisp blocks, in orgstar's own interpreter, and JavaScript blocks, in JavaScriptCore (see /JavaScript in JavaScriptCore/ above), run. Any other language, compiled languages included, fails with "/language/ blocks need the Mac to run." (for example "C blocks need the Mac to run."), and so does a block whose =:var= refers to a block in another language. 800- Only Emacs Lisp blocks, in orgstar's own interpreter, JavaScript blocks, in JavaScriptCore (see /JavaScript in JavaScriptCore/ above), and calc and sqlite blocks (see above) run. Any other language, compiled languages included, fails with "/language/ blocks need the Mac to run." (for example "C blocks need the Mac to run."), and so does a block whose =:var= refers to a block in another language.
752- JavaScript blocks can use =:session=. There are no other sessions and no graphics. 801- JavaScript blocks can use =:session=. There are no other sessions and no graphics.
753- The trust prompt works the same way, with its own =trusted.json= on the device. 802- The trust prompt works the same way, with its own =trusted.json= on the device.
754- There is no cancel command. 803- There is no cancel command.
@@ -759,7 +808,7 @@ See [[file:14-ios.org][iOS]] for the rest of the iOS app.
759 808
760* In the Mac App Store version 809* In the Mac App Store version
761 810
762- Only Emacs Lisp blocks, in the same interpreter as on iOS, and JavaScript blocks, in JavaScriptCore, run. Any other language, compiled languages included, fails with "/language/ blocks don't run in this version of orgstar." 811- Only Emacs Lisp blocks, in the same interpreter as on iOS, JavaScript blocks, in JavaScriptCore, and calc and sqlite blocks run. Any other language, compiled languages included, fails with "/language/ blocks don't run in this version of orgstar."
763- JavaScript blocks can use =:session=. There are no other sessions and no graphics. 812- JavaScript blocks can use =:session=. There are no other sessions and no graphics.
764- The trust prompt works the same way. 813- The trust prompt works the same way.
765- Tangling works as in the download version, =:shebang= included. A target outside your folders needs access to its folder first: orgstar asks with Grant Access…, as described in [[file:../install.org][Install]]. So does a =:file= result outside them. 814- Tangling works as in the download version, =:shebang= included. A target outside your folders needs access to its folder first: orgstar asks with Grant Access…, as described in [[file:../install.org][Install]]. So does a =:file= result outside them.
docs/manual/guide/14-ios.org +3 −2
@@ -343,11 +343,12 @@ Publishing works from Commands as on the Mac, with the =[[publish]]= projects in
343 343
344=C-c C-c= on a source block asks whether to run it (yes, no, or always for this block), as on the Mac. 344=C-c C-c= on a source block asks whether to run it (yes, no, or always for this block), as on the Mac.
345 345
346On iOS, only Emacs Lisp and JavaScript blocks run. orgstar evaluates Emacs Lisp with its own interpreter, which covers a subset of the language, and JavaScript in JavaScriptCore, as =node= would run it, sessions included. Other results: 346On iOS, only Emacs Lisp, JavaScript, calc and sqlite blocks run. orgstar evaluates Emacs Lisp with its own interpreter, which covers a subset of the language, JavaScript in JavaScriptCore, as =node= would run it, sessions included, calc with its own Calc and sqlite with the SQLite library, as =sqlite3= would; see [[file:11-code-blocks.org][Code blocks]]. Other results:
347 347
348- A block in another language: "/language/ blocks need the Mac to run." 348- A block in another language: "/language/ blocks need the Mac to run."
349- Emacs Lisp the interpreter doesn't have: "This block uses Emacs Lisp that runs only in Emacs, on the Mac." 349- Emacs Lisp the interpreter doesn't have: "This block uses Emacs Lisp that runs only in Emacs, on the Mac."
350- JavaScript that uses something only node has, such as =Buffer=: "This block uses /name/, which runs only in node." 350- JavaScript that uses something only node has, such as =Buffer=: "This block uses /name/, which runs only in node."
351- A calc or sqlite block orgstar can't run as Emacs would: "This calc block can't be calculated here: /reason/." or "This sqlite block can't run here: /reason/."
351 352
352Table formulas that orgstar computes itself work on iOS. In a table whose formulas need Emacs, orgstar applies the formulas up to the first one that needs it and stops there, as Emacs does when a formula fails: the fields written before it stay and the rest are unchanged. The message is "The table was recalculated up to /formula/, which needs Emacs on the Mac", with the formula's left-hand side and the reason. When nothing was written, it is "This table needs Emacs, which runs on the Mac", with the reason, and the table is unchanged. 353Table formulas that orgstar computes itself work on iOS. In a table whose formulas need Emacs, orgstar applies the formulas up to the first one that needs it and stops there, as Emacs does when a formula fails: the fields written before it stay and the rest are unchanged. The message is "The table was recalculated up to /formula/, which needs Emacs on the Mac", with the formula's left-hand side and the reason. When nothing was written, it is "This table needs Emacs, which runs on the Mac", with the reason, and the table is unchanged.
353 354
@@ -444,7 +445,7 @@ Quick Look in the Files app shows org files as the HTML export renders them.
444 445
445* What the Mac has that iOS doesn't 446* What the Mac has that iOS doesn't
446 447
447- In the download version: running code blocks in languages other than Emacs Lisp and JavaScript, Emacs Lisp beyond orgstar's interpreter, JavaScript that needs node, and tables that need Emacs. 448- In the download version: running code blocks in languages other than Emacs Lisp, JavaScript, calc and sqlite, Emacs Lisp beyond orgstar's interpreter, JavaScript that needs node, and tables that need Emacs.
448- In the download version, LaTeX-made PDF export. 449- In the download version, LaTeX-made PDF export.
449- Idle detection from keyboard and mouse input; iOS uses the time away from the app instead. 450- Idle detection from keyboard and mouse input; iOS uses the time away from the app instead.
450- In the download version, attaching by hard link or symbolic link. 451- In the download version, attaching by hard link or symbolic link.
docs/manual/install.org +3 −3
@@ -16,8 +16,8 @@ There are two versions of the Mac app. Both edit the same files in the same way;
16differ in where they come from, how orgstar+ is bought, and what they can run. 16differ in where they come from, how orgstar+ is bought, and what they can run.
17 17
18- The Mac App Store version runs in the App Sandbox and starts no other programs. Emacs 18- The Mac App Store version runs in the App Sandbox and starts no other programs. Emacs
19 Lisp blocks run in orgstar's own interpreter and JavaScript blocks in JavaScriptCore, as on 19 Lisp blocks run in orgstar's own interpreter, JavaScript blocks in JavaScriptCore, and calc and
20 iOS; other languages, Emacs and gnuplot are not used. orgstar+ is an in-app purchase shared 20 sqlite blocks built in, as on iOS; other languages, Emacs and gnuplot are not used. orgstar+ is an in-app purchase shared
21 with the iPhone and iPad app. 21 with the iPhone and iPad app.
22- The download version, from Homebrew or files.krz.sh, is signed with a Developer ID and 22- The download version, from Homebrew or files.krz.sh, is signed with a Developer ID and
23 notarized. It runs code blocks with the programs installed on the Mac, hands some tables and 23 notarized. It runs code blocks with the programs installed on the Mac, hands some tables and
@@ -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 and JavaScript in node, or built in without them | 57| Code blocks | Emacs Lisp, JavaScript, calc and sqlite, each built in | 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 |