docs/manual/guide/15-alongside-emacs.org
264 lines · 25225 bytes
1#+TITLE: Working alongside Emacs and other tools
2#+DESCRIPTION: How orgstar reads and writes files shared with Emacs and sync tools, merges outside changes, keeps recovery versions, calls Emacs, and differs from Emacs Org.
3#+LEDE: orgstar works on plain org files in ordinary folders, so Emacs, other apps and sync tools can work on the same files.
4
5* How orgstar treats files
6
7** Bytes on disk
8
9orgstar 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:
10
11- A file with no changes is never rewritten.
12- Untouched lines keep their bytes, including trailing whitespace, tabs, and the presence or absence of a final newline.
13- Line endings are kept as they are. A file with CRLF line endings keeps them, and on the Mac the modeline shows =CRLF= for such a file. orgstar doesn't convert line endings; new lines that orgstar's commands insert end with LF.
14
15** Encodings
16
17orgstar edits UTF-8 files, with or without a byte order mark. A file that starts with a BOM keeps it.
18
19A 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.
20
21** How a save works
22
23Saving 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:
24
251. 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).
262. Read the file again. If it changed in the meantime, start over, up to three times.
273. 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.
284. 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.
29
30Emacs 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.
31
32If the file keeps changing through all three attempts, the save fails with an error and your edits stay unsaved.
33
34In the Mac App Store version, when the folder doesn't let orgstar create the temporary file, orgstar writes the file in place instead.
35
36** Automatic and explicit saving
37
38With =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 [[file:13-configuration.org][Configuration]]. The iOS app always saves automatically.
39
40* Changes made outside orgstar
41
42orgstar 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:
43
44- If you have no unsaved edits in it, orgstar reloads it. Undo history for the file is cleared.
45- If you have unsaved edits, orgstar merges the disk version into them and, with automatic saving, saves the result.
46- If the changes conflict, nothing is saved and the conflict sheet opens.
47
48The 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.
49
50After a reload or merge, orgstar also reads the file's setup files again.
51
52** The conflict sheet
53
54The sheet shows what differs, with lines marked - on disk and + in your version, and offers:
55
56| Button | Effect |
57|--------------------+--------------------------------------------------------------------------------------------------|
58| Keep Mine | Writes your version over the disk version. The disk version goes to the recovery folder. |
59| Use Disk Version | Loads the disk version. Your version goes to the recovery folder. |
60| 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. |
61| 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. |
62
63On the Mac, File ▸ Revert to File on Disk loads the disk version at any time; unsaved changes go to the recovery folder.
64
65* Sync tools
66
67** iCloud Drive
68
69orgstar 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.
70
71** Syncthing
72
73Syncthing writes files without file coordination. orgstar sees its changes through file watching and merges them as described above.
74
75- Syncthing's temporary files (=.syncthing.*=) are ignored.
76- Its folders =.stfolder= and =.stversions= are in the default =ignored-folders=.
77- 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.
78
79When 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:
80
81| Button | Effect |
82|--------------------+--------------------------------------------------------------------------------------------|
83| Keep File | Leaves the file as it is. |
84| Use Copy | Replaces the buffer's text with the copy's, as an edit you can undo. |
85| 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. |
86
87Each choice then moves the copy to the recovery folder and deletes it from the folder.
88
89** Dropbox and other tools
90
91Any 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.
92
93** Files orgstar ignores
94
95When 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.
96
97* Recovery versions
98
99Every 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:
100
101- on the Mac, =~/Library/Application Support/Orgstar/Recovery= (or =$ORGSTAR_DATA_DIR/Recovery=),
102- in the Mac App Store version, =~/Library/Containers/sh.krz.orgstar/Data/Library/Application Support/Orgstar/Recovery=,
103- on iOS, the app's own Application Support folder.
104
105Each 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:
106
107| Label | Kept when |
108|-----------------+-------------------------------------------------------------------------------|
109| =external= | A version written by another program was replaced or merged |
110| =local= | orgstar's version was replaced, or set aside by Use Disk Version, Merge with Markers or Restore |
111| =sync-conflict= | A Syncthing conflict copy was resolved |
112| =snapshot= | A save changed the file and the last snapshot was more than an hour before |
113
114File ▸ 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.
115
116* Features that use Emacs on the Mac
117
118Some features run Emacs in batch mode on the Mac. Everything else works without Emacs installed. The [[file:../install.org][Mac App Store version]] never runs Emacs; it does what the download version does without Emacs, described below.
119
120| Feature | What runs |
121|----------------------------------------------------------------+-----------------------------------------------------------------------------------------------|
122| Emacs Lisp source blocks (=emacs-lisp=, =elisp=) | The block, in =emacs -Q --batch= |
123| 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 |
124| Lisp table formulas that orgstar's Emacs Lisp interpreter can't evaluate | The same; orgstar first asks whether to run Lisp (yes, no, always) |
125| 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= |
126| =calc= source blocks that orgstar's Calc refuses | The block, in =emacs -Q --batch= |
127| =elisp:= links | The form, after asking, in =emacs -Q --batch= in a copy of the file |
128
129HTML, Markdown, ODT, LaTeX and ASCII export don't use Emacs. See [[file:11-code-blocks.org][Code blocks]], [[file:10-tables.org][Tables]] and [[file:12-export.org][Export]].
130
131** How Emacs is found
132
133orgstar uses the first of these that is an executable file:
134
1351. the path in the environment variable =ORGSTAR_EMACS=,
1362. =/opt/homebrew/bin/emacs=,
1373. =/usr/local/bin/emacs=,
1384. =/Applications/Emacs.app/Contents/MacOS/Emacs=,
1395. =/run/current-system/sw/bin/emacs=,
1406. =/usr/bin/emacs=.
141
142An 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.
143
144** What Emacs sees
145
146- Emacs runs with =-Q=: your =init.el=, packages and customizations aren't loaded. Org and the exporters are the versions bundled with that Emacs.
147- 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.
148- File-local variables marked safe apply (=enable-local-variables= is =:safe=).
149- Export doesn't run source blocks (=org-export-use-babel= is =nil=). The exported file is written next to the org file, as Emacs writes it, or moved to the place you chose.
150- For export and table recalculation, Emacs gets your =PATH= with =/opt/homebrew/bin=, =/usr/local/bin=, =/Library/TeX/texbin=, =/usr/bin= and =/bin= added, as source blocks do, so the programs it starts, such as =pdflatex=, are found when orgstar was opened from the Dock.
151- PDF export needs a LaTeX installation that Org's LaTeX exporter can run.
152- 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.
153
154* Quick Look
155
156orgstar 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.
157
158Inside 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.
159
160* Spotlight
161
162On 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.
163
164On iOS, the app adds the files in your folders to Spotlight itself; see [[file:14-ios.org][iPhone and iPad]].
165
166* Finder
167
168orgstar 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.
169
170* org-protocol and Shortcuts
171
172orgstar 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:
173
174- =org-protocol://capture= opens Capture with the link's template, URL, title and body.
175- =org-protocol://store-link= stores the link for =C-c C-l= and copies it to the clipboard.
176
177Other sub-protocols, such as =open-source=, show "orgstar handles org-protocol capture and store-link".
178
179The Shortcuts action Capture to orgstar, on the Mac and iOS, files text with a capture template without opening the capture window. See [[file:08-capture.org][Capture]].
180
181* Compatibility notes
182
183** Defaults that differ from Emacs
184
185orgstar'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 [[file:13-configuration.org][Configuration]].
186
187| Setting | orgstar default | Plain Emacs default |
188|--------------------------------------+-------------------------------------+---------------------------------|
189| =fill-column= | 80 | 70 |
190| =org-M-RET-may-split-line= | =false= | =t= |
191| =org-list-allow-alphabetical= | =true= | =nil= |
192| =org-hide-emphasis-markers= | =true= | =nil= |
193| =org-pretty-entities= | =true= | =nil= |
194| =org-startup-indented= | =true= | =nil= |
195| =org-startup-truncated= | =false= | =t= |
196| =electric-pair-mode= | =true= | off |
197| =org-agenda-span= | 10 days | a week |
198| =org-agenda-show-all-dates= | =false= | =t= |
199
200=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.
201
202These 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).
203
204** How the agenda looks
205
206The agenda selects the same entries as Org's, but shows them its own way (see [[file:07-agenda.org][The agenda]]):
207
208- Rows have their own layout: the time or a status such as =Due in 2d= on the left, the category above the title, and the keyword and priority as badges. =org-agenda-prefix-format= doesn't change the layout; what the format has besides =%c=, =%t=, =%s= and =%i=, such as =%e= or =%b=, shows after the category, and =%t= in its =agenda= entry decides whether a time in the heading text leaves the title.
209- Days without entries are hidden unless =org-agenda-show-all-dates= is =true=; today always shows.
210- 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.
211- 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-grid= and =org-agenda-show-current-time-in-grid= put them. orgstar draws the lines itself, so the strings in =org-agenda-time-grid= and =org-agenda-current-time-string= have no equivalent.
212
213** Known differences from Emacs Org
214
215orgstar refuses some things with a message rather than doing something different from Emacs. These are the ones found in the current version.
216
217Code blocks (see [[file:11-code-blocks.org][Code blocks]]):
218
219- =:cmdline= is supported only for shells, =dot=, =plantuml=, =mermaid= and C, C++, D, Java, Fortran and Clojure.
220- =:prologue= and =:epilogue= aren't supported for =dot=, =plantuml= and =mermaid=; =:stdin= and =:shebang= only for shells.
221- =:post= and noweb references that run a block (=<<name()>>=) take a block in the same file, as =name= or =name(arg=value)=. =name[header arguments](…)=, an index such as =name()[0]=, and blocks in other files or the Library of Babel are refused: "References like … aren't supported yet."
222- A =:post= reference 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.
223- =org-sbe= in a table formula doesn't run a block that has =:post=; on the Mac download version the table is recalculated in Emacs.
224- =:session= is 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.
225- Clojure runs with babashka or the Clojure CLI only; other =:backend= values are refused.
226- R blocks return their standard output, whatever =:results= says; ob-R returns the value with =:results value=.
227- Header arguments, =:var= values and =:cache= that 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."
228- Tangling refuses =:var= and noweb references that would run a block, tables and lists in a shell block's =:var=, and =:var= in languages other than shells, Python, Emacs Lisp, C, C++, D, Java, Fortran and Clojure.
229- 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=, =:post= or noweb reference runs a block in another language runs nothing.
230
231Links (see [[file:09-links.org][Links]]):
232
233- =shell:= links aren't run. =elisp:= links run a form after asking, in Emacs in the Mac
234 download version when it is installed, otherwise in orgstar's interpreter; command names
235 aren't run.
236
237Capture templates (see [[file:08-capture.org][Capture]]):
238
239- =%(= 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.
240
241Tables and dynamic blocks (see [[file:10-tables.org][Tables]] and [[file:06-dates-and-clocking.org][Dates and clocking]]):
242
243- 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.
244- Clock tables ignore =:formatter= and refuse scopes given as functions.
245- Dynamic blocks other than =clocktable=, =columnview= and denote-org's aren't supported. A column view of another file doesn't write its summaries into that file.
246
247Other:
248
249- =C-c C-q= before the first heading (setting file tags) isn't supported.
250- The date prompt also reads =today=, =tomorrow=, =yesterday=, =next week= and =last week=, which Org's prompt ignores.
251- Priority ranges that aren't letters or numbers are refused.
252- =#+SETUPFILE= URLs aren't fetched.
253- Most =#+STARTUP= options for footnotes, entities, numbering and odd levels are accepted and ignored; see [[file:13-configuration.org][Configuration]].
254- 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.
255- Incremental search doesn't save the mark where it began, and has no =M-e= editing, =C-w= or =C-y= yanking into the string, or search ring beyond the last search.
256- =auto-fill-mode= fills on a typed space only, not on =RET=.
257- The agenda's text search (see [[file:07-agenda.org][The agenda]]) covers the agenda files only: =org-agenda-text-search-extra-files= and =org-agenda-search-view-max-outline-level= aren't supported. It runs from the view menu rather than the dispatcher's =s= and =S=, and the search view's =[=, =]=, ={= and =}= keys, which add words and regexps to the search, aren't supported.
258- In regexps, =\<=, =\>= and =\b= use 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).
259- 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 [[file:09-links.org][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 of =org-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.
260- org-timer: =org-timer-display= is always the mode line. The timer's =C-u= forms are separate commands bound to =C-u C-c C-x 0=, =C-u C-u C-c C-x 0= and =C-u C-c C-x ,=; Set Countdown Timer… has no prefix-argument forms.
261- Radio lists are Org 9.8's =#+ATTR_ORG: :radio= checkbox lists. The =#+ORGLST= radio lists of Org 9.1 and earlier, removed in Org 9.2, aren't supported, nor is =org-list-checkbox-radio-mode=.
262- org-attach: =org-attach-method= is always =cp= for Attach File… (the other methods have their own commands), =org-attach-auto-tag= is always =ATTACH=, =org-attach-preferred-new-method= is always =id=, and =org-attach-id-to-path-function-list= is Org's default. The dispatcher's =b=, =O= and =F= keys and =org-attach-archive-delete= aren't supported. Delete All Attachments… asks once and deletes the folder with what's in it.
263- org-crypt works with symmetric encryption only (=org-crypt-key= nil); public keys and =org-crypt-use-before-save-magic= aren't supported. =org-crypt-tag-matcher= is a single tag.
264- When TODO dependencies refuse a change on a =COMMENT= heading, the heading keeps =COMMENT=. Org removes it before the check and doesn't put it back.