Skip to content

Commit d91fc71

Browse files
authored
Merge pull request #48 from jghauser/improve_startup
Improve startup
2 parents a562767 + 50a59f3 commit d91fc71

14 files changed

+192
-191
lines changed

README.md

+9-22
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ Papis.nvim is a [neovim](https://github.com/neovim/neovim) companion plugin for
88
- Place your cursor over a citation key and get information about the entry
99
- Automatically format new notes
1010
- Tag completion in `info.yaml` files
11+
- Insert formatted references
1112

1213
And this is just the beginning! With its fast and always up-to-date sqlite database (courtesy of [sqlite.lua](https://github.com/tami5/sqlite.lua)), a host of [additional features](#planned-features-and-improvements) are just waiting to be implemented. My hope is for this plugin to eventually become neovim's answer to emacs plugins such as [org-ref](https://github.com/jkitchin/org-ref), [helm-bibtex](https://github.com/tmalsburg/helm-bibtex), and [citar](https://github.com/emacs-citar/citar).
1314

14-
This plugin is currently in early beta. Bugs and breaking changes are expected. Breaking changes are communicated in a pinned issue and commit messages.
15+
This plugin is currently in beta. Bugs and breaking changes are expected. Breaking changes are communicated in a pinned issue and commit messages.
1516

1617
While papis.nvim is likely buggy, it is equally likely unable to mess with your precious bibliography. First, it doesn't by itself alter your Papis `info.yaml` files; it always uses the `papis` command to do so. Second, this command is currently only invoked when adding new notes to an item. Your database should therefore be safe from corruption (**however**: have backups, gremlins waiting to pounce are not my responsibility). In the future, papis.nvim might directly edit `info.yaml` files, but if and when that happens, this will be clearly communicated as a breaking change.
1718

@@ -163,27 +164,17 @@ The `flake.nix` provides an overlay that can be used to install `papis.nvim`. Wi
163164

164165
Papis.nvim exposes a rather large number of configuration options, most of which can be left alone -- and quite a few of which probably *should* be left alone (or not, if you're feeling brave). Currently, papis.nvim doesn't check whether you've managed to set incompatible options, and weird failures will likely occur in such instances.
165166

166-
Note that an empty setup function should work reasonably well when just test-driving the plugin. It will, however, slow neovim startup down considerably and should be replaced with a proper configuration.
167-
168167
Minimal setup:
169168

170169
```lua
171170
require("papis").setup({
172-
-- These are configuration options of the `papis` program relevant to papis.nvim.
173-
-- Papis.nvim can get them automatically from papis, but this is very slow. It is
174-
-- recommended to copy the relevant settings from your papis configuration file.
175-
papis_python = {
176-
dir = "/path/to/my/library",
177-
info_name = "info.yaml", -- (when setting papis options `-` is replaced with `_`
178-
-- in the keys names)
179-
notes_name = [[notes.norg]],
180-
},
181171
-- Enable the default keymaps
182172
enable_keymaps = true,
183173
})
184174
```
185175

186-
Full list of configuration options (with defaults):
176+
<details>
177+
<summary>All configuration options (with defaults)</summary>
187178

188179
```lua
189180
-- List of enabled papis.nvim modules.
@@ -257,11 +248,6 @@ db_path = vim.fn.stdpath("data") .. "/papis_db/papis-nvim.sqlite3",
257248
-- Name of the `yq` executable.
258249
yq_bin = "yq",
259250

260-
-- The papis options relevant for papis.nvim (see above minimal config). By
261-
-- default it is unset, which prompts papis.nvim to call `papis config` to
262-
-- get the values.
263-
papis_python = nil,
264-
265251
-- Function to execute when adding a new note. `ref` is the citation key of the
266252
-- relevant entry and `notes_name` is defined in `papis_python` above.
267253
create_new_note_fn = function(papis_id, notes_name)
@@ -274,9 +260,8 @@ create_new_note_fn = function(papis_id, notes_name)
274260
)
275261
end,
276262

277-
-- Filename patterns that trigger papis.nvim to start. `%info_name%` needs to be
278-
-- first item; it is replaced with `info_name` as defined in `papis_python`.
279-
init_filenames = { "%info_name%", "*.md", "*.norg" },
263+
-- Filetypes that start papis.nvim.
264+
init_filetypes = { "markdown", "norg", "yaml" },
280265

281266
-- Configuration of the search module.
282267
["search"] = {
@@ -435,9 +420,11 @@ cmp.setup({
435420
})
436421
```
437422

423+
</details>
424+
438425
## Usage
439426

440-
Papis.nvim will start automatically according to the filename patterns defined in `init_filenames` (see the [setup section](#setup)). Additionally, it can also be started with `:PapisStart`. The rest of the functionality is covered in the [features section](#features).
427+
Papis.nvim will start automatically according to the filetypes defined in `init_filetypes` (see the [setup section](#setup)). When first starting, papis.nvim will import some configuration values from Papis and save them in the database. If you update your Papis configuration, you should re-import the configuration into papis.nvim with `:PapisReInitConfig`.
441428

442429
## Keymaps
443430

doc/papis.txt

+11-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*papis.txt* For NVIM v0.8.0 Last change: 2024 June 01
1+
*papis.txt* For NVIM v0.8.0 Last change: 2024 June 02
22

33
==============================================================================
44
Table of Contents *papis-table-of-contents*
@@ -28,6 +28,7 @@ access to their bibliography from within the comfort of their editor.
2828
- Place your cursor over a citation key and get information about the entry
2929
- Automatically format new notes
3030
- Tag completion in `info.yaml` files
31+
- Insert formatted references
3132

3233
And this is just the beginning! With its fast and always up-to-date sqlite
3334
database (courtesy of sqlite.lua <https://github.com/tami5/sqlite.lua>), a host
@@ -37,7 +38,7 @@ org-ref <https://github.com/jkitchin/org-ref>, helm-bibtex
3738
<https://github.com/tmalsburg/helm-bibtex>, and citar
3839
<https://github.com/emacs-citar/citar>.
3940

40-
This plugin is currently in early beta. Bugs and breaking changes are expected.
41+
This plugin is currently in beta. Bugs and breaking changes are expected.
4142
Breaking changes are communicated in a pinned issue and commit messages.
4243

4344
While papis.nvim is likely buggy, it is equally likely unable to mess with your
@@ -232,29 +233,16 @@ alone (or not, if you’re feeling brave). Currently, papis.nvim doesn’t
232233
check whether you’ve managed to set incompatible options, and weird failures
233234
will likely occur in such instances.
234235

235-
Note that an empty setup function should work reasonably well when just
236-
test-driving the plugin. It will, however, slow neovim startup down
237-
considerably and should be replaced with a proper configuration.
238-
239236
Minimal setup:
240237

241238
>lua
242239
require("papis").setup({
243-
-- These are configuration options of the `papis` program relevant to papis.nvim.
244-
-- Papis.nvim can get them automatically from papis, but this is very slow. It is
245-
-- recommended to copy the relevant settings from your papis configuration file.
246-
papis_python = {
247-
dir = "/path/to/my/library",
248-
info_name = "info.yaml", -- (when setting papis options `-` is replaced with `_`
249-
-- in the keys names)
250-
notes_name = [[notes.norg]],
251-
},
252240
-- Enable the default keymaps
253241
enable_keymaps = true,
254242
})
255243
<
256244

257-
Full list of configuration options (with defaults):
245+
All configuration options (with defaults) ~
258246

259247
>lua
260248
-- List of enabled papis.nvim modules.
@@ -328,11 +316,6 @@ Full list of configuration options (with defaults):
328316
-- Name of the `yq` executable.
329317
yq_bin = "yq",
330318

331-
-- The papis options relevant for papis.nvim (see above minimal config). By
332-
-- default it is unset, which prompts papis.nvim to call `papis config` to
333-
-- get the values.
334-
papis_python = nil,
335-
336319
-- Function to execute when adding a new note. `ref` is the citation key of the
337320
-- relevant entry and `notes_name` is defined in `papis_python` above.
338321
create_new_note_fn = function(papis_id, notes_name)
@@ -345,9 +328,8 @@ Full list of configuration options (with defaults):
345328
)
346329
end,
347330

348-
-- Filename patterns that trigger papis.nvim to start. `%info_name%` needs to be
349-
-- first item; it is replaced with `info_name` as defined in `papis_python`.
350-
init_filenames = { "%info_name%", "*.md", "*.norg" },
331+
-- Filetypes that start papis.nvim.
332+
init_filetypes = { "markdown", "norg", "yaml" },
351333

352334
-- Configuration of the search module.
353335
["search"] = {
@@ -510,10 +492,11 @@ cmp.
510492

511493
USAGE *papis-📚-papis.nvim-usage*
512494

513-
Papis.nvim will start automatically according to the filename patterns defined
514-
in `init_filenames` (see the |papis-setup-section|). Additionally, it can also
515-
be started with `:PapisStart`. The rest of the functionality is covered in the
516-
|papis-features-section|.
495+
Papis.nvim will start automatically according to the filetypes defined in
496+
`init_filetypes` (see the |papis-setup-section|). When first starting,
497+
papis.nvim will import some configuration values from Papis and save them in
498+
the database. If you update your Papis configuration, you should re-import the
499+
configuration into papis.nvim with `:PapisReInitConfig`.
517500

518501

519502
KEYMAPS *papis-📚-papis.nvim-keymaps*

flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
in [
7979
pkgs.sqlitebrowser
8080
pkgs.yq-go
81+
pkgs.luajit
8182
nvim-test
8283
];
8384
};

lua/papis/commands.lua

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ local config = require("papis.config")
99
local api = vim.api
1010

1111
local commands = {
12-
["init"] = {
13-
papis_start = {
14-
name = "PapisStart",
15-
command = function()
16-
require("papis").start()
17-
end,
18-
opts = { desc = "Start papis.nvim" },
19-
},
20-
},
2112
["base"] = {
22-
reset_db = {
13+
reinit_data = {
2314
name = "PapisReInitData",
2415
command = function()
2516
require("papis.data"):reset_db()
2617
end,
2718
opts = { desc = "Papis: empty and repopulate the sqlite database from disk" },
2819
},
20+
reinit_papis_py_config = {
21+
name = "PapisReInitConfig",
22+
command = function()
23+
local testing_session = config["enable_modules"]["testing"]
24+
local papis_py_conf_new = config:get_papis_py_conf(testing_session)
25+
config:compare_papis_py_conf(papis_py_conf_new)
26+
end,
27+
opts = { desc = "Papis: import configuration from Papis" },
28+
},
2929
},
3030
["debug"] = {
3131
stop_fw = {
@@ -91,13 +91,13 @@ function M.setup(module)
9191
for module_name, module_commands in pairs(commands) do
9292
if config["enable_modules"][module_name] then
9393
for _, command in pairs(module_commands) do
94-
api.nvim_create_user_command(command["name"], command["command"], command["opts"])
94+
api.nvim_buf_create_user_command(0, command["name"], command["command"], command["opts"])
9595
end
9696
end
9797
end
9898
else
9999
for _, command in pairs(commands[module]) do
100-
api.nvim_create_user_command(command["name"], command["command"], command["opts"])
100+
api.nvim_buf_create_user_command(0, command["name"], command["command"], command["opts"])
101101
end
102102
end
103103
end

lua/papis/completion/source.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ function M:is_available()
5555
local split_path = current_filepath:_split()
5656
local filename = current_filepath:_split()[#split_path]
5757

58-
if filename == config["papis_python"]["info_name"] then
58+
local info_name = db.config:get_value({ id = 1 }, "info_name")
59+
if filename == info_name then
5960
log.trace("we are in a papis info file")
6061
if not tag_delimiter then
6162
tag_delimiter = get_tag_delimiter()

0 commit comments

Comments
 (0)