Commit eb700e6739

eb700e67391c27d460f7c452d97d4020e4f4f021

parent: ab3da01d50

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-11 08:07 UTC

org-archive-location

config.toml's org-archive-location is the archive location for entries without an ARCHIVE property or #+ARCHIVE:, as in Org. Emacs import carries it over.

Closes #20

Layout: unified · split

Sources/OrgApp/EmacsImport.swift +3
@@ -479,6 +479,9 @@ public struct EmacsImport: Sendable {
479479 "org-startup-indented", "org-hide-leading-stars", "org-startup-align-all-tables", "org-startup-truncated",
480480 "org-enforce-todo-dependencies", "org-enforce-todo-checkbox-dependencies":
481481 add(name, .bool(truthy))
482 case "org-archive-location":
483 guard let location = value.string, location.contains("::") else { return note("not a file::heading location") }
484 add(name, .string(location))
482485 case "org-track-ordered-property-with-tag":
483486 if let tag = value.string { add(name, .string(tag)) } else { add(name, .string(truthy ? "t" : "nil")) }
484487 case "org-agenda-dim-blocked-tasks":
Sources/OrgApp/OrgPreferences.swift +1
@@ -35,6 +35,7 @@ public enum OrgPreferences {
3535 options.electricPair = bool("electricPair", defaults)
3636 options.enforceTodoDependencies = bool("enforceTodoDependencies", defaults)
3737 options.enforceTodoCheckboxDependencies = bool("enforceTodoCheckboxDependencies", defaults)
38 options.archiveLocation = string("archiveLocation", defaults).nonEmpty
3839 options.trackOrderedPropertyWithTag = switch string("trackOrderedTag", defaults) {
3940 case "", "nil": nil
4041 case "t": "ORDERED"
Sources/OrgApp/UserConfig.swift +2
@@ -121,6 +121,8 @@ public enum UserConfig {
121121 comment: "an entry can't be done before its TODO children, or under an ORDERED parent before its earlier siblings", legacy: ""),
122122 Setting(section: "", key: "org-enforce-todo-checkbox-dependencies", defaultsKey: "enforceTodoCheckboxDependencies", kind: .bool, fallback: .bool(false),
123123 comment: "an entry can't be done while it has unchecked boxes", legacy: ""),
124 Setting(section: "", key: "org-archive-location", defaultsKey: "archiveLocation", kind: .string, fallback: .string("%s_archive::"),
125 comment: "where Archive Subtree moves an entry without an ARCHIVE property or #+ARCHIVE: file::heading, %s the file's name", legacy: ""),
124126 Setting(section: "", key: "org-track-ordered-property-with-tag", defaultsKey: "trackOrderedTag", kind: .string, fallback: .string("nil"),
125127 comment: "nil, t (the tag ORDERED) or a tag that Toggle ORDERED Property toggles too", legacy: ""),
126128 Setting(section: "", key: "org-startup-indented", defaultsKey: "startupIndented", kind: .bool, fallback: .bool(true),
Sources/OrgCore/Commands/Archive.swift +2 −3
@@ -1,7 +1,6 @@
11import Foundation
22
3// Archiving (`org-archive-subtree`, Org 9.8.7) with the defaults: location "%s_archive::",
4// context info time, file, olpath, category, todo and itags, inherited tags added only within
3// Archiving (`org-archive-subtree`, Org 9.8.7) with `org-archive-location` and the defaults: context info time, file, olpath, category, todo and itags, inherited tags added only within
54// the same file, no marking DONE, the archive file's header for a new file.
65
76extension EmacsBuffer {
@@ -191,7 +190,7 @@ public enum Archive {
191190 public static func destination(_ context: EditContext, sourcePath: String) -> Result<Destination, ArchiveError> {
192191 let buffer = EmacsBuffer(context.text, point: context.caret, settings: context.tree.settings)
193192 guard !buffer.beforeFirstHeading else { return .failure(.message("Before first headline")) }
194 let spec = buffer.inheritedProperty("ARCHIVE")?.value ?? buffer.keyword("ARCHIVE") ?? "%s_archive::"
193 let spec = buffer.inheritedProperty("ARCHIVE")?.value ?? buffer.keyword("ARCHIVE") ?? context.options.archiveLocation ?? "%s_archive::"
195194 guard let separator = spec.range(of: "::") else { return .failure(.message("Invalid archive location: \"\(spec)\"")) }
196195 let name = (sourcePath as NSString).lastPathComponent
197196 let fileFormat = String(spec[..<separator.lowerBound])
Sources/OrgCore/Commands/Command.swift +3
@@ -27,6 +27,9 @@ public struct EditingOptions: Sendable, Equatable, Codable {
2727 public var enforceTodoDependencies = false
2828 /// `org-enforce-todo-checkbox-dependencies`: an entry can't become done with unchecked boxes.
2929 public var enforceTodoCheckboxDependencies = false
30 /// `org-archive-location`, for entries without an `ARCHIVE` property or `#+ARCHIVE:`; nil
31 /// for Org's default, `%s_archive::`.
32 public var archiveLocation: String?
3033 /// `org-track-ordered-property-with-tag`: the tag toggling `ORDERED` toggles too; nil for none.
3134 public var trackOrderedPropertyWithTag: String?
3235 /// `org-use-speed-commands`: single keys at the start of a heading line run commands.
Tests/OrgAppTests/EmacsImportTests.swift +3 −1
@@ -42,6 +42,7 @@ struct EmacsImportTests {
4242 org-deadline-warning-days 7
4343 org-agenda-start-on-weekday 0
4444 org-track-ordered-property-with-tag t
45 org-archive-location "archive/%s::"
4546 org-agenda-start-day "-3d"
4647 org-clock-idle-time 15
4748 org-clock-history-length 10
@@ -86,6 +87,7 @@ struct EmacsImportTests {
8687 #expect(s["org-deadline-warning-days"] == .integer(7))
8788 #expect(s["org-agenda-start-on-weekday"] == .string("0"))
8889 #expect(s["org-track-ordered-property-with-tag"] == .string("t"))
90 #expect(s["org-archive-location"] == .string("archive/%s::"))
8991 #expect(s["org-agenda-start-day"] == .string("-3d"))
9092 #expect(s["org-clock-idle-time"] == .integer(15))
9193 #expect(s["org-clock-history-length"] == .integer(10))
@@ -177,7 +179,7 @@ struct EmacsImportTests {
177179 let keymap = folder.appendingPathComponent("keymap.toml")
178180 #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty)
179181 #expect(KeymapLoader.load(.doom, userFile: keymap).keymap.keyLabels(for: "app.agenda", modes: ["normal"]).contains("C-c a"))
180 #expect(summary.hasPrefix("Imported 22 settings, 3 capture templates, 3 key bindings."), "\(summary)")
182 #expect(summary.hasPrefix("Imported 23 settings, 3 capture templates, 3 key bindings."), "\(summary)")
181183 #expect(defaults.string(forKey: "themeFont") == "JetBrains Mono")
182184 #expect(defaults.integer(forKey: "themeFontSize") == 14)
183185
Tests/OrgAppTests/OrgPreferencesTests.swift +3
@@ -14,6 +14,7 @@ struct OrgPreferencesTests {
1414 #expect(OrgPreferences.orgSettings(defaults).deadlineWarningDays == 14)
1515 #expect(OrgPreferences.agendaStartOnWeekday(defaults) == 1)
1616 #expect(OrgPreferences.options(defaults).trackOrderedPropertyWithTag == nil)
17 #expect(OrgPreferences.options(defaults).archiveLocation == "%s_archive::")
1718 #expect(OrgPreferences.agendaOptions(AgendaOptions(), defaults).deadlineWarningDays == 14)
1819 #expect(OrgPreferences.reminders(defaults) && OrgPreferences.reminderLead(defaults) == 12)
1920 let fallbacks = OrgPreferences.options(defaults)
@@ -30,6 +31,7 @@ struct OrgPreferencesTests {
3031 org-deadline-warning-days = 5
3132 org-agenda-start-on-weekday = "nil"
3233 org-track-ordered-property-with-tag = "t"
34 org-archive-location = "~/org/archive.org::* %s"
3335 org-M-RET-may-split-line = true
3436 org-hide-emphasis-markers = false
3537 org-pretty-entities = false
@@ -45,6 +47,7 @@ struct OrgPreferencesTests {
4547 #expect(OrgPreferences.orgSettings(defaults).deadlineWarningDays == 5)
4648 #expect(OrgPreferences.agendaStartOnWeekday(defaults) == nil)
4749 #expect(OrgPreferences.options(defaults).trackOrderedPropertyWithTag == "ORDERED")
50 #expect(OrgPreferences.options(defaults).archiveLocation == "~/org/archive.org::* %s")
4851 #expect(OrgPreferences.agendaOptions(AgendaOptions(), defaults).deadlineWarningDays == 5)
4952 #expect(!OrgPreferences.reminders(defaults) && OrgPreferences.reminderLead(defaults) == 30)
5053 #expect(UserConfig.apply("org-agenda-start-on-weekday = \"0\"", to: defaults).isEmpty)
Tests/OrgCoreTests/ArchiveTests.swift +10
@@ -21,6 +21,16 @@ struct ArchiveTests {
2121 #expect(keyword == Archive.Destination(path: "/n/done.org", heading: "* a.org", isSameFile: false))
2222 let local = try Archive.destination(context("* a\n:PROPERTIES:\n:ARCHIVE: ::* Old\n:END:\n", 0), sourcePath: "/n/a.org").get()
2323 #expect(local.isSameFile && local.heading == "* Old")
24 // org-archive-location, under the keyword and the property.
25 var options = EditingOptions.org
26 options.archiveLocation = "old/%s::* From %s"
27 func optioned(_ text: String, _ caret: Int) -> EditContext {
28 EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [caret..<caret], now: Self.now, calendar: Self.utc, options: options)
29 }
30 let global = try Archive.destination(optioned("* a\n", 0), sourcePath: "/n/a.org").get()
31 #expect(global == Archive.Destination(path: "/n/old/a.org", heading: "* From a.org", isSameFile: false))
32 let overridden = try Archive.destination(optioned("#+ARCHIVE: done.org::\n* a\n", 22), sourcePath: "/n/a.org").get()
33 #expect(overridden.path == "/n/done.org" && overridden.heading == nil)
2434 }
2535
2636 @Test func archivesToANewFile() throws {
docs/manual/guide/04-outlines.org +4 −5
@@ -771,7 +771,8 @@ Archive Subtree (=org-archive-subtree=, =C-c C-x C-s= or =C-c $=, Mac =⌃⌘A=,
771771=SPC m A= or =SPC m s A=) moves the subtree at the caret to an archive.
772772
773773The archive location is read from, in order: the =ARCHIVE= property of the entry or an
774ancestor, a =#+ARCHIVE:= line in the file, and Org's default =%s_archive::=. A location
774ancestor, a =#+ARCHIVE:= line in the file, and =org-archive-location= in =config.toml=
775(Org's default =%s_archive::=). A location
775776is =file::heading=, where =%s= stands for the current file's name:
776777
777778| Location | Where the subtree goes |
@@ -794,8 +795,7 @@ changed.
794795
795796If the archive file is open, the subtree goes into its buffer. Otherwise orgstar writes
796797the archive file first and removes the subtree from the source only after that
797succeeds. Org's option =org-archive-location= in Emacs is not read; use the =ARCHIVE=
798property or =#+ARCHIVE:=. Archiving from the agenda is covered in [[file:07-agenda.org][Agenda]].
798succeeds. Archiving from the agenda is covered in [[file:07-agenda.org][Agenda]].
799799
800800** The ARCHIVE tag
801801
@@ -887,5 +887,4 @@ These Org structure features are not in orgstar:
887887- The =ORDERED= property, radio lists and timer list items in the list commands.
888888- =S-<left>= and =S-<right>= to cycle bullets on an item; use =C-c -=.
889889- =org-drag-element= (=M-<up>= and =M-<down>= on paragraphs).
890- Custom =org-structure-template-alist=, =org-refile-targets= and
891 =org-archive-location=.
890- Custom =org-structure-template-alist= and =org-refile-targets=.
docs/manual/guide/13-configuration.org +2
@@ -155,6 +155,7 @@ These settings have no control in the Settings window. Some are in the View menu
155155| =tab-bar= | View ▸ Show Tab Bar |
156156| =show-markup= | View ▸ Show Markup (=⇧⌘M=) |
157157| =ignored-folders= | |
158| =org-archive-location= | |
158159| =org-track-ordered-property-with-tag= | |
159160| =org-agenda-start-on-weekday= | |
160161| =org-deadline-warning-days= | |
@@ -189,6 +190,7 @@ A key you remove from the file goes back to its default. A key that isn't in the
189190| =org-log-into-drawer= | string | =""= | The drawer state notes go in. ="LOGBOOK"= is Emacs's =t=; =""= puts them under the heading. Mirrors =org-log-into-drawer=. |
190191| =org-enforce-todo-dependencies= | boolean | =false= | An entry can't become done while a descendant has an active TODO keyword, or under an =ORDERED= parent while an earlier sibling has one. Mirrors =org-enforce-todo-dependencies=. |
191192| =org-enforce-todo-checkbox-dependencies= | boolean | =false= | An entry can't become done while its text has an unchecked checkbox. Mirrors =org-enforce-todo-checkbox-dependencies=. |
193| =org-archive-location= | string | ="%s_archive::"= | Where Archive Subtree moves an entry that has no =ARCHIVE= property and whose file has no =#+ARCHIVE:=, as =file::heading=; =%s= is the file's name. Mirrors =org-archive-location=. |
192194| =org-track-ordered-property-with-tag= | string | ="nil"= | A tag that Toggle ORDERED Property adds and removes with the property: ="t"= for the tag =ORDERED=, or a tag name. Mirrors =org-track-ordered-property-with-tag=. |
193195| =org-startup-indented= | boolean | =true= | Indent bodies under their headings, as =org-indent-mode=. =#+STARTUP: indent= / =noindent= override it. Mirrors =org-startup-indented=. |
194196| =org-hide-leading-stars= | boolean | =false= | Show only a heading's last star, without indentation. =#+STARTUP: hidestars= / =showstars= override it. Mirrors =org-hide-leading-stars=. |
docs/manual/guide/14-ios.org +1
@@ -348,6 +348,7 @@ These settings from =config.toml= apply on iOS:
348348- =[theme]= (=font=, =font-size=, =line-spacing=, =heading-size-step=, =theme-file= and colours), =[theme.light]=, =[theme.dark]=, =[theme.todo]=, =[theme.category]=
349349- =org-log-done=, =org-log-reschedule=, =org-log-redeadline=, =org-log-into-drawer=
350350- =org-enforce-todo-dependencies=, =org-enforce-todo-checkbox-dependencies=, =org-track-ordered-property-with-tag=, =org-agenda-dim-blocked-tasks=
351- =org-archive-location=
351352- =org-use-speed-commands=, with a hardware keyboard
352353- =electric-pair-mode=, =spell-check=
353354- =org-agenda-span=, =org-agenda-start-day=, =org-agenda-start-on-weekday=, =org-deadline-warning-days=, =agenda-include-subfolders=, =org-agenda-show-all-dates=, =org-agenda-skip-scheduled-if-done=, =org-agenda-skip-deadline-if-done=, =org-agenda-search-view-always-boolean=, =org-agenda-search-view-force-full-words=