Commit 424b251694
Copy SHA
424b251694c057659290bdc45000cd085f341417
parent: d92c7f39e4
Verified · cmc
cmc <hello@cleberg.net> · 2026-10-08 03:49 UTC
Read #+STARTUP from keyword lines only
The parser collects #+STARTUP words outside blocks into
OrgSettings.startup; logging, inline images and folding read them
there. A #+STARTUP line inside a block no longer sets logging or
inline images.
Changed files (8)
Sources/OrgCore/Commands/InlineImages.swift
+3 −5 · view
@@ -34,11 +34,9 @@ public enum InlineImages {
34 34 // / ` # + S T A R T U P : i n l i n e i m a g e s ` o r ` n o i n l i n e i m a g e s ` , i f t h e f i l e s a y s .
35 35 public static func startup ( _ tree : OrgTree ) -> Bool ? {
36 36 var shown : Bool ?
37 for m in ( tree . settings . setupKeywords + tree . root . text ) . matches ( of : # / ( ? mi ) ^ [ \ t ] * # \ + STARTUP : ( . * ) $ / # ) {
38 for word in m . 1. split ( whereSeparator : \ . isWhitespace ) {
39 if word . lowercased ( ) = = " inlineimages " { shown = tru e }
40 if word . lowercased ( ) = = " noinlineimages " { shown = false }
41 }
37 for word in tree . settings . startup {
38 if word . lowercased ( ) = = " inlineimages " { shown = true }
39 if word . lowercased ( ) = = " noinlineimages " { shown = fals e }
42 40 }
43 41 return shown
44 42 }
Sources/OrgCore/Commands/TodoLogging.swift
+1 −9 · view
@@ -82,15 +82,7 @@ extension EmacsBuffer {
82 82 if enter != nil || leave != nil , log . states [ keyword . name ] = = nil { log . states [ keyword . name ] = ( enter , leave ) }
83 83 }
84 84 }
85 for ( key , value ) in SetupFile . keywords ( settings . setupKeywords ) where key = = " STARTUP " {
86 for word in value . split ( whereSeparator : \ . isWhitespace ) { log . apply ( startup : String ( word ) ) }
87 }
88 let startup = try ! NSRegularExpression ( pattern : " ^[ \\ t]*# \\ +STARTUP:(.*)$ " , options : [ . anchorsMatchLines , . caseInsensitive ] )
89 for match in startup . matches ( in : string , range : NSRange ( location : 0 , length : length ) ) {
90 for word in substring ( match . range ( at : 1 ) . location , NSMaxRange ( match . range ( at : 1 ) ) ) . split ( whereSeparator : \ . isWhitespace ) {
91 log . apply ( startup : String ( word ) )
92 }
93 }
85 for word in settings . startup { log . apply ( startup : word ) }
94 86 if let logging = inheritedProperty ( " LOGGING " ) ? . value {
95 87 // ` o r g - l o c a l - l o g g i n g ` .
96 88 log . done = nil
Sources/OrgCore/Parser/Incremental.swift
+1 −1 · view
@@ -58,7 +58,7 @@ private struct ReparseContext {
58 58 // / C h a n g e i n U T F - 1 6 l e n g t h .
59 59 var delta : Int { edit . replacement . utf16 . count - edit . range . count }
60 60
61 static let settingsKeys : Set < String > = [ " TODO " , " SEQ_TODO " , " TYP_TODO " , " PRIORITIES " ]
61 static let settingsKeys : Set < String > = [ " TODO " , " SEQ_TODO " , " TYP_TODO " , " PRIORITIES " , " STARTUP " ]
62 62
63 63 // / E l e m e n t s t h a t p a r s e t h e s a m e i n i s o l a t i o n a s i n p l a c e , a s l o n g a s t h e i r l i n e s k e e p
64 64 // / t h e i r c l a s s e s .
Sources/OrgCore/Parser/Settings.swift
+7 −1 · view
@@ -50,6 +50,8 @@ public struct OrgSettings: Sendable, Equatable {
50 50 // / K e y w o r d l i n e s f r o m t h e f i l e ' s ` # + S E T U P F I L E ` s , a s ` # + K E Y : v a l u e ` l i n e s : t h e y c o u n t a s
51 51 // / t h e f i l e ' s o w n , b e f o r e t h e m .
52 52 public var setupKeywords = " "
53 // / W o r d s o f t h e ` # + S T A R T U P ` k e y w o r d l i n e s o u t s i d e b l o c k s , s e t u p f i l e s ' f i r s t .
54 public var startup : [ String ] = [ ]
53 55
54 56 public init ( todoSequences : [ TodoSequence ] , priorities : Priorities , radioTargets : [ String ] = [ ] ) {
55 57 self . todoSequences = todoSequences
@@ -82,12 +84,13 @@ public struct OrgSettings: Sendable, Equatable {
82 84 }
83 85
84 86 enum SettingsScanner {
85 // / R e a d s ` # + T O D O ` , ` # + S E Q _ T O D O ` , ` # + T Y P _ T O D O ` a n d ` # + P R I O R I T I E S ` o u t s i d e b l o c k s . A n y T O D O
87 // / R e a d s ` # + T O D O ` , ` # + S E Q _ T O D O ` , ` # + T Y P _ T O D O ` , ` # + P R I O R I T I E S ` a n d ` # + S T A R T U P ` o u t s i d e b l o c k s . A n y T O D O
86 88 // / l i n e r e p l a c e s t h e d e f a u l t s e q u e n c e s ; a s i n o r g , ` T Y P _ T O D O ` s e q u e n c e s c o m e f i r s t , t h e n
87 89 // / ` T O D O ` , t h e n ` S E Q _ T O D O ` .
88 90 static func scan ( lines : [ RawLine ] , info : [ ClassifiedLine ] , blockEnds : [ Int : Int ] , defaults : OrgSettings ) -> OrgSettings {
89 91 var types : [ TodoSequence ] = [ ] , todos : [ TodoSequence ] = [ ] , seqs : [ TodoSequence ] = [ ]
90 92 var priorities = defaults . priorities
93 var startup : [ String ] = [ ]
91 94 func apply ( _ key : String , _ value : Substring ) {
92 95 switch key {
93 96 case " TODO " :
@@ -96,6 +99,8 @@ enum SettingsScanner {
96 99 if let s = todoSequence ( value , kind : . sequence ) { seqs . append ( s ) }
97 100 case " TYP_TODO " :
98 101 if let s = todoSequence ( value , kind : . type ) { types . append ( s ) }
102 case " STARTUP " :
103 startup += value . split ( whereSeparator : \ . isWhitespace ) . map ( String . init )
99 104 case " PRIORITIES " :
100 105 let words = value . split ( whereSeparator : \ . isWhitespace )
101 106 if words . count = = 3 {
@@ -129,6 +134,7 @@ enum SettingsScanner {
129 134 radioTargets : radio . sorted { $0 . count > $1 . count } )
130 135 settings . listAllowAlphabetical = defaults . listAllowAlphabetical
131 136 settings . setupKeywords = defaults . setupKeywords
137 settings . startup = startup
132 138 return settings
133 139 }
134 140
Sources/OrgPresentation/Folding.swift
+3 −22 · view
@@ -217,28 +217,9 @@ extension Presentation {
217 217 return result
218 218 }
219 219
220 // / W o r d s o f e v e r y ` # + S T A R T U P : ` l i n e . O n l y e l e m e n t - l e v e l k e y w o r d s c o u n t , s o t e x t i n s i d e
221 // / b l o c k s a n d p a r a g r a p h s i s n e v e r r e a d a s a s e t t i n g .
220 // / W o r d s o f e v e r y ` # + S T A R T U P : ` k e y w o r d l i n e ( ` O r g S e t t i n g s . s t a r t u p ` ) ; l i n e s i n s i d e b l o c k s
221 // / a r e n o t s e t t i n g s .
222 222 public static func startupOptions ( _ tree : OrgTree ) -> [ String ] {
223 var options = tree . settings . setupKeywords . split ( separator : " \n " ) . filter { $0 . uppercased ( ) . hasPrefix ( " #+STARTUP: " ) }
224 . flatMap { $0 . dropFirst ( " #+STARTUP: " . count ) . split ( whereSeparator : \ . isWhitespace ) . map ( String . init ) }
225 func visit ( _ node : GreenNode ) {
226 for case . node ( let child ) in node . children {
227 switch child . kind {
228 case . keyword :
229 let text = child . text
230 if text . uppercased ( ) . drop ( while : { $0 = = " " || $0 = = " \t " } ) . hasPrefix ( " #+STARTUP: " ) ,
231 let colon = text . firstIndex ( of : " : " ) {
232 options += text [ text . index ( after : colon ) . . . ] . split ( whereSeparator : \ . isWhitespace ) . map ( String . init )
233 }
234 case . document , . zerothSection , . section , . drawer :
235 visit ( child )
236 default :
237 break
238 }
239 }
240 }
241 visit ( tree . green )
242 return options
223 tree . settings . startup
243 224 }
244 225 }
Tests/OrgCoreTests/InlineImagesTests.swift
+1 · view
@@ -12,5 +12,6 @@ struct InlineImagesTests {
12 12 # expect ( InlineImages . startup ( OrgParser . parse ( text as String ) ) = = true )
13 13 # expect ( InlineImages . startup ( OrgParser . parse ( " #+STARTUP: overview noinlineimages \n " ) ) = = false )
14 14 # expect ( InlineImages . startup ( OrgParser . parse ( " * x \n " ) ) = = nil )
15 # expect ( InlineImages . startup ( OrgParser . parse ( " #+begin_src org \n #+STARTUP: inlineimages \n #+end_src \n " ) ) = = nil )
15 16 }
16 17 }
Tests/OrgCoreTests/TodoLoggingTests.swift
+1 · view
@@ -9,6 +9,7 @@ struct TodoLoggingTests {
9 9 " * TODO Task \n :LOGBOOK: \n - State \" TODO \" from [2026-01-01 Thu 10:00] \n :END: \n " ,
10 10 " * DONE Task \n CLOSED: [2026-01-01 Thu 10:00] \n " ,
11 11 " #+STARTUP: lognotedone logdrawer \n * TODO Task \n " ,
12 " #+begin_example \n #+STARTUP: lognotedone logdrawer \n #+end_example \n * TODO Task \n " ,
12 13 " * TODO Task \n :PROPERTIES: \n :LOGGING: DONE(!) logrepeat \n :LOG_INTO_DRAWER: NOTES \n :END: \n " ,
13 14 " * TODO Task \n SCHEDULED: <2026-10-05 Mon +1w> \n " ,
14 15 " * TODO Task \n - item one \n " ,
Tests/OrgPresentationTests/PresentationTests.swift
+1 · view
@@ -128,6 +128,7 @@ struct CyclingTests {
128 128 let state = Presentation . startupFoldState ( levels )
129 129 # expect ( state ? . folds . count = = 1 && state ? . bodyFolds . count = = 2 )
130 130 # expect ( Presentation . startupOptions ( OrgParser . parse ( " #+begin_example \n #+STARTUP: overview \n #+end_example \n " ) ) . isEmpty )
131 # expect ( Presentation . startupOptions ( OrgParser . parse ( " #+STARTUP: content \n * a \n :LOGBOOK: \n #+startup: hideblocks \n :END: \n " ) ) = = [ " content " , " hideblocks " ] )
131 132 }
132 133 }
133 134