Commit 9dbb9003d3

9dbb9003d34eecd9ee933f0ca05f81c09bbc68a1

parent: 8f8f9a8c12

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-14 04:06 UTC

Readable text width; line numbers off by default

`[theme] text-width` (Settings ▸ Appearance ▸ Text width) keeps lines to that
many columns of the fixed-pitch font, centred in a wider editor, as olivetti
does; 0, the default, uses the whole width. On the Mac it is the text
container's inset, which the line number gutter already sets, so the numbers
stay beside the text; truncated lines take the whole width. The iOS editor
sets its side insets the same way.

display-line-numbers-type falls back to false, as in Emacs.

Closes #75

Layout: unified · split

Sources/OrgApp/OrgPreferences.swift +1
@@ -69,6 +69,7 @@ public enum OrgPreferences {
6969 spec.bodyFont = string("themeBodyFont", defaults)
7070 spec.fontSize = integer("themeFontSize", defaults)
7171 spec.lineSpacing = integer("themeLineSpacing", defaults)
72 spec.textWidth = integer("themeTextWidth", defaults)
7273 spec.headingSizeStep = integer("themeHeadingStep", defaults)
7374 return spec
7475 }
Sources/OrgApp/UserConfig.swift +3 −1
@@ -189,7 +189,7 @@ public enum UserConfig {
189189 comment: "fold drawers when a file opens; #+STARTUP: nohidedrawers overrides", legacy: ""),
190190 Setting(section: "", key: "org-cycle-hide-block-startup", defaultsKey: "hideBlockStartup", kind: .bool, fallback: .bool(false),
191191 comment: "fold blocks when a file opens; #+STARTUP: hideblocks overrides", legacy: ""),
192 Setting(section: "", key: "display-line-numbers-type", defaultsKey: "showLineNumbers", kind: .lineNumbers, fallback: .bool(true),
192 Setting(section: "", key: "display-line-numbers-type", defaultsKey: "showLineNumbers", kind: .lineNumbers, fallback: .bool(false),
193193 comment: "line numbers: true, false, \"relative\" or \"visual\" (View ▸ Line Numbers)", legacy: "editor.line-numbers"),
194194 Setting(section: "", key: "org-agenda-span", defaultsKey: "agendaSpan", kind: .integer, fallback: .integer(10),
195195 comment: "days the agenda shows", legacy: "agenda.span"),
@@ -301,6 +301,8 @@ public enum UserConfig {
301301 comment: "points", legacy: ""),
302302 Setting(section: "theme", key: "line-spacing", defaultsKey: "themeLineSpacing", kind: .integer, fallback: .integer(2),
303303 comment: "points between lines", legacy: ""),
304 Setting(section: "theme", key: "text-width", defaultsKey: "themeTextWidth", kind: .integer, fallback: .integer(0),
305 comment: "the widest the text runs, in columns, centred in a wider editor; 0 for the whole width", legacy: ""),
304306 Setting(section: "theme", key: "heading-size-step", defaultsKey: "themeHeadingStep", kind: .integer, fallback: .integer(1),
305307 comment: "points a heading is larger than the level below; level 4 and deeper are body size", legacy: ""),
306308 Setting(section: "theme", key: "theme-file", defaultsKey: "themeFile", kind: .string, fallback: .string(""),
Sources/OrgEditorAppKit/Keys.swift +10
@@ -54,6 +54,16 @@ final class OrgTextView: NSTextView {
5454 var showsLineNumbers = false {
5555 didSet { if showsLineNumbers != oldValue { updateGutter() } }
5656 }
57 /// The widest the text container gets, centred in the view; 0 for the view's width.
58 var textWidth: CGFloat = 0 {
59 didSet { if textWidth != oldValue { updateGutter() } }
60 }
61
62 override func setFrameSize(_ newSize: NSSize) {
63 let widthChanged = newSize.width != frame.width
64 super.setFrameSize(newSize)
65 if widthChanged, textWidth > 0 { updateGutter() }
66 }
5767 var lineNumbersType = LineNumbersType.absolute {
5868 didSet { if lineNumbersType != oldValue { needsDisplay = true } }
5969 }
Sources/OrgEditorAppKit/LineNumbers.swift +6
@@ -18,6 +18,12 @@ extension OrgTextView {
1818 let digits = max(2, String(lines).count)
1919 width = ceil(("0" as NSString).size(withAttributes: [.font: lineNumberFont]).width * CGFloat(digits) + 16)
2020 }
21 // A text width narrower than the view: the same margin either side, the numbers
22 // still just left of the text.
23 if textWidth > 0, textContainer?.widthTracksTextView == true {
24 let padding = 2 * (textContainer?.lineFragmentPadding ?? 0)
25 width = max(width, floor((bounds.width - textWidth - padding) / 2))
26 }
2127 if textContainerInset.width != width {
2228 textContainerInset = NSSize(width: width, height: textContainerInset.height)
2329 needsDisplay = true
Sources/OrgEditorAppKit/OrgEditor.swift +1
@@ -284,6 +284,7 @@ public final class OrgEditor: NSObject {
284284 for view in orgTextViews {
285285 view.font = theme.body
286286 view.typingAttributes = theme.base
287 view.textWidth = CGFloat(max(0, theme.spec.textWidth)) * theme.column
287288 view.drawsBackground = true
288289 view.backgroundColor = theme.color("background") ?? .textBackgroundColor
289290 view.insertionPointColor = theme.color("cursor") ?? .textColor
Sources/OrgEditorAppKit/ViewToggles.swift +2
@@ -54,6 +54,8 @@ extension OrgEditor {
5454 }
5555 textLayoutManager.invalidateLayout(for: textLayoutManager.documentRange)
5656 }
57 // Truncated lines take the whole width; wrapped ones the text width again.
58 (textView as? OrgTextView)?.updateGutter()
5759 textView.needsDisplay = true
5860 }
5961 }
Sources/OrgPresentation/ThemeSpec.swift +4 −1
@@ -44,6 +44,9 @@ public struct ThemeSpec: Equatable, Sendable {
4444 public var fontSize = 13
4545 /// Points between lines.
4646 public var lineSpacing = 2
47 /// The widest the text runs, in columns of `font`, centred in a wider editor; 0 for the
48 /// editor's whole width.
49 public var textWidth = 0
4750 /// Points a heading is larger than the next level down (level 4 and deeper are body size).
4851 public var headingSizeStep = 1
4952 public var light: [String: RGBA]
@@ -185,7 +188,7 @@ public struct ThemeSpec: Equatable, Sendable {
185188 // MARK: - Reading
186189
187190 /// Keys of `[theme]` that aren't colors; config.toml's settings handle them.
188 public static let typeKeys: Set<String> = ["font", "body-font", "font-size", "line-spacing", "heading-size-step", "theme-file"]
191 public static let typeKeys: Set<String> = ["font", "body-font", "font-size", "line-spacing", "text-width", "heading-size-step", "theme-file"]
189192
190193 /// Whether a table holds theme colors.
191194 public static func isThemeTable(_ name: String) -> Bool {
Sources/Orgstar/ContentView.swift +3 −1
@@ -87,7 +87,7 @@ struct ContentView: View {
8787 @AppStorage("backlinksShown") private var backlinksShown = true
8888 @AppStorage("inspectorShown") private var inspectorShown = false
8989 @AppStorage("showMarkup") private var showMarkup = false
90 @AppStorage("showLineNumbers") private var showLineNumbers = true
90 @AppStorage("showLineNumbers") private var showLineNumbers = false
9191 @AppStorage("lineNumbersType") private var lineNumbersType = "t"
9292 @AppStorage("showHiddenFiles") private var showHiddenFiles = true
9393 @AppStorage("ignoredFolders") private var ignoredFolders = ScanRules.defaultIgnoredFolders.sorted().joined(separator: " ")
@@ -95,6 +95,7 @@ struct ContentView: View {
9595 @AppStorage("themeBodyFont") private var themeBodyFont = ""
9696 @AppStorage("themeFontSize") private var themeFontSize = 13
9797 @AppStorage("themeLineSpacing") private var themeLineSpacing = 2
98 @AppStorage("themeTextWidth") private var themeTextWidth = 0
9899 @AppStorage("themeHeadingStep") private var themeHeadingStep = 1
99100
100101 /// The theme's colors from config.toml with the type settings.
@@ -104,6 +105,7 @@ struct ContentView: View {
104105 spec.bodyFont = themeBodyFont
105106 spec.fontSize = themeFontSize
106107 spec.lineSpacing = themeLineSpacing
108 spec.textWidth = themeTextWidth
107109 spec.headingSizeStep = themeHeadingStep
108110 return spec
109111 }
Sources/Orgstar/OrgstarApp.swift +7 −1
@@ -527,7 +527,7 @@ struct OrgMenuItems: View {
527527struct MarkupToggle: View {
528528 @AppStorage("showTabBar") private var showTabBar = false
529529 @AppStorage("showMarkup") private var showMarkup = false
530 @AppStorage("showLineNumbers") private var showLineNumbers = true
530 @AppStorage("showLineNumbers") private var showLineNumbers = false
531531 @AppStorage("lineNumbersType") private var lineNumbersType = "t"
532532
533533 var body: some View {
@@ -624,6 +624,7 @@ struct SettingsView: View {
624624 @AppStorage("themeBodyFont") private var themeBodyFont = ""
625625 @AppStorage("themeFontSize") private var themeFontSize = 13
626626 @AppStorage("themeLineSpacing") private var themeLineSpacing = 2
627 @AppStorage("themeTextWidth") private var themeTextWidth = 0
627628 @AppStorage("themeHeadingStep") private var themeHeadingStep = 1
628629
629630 /// Installed font families that aren't monospaced, for body text.
@@ -790,6 +791,11 @@ struct SettingsView: View {
790791 }
791792 Stepper("Size: \(themeFontSize) pt", value: $themeFontSize, in: 8...36)
792793 Stepper("Line spacing: \(themeLineSpacing) pt", value: $themeLineSpacing, in: 0...16)
794 Picker("Text width", selection: $themeTextWidth) {
795 Text("Whole editor").tag(0)
796 ForEach([60, 70, 80, 90, 100, 120], id: \.self) { Text("\($0) columns").tag($0) }
797 if ![0, 60, 70, 80, 90, 100, 120].contains(themeTextWidth) { Text("\(themeTextWidth) columns").tag(themeTextWidth) }
798 }
793799 Stepper("Headings grow by \(themeHeadingStep) pt a level", value: $themeHeadingStep, in: 0...8)
794800 } footer: {
795801 Text("Tags and tables line up in columns, so Font should be monospaced. With a Body text font, prose uses it while tables, code, dates, tags and drawers keep Font.")
Sources/OrgstarMobile/MobileEditor+Styling.swift +1
@@ -28,6 +28,7 @@ extension MobileEditor {
2828 view.backgroundColor = theme.color("background") ?? .systemBackground
2929 view.tintColor = theme.color("cursor")
3030 view.typingAttributes = theme.base
31 (view as? KeyedTextView)?.textWidth = CGFloat(max(0, theme.spec.textWidth)) * theme.column
3132 themeSelection(view)
3233 }
3334
Sources/OrgstarMobile/MobileFragments.swift +11
@@ -46,6 +46,12 @@ final class KeyedTextView: UITextView {
4646 var onLayout: (() -> Void)?
4747 /// The text container's width while lines are truncated.
4848 static let truncatedWidth: CGFloat = 100_000
49 /// The widest the text runs, centred in a wider view; 0 for the view's width.
50 var textWidth: CGFloat = 0 {
51 didSet { if textWidth != oldValue { setNeedsLayout() } }
52 }
53 /// The side inset without a text width.
54 static let sideInset: CGFloat = 8
4955
5056 /// Long lines run off the right edge and the view scrolls sideways.
5157 var truncates: Bool {
@@ -64,6 +70,11 @@ final class KeyedTextView: UITextView {
6470 }
6571
6672 override func layoutSubviews() {
73 let side = textWidth > 0 && !truncates ? max(Self.sideInset, floor((bounds.width - textWidth - 2 * textContainer.lineFragmentPadding) / 2)) : Self.sideInset
74 if textContainerInset.left != side {
75 textContainerInset.left = side
76 textContainerInset.right = side
77 }
6778 // The text view sets its container's width to its own when it lays out.
6879 if truncates, textContainer.size.width != Self.truncatedWidth {
6980 textContainer.size = CGSize(width: Self.truncatedWidth, height: CGFloat.greatestFiniteMagnitude)
Tests/OrgEditorAppKitTests/EditorTests.swift +18
@@ -244,6 +244,24 @@ struct EditingTests {
244244 h.checkInSync()
245245 }
246246
247 @Test func textWidth() throws {
248 let h = Harness("Prose that is long enough to wrap in a narrow text area, past sixty columns of text.\n")
249 let full = try #require(h.textView.textContainer).size.width
250 var spec = ThemeSpec.default
251 spec.textWidth = 40
252 h.editor.themeSpec = spec
253 h.layout()
254 let narrow = try #require(h.textView.textContainer).size.width
255 #expect(narrow < full)
256 #expect(abs(narrow - 40 * h.editor.theme.column - 2 * h.textView.textContainer!.lineFragmentPadding) < 1)
257 // Centred: the same margin either side.
258 #expect(abs(h.textView.textContainerInset.width * 2 + narrow - h.textView.bounds.width) < 1)
259 spec.textWidth = 0
260 h.editor.themeSpec = spec
261 h.layout()
262 #expect(try #require(h.textView.textContainer).size.width == full)
263 }
264
247265 @Test func mixedPitch() throws {
248266 let text = "**** Heading :tag:\nProse text.\n- item\n| a | b |\n#+begin_src sh\necho\n#+end_src\n"
249267 let h = Harness(text)
docs/manual/guide/02-the-editor.org +3 −3
@@ -30,7 +30,7 @@ The two Org options are in Settings ▸ Editing as "Emacs hides emphasis markers
3030- Blocks (=#+BEGIN_…= to =#+END_…=), dynamic blocks and fixed-width lines are drawn on a shaded band across the whole width of the editor, as Emacs extends the =org-block= face. Code in src blocks is highlighted for its language (see [[file:11-code-blocks.org][Code blocks]]).
3131- A folded heading shows an ellipsis after its line.
3232
33Colours come from the theme and follow the system's light or dark appearance. The font, size and line spacing are in Settings ▸ Appearance; colours are set in =config.toml=. See [[file:13-configuration.org][Configuration]]. The font should be monospaced, since tags and tables line up by columns. A body font for prose can be set beside it, as =mixed-pitch-mode= does in Emacs: prose and headings use it, and tables, code, dates, tags, drawers and the start of each line keep the monospaced font.
33Colours come from the theme and follow the system's light or dark appearance. The font, size, line spacing and text width are in Settings ▸ Appearance; colours are set in =config.toml=. See [[file:13-configuration.org][Configuration]]. The font should be monospaced, since tags and tables line up by columns. A body font for prose can be set beside it, as =mixed-pitch-mode= does in Emacs: prose and headings use it, and tables, code, dates, tags, drawers and the start of each line keep the monospaced font.
3434
3535** Indentation and stars
3636
@@ -307,7 +307,7 @@ Wrapping is display only. To rewrap the text of a paragraph, use Org ▸ Fill Pa
307307| Toggle | Menu | Keys | Default | =config.toml= | Scope |
308308|-------------------------------+-------------------------------+-------------------------------------------------+---------+----------------------------------+----------------|
309309| Show Markup | View ▸ Show Markup | =⇧⌘M= | off | =show-markup= | every buffer |
310| Show Line Numbers | View ▸ Show Line Numbers | =⇧⌘L= | on | =display-line-numbers-type= | every buffer |
310| Show Line Numbers | View ▸ Show Line Numbers | =⇧⌘L= | off | =display-line-numbers-type= | every buffer |
311311| Auto fill | View ▸ Turn Auto Fill On or Off | palette | off | =auto-fill-mode= | current buffer |
312312| Inline images | Org ▸ Show or Hide Inline Images | =C-c C-x C-v= (Emacs, Doom) | off | =org-startup-with-inline-images= | current buffer |
313313| LaTeX previews | palette | =C-c C-x C-l= (Emacs, Doom) | off | =org-startup-with-latex-preview= | current buffer |
@@ -318,7 +318,7 @@ Toggles that apply to the current buffer last until it closes; the =config.toml=
318318
319319** Line numbers
320320
321Line numbers show in a margin left of the text, as =display-line-numbers-mode= shows them: one number per line of the file, so wrapped lines are numbered once and folded lines are skipped. The caret's line number is brighter. Line numbers are on by default.
321Line numbers show in a margin left of the text, as =display-line-numbers-mode= shows them: one number per line of the file, so wrapped lines are numbered once and folded lines are skipped. The caret's line number is brighter. Line numbers are off by default, as in Emacs.
322322
323323View ▸ Line Numbers chooses how they count, as =display-line-numbers-type= does in =config.toml=:
324324
docs/manual/guide/13-configuration.org +4 −1
@@ -106,6 +106,7 @@ orgstar's menus, settings and agenda are in English and German, and follow the l
106106| Body text | Same as Font, System, or any installed proportional family | Same as Font | =body-font= |
107107| Size | 8 to 36 pt | 13 pt | =font-size= |
108108| Line spacing | 0 to 16 pt | 2 pt | =line-spacing= |
109| Text width | Whole editor, or 60 to 120 columns | Whole editor | =text-width= |
109110| Headings grow by N pt a level | 0 to 8 pt | 1 pt | =heading-size-step= |
110111| Colors: Edit in config.toml | Opens =config.toml= | | |
111112| Colors: Show Default Theme | Opens =default-theme.toml= | | |
@@ -251,7 +252,7 @@ A key you remove from the file goes back to its default. A key that isn't in the
251252| =org-use-speed-commands= | boolean | =false= | Single keys at the start of a heading line run commands (=n=, =p=, =t=, =c=, …). Mirrors =org-use-speed-commands=. |
252253| =org-cycle-hide-drawer-startup= | boolean | =true= | Fold drawers when a file opens. =#+STARTUP: hidedrawers= / =nohidedrawers= override it. Mirrors =org-cycle-hide-drawer-startup=. |
253254| =org-cycle-hide-block-startup= | boolean | =false= | Fold blocks when a file opens. =#+STARTUP: hideblocks= / =nohideblocks= override it. Mirrors =org-cycle-hide-block-startup=. |
254| =display-line-numbers-type= | boolean or string | =true= | Line numbers in the editor's gutter: =true=, =false=, ="relative"= or ="visual"=. See [[file:02-the-editor.org][The editor]]. |
255| =display-line-numbers-type= | boolean or string | =false= | Line numbers in the editor's gutter: =true=, =false=, ="relative"= or ="visual"=. See [[file:02-the-editor.org][The editor]]. |
255256| =org-agenda-span= | integer | =10= | Days the agenda shows. Mirrors =org-agenda-span=. |
256257| =org-agenda-start-day= | string | ="+0d"= | The agenda's first day relative to today, as ="-3d"= or ="+0d"=. Only day offsets are accepted. Mirrors =org-agenda-start-day=. |
257258| =org-agenda-start-on-weekday= | string | ="1"= | The day weeks start on, ="0"= (Sunday) to ="6"= (Saturday), for the week view and spans of 7 or 14 days. ="nil"= starts them on the day the view starts from. Mirrors =org-agenda-start-on-weekday=. |
@@ -363,6 +364,7 @@ Publishing projects, one table each, as =org-publish-project-alist= has them. Th
363364| =body-font= | string | =""= | A font family for prose, or ="system"= for the system's proportional font. =""= uses =font= throughout. |
364365| =font-size= | integer | =13= | Points. |
365366| =line-spacing= | integer | =2= | Points between lines. |
367| =text-width= | integer | =0= | The widest the text runs, in columns of =font=, centred in a wider editor. =0= uses the whole width. |
366368| =heading-size-step= | integer | =1= | Points a heading is larger than the level below. Level 4 and deeper are body size. |
367369| =theme-file= | string | =""= | A theme in its own file in the configuration folder, applied under the colors in =config.toml=. |
368370
@@ -774,5 +776,6 @@ By default the editor uses one font for everything: body text, headings, code an
774776- =font-size= is the body size, at least 6 points.
775777- Headings are bold. Level 1 is =font-size= plus three times =heading-size-step=, level 2 plus two times, level 3 plus one time; level 4 and deeper are body size. Set =heading-size-step = 0= for one size throughout.
776778- =line-spacing= adds space between lines, in points.
779- =text-width= keeps lines of text to that many columns of =font= in a wider editor, with equal margins either side and the line numbers beside the text, as =olivetti-mode= does in Emacs. Long lines wrap at it; with lines truncated (View ▸ Truncate or Wrap Long Lines) the text takes the whole width. It changes only the display: =M-q= still fills to =fill-column=.
777780
778781On iPhone and iPad, the editor and reader use the same theme, read from the synced configuration folder. =font= and =body-font= apply when the family is installed on the device, otherwise the system's monospaced font is used, and =font-size= is the size at the default Dynamic Type setting, scaled with the size chosen on the device. The =selection= color, the =cursor= color and the =syntax-*= colors apply there too. See [[file:14-ios.org][iPhone and iPad]].
docs/manual/guide/14-ios.org +2 −1
@@ -85,6 +85,7 @@ The editor and the reader use the theme set in the configuration folder's =confi
8585- Font :: =font= when that family is installed on the device, otherwise the system's monospaced font. =body-font=, when set, is used for prose as on the Mac.
8686- Size :: =font-size= is the size at the default Dynamic Type setting, 13 pt by default. Text grows and shrinks with the text size chosen in the system Settings app.
8787- Line spacing and headings :: =line-spacing= and =heading-size-step= apply as on the Mac.
88- Text width :: =text-width= keeps the editor's text to that many columns, centred, on an iPad or a wide window.
8889- Caret and selection :: the selection highlight takes the theme's =selection= colour, over block bands too; the caret and the selection handles take =cursor=.
8990
9091The editor and the reader apply these display settings; only the editor aligns tables when a file opens. The startup settings (=org-cycle-hide-*-startup=, =org-startup-*=, =org-hide-leading-stars=) apply when a file opens, and a =#+STARTUP= keyword in the file overrides them, as on the Mac.
@@ -401,7 +402,7 @@ These settings from =config.toml= apply on iOS:
401402- =org-tags-column=, =org-insert-heading-respect-content=, =org-M-RET-may-split-line=, =fill-column=
402403- =org-hide-emphasis-markers= and =org-pretty-entities=, for what hidden markup shows and for how tag and table alignment and filling measure text, as on the Mac
403404- =show-markup=, =org-startup-indented=, =org-hide-leading-stars=, =org-startup-with-inline-images=, =org-startup-with-latex-preview=, =org-startup-align-all-tables=, =org-startup-truncated=, =org-cycle-hide-drawer-startup=, =org-cycle-hide-block-startup=
404- =[theme]= (=font=, =font-size=, =line-spacing=, =heading-size-step=, =theme-file= and colours), =[theme.light]=, =[theme.dark]=, =[theme.todo]=, =[theme.category]=
405- =[theme]= (=font=, =body-font=, =font-size=, =line-spacing=, =text-width=, =heading-size-step=, =theme-file= and colours), =[theme.light]=, =[theme.dark]=, =[theme.todo]=, =[theme.category]=
405406- =org-log-done=, =org-log-reschedule=, =org-log-redeadline=, =org-log-into-drawer=
406407- =org-enforce-todo-dependencies=, =org-enforce-todo-checkbox-dependencies=, =org-track-ordered-property-with-tag=, =org-agenda-dim-blocked-tasks=
407408- =org-roam-directory=, =org-roam-dailies-directory=, =org-roam-dailies-file=, =org-roam-dailies-head=, =org-roam-dailies-entry=