Skip to content

Commit f14ce7d

Browse files
author
jghauser
committed
feat!: add pretty icons
1 parent 44dc0c3 commit f14ce7d

File tree

4 files changed

+71
-30
lines changed

4 files changed

+71
-30
lines changed

README.md

+24-10
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,18 @@ Note that fiddling with the plugin's options can leave the database in a messy s
6969

7070
Note that papis.nvim is only tested with the latest stable version of Neovim. It should work across various OSs, but most development has been done on Linux (do feel free to open issues if you run into trouble on non-Linux systems). An installation of Papis is required.
7171

72-
To run, papis.nvim requires the [yq](https://github.com/mikefarah/yq) utility to convert `.yaml` files to `.json` (which can then be read by neovim). Note that papis.nvim doesn't (currently) support the [python yq](https://github.com/kislyuk/yq).
72+
To run, papis.nvim requires:
73+
- [yq](https://github.com/mikefarah/yq). This is used to convert `.yaml` files to `.json` (which can then be read by neovim). Note that papis.nvim doesn't (currently) support the [python yq](https://github.com/kislyuk/yq).
74+
- sqlite3: Needed by the `sqlite.lua` dependency.
75+
76+
Optionally, you'll need:
77+
- [a font with icons](https://github.com/ryanoasis/nerd-fonts#font-installation) for increased prettiness. You can set
7378

7479
You'll need the [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) plugin if you intend to use the completion module.
7580

7681
### Neovim package managers
7782

7883
In addition to the below snippets, you might also need to install:
79-
- `sqlite3` (required by `sqlite.lua`)
8084
- *treesitter yaml parser* (if you want the completion module)
8185

8286
<details>
@@ -86,6 +90,8 @@ In addition to the below snippets, you might also need to install:
8690
:Rocks install papis.nvim
8791
```
8892

93+
Additionally, may want to install `telescope` (for search) and `cmp` (for completion).
94+
8995
</details>
9096

9197
<details>
@@ -294,6 +300,9 @@ init_filetypes = { "markdown", "norg", "yaml" },
294300
-- Papis options to import into papis.nvim.
295301
papis_conf_keys = { "info-name", "notes-name", "dir", "opentool" },
296302

303+
-- Whether to enable pretty icons (requires something like nerd font)
304+
enable_icons = true,
305+
297306
-- Configuration of the search module.
298307
["search"] = {
299308

@@ -317,23 +326,28 @@ papis_conf_keys = { "info-name", "notes-name", "dir", "opentool" },
317326
-- the value in the preview (even though it is defined after it in this
318327
-- configuration (e.g. `title = Critique of Pure Reason`)).
319328
-- `empty_line` is used to insert an empty line
329+
-- Strings that define the formatting (such as in 2. and 4. above) can optionally
330+
-- be a table, defining, first, an icon, and second, a non-icon version. What is
331+
-- used is defined by the `enable_icons` option.
320332
preview_format = {
321333
{ "author", "%s", "PapisPreviewAuthor" },
322334
{ "year", "%s", "PapisPreviewYear" },
323335
{ "title", "%s", "PapisPreviewTitle" },
324336
{ "empty_line" },
325-
{ "ref", "%s", "PapisPreviewValue", "show_key", "%s = ", "PapisPreviewKey" },
326-
{ "type", "%s", "PapisPreviewValue", "show_key", "%s = ", "PapisPreviewKey" },
327-
{ "tags", "%s", "PapisPreviewValue", "show_key", "%s = ", "PapisPreviewKey" },
328-
{ "files", "%s", "PapisPreviewValue", "show_key", "%s = ", "PapisPreviewKey" },
329-
{ "notes", "%s", "PapisPreviewValue", "show_key", "%s = ", "PapisPreviewKey" },
330-
{ "journal", "%s", "PapisPreviewValue", "show_key", "%s = ", "PapisPreviewKey" },
331-
{ "abstract", "%s", "PapisPreviewValue", "show_key", "%s = ", "PapisPreviewKey" },
337+
{ "journal", "%s", "PapisPreviewValue", "show_key", { "󱀁 ", "%s: " }, "PapisPreviewKey" },
338+
{ "type", "%s", "PapisPreviewValue", "show_key", { "", "%s: " }, "PapisPreviewKey" },
339+
{ "ref", "%s", "PapisPreviewValue", "show_key", { "", "%s: " }, "PapisPreviewKey" },
340+
{ "tags", "%s", "PapisPreviewValue", "show_key", { "", "%s: " }, "PapisPreviewKey" },
341+
{ "abstract", "%s", "PapisPreviewValue", "show_key", { "󰭷 ", "%s: " }, "PapisPreviewKey" },
332342
},
333343

334344
-- The format of each line in the the results window. Here, everything is show on
335-
-- one line (otherwise equivalent to points 1-3 of `preview_format`).
345+
-- one line (otherwise equivalent to points 1-3 of `preview_format`). The `force_space`
346+
-- value is used to force whitespace for icons (so that if e.g. a file is absent, it will
347+
-- show " ", ensuring that columns are aligned.)
336348
results_format = {
349+
{ "files", { "", "F " }, "PapisResultsFiles", "force_space" },
350+
{ "notes", { "󰆈 ", "N " }, "PapisResultsNotes", "force_space" },
337351
{ "author", "%s ", "PapisResultsAuthor" },
338352
{ "year", "(%s) ", "PapisResultsYear" },
339353
{ "title", "%s", "PapisResultsTitle" },

lua/papis/colors.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ local links = {
1111
PreviewAuthor = "Title",
1212
PreviewYear = "@string",
1313
PreviewTitle = "@variable",
14-
PreviewKey = "@string",
14+
PreviewKey = "@property",
1515
PreviewValue = "@variable",
1616
PopupAuthor = "Title",
1717
PopupYear = "@string",
1818
PopupTitle = "@variable",
19-
ResultsAuthor = "@tag",
19+
ResultsAuthor = "Title",
2020
ResultsYear = "@string",
2121
ResultsTitle = "@variable",
22+
ResultsFiles = "@property",
23+
ResultsNotes = "@comment.warning",
2224
}
2325

2426
---Sets up all the default highlight groups

lua/papis/config.lua

+14-13
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ local default_config = {
6767
end,
6868
init_filetypes = { "markdown", "norg", "yaml" },
6969
papis_conf_keys = { "info-name", "notes-name", "dir", "opentool" },
70+
enable_icons = true,
7071
["formatter"] = {
7172
format_notes_fn = function(entry)
7273
local title_format = {
@@ -115,22 +116,22 @@ local default_config = {
115116
initial_sort_by_time_added = true,
116117
search_keys = { "author", "editor", "year", "title", "tags" }, -- also possible: "type"
117118
preview_format = {
118-
{ "author", "%s", "PapisPreviewAuthor" },
119-
{ "year", "%s", "PapisPreviewYear" },
120-
{ "title", "%s", "PapisPreviewTitle" },
119+
{ "author", "%s", "PapisPreviewAuthor" },
120+
{ "year", "%s", "PapisPreviewYear" },
121+
{ "title", "%s", "PapisPreviewTitle" },
121122
{ "empty_line" },
122-
{ "ref", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
123-
{ "type", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
124-
{ "tags", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
125-
{ "files", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
126-
{ "notes", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
127-
{ "journal", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
128-
{ "abstract", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
123+
{ "journal", "%s", "PapisPreviewValue", "show_key", { "󱀁 ", "%s: " }, "PapisPreviewKey" },
124+
{ "type", "%s", "PapisPreviewValue", "show_key", { "", "%s: " }, "PapisPreviewKey" },
125+
{ "ref", "%s", "PapisPreviewValue", "show_key", { "", "%s: " }, "PapisPreviewKey" },
126+
{ "tags", "%s", "PapisPreviewValue", "show_key", { "", "%s: " }, "PapisPreviewKey" },
127+
{ "abstract", "%s", "PapisPreviewValue", "show_key", { "󰭷 ", "%s: " }, "PapisPreviewKey" },
129128
},
130129
results_format = {
131-
{ "author", "%s ", "PapisResultsAuthor" },
132-
{ "year", "(%s) ", "PapisResultsYear" },
133-
{ "title", "%s", "PapisResultsTitle" },
130+
{ "files", { "", "F " }, "PapisResultsFiles", "force_space" },
131+
{ "notes", { "󰆈 ", "N " }, "PapisResultsNotes", "force_space" },
132+
{ "author", "%s ", "PapisResultsAuthor" },
133+
{ "year", "(%s) ", "PapisResultsYear" },
134+
{ "title", "%s", "PapisResultsTitle" },
134135
},
135136
},
136137
["papis-storage"] = {

lua/papis/utils.lua

+29-5
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,35 @@ end
224224
---@param remove_editor_if_author boolean? #If true we don't add the editor if the entry has an author
225225
---@return table #Same format as `format_table` but with k = v pairs removed
226226
function M.do_clean_format_tbl(format_table, entry, remove_editor_if_author)
227+
local enable_icons = require("papis.config")["enable_icons"]
227228
local clean_format_table = {}
228229
for _, v in ipairs(format_table) do
230+
local f = vim.deepcopy(v) -- TODO: check if deepcopy necessary
229231
-- add entry value if either there's an entry value corresponding to the value in the
230232
-- format table or the value in the format table is "empty_line"
231-
if entry[v[1]] or v[1] == "empty_line" then
232-
table.insert(clean_format_table, v)
233+
if entry[f[1]] or f[1] == "empty_line" then
234+
table.insert(clean_format_table, f)
233235
-- don't add editor if there is author and use_author_if_editor is true
234-
elseif remove_editor_if_author and v[1] == "author" and entry["editor"] then
235-
table.insert(clean_format_table, v)
236+
elseif remove_editor_if_author and f[1] == "author" and entry["editor"] then
237+
table.insert(clean_format_table, f)
238+
-- add empty space if space is forced but the element doesn't exist for entry
239+
elseif f[4] == "force_space" then
240+
f[2] = " " -- TODO: this only works for icons, hardcoded because luajit doesn't support utf8.len
241+
table.insert(clean_format_table, f)
242+
end
243+
if type(f[2]) == "table" then
244+
if enable_icons then
245+
f[2] = f[2][1]
246+
else
247+
f[2] = f[2][2]
248+
end
249+
end
250+
if type(f[5]) == "table" then
251+
if enable_icons then
252+
f[5] = f[5][1]
253+
else
254+
f[5] = f[5][2]
255+
end
236256
end
237257
end
238258
return clean_format_table
@@ -370,7 +390,11 @@ function M:format_display_strings(entry, format_table, use_shortitle)
370390
local shortitle = entry["title"]:match("([^:]+)")
371391
table.insert(str_elements, shortitle)
372392
else
373-
table.insert(str_elements, entry[v[1]])
393+
if entry[v[1]] then
394+
table.insert(str_elements, entry[v[1]])
395+
elseif v[4] == "force_space" then
396+
table.insert(str_elements, "dummy")
397+
end
374398
end
375399
end
376400

0 commit comments

Comments
 (0)