@@ -109,28 +109,26 @@ end
109109-- This is the main entry point for the plugin. It determines whether to open
110110-- the files in fixed order or any order based on `M.fixed_order`.
111111function M .handle_pairing ()
112- if M .config .open_header_sources then
113- local current_file = vim .fn .expand (" %:p" )
114- local is_header = current_file :match (" %.h$" ) or current_file :match (" %.hpp$" )
115- local pair = " "
112+ local current_file = vim .fn .expand (" %:p" )
113+ local is_header = current_file :match (" %.h$" ) or current_file :match (" %.hpp$" )
114+ local pair = " "
116115
117- -- Determine the paired file
118- if is_header then
119- pair = current_file :gsub (" %.h$" , " .c" ):gsub (" %.hpp$" , " .cpp" )
120- else
121- pair = current_file :gsub (" %.c$" , " .h" ):gsub (" %.cpp$" , " .hpp" )
122- end
116+ -- Determine the paired file
117+ if is_header then
118+ pair = current_file :gsub (" %.h$" , " .c" ):gsub (" %.hpp$" , " .cpp" )
119+ else
120+ pair = current_file :gsub (" %.c$" , " .h" ):gsub (" %.cpp$" , " .hpp" )
121+ end
123122
124- local f_exists = M .file_exists (pair )
125- local has_left = M .has_adjacent_window (" h" )
126- local has_right = M .has_adjacent_window (" l" )
123+ local f_exists = M .file_exists (pair )
124+ local has_left = M .has_adjacent_window (" h" )
125+ local has_right = M .has_adjacent_window (" l" )
127126
128- if pair and f_exists then
129- if M .config .fixed_order then
130- M .open_fixed_order (has_left , has_right , pair , is_header , current_file )
131- else
132- M .open_any_order (has_left , has_right , pair )
133- end
127+ if pair and f_exists then
128+ if M .config .fixed_order then
129+ M .open_fixed_order (has_left , has_right , pair , is_header , current_file )
130+ else
131+ M .open_any_order (has_left , has_right , pair )
134132 end
135133 end
136134end
139137vim .api .nvim_create_autocmd (" BufReadPost" , {
140138 pattern = { " *.h" , " *.hpp" , " *.c" , " *.cpp" },
141139 callback = function ()
142- M .handle_pairing ()
140+ if M .config .open_header_sources then
141+ M .handle_pairing ()
142+ end
143143 end ,
144144})
145145
0 commit comments