org-archive-location !247

merged merged by cmc on 2026-10-11 08:07 UTC · krz/orgstar:archive-location into main

11 files changed, +34 −9

Layout: unified · split

Sources/OrgApp/EmacsImport.swift +3
@@ -479,6 +479,9 @@ public struct EmacsImport: Sendable {
479 "org-startup-indented", "org-hide-leading-stars", "org-startup-align-all-tables", "org-startup-truncated", 479 "org-startup-indented", "org-hide-leading-stars", "org-startup-align-all-tables", "org-startup-truncated",
480 "org-enforce-todo-dependencies", "org-enforce-todo-checkbox-dependencies": 480 "org-enforce-todo-dependencies", "org-enforce-todo-checkbox-dependencies":
481 add(name, .bool(truthy)) 481 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))
482 case "org-track-ordered-property-with-tag": 485 case "org-track-ordered-property-with-tag":
483 if let tag = value.string { add(name, .string(tag)) } else { add(name, .string(truthy ? "t" : "nil")) } 486 if let tag = value.string { add(name, .string(tag)) } else { add(name, .string(truthy ? "t" : "nil")) }
484 case "org-agenda-dim-blocked-tasks": 487 case "org-agenda-dim-blocked-tasks":
Sources/OrgApp/OrgPreferences.swift +1
@@ -35,6 +35,7 @@ public enum OrgPreferences {
35 options.electricPair = bool("electricPair", defaults) 35 options.electricPair = bool("electricPair", defaults)
36 options.enforceTodoDependencies = bool("enforceTodoDependencies", defaults) 36 options.enforceTodoDependencies = bool("enforceTodoDependencies", defaults)
37 options.enforceTodoCheckboxDependencies = bool("enforceTodoCheckboxDependencies", defaults) 37 options.enforceTodoCheckboxDependencies = bool("enforceTodoCheckboxDependencies", defaults)
38 options.archiveLocation = string("archiveLocation", defaults).nonEmpty
38 options.trackOrderedPropertyWithTag = switch string("trackOrderedTag", defaults) { 39 options.trackOrderedPropertyWithTag = switch string("trackOrderedTag", defaults) {
39 case "", "nil": nil 40 case "", "nil": nil
40 case "t": "ORDERED" 41 case "t": "ORDERED"
Sources/OrgApp/UserConfig.swift +2
@@ -121,6 +121,8 @@ public enum UserConfig {
121 comment: "an entry can't be done before its TODO children, or under an ORDERED parent before its earlier siblings", legacy: ""), 121 comment: "an entry can't be done before its TODO children, or under an ORDERED parent before its earlier siblings", legacy: ""),
122 Setting(section: "", key: "org-enforce-todo-checkbox-dependencies", defaultsKey: "enforceTodoCheckboxDependencies", kind: .bool, fallback: .bool(false), 122 Setting(section: "", key: "org-enforce-todo-checkbox-dependencies", defaultsKey: "enforceTodoCheckboxDependencies", kind: .bool, fallback: .bool(false),
123 comment: "an entry can't be done while it has unchecked boxes", legacy: ""), 123 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: ""),
124 Setting(section: "", key: "org-track-ordered-property-with-tag", defaultsKey: "trackOrderedTag", kind: .string, fallback: .string("nil"), 126 Setting(section: "", key: "org-track-ordered-property-with-tag", defaultsKey: "trackOrderedTag", kind: .string, fallback: .string("nil"),
125 comment: "nil, t (the tag ORDERED) or a tag that Toggle ORDERED Property toggles too", legacy: ""), 127 comment: "nil, t (the tag ORDERED) or a tag that Toggle ORDERED Property toggles too", legacy: ""),
126 Setting(section: "", key: "org-startup-indented", defaultsKey: "startupIndented", kind: .bool, fallback: .bool(true), 128 Setting(section: "", key: "org-startup-indented", defaultsKey: "startupIndented", kind: .bool, fallback: .bool(true),
Sources/OrgCore/Commands/Archive.swift +2 −3
@@ -1,7 +1,6 @@
1import Foundation 1import Foundation
2 2
3// Archiving (`org-archive-subtree`, Org 9.8.7) with the defaults: location "%s_archive::", 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
4// context info time, file, olpath, category, todo and itags, inherited tags added only within
5// the same file, no marking DONE, the archive file's header for a new file. 4// the same file, no marking DONE, the archive file's header for a new file.
6 5
7extension EmacsBuffer { 6extension EmacsBuffer {
@@ -191,7 +190,7 @@ public enum Archive {
191 public static func destination(_ context: EditContext, sourcePath: String) -> Result<Destination, ArchiveError> { 190 public static func destination(_ context: EditContext, sourcePath: String) -> Result<Destination, ArchiveError> {
192 let buffer = EmacsBuffer(context.text, point: context.caret, settings: context.tree.settings) 191 let buffer = EmacsBuffer(context.text, point: context.caret, settings: context.tree.settings)
193 guard !buffer.beforeFirstHeading else { return .failure(.message("Before first headline")) } 192 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::"
195 guard let separator = spec.range(of: "::") else { return .failure(.message("Invalid archive location: \"\(spec)\"")) } 194 guard let separator = spec.range(of: "::") else { return .failure(.message("Invalid archive location: \"\(spec)\"")) }
196 let name = (sourcePath as NSString).lastPathComponent 195 let name = (sourcePath as NSString).lastPathComponent
197 let fileFormat = String(spec[..<separator.lowerBound]) 196 let fileFormat = String(spec[..<separator.lowerBound])
Sources/OrgCore/Commands/Command.swift +3
@@ -27,6 +27,9 @@ public struct EditingOptions: Sendable, Equatable, Codable {
27 public var enforceTodoDependencies = false 27 public var enforceTodoDependencies = false
28 /// `org-enforce-todo-checkbox-dependencies`: an entry can't become done with unchecked boxes. 28 /// `org-enforce-todo-checkbox-dependencies`: an entry can't become done with unchecked boxes.
29 public var enforceTodoCheckboxDependencies = false 29 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?
30 /// `org-track-ordered-property-with-tag`: the tag toggling `ORDERED` toggles too; nil for none. 33 /// `org-track-ordered-property-with-tag`: the tag toggling `ORDERED` toggles too; nil for none.
31 public var trackOrderedPropertyWithTag: String? 34 public var trackOrderedPropertyWithTag: String?
32 /// `org-use-speed-commands`: single keys at the start of a heading line run commands. 35 /// `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 {
42 org-deadline-warning-days 7 42 org-deadline-warning-days 7
43 org-agenda-start-on-weekday 0 43 org-agenda-start-on-weekday 0
44 org-track-ordered-property-with-tag t 44 org-track-ordered-property-with-tag t
45 org-archive-location "archive/%s::"
45 org-agenda-start-day "-3d" 46 org-agenda-start-day "-3d"
46 org-clock-idle-time 15 47 org-clock-idle-time 15
47 org-clock-history-length 10 48 org-clock-history-length 10
@@ -86,6 +87,7 @@ struct EmacsImportTests {
86 #expect(s["org-deadline-warning-days"] == .integer(7)) 87 #expect(s["org-deadline-warning-days"] == .integer(7))
87 #expect(s["org-agenda-start-on-weekday"] == .string("0")) 88 #expect(s["org-agenda-start-on-weekday"] == .string("0"))
88 #expect(s["org-track-ordered-property-with-tag"] == .string("t")) 89 #expect(s["org-track-ordered-property-with-tag"] == .string("t"))
90 #expect(s["org-archive-location"] == .string("archive/%s::"))
89 #expect(s["org-agenda-start-day"] == .string("-3d")) 91 #expect(s["org-agenda-start-day"] == .string("-3d"))
90 #expect(s["org-clock-idle-time"] == .integer(15)) 92 #expect(s["org-clock-idle-time"] == .integer(15))
91 #expect(s["org-clock-history-length"] == .integer(10)) 93 #expect(s["org-clock-history-length"] == .integer(10))
@@ -177,7 +179,7 @@ struct EmacsImportTests {
177 let keymap = folder.appendingPathComponent("keymap.toml") 179 let keymap = folder.appendingPathComponent("keymap.toml")
178 #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty) 180 #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty)
179 #expect(KeymapLoader.load(.doom, userFile: keymap).keymap.keyLabels(for: "app.agenda", modes: ["normal"]).contains("C-c a")) 181 #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)")
181 #expect(defaults.string(forKey: "themeFont") == "JetBrains Mono") 183 #expect(defaults.string(forKey: "themeFont") == "JetBrains Mono")
182 #expect(defaults.integer(forKey: "themeFontSize") == 14) 184 #expect(defaults.integer(forKey: "themeFontSize") == 14)
183 185
Tests/OrgAppTests/OrgPreferencesTests.swift +3
@@ -14,6 +14,7 @@ struct OrgPreferencesTests {
14 #expect(OrgPreferences.orgSettings(defaults).deadlineWarningDays == 14) 14 #expect(OrgPreferences.orgSettings(defaults).deadlineWarningDays == 14)
15 #expect(OrgPreferences.agendaStartOnWeekday(defaults) == 1) 15 #expect(OrgPreferences.agendaStartOnWeekday(defaults) == 1)
16 #expect(OrgPreferences.options(defaults).trackOrderedPropertyWithTag == nil) 16 #expect(OrgPreferences.options(defaults).trackOrderedPropertyWithTag == nil)
17 #expect(OrgPreferences.options(defaults).archiveLocation == "%s_archive::")
17 #expect(OrgPreferences.agendaOptions(AgendaOptions(), defaults).deadlineWarningDays == 14) 18 #expect(OrgPreferences.agendaOptions(AgendaOptions(), defaults).deadlineWarningDays == 14)
18 #expect(OrgPreferences.reminders(defaults) && OrgPreferences.reminderLead(defaults) == 12) 19 #expect(OrgPreferences.reminders(defaults) && OrgPreferences.reminderLead(defaults) == 12)
19 let fallbacks = OrgPreferences.options(defaults) 20 let fallbacks = OrgPreferences.options(defaults)
@@ -30,6 +31,7 @@ struct OrgPreferencesTests {
30 org-deadline-warning-days = 5 31 org-deadline-warning-days = 5
31 org-agenda-start-on-weekday = "nil" 32 org-agenda-start-on-weekday = "nil"
32 org-track-ordered-property-with-tag = "t" 33 org-track-ordered-property-with-tag = "t"
34 org-archive-location = "~/org/archive.org::* %s"
33 org-M-RET-may-split-line = true 35 org-M-RET-may-split-line = true
34 org-hide-emphasis-markers = false 36 org-hide-emphasis-markers = false
35 org-pretty-entities = false 37 org-pretty-entities = false
@@ -45,6 +47,7 @@ struct OrgPreferencesTests {
45 #expect(OrgPreferences.orgSettings(defaults).deadlineWarningDays == 5) 47 #expect(OrgPreferences.orgSettings(defaults).deadlineWarningDays == 5)
46 #expect(OrgPreferences.agendaStartOnWeekday(defaults) == nil) 48 #expect(OrgPreferences.agendaStartOnWeekday(defaults) == nil)
47 #expect(OrgPreferences.options(defaults).trackOrderedPropertyWithTag == "ORDERED") 49 #expect(OrgPreferences.options(defaults).trackOrderedPropertyWithTag == "ORDERED")
50 #expect(OrgPreferences.options(defaults).archiveLocation == "~/org/archive.org::* %s")
48 #expect(OrgPreferences.agendaOptions(AgendaOptions(), defaults).deadlineWarningDays == 5) 51 #expect(OrgPreferences.agendaOptions(AgendaOptions(), defaults).deadlineWarningDays == 5)
49 #expect(!OrgPreferences.reminders(defaults) && OrgPreferences.reminderLead(defaults) == 30) 52 #expect(!OrgPreferences.reminders(defaults) && OrgPreferences.reminderLead(defaults) == 30)
50 #expect(UserConfig.apply("org-agenda-start-on-weekday = \"0\"", to: defaults).isEmpty) 53 #expect(UserConfig.apply("org-agenda-start-on-weekday = \"0\"", to: defaults).isEmpty)
Tests/OrgCoreTests/ArchiveTests.swift +10
@@ -21,6 +21,16 @@ struct ArchiveTests {
21 #expect(keyword == Archive.Destination(path: "/n/done.org", heading: "* a.org", isSameFile: false)) 21 #expect(keyword == Archive.Destination(path: "/n/done.org", heading: "* a.org", isSameFile: false))
22 let local = try Archive.destination(context("* a\n:PROPERTIES:\n:ARCHIVE: ::* Old\n:END:\n", 0), sourcePath: "/n/a.org").get() 22 let local = try Archive.destination(context("* a\n:PROPERTIES:\n:ARCHIVE: ::* Old\n:END:\n", 0), sourcePath: "/n/a.org").get()
23 #expect(local.isSameFile && local.heading == "* Old") 23 #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)
24 } 34 }
25 35
26 @Test func archivesToANewFile() throws { 36 @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=,
771=SPC m A= or =SPC m s A=) moves the subtree at the caret to an archive. 771=SPC m A= or =SPC m s A=) moves the subtree at the caret to an archive.
772 772
773The archive location is read from, in order: the =ARCHIVE= property of the entry or an 773The 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
775is =file::heading=, where =%s= stands for the current file's name: 776is =file::heading=, where =%s= stands for the current file's name:
776 777
777| Location | Where the subtree goes | 778| Location | Where the subtree goes |
@@ -794,8 +795,7 @@ changed.
794 795
795If the archive file is open, the subtree goes into its buffer. Otherwise orgstar writes 796If the archive file is open, the subtree goes into its buffer. Otherwise orgstar writes
796the archive file first and removes the subtree from the source only after that 797the 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= 798succeeds. Archiving from the agenda is covered in [[file:07-agenda.org][Agenda]].
798property or =#+ARCHIVE:=. Archiving from the agenda is covered in [[file:07-agenda.org][Agenda]].
799 799
800** The ARCHIVE tag 800** The ARCHIVE tag
801 801
@@ -887,5 +887,4 @@ These Org structure features are not in orgstar:
887- The =ORDERED= property, radio lists and timer list items in the list commands. 887- The =ORDERED= property, radio lists and timer list items in the list commands.
888- =S-<left>= and =S-<right>= to cycle bullets on an item; use =C-c -=. 888- =S-<left>= and =S-<right>= to cycle bullets on an item; use =C-c -=.
889- =org-drag-element= (=M-<up>= and =M-<down>= on paragraphs). 889- =org-drag-element= (=M-<up>= and =M-<down>= on paragraphs).
890- Custom =org-structure-template-alist=, =org-refile-targets= and 890- Custom =org-structure-template-alist= and =org-refile-targets=.
891 =org-archive-location=.
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
155| =tab-bar= | View ▸ Show Tab Bar | 155| =tab-bar= | View ▸ Show Tab Bar |
156| =show-markup= | View ▸ Show Markup (=⇧⌘M=) | 156| =show-markup= | View ▸ Show Markup (=⇧⌘M=) |
157| =ignored-folders= | | 157| =ignored-folders= | |
158| =org-archive-location= | |
158| =org-track-ordered-property-with-tag= | | 159| =org-track-ordered-property-with-tag= | |
159| =org-agenda-start-on-weekday= | | 160| =org-agenda-start-on-weekday= | |
160| =org-deadline-warning-days= | | 161| =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
189| =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=. | 190| =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=. |
190| =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=. | 191| =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=. |
191| =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=. | 192| =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=. |
192| =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=. | 194| =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=. |
193| =org-startup-indented= | boolean | =true= | Indent bodies under their headings, as =org-indent-mode=. =#+STARTUP: indent= / =noindent= override it. Mirrors =org-startup-indented=. | 195| =org-startup-indented= | boolean | =true= | Indent bodies under their headings, as =org-indent-mode=. =#+STARTUP: indent= / =noindent= override it. Mirrors =org-startup-indented=. |
194| =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=. | 196| =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:
348- =[theme]= (=font=, =font-size=, =line-spacing=, =heading-size-step=, =theme-file= and colours), =[theme.light]=, =[theme.dark]=, =[theme.todo]=, =[theme.category]= 348- =[theme]= (=font=, =font-size=, =line-spacing=, =heading-size-step=, =theme-file= and colours), =[theme.light]=, =[theme.dark]=, =[theme.todo]=, =[theme.category]=
349- =org-log-done=, =org-log-reschedule=, =org-log-redeadline=, =org-log-into-drawer= 349- =org-log-done=, =org-log-reschedule=, =org-log-redeadline=, =org-log-into-drawer=
350- =org-enforce-todo-dependencies=, =org-enforce-todo-checkbox-dependencies=, =org-track-ordered-property-with-tag=, =org-agenda-dim-blocked-tasks= 350- =org-enforce-todo-dependencies=, =org-enforce-todo-checkbox-dependencies=, =org-track-ordered-property-with-tag=, =org-agenda-dim-blocked-tasks=
351- =org-archive-location=
351- =org-use-speed-commands=, with a hardware keyboard 352- =org-use-speed-commands=, with a hardware keyboard
352- =electric-pair-mode=, =spell-check= 353- =electric-pair-mode=, =spell-check=
353- =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= 354- =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=