Skip to content

Commit

Permalink
feat(at-cursor)!: add icon to at-cursor popup
Browse files Browse the repository at this point in the history
- also refactors the formatting of strings
  • Loading branch information
jghauser committed Jun 19, 2024
1 parent 359fef2 commit 9da554d
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 140 deletions.
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,15 @@ enable_icons = true,
-- What keys to search for matches.
search_keys = { "author", "editor", "year", "title", "tags" },

-- The format for the previewer. Each line in the config represents a line in
-- the preview. For each line, we define:
-- Papis.nvim uses a common configuration format for defining the formatting
-- of strings. Sometimes -- as for instance in the below `preview_format` option --
-- we define a set of lines. At other times -- as for instance in the `results_format`
-- option -- we define a single line. Sets of lines are composed of single lines.
-- A line can be composed of either a single element or multiple elements. The below
-- `preview_format` shows an example where each line is defined by a table with just
-- one element. The `results_format` and `popup_format` are examples where (some) of
-- the lines contain multiple elements (and are represented by a table of tables).
-- Each element contains:
-- 1. The key whose value is shown
-- 2. How it is formatted (here, each is just given as is)
-- 3. The highlight group
Expand All @@ -323,10 +330,10 @@ enable_icons = true,
-- formatting of the key and its highlight group. The key is shown *before*
-- 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
-- An element may also just contain `empty_line`. This 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.
-- be a table, defining, first, an icon, and second, a non-icon version. The
-- `enable_icons` option determines what is used.
preview_format = {
{ "author", "%s", "PapisPreviewAuthor" },
{ "year", "%s", "PapisPreviewYear" },
Expand Down Expand Up @@ -356,10 +363,18 @@ enable_icons = true,
["at-cursor"] = {

-- The format of the popup shown on `:Papis at-cursor show-popup` (equivalent to points 1-3
-- of `preview_format`)
-- of `preview_format`). Note that one of the lines is composed of multiple elements. Note
-- also the `{ "vspace", "vspace" },` line which is exclusive to `popup_format` and which tells
-- papis.nvim to fill the space between the previous and next element with whitespace (and
-- in effect make whatever comes after right-aligned). It can only occur once in a line.
popup_format = {
{ "author", "%s", "PapisPopupAuthor" },
{ "year", "%s", "PapisPopupYear" },
{
{ "author", "%s", "PapisPopupAuthor" },
{ "vspace", "vspace" },
{ "files", { "", "F " }, "PapisResultsFiles" },
{ "notes", { "󰆈 ", "N " }, "PapisResultsNotes" },
},
{ "year", "%s", "PapisPopupYear" },
{ "title", "%s", "PapisPopupTitle" },
},
},
Expand Down
6 changes: 2 additions & 4 deletions lua/papis/at-cursor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ local db = require("papis.sqlite-wrapper")
if not db then
return nil
end
local hover_required_db_keys = utils:get_required_db_keys({ popup_format })

---Tries to identify the ref under cursor
---@return string|nil #Nil if nothing is found, otherwise is the identified ref
Expand Down Expand Up @@ -72,9 +71,8 @@ end
---Creates a popup with information regarding the entry specified by `ref`
---@param papis_id string #The `papis_id` of the entry
local function create_hover_popup(papis_id)
local entry = db.data:get({ papis_id = papis_id }, hover_required_db_keys)[1]
local clean_popup_format = utils.do_clean_format_tbl(popup_format, entry)
local popup_lines, width = utils.make_nui_lines(clean_popup_format, entry)
local entry = db.data:get({ papis_id = papis_id })[1]
local popup_lines, width = utils:make_nui_lines(popup_format, entry)

local popup = NuiPopup({
position = 1,
Expand Down
12 changes: 9 additions & 3 deletions lua/papis/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ local default_config = {
editor = "text",
year = "text",
title = "text",
shorttitle = "text",
type = "text",
abstract = "text",
time_added = "text",
Expand Down Expand Up @@ -105,9 +106,14 @@ local default_config = {
},
["at-cursor"] = {
popup_format = {
{ "author", "%s", "PapisPopupAuthor" },
{ "year", "%s", "PapisPopupYear" },
{ "title", "%s", "PapisPopupTitle" },
{
{ "author", "%s", "PapisPopupAuthor" },
{ "vspace", "vspace" },
{ "files", { "", "F " }, "PapisResultsFiles" },
{ "notes", { "󰆈 ", "N " }, "PapisResultsNotes" },
},
{ "year", "%s", "PapisPopupYear" },
{ "title", "%s", "PapisPopupTitle" },
},
},
["search"] = {
Expand Down
2 changes: 1 addition & 1 deletion lua/papis/search/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ local function init_tbl()
local entry = db["data"]:__get({
where = { id = id }
})[1]
local display_strings = utils:format_display_strings(entry, results_format)
local display_strings = utils:format_display_strings(entry, results_format, false, true)
local search_string = format_search_string(entry)

local items = {}
Expand Down
Loading

0 comments on commit 9da554d

Please sign in to comment.