Skip to content

Commit

Permalink
feat!: add pretty icons
Browse files Browse the repository at this point in the history
  • Loading branch information
jghauser committed Jun 18, 2024
1 parent 44dc0c3 commit f14ce7d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 30 deletions.
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ Note that fiddling with the plugin's options can leave the database in a messy s

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.

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).
To run, papis.nvim requires:
- [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).
- sqlite3: Needed by the `sqlite.lua` dependency.

Optionally, you'll need:
- [a font with icons](https://github.com/ryanoasis/nerd-fonts#font-installation) for increased prettiness. You can set

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

### Neovim package managers

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

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

Additionally, may want to install `telescope` (for search) and `cmp` (for completion).

</details>

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

-- Whether to enable pretty icons (requires something like nerd font)
enable_icons = true,

-- Configuration of the search module.
["search"] = {

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

-- The format of each line in the the results window. Here, everything is show on
-- one line (otherwise equivalent to points 1-3 of `preview_format`).
-- one line (otherwise equivalent to points 1-3 of `preview_format`). The `force_space`
-- value is used to force whitespace for icons (so that if e.g. a file is absent, it will
-- show " ", ensuring that columns are aligned.)
results_format = {
{ "files", { "", "F " }, "PapisResultsFiles", "force_space" },
{ "notes", { "󰆈 ", "N " }, "PapisResultsNotes", "force_space" },
{ "author", "%s ", "PapisResultsAuthor" },
{ "year", "(%s) ", "PapisResultsYear" },
{ "title", "%s", "PapisResultsTitle" },
Expand Down
6 changes: 4 additions & 2 deletions lua/papis/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ local links = {
PreviewAuthor = "Title",
PreviewYear = "@string",
PreviewTitle = "@variable",
PreviewKey = "@string",
PreviewKey = "@property",
PreviewValue = "@variable",
PopupAuthor = "Title",
PopupYear = "@string",
PopupTitle = "@variable",
ResultsAuthor = "@tag",
ResultsAuthor = "Title",
ResultsYear = "@string",
ResultsTitle = "@variable",
ResultsFiles = "@property",
ResultsNotes = "@comment.warning",
}

---Sets up all the default highlight groups
Expand Down
27 changes: 14 additions & 13 deletions lua/papis/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ local default_config = {
end,
init_filetypes = { "markdown", "norg", "yaml" },
papis_conf_keys = { "info-name", "notes-name", "dir", "opentool" },
enable_icons = true,
["formatter"] = {
format_notes_fn = function(entry)
local title_format = {
Expand Down Expand Up @@ -115,22 +116,22 @@ local default_config = {
initial_sort_by_time_added = true,
search_keys = { "author", "editor", "year", "title", "tags" }, -- also possible: "type"
preview_format = {
{ "author", "%s", "PapisPreviewAuthor" },
{ "year", "%s", "PapisPreviewYear" },
{ "title", "%s", "PapisPreviewTitle" },
{ "author", "%s", "PapisPreviewAuthor" },
{ "year", "%s", "PapisPreviewYear" },
{ "title", "%s", "PapisPreviewTitle" },
{ "empty_line" },
{ "ref", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
{ "type", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
{ "tags", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
{ "files", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
{ "notes", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
{ "journal", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
{ "abstract", "%s", "PapisPreviewValue", "show_key", "%s: ", "PapisPreviewKey" },
{ "journal", "%s", "PapisPreviewValue", "show_key", { "󱀁 ", "%s: " }, "PapisPreviewKey" },
{ "type", "%s", "PapisPreviewValue", "show_key", { "", "%s: " }, "PapisPreviewKey" },
{ "ref", "%s", "PapisPreviewValue", "show_key", { "", "%s: " }, "PapisPreviewKey" },
{ "tags", "%s", "PapisPreviewValue", "show_key", { "", "%s: " }, "PapisPreviewKey" },
{ "abstract", "%s", "PapisPreviewValue", "show_key", { "󰭷 ", "%s: " }, "PapisPreviewKey" },
},
results_format = {
{ "author", "%s ", "PapisResultsAuthor" },
{ "year", "(%s) ", "PapisResultsYear" },
{ "title", "%s", "PapisResultsTitle" },
{ "files", { "", "F " }, "PapisResultsFiles", "force_space" },
{ "notes", { "󰆈 ", "N " }, "PapisResultsNotes", "force_space" },
{ "author", "%s ", "PapisResultsAuthor" },
{ "year", "(%s) ", "PapisResultsYear" },
{ "title", "%s", "PapisResultsTitle" },
},
},
["papis-storage"] = {
Expand Down
34 changes: 29 additions & 5 deletions lua/papis/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,35 @@ end
---@param remove_editor_if_author boolean? #If true we don't add the editor if the entry has an author
---@return table #Same format as `format_table` but with k = v pairs removed
function M.do_clean_format_tbl(format_table, entry, remove_editor_if_author)
local enable_icons = require("papis.config")["enable_icons"]
local clean_format_table = {}
for _, v in ipairs(format_table) do
local f = vim.deepcopy(v) -- TODO: check if deepcopy necessary
-- add entry value if either there's an entry value corresponding to the value in the
-- format table or the value in the format table is "empty_line"
if entry[v[1]] or v[1] == "empty_line" then
table.insert(clean_format_table, v)
if entry[f[1]] or f[1] == "empty_line" then
table.insert(clean_format_table, f)
-- don't add editor if there is author and use_author_if_editor is true
elseif remove_editor_if_author and v[1] == "author" and entry["editor"] then
table.insert(clean_format_table, v)
elseif remove_editor_if_author and f[1] == "author" and entry["editor"] then
table.insert(clean_format_table, f)
-- add empty space if space is forced but the element doesn't exist for entry
elseif f[4] == "force_space" then
f[2] = " " -- TODO: this only works for icons, hardcoded because luajit doesn't support utf8.len
table.insert(clean_format_table, f)
end
if type(f[2]) == "table" then
if enable_icons then
f[2] = f[2][1]
else
f[2] = f[2][2]
end
end
if type(f[5]) == "table" then
if enable_icons then
f[5] = f[5][1]
else
f[5] = f[5][2]
end
end
end
return clean_format_table
Expand Down Expand Up @@ -370,7 +390,11 @@ function M:format_display_strings(entry, format_table, use_shortitle)
local shortitle = entry["title"]:match("([^:]+)")
table.insert(str_elements, shortitle)
else
table.insert(str_elements, entry[v[1]])
if entry[v[1]] then
table.insert(str_elements, entry[v[1]])
elseif v[4] == "force_space" then
table.insert(str_elements, "dummy")
end
end
end

Expand Down

0 comments on commit f14ce7d

Please sign in to comment.