Skip to content

Commit 4eeb7bc

Browse files
author
jghauser
committed
feat(at-cursor)!: add icon to at-cursor popup
- also refactors the formatting of strings
1 parent c73fa2f commit 4eeb7bc

File tree

6 files changed

+181
-140
lines changed

6 files changed

+181
-140
lines changed

README.md

+23-8
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,15 @@ enable_icons = true,
314314
-- What keys to search for matches.
315315
search_keys = { "author", "editor", "year", "title", "tags" },
316316

317-
-- The format for the previewer. Each line in the config represents a line in
318-
-- the preview. For each line, we define:
317+
-- Papis.nvim uses a common configuration format for defining the formatting
318+
-- of strings. Sometimes -- as for instance in the below `preview_format` option --
319+
-- we define a set of lines. At other times -- as for instance in the `results_format`
320+
-- option -- we define a single line. Sets of lines are composed of single lines.
321+
-- A line can be composed of either a single element or multiple elements. The below
322+
-- `preview_format` shows an example where each line is defined by a table with just
323+
-- one element. The `results_format` and `popup_format` are examples where (some) of
324+
-- the lines contain multiple elements (and are represented by a table of tables).
325+
-- Each element contains:
319326
-- 1. The key whose value is shown
320327
-- 2. How it is formatted (here, each is just given as is)
321328
-- 3. The highlight group
@@ -324,10 +331,10 @@ enable_icons = true,
324331
-- formatting of the key and its highlight group. The key is shown *before*
325332
-- the value in the preview (even though it is defined after it in this
326333
-- configuration (e.g. `title = Critique of Pure Reason`)).
327-
-- `empty_line` is used to insert an empty line
334+
-- An element may also just contain `empty_line`. This is used to insert an empty line
328335
-- Strings that define the formatting (such as in 2. and 4. above) can optionally
329-
-- be a table, defining, first, an icon, and second, a non-icon version. What is
330-
-- used is defined by the `enable_icons` option.
336+
-- be a table, defining, first, an icon, and second, a non-icon version. The
337+
-- `enable_icons` option determines what is used.
331338
preview_format = {
332339
{ "author", "%s", "PapisPreviewAuthor" },
333340
{ "year", "%s", "PapisPreviewYear" },
@@ -357,10 +364,18 @@ enable_icons = true,
357364
["at-cursor"] = {
358365

359366
-- The format of the popup shown on `:Papis at-cursor show-popup` (equivalent to points 1-3
360-
-- of `preview_format`)
367+
-- of `preview_format`). Note that one of the lines is composed of multiple elements. Note
368+
-- also the `{ "vspace", "vspace" },` line which is exclusive to `popup_format` and which tells
369+
-- papis.nvim to fill the space between the previous and next element with whitespace (and
370+
-- in effect make whatever comes after right-aligned). It can only occur once in a line.
361371
popup_format = {
362-
{ "author", "%s", "PapisPopupAuthor" },
363-
{ "year", "%s", "PapisPopupYear" },
372+
{
373+
{ "author", "%s", "PapisPopupAuthor" },
374+
{ "vspace", "vspace" },
375+
{ "files", { "", "F " }, "PapisResultsFiles" },
376+
{ "notes", { "󰆈 ", "N " }, "PapisResultsNotes" },
377+
},
378+
{ "year", "%s", "PapisPopupYear" },
364379
{ "title", "%s", "PapisPopupTitle" },
365380
},
366381
},

lua/papis/at-cursor/init.lua

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ local db = require("papis.sqlite-wrapper")
2121
if not db then
2222
return nil
2323
end
24-
local hover_required_db_keys = utils:get_required_db_keys({ popup_format })
2524

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

7977
local popup = NuiPopup({
8078
position = 1,

lua/papis/config.lua

+9-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ local default_config = {
3737
editor = "text",
3838
year = "text",
3939
title = "text",
40+
shorttitle = "text",
4041
type = "text",
4142
abstract = "text",
4243
time_added = "text",
@@ -105,9 +106,14 @@ local default_config = {
105106
},
106107
["at-cursor"] = {
107108
popup_format = {
108-
{ "author", "%s", "PapisPopupAuthor" },
109-
{ "year", "%s", "PapisPopupYear" },
110-
{ "title", "%s", "PapisPopupTitle" },
109+
{
110+
{ "author", "%s", "PapisPopupAuthor" },
111+
{ "vspace", "vspace" },
112+
{ "files", { "", "F " }, "PapisResultsFiles" },
113+
{ "notes", { "󰆈 ", "N " }, "PapisResultsNotes" },
114+
},
115+
{ "year", "%s", "PapisPopupYear" },
116+
{ "title", "%s", "PapisPopupTitle" },
111117
},
112118
},
113119
["search"] = {

lua/papis/search/data.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ local function init_tbl()
101101
local entry = db["data"]:__get({
102102
where = { id = id }
103103
})[1]
104-
local display_strings = utils:format_display_strings(entry, results_format)
104+
local display_strings = utils:format_display_strings(entry, results_format, false, true)
105105
local search_string = format_search_string(entry)
106106

107107
local items = {}

0 commit comments

Comments
 (0)