Setting for org-habit-show-habits-only-for-today !310

merged merged by cmc on 2026-10-12 01:02 UTC · krz/orgstar:habits-future-days into main

11 files changed, +47 −10

Layout: unified · split

Sources/OrgApp/EmacsImport.swift +2 −1
@@ -506,7 +506,8 @@ public struct EmacsImport: Sendable {
506506 "org-startup-indented", "org-hide-leading-stars", "org-startup-align-all-tables", "org-startup-truncated", "auto-fill-mode",
507507 "org-enforce-todo-dependencies", "org-enforce-todo-checkbox-dependencies",
508508 "org-agenda-todo-ignore-with-date", "org-agenda-tags-todo-honor-ignore-options", "org-clock-out-remove-zero-time-clocks",
509 "org-agenda-sort-notime-is-late", "org-agenda-sort-noeffort-is-high", "org-agenda-use-time-grid", "org-agenda-show-current-time-in-grid":
509 "org-agenda-sort-notime-is-late", "org-agenda-sort-noeffort-is-high", "org-agenda-use-time-grid", "org-agenda-show-current-time-in-grid",
510 "org-habit-show-habits-only-for-today":
510511 add(name, .bool(truthy))
511512 case "org-archive-location":
512513 guard let location = value.string, location.contains("::") else { return note("not a file::heading location") }
Sources/OrgApp/OrgPreferences.swift +2
@@ -90,6 +90,7 @@ public enum OrgPreferences {
9090 /// `org-agenda-show-all-dates`: days without entries show.
9191 public static func agendaShowAllDates(_ defaults: UserDefaults = .standard) -> Bool { bool("agendaShowAllDates", defaults) }
9292 public static func agendaSkipScheduledIfDone(_ defaults: UserDefaults = .standard) -> Bool { bool("agendaSkipScheduledIfDone", defaults) }
93 public static func habitsOnlyForToday(_ defaults: UserDefaults = .standard) -> Bool { bool("habitsOnlyForToday", defaults) }
9394 public static func agendaSkipDeadlineIfDone(_ defaults: UserDefaults = .standard) -> Bool { bool("agendaSkipDeadlineIfDone", defaults) }
9495 public static func agendaSearchAlwaysBoolean(_ defaults: UserDefaults = .standard) -> Bool { bool("agendaSearchAlwaysBoolean", defaults) }
9596 public static func agendaSearchForceFullWords(_ defaults: UserDefaults = .standard) -> Bool { bool("agendaSearchForceFullWords", defaults) }
@@ -99,6 +100,7 @@ public enum OrgPreferences {
99100 options.deadlineWarningDays = integer("deadlineWarningDays", defaults)
100101 options.skipScheduledIfDone = agendaSkipScheduledIfDone(defaults)
101102 options.skipDeadlineIfDone = agendaSkipDeadlineIfDone(defaults)
103 options.habitsOnlyForToday = habitsOnlyForToday(defaults)
102104 options.searchAlwaysBoolean = agendaSearchAlwaysBoolean(defaults)
103105 options.searchForceFullWords = agendaSearchForceFullWords(defaults)
104106 options.enforceTodoDependencies = bool("enforceTodoDependencies", defaults)
Sources/OrgApp/UserConfig.swift +2
@@ -201,6 +201,8 @@ public enum UserConfig {
201201 comment: "leave done entries out of the agenda even on the day they are scheduled", legacy: ""),
202202 Setting(section: "", key: "org-agenda-skip-deadline-if-done", defaultsKey: "agendaSkipDeadlineIfDone", kind: .bool, fallback: .bool(false),
203203 comment: "leave done entries out of the agenda even on the day they are due", legacy: ""),
204 Setting(section: "", key: "org-habit-show-habits-only-for-today", defaultsKey: "habitsOnlyForToday", kind: .bool, fallback: .bool(true),
205 comment: "habits show only on today's agenda, not on the later days they are scheduled for", legacy: ""),
204206 Setting(section: "", key: "org-agenda-log-mode-items", defaultsKey: "agendaLogModeItems", kind: .string, fallback: .string("closed clock"),
205207 comment: "what log mode shows, separated by spaces: closed, clock, state", legacy: ""),
206208 Setting(section: "", key: "org-agenda-todo-ignore-with-date", defaultsKey: "agendaTodoIgnoreWithDate", kind: .bool, fallback: .bool(false),
Sources/OrgCore/Agenda/Agenda.swift +6 −2
@@ -112,6 +112,9 @@ public struct AgendaOptions: Sendable, Equatable {
112112 /// `org-agenda-skip-scheduled-if-done`: done entries' scheduled items are left out even
113113 /// on the day they are scheduled.
114114 public var skipScheduledIfDone = false
115 /// `org-habit-show-habits-only-for-today`: habits show only on today's agenda, not on the
116 /// later days they are scheduled for.
117 public var habitsOnlyForToday = true
115118 /// `org-agenda-skip-deadline-if-done`: done entries' deadlines are left out even on the day due.
116119 public var skipDeadlineIfDone = false
117120 /// `org-agenda-search-view-always-boolean`: search strings are always `+word -word` snippets.
@@ -283,8 +286,9 @@ public enum Agenda {
283286 continue
284287 }
285288 if heading.isDone, options.skipScheduledIfDone || schedule != current { continue }
286 // org-habit: habits only on today's agenda, and not when done.
287 if heading.isHabit, heading.isDone || !isToday { continue }
289 // org-habit: done habits never show, others only on today's agenda unless
290 // `org-habit-show-habits-only-for-today` is off.
291 if heading.isHabit, heading.isDone || (options.habitsOnlyForToday && !isToday) { continue }
288292 let time: Dotime? = !heading.isHabit && current != schedule && current != repeat_ ? nil : (timeIn(s).map { .string($0) } ?? .headline)
289293 let extra = heading.isHabit ? "" : isToday && past ? String(format: "Sched.%2dx: ", diff) : "Scheduled: "
290294 let habit = heading.isHabit ? heading.habit : nil
Sources/Orgstar/OrgstarApp.swift +2
@@ -587,6 +587,7 @@ struct SettingsView: View {
587587 @AppStorage("agendaStartOffset") private var agendaStartOffset = 0
588588 @AppStorage("agendaSubfolders") private var agendaSubfolders = false
589589 @AppStorage("agendaShowAllDates") private var agendaShowAllDates = false
590 @AppStorage("habitsOnlyForToday") private var habitsOnlyForToday = true
590591 @AppStorage("agendaDimBlockedTasks") private var agendaDimBlockedTasks = "t"
591592 @AppStorage("calendarEvents") private var calendarEvents = false
592593 @AppStorage("calendarEventCalendars") private var calendarEventCalendars = ""
@@ -766,6 +767,7 @@ struct SettingsView: View {
766767 Stepper(agendaStartOffset == 0 ? "Agenda starts today" : "Agenda starts \(-agendaStartOffset) days before today", value: $agendaStartOffset, in: -14...0)
767768 Toggle("Include files in subfolders", isOn: $agendaSubfolders)
768769 Toggle("Show days without entries", isOn: $agendaShowAllDates)
770 Toggle("Habits only today", isOn: $habitsOnlyForToday)
769771 Picker("Blocked entries", selection: $agendaDimBlockedTasks) {
770772 Text("Dimmed").tag("t")
771773 Text("Hidden").tag("invisible")
Sources/OrgstarMobile/SettingsScreen.swift +3
@@ -45,6 +45,9 @@ struct SettingsScreen: View {
4545 Toggle("Show days without entries", isOn: Binding {
4646 OrgPreferences.agendaShowAllDates()
4747 } set: { model.set("agendaShowAllDates", to: .bool($0)) })
48 Toggle("Habits only today", isOn: Binding {
49 OrgPreferences.habitsOnlyForToday()
50 } set: { model.set("habitsOnlyForToday", to: .bool($0)) })
4851 Picker("Blocked entries", selection: Binding {
4952 UserDefaults.standard.string(forKey: "agendaDimBlockedTasks") ?? "t"
5053 } set: { model.set("agendaDimBlockedTasks", to: .string($0)) }) {
Tests/OrgAppTests/EmacsImportTests.swift +3 −2
@@ -21,7 +21,7 @@ struct EmacsImportTests {
2121 (setq org-log-done 'note org-log-into-drawer t org-log-reschedule 'time)
2222 (setq org-agenda-prefix-format '((agenda . " %i %-12:c%?-12t% s%b") (todo . " %-8:c")))
2323 (setq org-agenda-sorting-strategy '((agenda time-up priority-down) (todo . (alpha-up))) org-agenda-sort-notime-is-late nil)
24 (setq org-agenda-time-grid '((daily today) (800 1300) "......" "----") org-agenda-use-time-grid nil)
24 (setq org-agenda-time-grid '((daily today) (800 1300) "......" "----") org-agenda-use-time-grid nil org-habit-show-habits-only-for-today nil)
2525 (setq org-stuck-projects '("+project/-DONE" ("NEXT" "TODO") ("errand") "\\<IGNORE\\>"))
2626 (setq org-agenda-custom-commands
2727 '(("d" "Daily" ((agenda "" ((org-agenda-span 'day) (org-agenda-overriding-header "Today")))
@@ -113,6 +113,7 @@ struct EmacsImportTests {
113113 #expect(s["org-agenda-time-grid.when"] == .string("daily today"))
114114 #expect(s["org-agenda-time-grid.times"] == .string("800 1300"))
115115 #expect(s["org-agenda-use-time-grid"] == .bool(false))
116 #expect(s["org-habit-show-habits-only-for-today"] == .bool(false))
116117 #expect(s["org-agenda-files"] == .string("~/notes/\n~/work/plan.org"))
117118 #expect(s["org-refile-targets"] == .string("((nil :maxlevel . 2) (org-agenda-files :tag . \"project\"))"))
118119 #expect(s["org-refile-use-outline-path"] == .string("title"))
@@ -351,7 +352,7 @@ struct EmacsImportTests {
351352 let keymap = folder.appendingPathComponent("keymap.toml")
352353 #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty)
353354 #expect(KeymapLoader.load(.doom, userFile: keymap).keymap.keyLabels(for: "app.agenda", modes: ["normal"]).contains("C-c a"))
354 #expect(summary.hasPrefix("Imported 47 settings, 3 capture templates, 3 key bindings, 2 structure templates, 3 agenda views."), "\(summary)")
355 #expect(summary.hasPrefix("Imported 48 settings, 3 capture templates, 3 key bindings, 2 structure templates, 3 agenda views."), "\(summary)")
355356 let views = AgendaViewLoader.load(userFile: folder.appendingPathComponent("views.toml"))
356357 #expect(views.problems.isEmpty, "\(views.problems)")
357358 #expect(views.views.dropFirst(3).map(\.name) == ["Daily", "Work", "Stuck"])
Tests/OrgCoreTests/AgendaTests.swift +19 −1
@@ -115,7 +115,8 @@ enum AgendaOracle {
115115
116116 static func compare(
117117 files: [(name: String, text: String)], start: Int, span: Int, today: Int, hour: Int = 9, minute: Int = 30,
118 prefix: [String: String]? = nil, logMode: Bool = false, logItems: Set<String>? = nil, skipIfDone: Bool = false
118 prefix: [String: String]? = nil, logMode: Bool = false, logItems: Set<String>? = nil, skipIfDone: Bool = false,
119 habitsOnlyForToday: Bool = true
119120 ) throws {
120121 let date = Days.date(start)
121122 var form = "(org-agenda-list nil \"\(String(format: "%04d-%02d-%02d", date.year, date.month, date.day))\" \(span))"
@@ -123,6 +124,7 @@ enum AgendaOracle {
123124 if logMode { form = "(let ((org-agenda-start-with-log-mode t)) \(form))" }
124125 if let logItems { form = "(let ((org-agenda-log-mode-items '(\(logItems.sorted().joined(separator: " "))))) \(form))" }
125126 if skipIfDone { form = "(let ((org-agenda-skip-scheduled-if-done t) (org-agenda-skip-deadline-if-done t)) \(form))" }
127 if !habitsOnlyForToday { form = "(let ((org-habit-show-habits-only-for-today nil)) \(form))" }
126128 form = "(let ((org-agenda-sorting-strategy '((agenda \(AgendaSort.defaults["agenda"]!.joined(separator: " ")))))) \(form))"
127129 let emacs = try run(files: files, form: form, today: today, hour: hour, minute: minute)
128130 let defaults = OrgSettings.default.withTodoKeywords(keywords)!
@@ -133,6 +135,7 @@ enum AgendaOracle {
133135 if let logItems { options.logItems = logItems }
134136 options.skipScheduledIfDone = skipIfDone
135137 options.skipDeadlineIfDone = skipIfDone
138 options.habitsOnlyForToday = habitsOnlyForToday
136139 let ours = Agenda.list(sources, start: start, days: span, today: today, now: (hour, minute), options: options)
137140 #expect(ours.count == emacs.count)
138141 for (o, e) in zip(ours, emacs) {
@@ -339,6 +342,21 @@ struct AgendaTests {
339342 try AgendaOracle.compare(files: files, start: day + 1, span: 1, today: day)
340343 }
341344
345 @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil))
346 func habitsOnLaterDaysMatchEmacs() throws {
347 let files = [("h.org", HabitTests.habits)]
348 for today in [(2026, 10, 5), (2026, 10, 8)] {
349 let day = Days.absolute(year: today.0, month: today.1, day: today.2)
350 for only in [true, false] {
351 try AgendaOracle.compare(files: files, start: day - 2, span: 10, today: day, habitsOnlyForToday: only)
352 }
353 var options = AgendaOptions.terminal
354 options.habitsOnlyForToday = false
355 let later = Agenda.list([AgendaSource(path: "h.org", text: HabitTests.habits)], start: day + 1, days: 7, today: day, now: (9, 30), options: options)
356 #expect(later.flatMap(\.items).contains { $0.habit != nil })
357 }
358 }
359
342360 static let doneEntries = """
343361 * DONE Scheduled today
344362 SCHEDULED: <2026-10-05 Mon>
docs/manual/guide/07-agenda.org +3 −3
@@ -103,7 +103,7 @@ The entries follow =org-agenda-get-day-entries= with Org's default entry types.
103103| Repeating timestamp =<… +1w>= | On each occurrence within the span | =All day= |
104104| Date range =<…>--<…>= | On every day of the range | =Day 2/5= (day 2 of 5) |
105105| Diary sexp =%%(…)= line or =<%%(…)>= | On each day the sexp applies; see [[*Diary sexps][Diary sexps]] | =All day= |
106| Habit (=STYLE: habit=) | On today only, while not done; see [[*Habits][Habits]] | =Habit=, with a consistency graph |
106| Habit (=STYLE: habit=) | On today only, while not done, unless habits only today is off; see [[*Habits][Habits]] | =Habit=, with a consistency graph |
107107
108108An entry with a time of day shows the time instead of the status: =08:00=, or =13:50–14:30= with an end time.
109109
@@ -132,7 +132,7 @@ Days with a time grid show dotted lines at the grid's times among the timed entr
132132
133133** Sorting
134134
135Lines are sorted by =org-agenda-sorting-strategy=, set per kind of view in the =[org-agenda-sorting-strategy]= table of =config.toml= (see [[file:13-configuration.org][Configuration]]) or for one view in =views.toml=. The defaults are Org's: =habit-down time-up urgency-down category-keep= for days, =urgency-down category-keep= for the TODO list and matches, and =category-keep= for text search. With those, habits go last; timed entries come first, earliest first; the rest by urgency, which combines priority with how overdue an entry is; ties keep file order. Calendar events go among them as described in [[*Calendar events][Calendar events]].
135Lines are sorted by =org-agenda-sorting-strategy=, set per kind of view in the =[org-agenda-sorting-strategy]= table of =config.toml= (see [[file:13-configuration.org][Configuration]]) or for one view in =views.toml=. The defaults are =time-up habit-down urgency-down category-keep= for days, =urgency-down category-keep= for the TODO list and matches, and =category-keep= for text search. With those, timed entries come first, earliest first, timed habits among them; then untimed entries, habits last, by urgency, which combines priority with how overdue an entry is; ties keep file order. Calendar events go among them as described in [[*Calendar events][Calendar events]].
136136
137137Each key compares two lines, and the next key is tried when they tie:
138138
@@ -315,7 +315,7 @@ To make every entry of a file a habit, put =#+PROPERTY: STYLE habit= at the top
315315
316316The repeater can be =+=, =++= or =.+=, with an optional =/Nd= maximum interval. Days the habit was done are read from =- State "DONE" … [date]= lines (for any done keyword) and =CLOSING NOTE [date]= lines in the entry.
317317
318A habit appears only on today's agenda and not once it is done for the day. Its row carries the consistency graph: one cell per day for the 21 days before today and the 7 after (=org-habit-preceding-days= and =org-habit-following-days=). On the Mac the graph is at the right of the row, with =*= on days the habit was done and =!= on today; on iOS it is a strip under the title, with a dot on days it was done and today outlined. Cell colors follow org-habit's faces:
318A habit appears only on today's agenda and not once it is done for the day. To show habits on the later days they are scheduled for too, turn off Settings ▸ Agenda ▸ Habits only today, or set =org-habit-show-habits-only-for-today = false= in =config.toml=. Its row carries the consistency graph: one cell per day for the 21 days before today and the 7 after (=org-habit-preceding-days= and =org-habit-following-days=). On the Mac the graph is at the right of the row, with =*= on days the habit was done and =!= on today; on iOS it is a strip under the title, with a dot on days it was done and today outlined. Cell colors follow org-habit's faces:
319319
320320| Color | Meaning | Theme key |
321321|--------+--------------------------------------------+-----------------|
docs/manual/guide/13-configuration.org +3
@@ -113,6 +113,7 @@ See Themes and Fonts below.
113113| Agenda starts N days before today | 0 to 14 days before | 3 days | =org-agenda-start-day= |
114114| Include files in subfolders | On or off | Off | =agenda-include-subfolders= |
115115| Show days without entries | On or off | Off | =org-agenda-show-all-dates= |
116| Habits only today | On or off | On | =org-habit-show-habits-only-for-today= |
116117| Blocked entries | Dimmed; Hidden; Shown as usual | Dimmed | =org-agenda-dim-blocked-tasks= |
117118| Show events from Calendar | On or off | Off | =calendar-events= |
118119| A checkbox for each calendar | On or off | All on | =calendar-event-calendars= |
@@ -175,6 +176,7 @@ These settings have no control in the Settings window. Some are in the View menu
175176| =org-deadline-warning-days= | |
176177| =org-agenda-skip-scheduled-if-done= | |
177178| =org-agenda-skip-deadline-if-done= | |
179| =org-habit-show-habits-only-for-today= | |
178180| =org-agenda-log-mode-items= | |
179181| =org-clock-into-drawer= | |
180182| =org-clock-rounding-minutes=, =org-clock-out-remove-zero-time-clocks=, =org-clock-in-switch-to-state=, =org-clock-out-when-done= | |
@@ -251,6 +253,7 @@ A key you remove from the file goes back to its default. A key that isn't in the
251253| =org-agenda-show-all-dates= | boolean | =false= | Show days without entries in the agenda; today always shows. Emacs's default is =t=. Mirrors =org-agenda-show-all-dates=. |
252254| =org-agenda-skip-scheduled-if-done= | boolean | =false= | Leave a done entry's scheduled date out of the agenda, even on its own day. Mirrors =org-agenda-skip-scheduled-if-done=. |
253255| =org-agenda-skip-deadline-if-done= | boolean | =false= | Leave a done entry's deadline out of the agenda, even on its own day. Mirrors =org-agenda-skip-deadline-if-done=. |
256| =org-habit-show-habits-only-for-today= | boolean | =true= | Show habits only on today's agenda. Off, a habit also shows on the later days it is scheduled for. Mirrors =org-habit-show-habits-only-for-today=. |
254257| =org-agenda-log-mode-items= | string | ="closed clock"= | What log mode shows, separated by spaces: =closed=, =clock= and =state=. Mirrors =org-agenda-log-mode-items=. |
255258| =org-agenda-todo-ignore-with-date= | boolean | =false= | The TODO list leaves out entries with an active timestamp anywhere in their text. Mirrors =org-agenda-todo-ignore-with-date=. |
256259| =org-agenda-todo-ignore-scheduled= | string | ="nil"= | The TODO list leaves out scheduled entries: ="all"= (or ="t"=) all of them, ="future"= those scheduled after today, ="past"= today or before, ="N"= N or more days ahead, ="-N"= N or more days ago. Mirrors =org-agenda-todo-ignore-scheduled=. |
docs/manual/guide/14-ios.org +2 −1
@@ -384,6 +384,7 @@ With a configuration folder, settings and structure templates are written to its
384384The Agenda, TODO Dependencies, Calendar and Reminders sections are the only places the app changes a setting itself, besides Import from Emacs:
385385
386386- Show days without entries :: turns =org-agenda-show-all-dates= on or off.
387- Habits only today :: turns =org-habit-show-habits-only-for-today= on or off.
387388- Blocked entries :: Dimmed, Hidden or Shown as usual (=org-agenda-dim-blocked-tasks=).
388389- TODO Dependencies :: Not done before TODO children (=org-enforce-todo-dependencies=) and Not done with unchecked boxes (=org-enforce-todo-checkbox-dependencies=).
389390- Show Calendar Events :: turns on =calendar-events=, and asks for access to your calendars. iOS asks for full access, as Calendar has no read-only level; orgstar changes a calendar only when you edit an event or add an entry. While access is missing the section shows Allow Access to Calendars…; if you declined, allow it in the Settings app under Privacy & Security ▸ Calendars.
@@ -409,7 +410,7 @@ These settings from =config.toml= apply on iOS:
409410- =org-use-tag-inheritance=, =org-tags-exclude-from-inheritance=, =org-tag-alist=
410411- =org-use-speed-commands=, with a hardware keyboard
411412- =electric-pair-mode=, =spell-check=, =auto-fill-mode=
412- =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=
413- =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-habit-show-habits-only-for-today=, =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=
413414- =calendar-events=, =calendar-event-calendars=, =agenda-reminders=, =agenda-reminder-lists=
414415- =reminders=, =appt-message-warning-time=
415416- =org-clock-history-length=, =org-clock-into-drawer=, =org-clock-rounding-minutes=, =org-clock-out-remove-zero-time-clocks=, =org-clock-in-switch-to-state=, =org-clock-out-when-done=