docs/manual/guide/15-alongside-emacs.org

v1.1.0
orgstar/docs/manual/guide/15-alongside-emacs.org rendered · source · history · blame · raw

258 lines · 22417 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
 34** Automatic and explicit saving
 35
 36With =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.
 37
 38* Changes made outside orgstar
 39
 40orgstar 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:
 41
 42- If you have no unsaved edits in it, orgstar reloads it. Undo history for the file is cleared.
 43- If you have unsaved edits, orgstar merges the disk version into them and saves the result.
 44- If the changes conflict, nothing is saved and the conflict sheet opens.
 45
 46The 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.
 47
 48After a reload or merge, orgstar also reads the file's setup files again.
 49
 50** The conflict sheet
 51
 52The sheet shows what differs, with lines marked - on disk and + in your version, and offers:
 53
 54| Button             | Effect                                                                                           |
 55|--------------------+--------------------------------------------------------------------------------------------------|
 56| Keep Mine          | Writes your version over the disk version. The disk version goes to the recovery folder.        |
 57| Use Disk Version   | Loads the disk version. Your version goes to the recovery folder.                                |
 58| 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. |
 59| Decide Later       | Closes the sheet. Automatic saving stops for the file until you decide; the Conflict button in the toolbar opens the sheet again. |
 60
 61On the Mac, File ▸ Revert to File on Disk loads the disk version at any time; unsaved changes go to the recovery folder.
 62
 63* Sync tools
 64
 65** iCloud Drive
 66
 67orgstar 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.
 68
 69** Syncthing
 70
 71Syncthing writes files without file coordination. orgstar sees its changes through file watching and merges them as described above.
 72
 73- Syncthing's temporary files (=.syncthing.*=) are ignored.
 74- Its folders =.stfolder= and =.stversions= are in the default =ignored-folders=.
 75- 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.
 76
 77When 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:
 78
 79| Button             | Effect                                                                                     |
 80|--------------------+--------------------------------------------------------------------------------------------|
 81| Keep File          | Leaves the file as it is.                                                                  |
 82| Use Copy           | Replaces the buffer's text with the copy's, as an edit you can undo.                       |
 83| 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. |
 84
 85Each choice then moves the copy to the recovery folder and deletes it from the folder.
 86
 87** Dropbox and other tools
 88
 89Any 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.
 90
 91** Files orgstar ignores
 92
 93When 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.
 94
 95* Recovery versions
 96
 97Every 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:
 98
 99- on the Mac, =~/Library/Application Support/Orgstar/Recovery= (or =$ORGSTAR_DATA_DIR/Recovery=),
