@@ -143,12 +143,10 @@ local default_config = {
143
143
},
144
144
}
145
145
146
- local M = vim .deepcopy (default_config )
147
-
148
- --- Queries papis to get info-name and dir settings.
146
+ --- Queries Papis to get various options.
149
147
--- @param testing_session boolean #If true, will use testing papis conf
150
148
--- @return table #A table { info_name = val, dir = val }
151
- function M : get_papis_py_conf (testing_session )
149
+ local function get_papis_py_conf (testing_session )
152
150
local papis_conf_keys = { " info-name" , " notes-name" , " dir" }
153
151
local papis_py_conf_new = {}
154
152
local testing_conf_path = " "
@@ -172,15 +170,18 @@ function M:get_papis_py_conf(testing_session)
172
170
return papis_py_conf_new
173
171
end
174
172
173
+ local M = vim .deepcopy (default_config )
174
+
175
175
--- Compares and updates Queries papis to get info-name and dir settings. It is very slow and shouldn't be used
176
176
--- if possible.
177
- --- @param papis_py_conf_new table #A table with new (read from Papis) config entries
178
- function M :compare_papis_py_conf (papis_py_conf_new )
177
+ function M :update_papis_py_conf ()
179
178
local db = require (" papis.sqlite-wrapper" )
180
179
if not db then
181
180
return
182
181
end
183
182
183
+ local is_testing_session = self [" enable_modules" ][" testing" ]
184
+ local papis_py_conf_new = get_papis_py_conf (is_testing_session )
184
185
local papis_py_conf_old = db .config :get ()[1 ]
185
186
papis_py_conf_old [" id" ] = nil
186
187
@@ -194,6 +195,24 @@ function M:compare_papis_py_conf(papis_py_conf_new)
194
195
end
195
196
end
196
197
198
+ --- Sets up Papis configuration values if not already done.
199
+ function M :setup_papis_py_conf ()
200
+ local db = require (" papis.sqlite-wrapper" )
201
+ if not db then
202
+ return
203
+ end
204
+ local log = require (" papis.log" )
205
+
206
+ -- get config from Papis if not already in db
207
+ if not db .config :is_setup () then
208
+ log .info (" Papis.nvim configuration not setup, importing values from Papis now" )
209
+ local testing_session = self [" enable_modules" ][" testing" ]
210
+ local papis_py_conf_new = get_papis_py_conf (testing_session )
211
+ db .config :drop ()
212
+ db .config :update ({ id = 1 }, papis_py_conf_new )
213
+ end
214
+ end
215
+
197
216
--- Updates the default configuration with user supplied options and gets conf from Papis
198
217
--- @param opts table #Same format as default_config and contains user config
199
218
function M :update (opts )
@@ -219,25 +238,6 @@ function M:update(opts)
219
238
for k , v in pairs (newconf ) do
220
239
self [k ] = v
221
240
end
222
-
223
- local db = require (" papis.sqlite-wrapper" )
224
- if not db then
225
- return
226
- end
227
- local log = require (" papis.log" )
228
- if not log then
229
- return
230
- end
231
-
232
- -- get config from Papis if not already in db
233
- if not db .config :is_setup () then
234
- log .new (self [" log" ] or log .get_default_config (), true )
235
- log .info (" Papis.nvim configuration not setup, importing values from Papis now" )
236
- local testing_session = self [" enable_modules" ][" testing" ]
237
- local papis_py_conf_new = self :get_papis_py_conf (testing_session )
238
- db .config :drop ()
239
- db .config :update ({ id = 1 }, papis_py_conf_new )
240
- end
241
241
end
242
242
243
243
return M
0 commit comments