Clocks: org-clock-into-drawer and CLOCK_INTO_DRAWER !255
11 files changed, +156 −30
Layout: unified · split
Sources/OrgApp/EmacsImport.swift +2
| @@ -543,6 +543,8 @@ public struct EmacsImport: Sendable { | |||
| 543 | case "org-clock-idle-time": | 543 | case "org-clock-idle-time": |
| 544 | // nil is never; a number is minutes. | 544 | // nil is never; a number is minutes. |
| 545 | if value.symbol == "nil" { add(name, .integer(0)) } else if let minutes = value.integer, minutes > 0 { add(name, .integer(minutes)) } else { note("not a number of minutes") } | 545 | if value.symbol == "nil" { add(name, .integer(0)) } else if let minutes = value.integer, minutes > 0 { add(name, .integer(minutes)) } else { note("not a number of minutes") } |
| 546 | case "org-clock-into-drawer": | ||
| 547 | if let drawer = value.string { add(name, .string(drawer)) } else if let n = value.integer { add(name, .string("\(n)")) } else { add(name, .string(truthy ? "t" : "nil")) } | ||
| 546 | case "org-clock-history-length": | 548 | case "org-clock-history-length": |
| 547 | guard let length = value.integer, length > 0 else { return note("not a positive number") } | 549 | guard let length = value.integer, length > 0 else { return note("not a positive number") } |
| 548 | add(name, .integer(length)) | 550 | add(name, .integer(length)) |
Sources/OrgApp/OrgPreferences.swift +1
| @@ -36,6 +36,7 @@ public enum OrgPreferences { | |||
| 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.archiveLocation = string("archiveLocation", defaults).nonEmpty |
| 39 | options.clockIntoDrawer = string("clockIntoDrawer", defaults).nonEmpty | ||
| 39 | let templates = UserConfig.structureTemplates(defaults) | 40 | let templates = UserConfig.structureTemplates(defaults) |
| 40 | options.structureTemplates = templates.isEmpty ? nil : StructureTemplate.merged(templates) | 41 | options.structureTemplates = templates.isEmpty ? nil : StructureTemplate.merged(templates) |
| 41 | options.trackOrderedPropertyWithTag = switch string("trackOrderedTag", defaults) { | 42 | options.trackOrderedPropertyWithTag = switch string("trackOrderedTag", defaults) { |
Sources/OrgApp/UserConfig.swift +2
| @@ -185,6 +185,8 @@ public enum UserConfig { | |||
| 185 | comment: "minutes of warning before timed entries; APPT_WARNTIME overrides", legacy: "agenda.reminder-lead"), | 185 | comment: "minutes of warning before timed entries; APPT_WARNTIME overrides", legacy: "agenda.reminder-lead"), |
| 186 | Setting(section: "", key: "org-clock-idle-time", defaultsKey: "clockIdleTime", kind: .integer, fallback: .integer(0), | 186 | Setting(section: "", key: "org-clock-idle-time", defaultsKey: "clockIdleTime", kind: .integer, fallback: .integer(0), |
| 187 | comment: "minutes idle with a clock running before asking what to do with the time; 0 never (nil)", legacy: ""), | 187 | comment: "minutes idle with a clock running before asking what to do with the time; 0 never (nil)", legacy: ""), |
| 188 | Setting(section: "", key: "org-clock-into-drawer", defaultsKey: "clockIntoDrawer", kind: .string, fallback: .string("t"), | ||
| 189 | comment: "t: clock lines go in the log drawer (LOGBOOK); nil: none; a number: once there are that many; or a drawer name", legacy: ""), | ||
| 188 | Setting(section: "", key: "org-clock-history-length", defaultsKey: "clockHistoryLength", kind: .integer, fallback: .integer(5), | 190 | Setting(section: "", key: "org-clock-history-length", defaultsKey: "clockHistoryLength", kind: .integer, fallback: .integer(5), |
| 189 | comment: "recently clocked entries to remember", legacy: ""), | 191 | comment: "recently clocked entries to remember", legacy: ""), |
| 190 | Setting(section: "org-agenda-prefix-format", key: "agenda", defaultsKey: "agendaPrefixAgenda", kind: .string, fallback: .string(PrefixFormat.defaults["agenda"]!), | 192 | Setting(section: "org-agenda-prefix-format", key: "agenda", defaultsKey: "agendaPrefixAgenda", kind: .string, fallback: .string(PrefixFormat.defaults["agenda"]!), |
Sources/OrgCore/Commands/Clock.swift +72 −16
| @@ -1,11 +1,46 @@ | |||
| 1 | import Foundation | 1 | import Foundation |
| 2 | 2 | ||
| 3 | // Clocking (org-clock.el, Org 9.8.7) with `org-clock-into-drawer` t (a LOGBOOK drawer), | 3 | // Clocking (org-clock.el, Org 9.8.7) with `org-clock-into-drawer` and the CLOCK_INTO_DRAWER |
| 4 | // `org-log-states-order-reversed` t (newest first), no rounding, no resume, and zero-time | 4 | // property, `org-log-states-order-reversed` t (newest first), no rounding, no resume, and |
| 5 | // clocks kept. | 5 | // zero-time clocks kept. |
| 6 | 6 | ||
| 7 | extension EmacsBuffer { | 7 | extension EmacsBuffer { |
| 8 | static let clockDrawer = "LOGBOOK" | 8 | /// What `org-clock-into-drawer` comes to for an entry. |
| 9 | enum ClockDrawer: Equatable { | ||
| 10 | case none | ||
| 11 | /// Into the drawer once there are this many clock lines. | ||
| 12 | case count(Int) | ||
| 13 | case named(String) | ||
| 14 | } | ||
| 15 | |||
| 16 | /// `org-log-into-drawer` for the entry: the setting, `#+STARTUP: logdrawer` and the | ||
| 17 | /// LOG_INTO_DRAWER property. | ||
| 18 | func logIntoDrawer() -> String? { logSettings().drawer } | ||
| 19 | |||
| 20 | /// `org-clock-into-drawer` (the function): the entry's CLOCK_INTO_DRAWER over the setting. | ||
| 21 | func clockIntoDrawer() -> ClockDrawer { | ||
| 22 | func read(_ value: String) -> ClockDrawer? { | ||
| 23 | switch value.trimmingCharacters(in: .whitespaces) { | ||
| 24 | case "nil": return ClockDrawer.none | ||
| 25 | case "t": return .named(logIntoDrawer() ?? "LOGBOOK") | ||
| 26 | case "": return nil | ||
| 27 | case let text where text.allSatisfy(\.isASCII) && text.allSatisfy(\.isNumber): return .count(Int(text) ?? 0) | ||
| 28 | case let name: return .named(name) | ||
| 29 | } | ||
| 30 | } | ||
| 31 | if let property = inheritedProperty("CLOCK_INTO_DRAWER")?.value, let value = read(property) { return value } | ||
| 32 | return options.clockIntoDrawer.flatMap(read) ?? .named(logIntoDrawer() ?? "LOGBOOK") | ||
| 33 | } | ||
| 34 | |||
| 35 | /// `org-clock-drawer-name`. | ||
| 36 | func clockDrawerName() -> String? { | ||
| 37 | switch clockIntoDrawer() { | ||
| 38 | case .none: nil | ||
| 39 | case .count: logIntoDrawer() ?? "LOGBOOK" | ||
| 40 | case .named(let name): name | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 9 | static let openClockPattern = "^[ \\t]*CLOCK: \\[([0-9]{4}-[0-9]{2}-[0-9]{2} *[^\\]\\s]+ +[012][0-9]:[0-5][0-9])\\][ \\t]*$" | 44 | static let openClockPattern = "^[ \\t]*CLOCK: \\[([0-9]{4}-[0-9]{2}-[0-9]{2} *[^\\]\\s]+ +[012][0-9]:[0-5][0-9])\\][ \\t]*$" |
| 10 | 45 | ||
| 11 | /// `org-clock-find-position` without `find-unclosed`. | 46 | /// `org-clock-find-position` without `find-unclosed`. |
| @@ -15,13 +50,17 @@ extension EmacsBuffer { | |||
| 15 | _ = outlineNextHeading() | 50 | _ = outlineNextHeading() |
| 16 | return point | 51 | return point |
| 17 | } | 52 | } |
| 18 | let drawerPattern = "^[ \\t]*:" + Self.clockDrawer + ":[ \\t]*$" | 53 | let into = clockIntoDrawer() |
| 19 | point = beg | 54 | let drawer = clockDrawerName() |
| 20 | while let match = searchForward(drawerPattern, bound: end, caseInsensitive: false) { | 55 | if let drawer { |
| 21 | if element(at: lineStart(match[0]!.lowerBound))?.kind == .drawer { | 56 | let drawerPattern = "^[ \\t]*:" + NSRegularExpression.escapedPattern(for: drawer) + ":[ \\t]*$" |
| 22 | point = match[0]!.upperBound | 57 | point = beg |
| 23 | forwardLine(1) | 58 | while let match = searchForward(drawerPattern, bound: end, caseInsensitive: false) { |
| 24 | return | 59 | if element(at: lineStart(match[0]!.lowerBound))?.kind == .drawer { |
| 60 | point = match[0]!.upperBound | ||
| 61 | forwardLine(1) | ||
| 62 | return | ||
| 63 | } | ||
| 25 | } | 64 | } |
| 26 | } | 65 | } |
| 27 | point = beg | 66 | point = beg |
| @@ -34,8 +73,25 @@ extension EmacsBuffer { | |||
| 34 | if positions.isEmpty { | 73 | if positions.isEmpty { |
| 35 | endOfMetaData() | 74 | endOfMetaData() |
| 36 | if !bolp { insertBeforeMarkers("\n") } | 75 | if !bolp { insertBeforeMarkers("\n") } |
| 37 | insertBeforeMarkers(":" + Self.clockDrawer + ":\n:END:\n") | 76 | let creates: Bool = switch into { |
| 38 | forwardLine(-1) | 77 | case .none: false |
| 78 | case .count(let n): n < 2 | ||
| 79 | case .named: true | ||
| 80 | } | ||
| 81 | if creates, let drawer { | ||
| 82 | insertBeforeMarkers(":" + drawer + ":\n:END:\n") | ||
| 83 | forwardLine(-1) | ||
| 84 | } | ||
| 85 | return | ||
| 86 | } | ||
| 87 | // Without a drawer, or with fewer clocks than the setting's number, the new clock goes | ||
| 88 | // first. | ||
| 89 | let wraps: Bool = switch into { | ||
| 90 | case .count(let n): positions.count + 1 >= n | ||
| 91 | default: drawer != nil | ||
| 92 | } | ||
| 93 | guard wraps, let drawer else { | ||
| 94 | point = positions.last! | ||
| 39 | return | 95 | return |
| 40 | } | 96 | } |
| 41 | // Clocks outside a drawer move into a new one. | 97 | // Clocks outside a drawer move into a new one. |
| @@ -58,7 +114,7 @@ extension EmacsBuffer { | |||
| 58 | let endMarker = marker(point) | 114 | let endMarker = marker(point) |
| 59 | defer { release(endMarker) } | 115 | defer { release(endMarker) } |
| 60 | point = start | 116 | point = start |
| 61 | saveExcursion { insertBeforeMarkers(":" + Self.clockDrawer + ":\n") } | 117 | saveExcursion { insertBeforeMarkers(":" + drawer + ":\n") } |
| 62 | forwardLine(1) | 118 | forwardLine(1) |
| 63 | } | 119 | } |
| 64 | 120 | ||
| @@ -136,13 +192,13 @@ extension EmacsBuffer { | |||
| 136 | /// `org-clock-remove-empty-clock-drawer` for the subtree at point. | 192 | /// `org-clock-remove-empty-clock-drawer` for the subtree at point. |
| 137 | func removeEmptyClockDrawer() { | 193 | func removeEmptyClockDrawer() { |
| 138 | saveExcursion { | 194 | saveExcursion { |
| 139 | guard let heading = try? backToHeading() else { return } | 195 | guard let heading = try? backToHeading(), let drawer = clockDrawerName() else { return } |
| 140 | let end = saveExcursion { () -> Int in | 196 | let end = saveExcursion { () -> Int in |
| 141 | point = heading | 197 | point = heading |
| 142 | return endOfSubtree() | 198 | return endOfSubtree() |
| 143 | } | 199 | } |
| 144 | point = heading | 200 | point = heading |
| 145 | let pattern = "(?i)^[ \\t]*:" + Self.clockDrawer + ":[ \\t]*$" | 201 | let pattern = "(?i)^[ \\t]*:" + NSRegularExpression.escapedPattern(for: drawer) + ":[ \\t]*$" |
| 146 | while let match = searchForward(pattern, bound: end, caseInsensitive: true) { | 202 | while let match = searchForward(pattern, bound: end, caseInsensitive: true) { |
| 147 | removeEmptyDrawer(at: match[0]!.upperBound) | 203 | removeEmptyDrawer(at: match[0]!.upperBound) |
| 148 | } | 204 | } |
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-clock-into-drawer` as `config.toml` writes it: `nil`, `t`, a number of clock lines, | ||
| 31 | /// or a drawer name; nil for Org's default, `t`. | ||
| 32 | public var clockIntoDrawer: String? | ||
| 30 | /// `org-structure-template-alist`, for C-c C-, and `<` completion; nil for Org's. | 33 | /// `org-structure-template-alist`, for C-c C-, and `<` completion; nil for Org's. |
| 31 | public var structureTemplates: [StructureTemplate]? | 34 | public var structureTemplates: [StructureTemplate]? |
| 32 | /// `org-archive-location`, for entries without an `ARCHIVE` property or `#+ARCHIVE:`; nil | 35 | /// `org-archive-location`, for entries without an `ARCHIVE` property or `#+ARCHIVE:`; nil |
Tests/OrgAppTests/EmacsImportTests.swift +3 −2
| @@ -48,6 +48,7 @@ struct EmacsImportTests { | |||
| 48 | org-agenda-todo-ignore-scheduled 'future | 48 | org-agenda-todo-ignore-scheduled 'future |
| 49 | org-agenda-todo-ignore-deadlines 7 | 49 | org-agenda-todo-ignore-deadlines 7 |
| 50 | org-agenda-log-mode-items '(closed clock state) | 50 | org-agenda-log-mode-items '(closed clock state) |
| 51 | org-clock-into-drawer "CLOCKS" | ||
| 51 | org-agenda-start-day "-3d" | 52 | org-agenda-start-day "-3d" |
| 52 | org-clock-idle-time 15 | 53 | org-clock-idle-time 15 |
| 53 | org-clock-history-length 10 | 54 | org-clock-history-length 10 |
| @@ -93,7 +94,7 @@ struct EmacsImportTests { | |||
| 93 | #expect(s["org-agenda-start-on-weekday"] == .string("0")) | 94 | #expect(s["org-agenda-start-on-weekday"] == .string("0")) |
| 94 | #expect(s["org-track-ordered-property-with-tag"] == .string("t")) | 95 | #expect(s["org-track-ordered-property-with-tag"] == .string("t")) |
| 95 | #expect(s["org-archive-location"] == .string("archive/%s::")) | 96 | #expect(s["org-archive-location"] == .string("archive/%s::")) |
| 96 | #expect(s["org-agenda-log-mode-items"] == .string("closed clock state")) | 97 | #expect(s["org-agenda-log-mode-items"] == .string("closed clock state") && s["org-clock-into-drawer"] == .string("CLOCKS")) |
| 97 | #expect(s["org-agenda-todo-ignore-scheduled"] == .string("future") && s["org-agenda-todo-ignore-deadlines"] == .string("7")) | 98 | #expect(s["org-agenda-todo-ignore-scheduled"] == .string("future") && s["org-agenda-todo-ignore-deadlines"] == .string("7")) |
| 98 | #expect(s["org-agenda-start-day"] == .string("-3d")) | 99 | #expect(s["org-agenda-start-day"] == .string("-3d")) |
| 99 | #expect(s["org-clock-idle-time"] == .integer(15)) | 100 | #expect(s["org-clock-idle-time"] == .integer(15)) |
| @@ -186,7 +187,7 @@ struct EmacsImportTests { | |||
| 186 | let keymap = folder.appendingPathComponent("keymap.toml") | 187 | let keymap = folder.appendingPathComponent("keymap.toml") |
| 187 | #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty) | 188 | #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty) |
| 188 | #expect(KeymapLoader.load(.doom, userFile: keymap).keymap.keyLabels(for: "app.agenda", modes: ["normal"]).contains("C-c a")) | 189 | #expect(KeymapLoader.load(.doom, userFile: keymap).keymap.keyLabels(for: "app.agenda", modes: ["normal"]).contains("C-c a")) |
| 189 | #expect(summary.hasPrefix("Imported 26 settings, 3 capture templates, 3 key bindings, 2 structure templates."), "\(summary)") | 190 | #expect(summary.hasPrefix("Imported 27 settings, 3 capture templates, 3 key bindings, 2 structure templates."), "\(summary)") |
| 190 | #expect(UserConfig.structureTemplates(defaults) == [.init(key: "el", type: "src emacs-lisp"), .init(key: "q", type: "QUOTE")]) | 191 | #expect(UserConfig.structureTemplates(defaults) == [.init(key: "el", type: "src emacs-lisp"), .init(key: "q", type: "QUOTE")]) |
| 191 | #expect(OrgPreferences.options(defaults).structureTemplates?.first { $0.key == "q" }?.type == "QUOTE") | 192 | #expect(OrgPreferences.options(defaults).structureTemplates?.first { $0.key == "q" }?.type == "QUOTE") |
| 192 | #expect(defaults.string(forKey: "themeFont") == "JetBrains Mono") | 193 | #expect(defaults.string(forKey: "themeFont") == "JetBrains Mono") |
Tests/OrgAppTests/OrgPreferencesTests.swift +2 −1
| @@ -35,6 +35,7 @@ struct OrgPreferencesTests { | |||
| 35 | org-agenda-todo-ignore-deadlines = "t" | 35 | org-agenda-todo-ignore-deadlines = "t" |
| 36 | org-agenda-todo-ignore-scheduled = "-2" | 36 | org-agenda-todo-ignore-scheduled = "-2" |
| 37 | org-agenda-log-mode-items = "closed state" | 37 | org-agenda-log-mode-items = "closed state" |
| 38 | org-clock-into-drawer = "3" | ||
| 38 | org-M-RET-may-split-line = true | 39 | org-M-RET-may-split-line = true |
| 39 | org-hide-emphasis-markers = false | 40 | org-hide-emphasis-markers = false |
| 40 | org-pretty-entities = false | 41 | org-pretty-entities = false |
| @@ -52,7 +53,7 @@ struct OrgPreferencesTests { | |||
| 52 | #expect(OrgPreferences.options(defaults).trackOrderedPropertyWithTag == "ORDERED") | 53 | #expect(OrgPreferences.options(defaults).trackOrderedPropertyWithTag == "ORDERED") |
| 53 | #expect(OrgPreferences.options(defaults).archiveLocation == "~/org/archive.org::* %s") | 54 | #expect(OrgPreferences.options(defaults).archiveLocation == "~/org/archive.org::* %s") |
| 54 | let ignoring = OrgPreferences.agendaOptions(AgendaOptions(), defaults) | 55 | let ignoring = OrgPreferences.agendaOptions(AgendaOptions(), defaults) |
| 55 | #expect(ignoring.logItems == ["closed", "state"]) | 56 | #expect(ignoring.logItems == ["closed", "state"] && OrgPreferences.options(defaults).clockIntoDrawer == "3") |
| 56 | #expect(ignoring.todoIgnoreDeadlines == .near && ignoring.todoIgnoreScheduled == .days(-2) && ignoring.todoIgnoreTimestamp == .off) | 57 | #expect(ignoring.todoIgnoreDeadlines == .near && ignoring.todoIgnoreScheduled == .days(-2) && ignoring.todoIgnoreTimestamp == .off) |
| 57 | #expect(OrgPreferences.agendaOptions(AgendaOptions(), defaults).deadlineWarningDays == 5) | 58 | #expect(OrgPreferences.agendaOptions(AgendaOptions(), defaults).deadlineWarningDays == 5) |
| 58 | #expect(!OrgPreferences.reminders(defaults) && OrgPreferences.reminderLead(defaults) == 30) | 59 | #expect(!OrgPreferences.reminders(defaults) && OrgPreferences.reminderLead(defaults) == 30) |
Tests/OrgCoreTests/ClockTests.swift +52 −7
| @@ -21,8 +21,8 @@ struct ClockTests { | |||
| 21 | return c | 21 | return c |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | func run(_ command: any OrgCommand, _ text: String, caret: Int, at seconds: Int) -> (text: String, caret: Int, failure: String?) { | 24 | func run(_ command: any OrgCommand, _ text: String, caret: Int, at seconds: Int, options: EditingOptions = .org) -> (text: String, caret: Int, failure: String?) { |
| 25 | let context = EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [caret..<caret], now: Date(timeIntervalSince1970: Double(seconds)), calendar: Self.utc) | 25 | let context = EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [caret..<caret], now: Date(timeIntervalSince1970: Double(seconds)), calendar: Self.utc, options: options) |
| 26 | switch command.run(in: context) { | 26 | switch command.run(in: context) { |
| 27 | case .commit(let result): | 27 | case .commit(let result): |
| 28 | var new = text | 28 | var new = text |
| @@ -35,27 +35,50 @@ struct ClockTests { | |||
| 35 | 35 | ||
| 36 | @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil)) | 36 | @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil)) |
| 37 | func matchesEmacs() throws { | 37 | func matchesEmacs() throws { |
| 38 | try compare(Self.texts) | ||
| 39 | } | ||
| 40 | |||
| 41 | /// `org-clock-into-drawer` values, `org-log-into-drawer`, and the CLOCK_INTO_DRAWER and | ||
| 42 | /// LOG_INTO_DRAWER properties. | ||
| 43 | @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil)) | ||
| 44 | func intoDrawerMatchesEmacs() throws { | ||
| 45 | let texts = Self.texts + [ | ||
| 46 | "* Task\nCLOCK: [2026-10-03 Sat 09:00]--[2026-10-03 Sat 10:00] => 1:00\nCLOCK: [2026-10-04 Sun 09:00]--[2026-10-04 Sun 10:00] => 1:00\n", | ||
| 47 | "* Task\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: nil\n:END:\nBody\n", | ||
| 48 | "* Parent\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: TIMES\n:END:\n** Task\nBody\n", | ||
| 49 | "* Task\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: 2\n:END:\nCLOCK: [2026-10-04 Sun 09:00]--[2026-10-04 Sun 10:00] => 1:00\n", | ||
| 50 | "* Task\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: t\n:LOG_INTO_DRAWER: NOTES\n:END:\n", | ||
| 51 | ] | ||
| 52 | for (lisp, value, log) in [("nil", "nil", nil), ("2", "2", nil), ("3", "3", nil), ("\"CLOCKS\"", "CLOCKS", nil), ("t", nil, "NOTES"), ("2", "2", "NOTES")] as [(String, String?, String?)] { | ||
| 53 | var options = EditingOptions.org | ||
| 54 | options.clockIntoDrawer = value | ||
| 55 | options.logIntoDrawer = log | ||
| 56 | try compare(texts, lisp: lisp, log: log.map { "\"\($0)\"" } ?? "nil", options: options) | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | func compare(_ texts: [String], lisp: String = "t", log: String = "nil", options: EditingOptions = .org) throws { | ||
| 38 | let t1 = 1_789_000_000 // Thu 2026-09-10 00:26 | 61 | let t1 = 1_789_000_000 // Thu 2026-09-10 00:26 |
| 39 | let t2 = t1 + 3 * 3600 + 17 * 60 + 42 | 62 | let t2 = t1 + 3 * 3600 + 17 * 60 + 42 |
| 40 | var cases: [EmacsOracle.Case] = [] | 63 | var cases: [EmacsOracle.Case] = [] |
| 41 | var ours: [(String, String)] = [] | 64 | var ours: [(String, String)] = [] |
| 42 | for text in Self.texts { | 65 | for text in texts { |
| 43 | let caret = (text as NSString).range(of: "Task").location | 66 | let caret = (text as NSString).range(of: "Task").location |
| 44 | for mode in ["out", "cancel"] { | 67 | for mode in ["out", "cancel"] { |
| 45 | // Clock in at t1, then out (or cancel) at t2. | 68 | // Clock in at t1, then out (or cancel) at t2. |
| 46 | let first = run(ClockIn(), text, caret: caret, at: t1) | 69 | let first = run(ClockIn(), text, caret: caret, at: t1, options: options) |
| 47 | guard let start = ClockIn.runningStart(in: first.text, near: caret) else { | 70 | guard let start = ClockIn.runningStart(in: first.text, near: caret) else { |
| 48 | ours.append(("no running clock: \(first.failure ?? "")", text)) | 71 | ours.append(("no running clock: \(first.failure ?? "")", text)) |
| 49 | cases.append(EmacsOracle.Case(text: text, point: 1, form: "nil")) | 72 | cases.append(EmacsOracle.Case(text: text, point: 1, form: "nil")) |
| 50 | continue | 73 | continue |
| 51 | } | 74 | } |
| 52 | let second = run(ClockOut(start: start, cancel: mode == "cancel"), first.text, caret: first.caret, at: t2) | 75 | let second = run(ClockOut(start: start, cancel: mode == "cancel"), first.text, caret: first.caret, at: t2, options: options) |
| 53 | ours.append((second.text, first.text)) | 76 | ours.append((second.text, first.text)) |
| 54 | let out = mode == "cancel" ? "(org-clock-cancel)" : "(org-clock-out)" | 77 | let out = mode == "cancel" ? "(org-clock-cancel)" : "(org-clock-out)" |
| 55 | cases.append(EmacsOracle.Case(text: text, point: EmacsOracle.point(caret, in: text), form: """ | 78 | cases.append(EmacsOracle.Case(text: text, point: EmacsOracle.point(caret, in: text), form: """ |
| 56 | (progn | 79 | (progn |
| 57 | (require 'org-clock) | 80 | (require 'org-clock) |
| 58 | (setq org-clock-persist nil org-clock-idle-time nil org-clock-auto-clock-resolution nil org-clock-into-drawer t) | 81 | (setq org-clock-persist nil org-clock-idle-time nil org-clock-auto-clock-resolution nil org-clock-into-drawer \(lisp) org-log-into-drawer \(log)) |
| 59 | \(frozenClock(t1, "(org-clock-in)")) | 82 | \(frozenClock(t1, "(org-clock-in)")) |
| 60 | (setq orgstar-after-in (buffer-substring-no-properties (point-min) (point-max))) | 83 | (setq orgstar-after-in (buffer-substring-no-properties (point-min) (point-max))) |
| 61 | \(frozenClock(t2, out))) | 84 | \(frozenClock(t2, out))) |
| @@ -64,7 +87,7 @@ struct ClockTests { | |||
| 64 | } | 87 | } |
| 65 | let emacs = try EmacsOracle.run(cases) | 88 | let emacs = try EmacsOracle.run(cases) |
| 66 | for (i, (mine, theirs)) in zip(ours, emacs).enumerated() { | 89 | for (i, (mine, theirs)) in zip(ours, emacs).enumerated() { |
| 67 | #expect(mine.0 == theirs.text, "case \(i) \(cases[i].form.contains("cancel") ? "cancel" : "out")\n\(cases[i].text.debugDescription)\nafter in (ours): \(mine.1.debugDescription)\nours: \(mine.0.debugDescription)\nemacs: \(theirs.text.debugDescription) \(theirs.error)") | 90 | #expect(mine.0 == theirs.text, "case \(i) \(lisp) \(cases[i].form.contains("cancel") ? "cancel" : "out")\n\(cases[i].text.debugDescription)\nafter in (ours): \(mine.1.debugDescription)\nours: \(mine.0.debugDescription)\nemacs: \(theirs.text.debugDescription) \(theirs.error)") |
| 68 | } | 91 | } |
| 69 | } | 92 | } |
| 70 | } | 93 | } |
| @@ -139,3 +162,25 @@ struct ClockReportTests { | |||
| 139 | } | 162 | } |
| 140 | } | 163 | } |
| 141 | } | 164 | } |
| 165 | |||
| 166 | struct ClockDrawerStartupTests { | ||
| 167 | @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil)) | ||
| 168 | func startupLogdrawerMatchesEmacs() throws { | ||
| 169 | let text = "#+STARTUP: nologdrawer\n* Task\nBody\n" | ||
| 170 | let caret = (text as NSString).range(of: "Task").location | ||
| 171 | let t1 = 1_789_000_000 | ||
| 172 | var options = EditingOptions.org | ||
| 173 | options.logIntoDrawer = "NOTES" | ||
| 174 | let context = EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [caret..<caret], now: Date(timeIntervalSince1970: Double(t1)), calendar: ClockTests.utc, options: options) | ||
| 175 | guard case .commit(let result) = ClockIn().run(in: context) else { Issue.record("no commit"); return } | ||
| 176 | let ours = result.edits.sorted { $0.range.lowerBound > $1.range.lowerBound }.reduce(text) { $1.apply(to: $0) } | ||
| 177 | let emacs = try EmacsOracle.run([EmacsOracle.Case(text: text, point: EmacsOracle.point(caret, in: text), form: """ | ||
| 178 | (progn (require 'org-clock) | ||
| 179 | (setq org-clock-persist nil org-clock-idle-time nil org-clock-auto-clock-resolution nil org-clock-into-drawer t) | ||
| 180 | (setq-default org-log-into-drawer "NOTES") | ||
| 181 | (org-mode) | ||
| 182 | \(frozenClock(t1, "(org-clock-in)"))) | ||
| 183 | """)]) | ||
| 184 | #expect(ours == emacs[0].text, "ours: \(ours.debugDescription)\nemacs: \(emacs[0].text.debugDescription) \(emacs[0].error)") | ||
| 185 | } | ||
| 186 | } | ||
docs/manual/guide/06-dates-and-clocking.org +15 −3
| @@ -226,7 +226,7 @@ orgstar has no =C-u= forms of these commands. Clock In to Recent Entry… and Go | |||
| 226 | 226 | ||
| 227 | ** Clocking in and out | 227 | ** Clocking in and out |
| 228 | 228 | ||
| 229 | Clock In starts a clock on the heading at the caret and inserts a line at the top of its =LOGBOOK= drawer, creating the drawer after the planning line and property drawer if needed: | 229 | Clock In starts a clock on the heading at the caret and inserts a line at the top of its =LOGBOOK= drawer, creating the drawer after the planning line and property drawer if needed (see "The clock drawer" below for other drawers): |
| 230 | 230 | ||
| 231 | #+BEGIN_SRC org | 231 | #+BEGIN_SRC org |
| 232 | ,* TODO Write the report | 232 | ,* TODO Write the report |
| @@ -250,8 +250,20 @@ orgstar remembers the running clock and the clock history across restarts, in =c | |||
| 250 | These parts of Org's clocking are not implemented: | 250 | These parts of Org's clocking are not implemented: |
| 251 | 251 | ||
| 252 | - sharing the running clock with Emacs: orgstar does not read or write Emacs's =org-clock-persist= file, so a clock started in one is not known to the other, although both see the open =CLOCK:= line; | 252 | - sharing the running clock with Emacs: orgstar does not read or write Emacs's =org-clock-persist= file, so a clock started in one is not known to the other, although both see the open =CLOCK:= line; |
| 253 | - rounding, changing the TODO state on clock-in (=org-clock-in-switch-to-state=), and clocking out when the entry is marked done (=org-clock-out-when-done=): the clock keeps running; | 253 | - rounding, changing the TODO state on clock-in (=org-clock-in-switch-to-state=), and clocking out when the entry is marked done (=org-clock-out-when-done=): the clock keeps running. |
| 254 | - a =CLOCK_INTO_DRAWER= property or another drawer name: clocks always go into =LOGBOOK=. | 254 | |
| 255 | ** The clock drawer | ||
| 256 | |||
| 257 | Where clock lines go follows =org-clock-into-drawer= in =config.toml=, or an entry's =CLOCK_INTO_DRAWER= property, which its subtree inherits: | ||
| 258 | |||
| 259 | | Value | Clock lines go | | ||
| 260 | |----------------+-----------------------------------------------------------------------------------------------------| | ||
| 261 | | =t= (default) | into the drawer =org-log-into-drawer= (or a =LOG_INTO_DRAWER= property) names, else =LOGBOOK= | | ||
| 262 | | =nil= | under the heading, newest first, without a drawer | | ||
| 263 | | a number /n/ | under the heading until there would be /n/ of them; then all of them move into the log drawer | | ||
| 264 | | a drawer name | into that drawer | | ||
| 265 | |||
| 266 | An existing drawer of that name always takes the new line. | ||
| 255 | 267 | ||
| 256 | ** The running clock | 268 | ** The running clock |
| 257 | 269 | ||
docs/manual/guide/13-configuration.org +3
| @@ -162,6 +162,7 @@ These settings have no control in the Settings window. Some are in the View menu | |||
| 162 | | =org-agenda-skip-scheduled-if-done= | | | 162 | | =org-agenda-skip-scheduled-if-done= | | |
| 163 | | =org-agenda-skip-deadline-if-done= | | | 163 | | =org-agenda-skip-deadline-if-done= | | |
| 164 | | =org-agenda-log-mode-items= | | | 164 | | =org-agenda-log-mode-items= | | |
| 165 | | =org-clock-into-drawer= | | | ||
| 165 | | =org-agenda-todo-ignore-with-date=, =org-agenda-todo-ignore-scheduled=, =org-agenda-todo-ignore-deadlines=, =org-agenda-todo-ignore-timestamp=, =org-agenda-tags-todo-honor-ignore-options= | | | 166 | | =org-agenda-todo-ignore-with-date=, =org-agenda-todo-ignore-scheduled=, =org-agenda-todo-ignore-deadlines=, =org-agenda-todo-ignore-timestamp=, =org-agenda-tags-todo-honor-ignore-options= | | |
| 166 | | =org-agenda-search-view-always-boolean= | | | 167 | | =org-agenda-search-view-always-boolean= | | |
| 167 | | =org-agenda-search-view-force-full-words= | | | 168 | | =org-agenda-search-view-force-full-words= | | |
| @@ -223,6 +224,7 @@ A key you remove from the file goes back to its default. A key that isn't in the | |||
| 223 | | =org-agenda-dim-blocked-tasks= | string | ="t"= | =t= dims entries the two enforce settings block, =invisible= hides them (entries blocked only by checkboxes are still dimmed), =nil= shows them as usual. Mirrors =org-agenda-dim-blocked-tasks=. | | 224 | | =org-agenda-dim-blocked-tasks= | string | ="t"= | =t= dims entries the two enforce settings block, =invisible= hides them (entries blocked only by checkboxes are still dimmed), =nil= shows them as usual. Mirrors =org-agenda-dim-blocked-tasks=. | |
| 224 | | =appt-message-warning-time= | integer | =12= | Minutes of warning before timed entries. An entry's =APPT_WARNTIME= property overrides it. Mirrors =appt-message-warning-time=. | | 225 | | =appt-message-warning-time= | integer | =12= | Minutes of warning before timed entries. An entry's =APPT_WARNTIME= property overrides it. Mirrors =appt-message-warning-time=. | |
| 225 | | =org-clock-idle-time= | integer | =0= | Minutes without keyboard or mouse input, with a clock running, before orgstar asks what to do with the idle time. =0= never asks (Emacs's =nil=). Mac only. Mirrors =org-clock-idle-time=. | | 226 | | =org-clock-idle-time= | integer | =0= | Minutes without keyboard or mouse input, with a clock running, before orgstar asks what to do with the idle time. =0= never asks (Emacs's =nil=). Mac only. Mirrors =org-clock-idle-time=. | |
| 227 | | =org-clock-into-drawer= | string | ="t"= | Where clock lines go: ="t"= the log drawer (=LOGBOOK=), ="nil"= no drawer, ="N"= a drawer once there are N clock lines, or a drawer's name. An entry's =CLOCK_INTO_DRAWER= property overrides it. Mirrors =org-clock-into-drawer=. | | ||
| 226 | | =org-clock-history-length= | integer | =5= | How many recently clocked entries orgstar remembers. Mirrors =org-clock-history-length=. | | 228 | | =org-clock-history-length= | integer | =5= | How many recently clocked entries orgstar remembers. Mirrors =org-clock-history-length=. | |
| 227 | 229 | ||
| 228 | The default =org-todo-keywords= is the first sequence of Doom Emacs's default: | 230 | The default =org-todo-keywords= is the first sequence of Doom Emacs's default: |
| @@ -471,6 +473,7 @@ Only variables whose names start with =org-=, =appt-=, =display-line-numbers=, = | |||
| 471 | | =org-agenda-span= | A number, or =day= (1), =week= (7), =fortnight= (14), =month= (30), =year= (365) | | 473 | | =org-agenda-span= | A number, or =day= (1), =week= (7), =fortnight= (14), =month= (30), =year= (365) | |
| 472 | | =org-clock-idle-time= | Minutes; =nil= becomes =0= (never) | | 474 | | =org-clock-idle-time= | Minutes; =nil= becomes =0= (never) | |
| 473 | | =org-clock-history-length= | The same key, when the value is a positive number | | 475 | | =org-clock-history-length= | The same key, when the value is a positive number | |
| 476 | | =org-clock-into-drawer= | A drawer name as given, a number as a string, =t= or =nil= | | ||
| 474 | | =org-agenda-start-day= | A day offset such as ="-3d"=; =nil= becomes ="+0d"=. Other forms aren't supported. | | 477 | | =org-agenda-start-day= | A day offset such as ="-3d"=; =nil= becomes ="+0d"=. Other forms aren't supported. | |
| 475 | | =org-agenda-start-on-weekday= | ="0"= to ="6"=, or ="nil"= | | 478 | | =org-agenda-start-on-weekday= | ="0"= to ="6"=, or ="nil"= | |
| 476 | | =org-agenda-log-mode-items= | The symbols =closed=, =clock= and =state= of the list, separated by spaces | | 479 | | =org-agenda-log-mode-items= | The symbols =closed=, =clock= and =state= of the list, separated by spaces | |
docs/manual/guide/14-ios.org +1 −1
| @@ -354,7 +354,7 @@ These settings from =config.toml= apply on iOS: | |||
| 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=, =org-agenda-log-mode-items=, the =org-agenda-todo-ignore-= settings, =org-agenda-tags-todo-honor-ignore-options= | 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=, =org-agenda-log-mode-items=, the =org-agenda-todo-ignore-= settings, =org-agenda-tags-todo-honor-ignore-options= |
| 355 | - =calendar-events=, =calendar-event-calendars= | 355 | - =calendar-events=, =calendar-event-calendars= |
| 356 | - =reminders=, =appt-message-warning-time= | 356 | - =reminders=, =appt-message-warning-time= |
| 357 | - =org-clock-history-length= | 357 | - =org-clock-history-length=, =org-clock-into-drawer= |
| 358 | 358 | ||
| 359 | =capture.toml= and =views.toml= in the folder apply too. Other settings, including =keymap=, =save= and =org-clock-idle-time=, don't apply on iOS. See [[file:13-configuration.org][Configuration]]. | 359 | =capture.toml= and =views.toml= in the folder apply too. Other settings, including =keymap=, =save= and =org-clock-idle-time=, don't apply on iOS. See [[file:13-configuration.org][Configuration]]. |
| 360 | 360 | ||