docs/manual/guide/15-alongside-emacs.org
264 lines · 25225 bytes
Working alongside Emacs and other tools
- How orgstar treats files
- Changes made outside orgstar
- Sync tools
- Recovery versions
- Features that use Emacs on the Mac
- Quick Look
- Spotlight
- Finder
- org-protocol and Shortcuts
- Compatibility notes
How orgstar treats files
Bytes on disk
orgstar edits the file's text directly; there is no separate document format. When it saves, text you didn't change is written back exactly as it was read:
- A file with no changes is never rewritten.
- Untouched lines keep their bytes, including trailing whitespace, tabs, and the presence or absence of a final newline.
- Line endings are kept as they are. A file with CRLF line endings keeps them, and on the Mac the modeline shows
CRLFfor such a file. orgstar doesn't convert line endings; new lines that orgstar's commands insert end with LF.
Encodings
orgstar edits UTF-8 files, with or without a byte order mark. A file that starts with a BOM keeps it.
A file that isn't valid UTF-8 (UTF-16, Latin-1, or a file with invalid bytes) opens read-only. The window's subtitle says "Read-only: not UTF-8", undecodable bytes show as replacement characters, and commands that would change the file report that it "isn't UTF-8, so it can't be changed". orgstar never converts such a file.
How a save works
Saving replaces the file through a temporary file in the same folder (named .name.org.orgstar-…), under the system's file coordination, so iCloud and other coordinating apps see a complete file. The steps are:
- Read the file on disk. If it changed since orgstar last read or wrote it, keep both versions in the recovery folder and merge the change into your edits (see below).
- Read the file again. If it changed in the meantime, start over, up to three times.
- Replace the file. If another program replaced it between the check and the write, its version goes to the recovery folder and is merged into your edits.
- Read the file back. If it changed right after the write, orgstar's version goes to the recovery folder and the new disk version is merged in.
Emacs and Syncthing don't use file coordination, so these checks can't lock them out. They narrow the window in which two writers can collide, and every version a save displaces is kept in the recovery folder.
If the file keeps changing through all three attempts, the save fails with an error and your edits stay unsaved.
In the Mac App Store version, when the folder doesn't let orgstar create the temporary file, orgstar writes the file in place instead.
Automatic and explicit saving
With save = "automatic" (the default), orgstar saves a file one second after you stop typing. With "explicit", only ⌘S (Save) and ⌥⌘S (Save All) save. See Configuration. The iOS app always saves automatically.
Changes made outside orgstar
orgstar watches your folders. On the Mac it uses FSEvents; on iOS it is told of changes by file coordination and reads the folders again when you return to the app. When a file that is open in orgstar changes on disk:
- If you have no unsaved edits in it, orgstar reloads it. Undo history for the file is cleared.
- If you have unsaved edits, orgstar merges the disk version into them and, with automatic saving, saves the result.
- If the changes conflict, nothing is saved and the conflict sheet opens.
The merge is a line-based three-way merge between the version orgstar last read or wrote, your edits, and the disk version. A run of lines changed on one side only takes that side; changed the same way on both, it is taken once; changed differently on both, it is a conflict. Lines keep their endings, so CRLF files and a missing final newline survive a merge. A disk version that isn't valid UTF-8 always conflicts.
After a reload or merge, orgstar also reads the file's setup files again.
The conflict sheet
The sheet shows what differs, with lines marked - on disk and + in your version, and offers:
| Button | Effect |
|---|---|
| Keep Mine | Writes your version over the disk version. The disk version goes to the recovery folder. |
| Use Disk Version | Loads the disk version. Your version goes to the recovery folder. |
| Merge with Markers | Puts both sets of changes in the buffer, with conflicting lines between <<<<<<< yours and >>>>>>> disk markers, as git merge leaves them. Edit and save. Your version as it was goes to the recovery folder. |
| Decide Later | Closes the sheet. Automatic saving stops for the file until you decide; the Conflict button in the toolbar opens the sheet again. On iOS the button is Later. |
On the Mac, File ▸ Revert to File on Disk loads the disk version at any time; unsaved changes go to the recovery folder.
Sync tools
iCloud Drive
orgstar reads and writes files under file coordination, which is how iCloud expects apps to work. Files iCloud hasn't downloaded yet (.name.org.icloud placeholders) aren't indexed; orgstar asks iCloud to download them and indexes them when they arrive. On iOS they appear in the Folders tab with a cloud icon until then.
Syncthing
Syncthing writes files without file coordination. orgstar sees its changes through file watching and merges them as described above.
- Syncthing's temporary files (
.syncthing.*) are ignored. - Its folders
.stfolderand.stversionsare in the defaultignored-folders. - Conflict copies (
name.sync-conflict-YYYYMMDD-HHMMSS-ID.org) are listed in the sidebar but never indexed, so they don't appear in the agenda, search or ID links.
When a file with conflict copies opens, a message says how many there are. File ▸ Resolve Sync Conflicts… (More ▸ Sync Conflict Copies on iOS) lists each copy against the file, with lines marked - in the file and + in the copy:
| Button | Effect |
|---|---|
| Keep File | Leaves the file as it is. |
| Use Copy | Replaces the buffer's text with the copy's, as an edit you can undo. |
| Merge with Markers | Puts every difference between the file and the copy between conflict markers in the buffer. There is no common base, so every difference is marked. |
Each choice then moves the copy to the recovery folder and deletes it from the folder.
Dropbox and other tools
Any program that writes files in your folders is treated the same way: orgstar sees the change, reloads or merges, and keeps displaced versions. Programs that write through file coordination (iCloud, File Provider apps on iOS) are seen as they write; others are seen through FSEvents on the Mac and when you return to the app on iOS.
Files orgstar ignores
When scanning folders, orgstar skips Emacs lock files (.#name), backups (name~) and auto-save files (#name#), its own temporary and backup files (names containing .orgstar-), .DS_Store, .localized, and the folders in ignored-folders. With show-hidden-files = false, every dotfile and dot folder is skipped. orgstar doesn't create or honour Emacs lock files.
Recovery versions
Every version a save, a merge or a conflict resolution displaces is kept in the recovery folder, and so is a snapshot of the file before a save, at most once an hour:
- on the Mac,
~/Library/Application Support/Orgstar/Recovery(or$ORGSTAR_DATA_DIR/Recovery), - in the Mac App Store version,
~/Library/Containers/sh.krz.orgstar/Data/Library/Application Support/Orgstar/Recovery, - on iOS, the app's own Application Support folder.
Each file has a subfolder named from a hash of its path, holding its last 20 replaced versions and, apart from them, its last 10 snapshots. A version's file name has a timestamp, a label and the file's name. The labels are:
| Label | Kept when |
|---|---|
external |
A version written by another program was replaced or merged |
local |
orgstar's version was replaced, or set aside by Use Disk Version, Merge with Markers or Restore |
sync-conflict |
A Syncthing conflict copy was resolved |
snapshot |
A save changed the file and the last snapshot was more than an hour before |
File ▸ Recovery Versions… (More ▸ Recovered Versions on iOS) lists the open file's kept versions, newest first, each compared with the buffer (lines marked - in the buffer, + in the kept version). Restore puts a version's text in the buffer as an edit you can undo; the buffer as it was goes to the recovery folder first. On the Mac, Show in Finder selects the version's file.
Features that use Emacs on the Mac
Some features run Emacs in batch mode on the Mac. Everything else works without Emacs installed. The Mac App Store version never runs Emacs; it does what the download version does without Emacs, described below.
| Feature | What runs |
|---|---|
Emacs Lisp source blocks (emacs-lisp, elisp) |
The block, in emacs -Q --batch |
| Table formulas outside what orgstar computes itself | org-table-recalculate on a copy of the file; the table's new text replaces the old one if the table didn't change meanwhile |
| Lisp table formulas that orgstar's Emacs Lisp interpreter can't evaluate | The same; orgstar first asks whether to run Lisp (yes, no, always) |
| Export to PDF, and LaTeX and plain text orgstar can't write itself | org-latex-export-to-pdf, org-latex-export-to-latex or org-ascii-export-to-ascii |
calc source blocks that orgstar's Calc refuses |
The block, in emacs -Q --batch |
elisp: links |
The form, after asking, in emacs -Q --batch in a copy of the file |
HTML, Markdown, ODT, LaTeX and ASCII export don't use Emacs. See Code blocks, Tables and Export.
How Emacs is found
orgstar uses the first of these that is an executable file:
- the path in the environment variable
ORGSTAR_EMACS, /opt/homebrew/bin/emacs,/usr/local/bin/emacs,/Applications/Emacs.app/Contents/MacOS/Emacs,/run/current-system/sw/bin/emacs,/usr/bin/emacs.
An app started from the Dock doesn't see your shell's PATH, which is why orgstar looks in fixed places. Without Emacs, Emacs Lisp blocks and elisp: links run in orgstar's own Emacs Lisp interpreter, and a block or form that uses something the interpreter doesn't have fails with a message. A table is recalculated up to the first formula orgstar can't compute, and the echo area names the formula and the reason. A calc block that orgstar's Calc refuses isn't run. Export to PDF with Emacs, which the Mac App Store version leaves out, reports "Emacs isn't installed, so this format can't be exported.", and a LaTeX or plain text export orgstar can't write itself stops with the reason.
What Emacs sees
- Emacs runs with
-Q: yourinit.el, packages and customizations aren't loaded. Org and the exporters are the versions bundled with that Emacs. - orgstar writes a snapshot of the buffer to a temporary folder and runs Emacs on it, so unsaved edits are included. The working directory is the file's folder.
- File-local variables marked safe apply (
enable-local-variablesis:safe). - Export doesn't run source blocks (
org-export-use-babelisnil). The exported file is written next to the org file, as Emacs writes it, or moved to the place you chose. - For export and table recalculation, Emacs gets your
PATHwith/opt/homebrew/bin,/usr/local/bin,/Library/TeX/texbin,/usr/binand/binadded, as source blocks do, so the programs it starts, such aspdflatex, are found when orgstar was opened from the Dock. - PDF export needs a LaTeX installation that Org's LaTeX exporter can run.
- A table recalculation that takes more than 60 seconds, or an export that takes more than 120 seconds, is stopped. Source blocks have a limit of 300 seconds.
⌘.(Cancel Running Task) stops a running block, export or table recalculation sooner.
Quick Look
orgstar includes a Quick Look extension for org files (.org and .org_archive). Pressing Space on an org file in Finder, or in the Files app on iOS, shows the file as the HTML export renders it, with its #+SETUPFILE keywords applied. The preview reads a file as UTF-8, or as Latin-1 when it isn't valid UTF-8.
Inside orgstar, selecting a file in the sidebar that isn't text shows a Quick Look preview, with Open with Default App and Show in Finder below it.
Spotlight
On the Mac, orgstar includes a Spotlight importer for org files. Spotlight indexes each file's text, its title (#+TITLE, else the file name), #+AUTHOR, #+DESCRIPTION, and its tags (#+FILETAGS and heading tags) and headings as keywords. The importer reads only UTF-8 files.
On iOS, the app adds the files in your folders to Spotlight itself; see iPhone and iPad.
Finder
orgstar declares the org.orgmode.org file type for the extensions .org and .org_archive, and registers as an editor for it, and as an alternate editor for plain text. Double-clicking an org file in Finder, dropping files on orgstar's Dock icon, or running open -a orgstar file.org opens each file as a buffer. Files opened while orgstar is starting open once its window is ready. To make orgstar the app that opens org files, use Finder's Get Info ▸ Open with ▸ Change All.
org-protocol and Shortcuts
orgstar registers the org-protocol: URL scheme on the Mac and iOS, and handles two sub-protocols, in both the ?key=value form and the older :/a/b/c form:
org-protocol://captureopens Capture with the link's template, URL, title and body.org-protocol://store-linkstores the link forC-c C-land copies it to the clipboard.
Other sub-protocols, such as open-source, show "orgstar handles org-protocol capture and store-link".
The Shortcuts action Capture to orgstar, on the Mac and iOS, files text with a capture template without opening the capture window. See Capture.
Compatibility notes
Defaults that differ from Emacs
orgstar's defaults follow a common Doom Emacs setup rather than plain Emacs in several places. If you use plain Emacs on the same files, set these in config.toml to match your Emacs, or use Import from Emacs; see Configuration.
| Setting | orgstar default | Plain Emacs default |
|---|---|---|
fill-column |
80 | 70 |
org-M-RET-may-split-line |
false |
t |
org-list-allow-alphabetical |
true |
nil |
org-hide-emphasis-markers |
true |
nil |
org-pretty-entities |
true |
nil |
org-startup-indented |
true |
nil |
org-startup-truncated |
false |
t |
electric-pair-mode |
true |
off |
org-agenda-span |
10 days | a week |
org-agenda-show-all-dates |
false |
t |
org-hide-emphasis-markers and org-pretty-entities matter for files you also edit in Emacs: orgstar aligns tags and tables, and fills paragraphs, by the width text has on screen in your Emacs. If they don't match your Emacs, tags and tables that orgstar aligns look misaligned in Emacs.
These behave as Emacs's defaults and have no setting in config.toml: org-log-repeat is time unless #+STARTUP says otherwise, fast TODO selection is on when keywords have keys, priorities are A to C with B as default unless #+PRIORITIES says otherwise, and org-use-sub-superscripts is {} for display (only x_{1} and x^{2} are lowered and raised).
How the agenda looks
The agenda selects the same entries as Org's, but shows them its own way (see The agenda):
- Rows have their own layout: the time or a status such as
Due in 2don the left, the category above the title, and the keyword and priority as badges.org-agenda-prefix-formatdoesn't change the layout; what the format has besides%c,%t,%sand%i, such as%eor%b, shows after the category, and%tin itsagendaentry decides whether a time in the heading text leaves the title. - Days without entries are hidden unless
org-agenda-show-all-datesistrue; today always shows. - Today's past deadlines and past scheduled entries are gathered in an Overdue group, oldest first, rather than sorted among today's entries by urgency.
- The time grid and the now line are drawn as lines among a day's timed entries, where
org-agenda-time-grid,org-agenda-use-time-gridandorg-agenda-show-current-time-in-gridput them. orgstar draws the lines itself, so the strings inorg-agenda-time-gridandorg-agenda-current-time-stringhave no equivalent.
Known differences from Emacs Org
orgstar refuses some things with a message rather than doing something different from Emacs. These are the ones found in the current version.
Code blocks (see Code blocks):
:cmdlineis supported only for shells,dot,plantuml,mermaidand C, C++, D, Java, Fortran and Clojure.:prologueand:epiloguearen't supported fordot,plantumlandmermaid;:stdinand:shebangonly for shells.:postand noweb references that run a block (<<name()>>) take a block in the same file, asnameorname(arg=value).name[header arguments](…), an index such asname()[0], and blocks in other files or the Library of Babel are refused: "References like … aren't supported yet."- A
:postreference is resolved once with an empty*this*before the block runs, so one that can't be resolved stops the run before it starts; Org runs the block and then fails. org-sbein a table formula doesn't run a block that has:post; on the Mac download version the table is recalculated in Emacs.:sessionis supported only for shells, Python, Ruby, JavaScript and R; on iOS and in the Mac App Store version, only for JavaScript. C, C++, D, Java, Fortran and Clojure ignore it, as in Org.- Clojure runs with babashka or the Clojure CLI only; other
:backendvalues are refused. - R blocks return their standard output, whatever
:resultssays; ob-R returns the value with:results value. - Header arguments,
:varvalues and:cachethat need Lisp evaluated by Emacs are refused when orgstar's interpreter can't evaluate them: "… is Lisp that only Emacs can evaluate; nothing was run." - Tangling refuses
:varand noweb references that would run a block, tables and lists in a shell block's:var, and:varin languages other than shells, Python, Emacs Lisp, C, C++, D, Java, Fortran and Clojure. - On iOS and in the Mac App Store version, only Emacs Lisp, JavaScript, calc, sqlite, dot and mermaid blocks run: Emacs Lisp in orgstar's own interpreter, JavaScript in JavaScriptCore. A block whose
:var,:postor noweb reference runs a block in another language runs nothing.
Links (see Links):
shell:links aren't run.elisp:links run a form after asking, in Emacs in the Mac download version when it is installed, otherwise in orgstar's interpreter; command names aren't run.
Capture templates (see Capture):
%(escapes run in orgstar's Emacs Lisp interpreter, not in Emacs. A form that uses something the interpreter doesn't have stops the capture with a message.
Tables and dynamic blocks (see Tables and Dates and clocking):
- Formulas outside orgstar's own calculator go to Emacs in the Mac download version, and are refused in the Mac App Store version and on iOS.
- Clock tables ignore
:formatterand refuse scopes given as functions. - Dynamic blocks other than
clocktable,columnviewand denote-org's aren't supported. A column view of another file doesn't write its summaries into that file.
Other:
C-c C-qbefore the first heading (setting file tags) isn't supported.- The date prompt also reads
today,tomorrow,yesterday,next weekandlast week, which Org's prompt ignores. - Priority ranges that aren't letters or numbers are refused.
#+SETUPFILEURLs aren't fetched.- Most
#+STARTUPoptions for footnotes, entities, numbering and odd levels are accepted and ignored; see Configuration. - Line numbers are on the Mac only. Visual line numbers count the screen lines in view; with the caret scrolled out of view they count lines of the file.
- Incremental search doesn't save the mark where it began, and has no
M-eediting,C-worC-yyanking into the string, or search ring beyond the last search. auto-fill-modefills on a typed space only, not onRET.- The agenda's text search (see The agenda) covers the agenda files only:
org-agenda-text-search-extra-filesandorg-agenda-search-view-max-outline-levelaren't supported. It runs from the view menu rather than the dispatcher'ssandS, and the search view's[,],{and}keys, which add words and regexps to the search, aren't supported. - In regexps,
\<,\>and\buse Org's word syntax but don't find a word boundary where the script changes between two word characters, as Emacs does (for example between an emoji and a letter). - org-roam: nodes come from orgstar's index, not org-roam's database, so
ROAM_ALIASES,ROAM_REFS,ROAM_EXCLUDE, and node tags in the chooser aren't supported; the graph is orgstar's own (see Links), not org-roam-ui's. Insert Node Link… and Find Node… make a new node from a title that isn't found with org-roam's default template only, and file it at once rather than in a capture buffer. Daily notes use the first oforg-roam-dailies-capture-templates, without choosing among several, and the date prompt prefers future dates, where org-roam prefers past ones. Capturing to a daily note files the entry at once rather than in a capture buffer. - org-timer:
org-timer-displayis always the mode line. The timer'sC-uforms are separate commands bound toC-u C-c C-x 0,C-u C-u C-c C-x 0andC-u C-c C-x ,; Set Countdown Timer… has no prefix-argument forms. - Radio lists are Org 9.8's
#+ATTR_ORG: :radiocheckbox lists. The#+ORGLSTradio lists of Org 9.1 and earlier, removed in Org 9.2, aren't supported, nor isorg-list-checkbox-radio-mode. - org-attach:
org-attach-methodis alwayscpfor Attach File… (the other methods have their own commands),org-attach-auto-tagis alwaysATTACH,org-attach-preferred-new-methodis alwaysid, andorg-attach-id-to-path-function-listis Org's default. The dispatcher'sb,OandFkeys andorg-attach-archive-deletearen't supported. Delete All Attachments… asks once and deletes the folder with what's in it. - org-crypt works with symmetric encryption only (
org-crypt-keynil); public keys andorg-crypt-use-before-save-magicaren't supported.org-crypt-tag-matcheris a single tag. - When TODO dependencies refuse a change on a
COMMENTheading, the heading keepsCOMMENT. Org removes it before the check and doesn't put it back.