100- on iOS, the app's own Application Support folder.
101
102Each 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:
103
104| Label           | Kept when                                                                     |
105|-----------------+-------------------------------------------------------------------------------|
106| =external=      | A version written by another program was replaced or merged                   |
107| =local=         | orgstar's version was replaced, or set aside by Use Disk Version, Merge with Markers or Restore |
108| =sync-conflict= | A Syncthing conflict copy was resolved                                        |
109| =snapshot=      | A save changed the file and the last snapshot was more than an hour before    |
110
111File ▸ 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.
112
113* Features that use Emacs on the Mac
114
115Some features run Emacs in batch mode on the Mac. Everything else works without Emacs installed.
116
117| Feature                                                        | What runs                                                                                     |
118|----------------------------------------------------------------+-----------------------------------------------------------------------------------------------|
119| Emacs Lisp source blocks (=emacs-lisp=, =elisp=)               | The block, in =emacs -Q --batch=                                                              |
120| 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 |
121| Lisp table formulas that orgstar's Emacs Lisp interpreter can't evaluate | The same; orgstar first asks whether to run Lisp (yes, no, always)                  |
122| Export to PDF, ODT, LaTeX and plain text                       | =org-latex-export-to-pdf=, =org-odt-export-to-odt=, =org-latex-export-to-latex= or =org-ascii-export-to-ascii= |
123
124HTML and Markdown export don't use Emacs. See [[file:11-code-blocks.org][Code blocks]], [[file:10-tables.org][Tables]] and [[file:12-export.org][Export]].
125
126** How Emacs is found
127
128orgstar uses the first of these that is an executable file:
129
1301. the path in the environment variable =ORGSTAR_EMACS=,
1312. =/opt/homebrew/bin/emacs=,
1323. =/usr/local/bin/emacs=,
1334. =/Applications/Emacs.app/Contents/MacOS/Emacs=,
1345. =/run/current-system/sw/bin/emacs=,
1356. =/usr/bin/emacs=.
136
137An app started from the Dock doesn't see your shell's =PATH=, which is why orgstar looks in fixed places. Without Emacs, these features report "Emacs isn't installed, so …" and change nothing.
138
139** What Emacs sees
140
141- Emacs runs with =-Q=: your =init.el=, packages and customizations aren't loaded. Org and the exporters are the versions bundled with that Emacs.
142- 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.
143- File-local variables marked safe apply (=enable-local-variables= is =:safe=).
144- 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.
145- 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.
146- PDF export needs a LaTeX installation that Org's LaTeX exporter can run.
147- 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.
148
149* Quick Look
150
151orgstar 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 only UTF-8 files.
152
153Inside 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.
154
155* Spotlight
156
157On 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.
158
159On iOS, the app adds the files in your folders to Spotlight itself; see [[file:14-ios.org][iPhone and iPad]].
160
161* Finder
162
163orgstar 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.
164
165* org-protocol and Shortcuts
166
167orgstar 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:
168
169- =org-protocol://capture= opens Capture with the link's template, URL, title and body.
170- =org-protocol://store-link= stores the link for =C-c C-l= and copies it to the clipboard.
171
172Other sub-protocols, such as =open-source=, show "orgstar handles org-protocol capture and store-link".
173
174The 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]].
175
176* Compatibility notes
177
178** Defaults that differ from Emacs
179
180orgstar'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]].
181
182| Setting                              | orgstar default                     | Plain Emacs default             |
183|--------------------------------------+-------------------------------------+---------------------------------|
184| =fill-column=                        | 80                                  | 70                              |
185| =org-M-RET-may-split-line=           | =false=                             | =t=                             |
186| =org-list-allow-alphabetical=        | =true=                              | =nil=                           |
187| =org-hide-emphasis-markers=          | =true=                              | =nil=                           |
188| =org-pretty-entities=                | =true=                              | =nil=                           |
189| =org-startup-indented=               | =true=                              | =nil=                           |
190| =org-startup-truncated=              | =false=                             | =t=                             |
191| =electric-pair-mode=                 | =true=                              | off                             |
192| =org-agenda-span=                    | 10 days                             | a week                          |
193| =org-agenda-start-day=               | ="+0d"=                             | today                           |
194| =org-agenda-show-all-dates=          | =false=                             | =t=                             |
195
196=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.
197
198These behave as Emacs's defaults and can't be changed: =org-log-repeat= is =time=, 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).
199
200** How the agenda looks
201
202The agenda selects the same entries as Org's, but shows them its own way (see [[file:07-agenda.org][The agenda]]):
203
204- 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 it; only =%t= in its =agenda= entry still decides whether a time in the heading text leaves the title.
205- Days without entries are hidden unless =org-agenda-show-all-dates= is =true=.
206- 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.
207- The time grid isn't shown. The now line is, between today's timed entries.
208
209** Known differences from Emacs Org
210
211orgstar refuses some things with a message rather than doing something different from Emacs. These are the ones found in the current version.
212
213Code blocks (see [[file:11-code-blocks.org][Code blocks]]):
214
215- =:cmdline= is supported only for shells, =dot=, =plantuml=, =mermaid= and C, C++, D, Java, Fortran and Clojure.
216- =:post= isn't supported; =:prologue= and =:epilogue= aren't for =dot=, =plantuml= and =mermaid=; =:stdin= and =:shebang= only for shells.
217- =:session= is supported only for shells and Python. C, C++, D, Java, Fortran and Clojure ignore it, as in Org.
218- Clojure runs with babashka or the Clojure CLI only; other =:backend= values are refused.
219- R blocks return their standard output, whatever =:results= says; ob-R returns the value with =:results value=.
220- 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."
221- Noweb references that run a block aren't supported.
222- Tangling refuses =:var= that would run a block, and tables and lists in =:var= for some languages.
223- On iOS, only Emacs Lisp blocks run.
224
225Links (see [[file:09-links.org][Links]]):
226
227- =shell:= and =elisp:= links aren't run.
228
229Capture templates (see [[file:08-capture.org][Capture]]):
230
231- =%(= escapes, which run Emacs Lisp, aren't supported.
232- =%[file]= escapes aren't supported.
233
234Tables and dynamic blocks (see [[file:10-tables.org][Tables]] and [[file:06-dates-and-clocking.org][Dates and clocking]]):
235
236- Formulas outside orgstar's own calculator go to Emacs on the Mac and are refused on iOS.
237- Clock tables support the scopes =nil=, =file=, =subtree= and =treeN=; other scopes, =:match= and =:step= aren't supported.
238- Dynamic blocks other than =clocktable=, =columnview= and denote-org's aren't supported. Column views of other files aren't supported.
239
240Other:
241
242- =C-c C-q= before the first heading (setting file tags) isn't supported.
243- The date prompt also reads =today=, =tomorrow=, =yesterday=, =next week= and =last week=, which Org's prompt ignores.
244- Priority ranges that aren't letters or numbers are refused.
245- =#+SETUPFILE= URLs aren't fetched.
246- Most =#+STARTUP= options for footnotes, entities, numbering and odd levels are accepted and ignored; see [[file:13-configuration.org][Configuration]].
247- 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.
248- 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.
249- =auto-fill-mode= fills on a typed space only, not on =RET=.
250- 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.
251- 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).
252- org-roam: nodes come from orgstar's index, not org-roam's database, so =ROAM_ALIASES=, =ROAM_REFS=, =ROAM_EXCLUDE=, node tags in the chooser and the graph aren't supported. 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.
253- 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.
254- 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=.
255- 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.
256- 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.
257- =org-track-ordered-property-with-tag= isn't supported; Toggle ORDERED Property sets only the property.
258- 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.