@@ -4,14 +4,13 @@ local M = {
44 },
55}
66
7- local flatdb = require " feed.db"
87local config = require " feed.config"
8+ local db = require (" feed.db" ).db (config .db_dir )
99local ut = require " feed.utils"
10- local db = flatdb .db (config .db_dir )
1110local format = require " feed.format"
1211
1312--- @return feed.entry
14- function M .current_entry ()
13+ function M .get_entry_under_cursor ()
1514 local row = vim .api .nvim_win_get_cursor (0 )[1 ]
1615 return db .index [row - 1 ]
1716end
5049function M .prepare_bufs (cmds )
5150 M .buf = {
5251 index = vim .api .nvim_create_buf (false , true ),
53- entry = {} ,
52+ entry = vim . api . nvim_create_buf ( false , true ) ,
5453 }
55- for i = 1 , 3 do
56- M .buf .entry [i ] = vim .api .nvim_create_buf (false , true )
57- for rhs , lhs in pairs (config .keymaps .entry ) do
58- ut .push_keymap (M .buf .entry [i ], lhs , cmds [rhs ], rhs )
59- end
54+ for rhs , lhs in pairs (config .keymaps .entry ) do
55+ ut .push_keymap (M .buf .entry , lhs , cmds [rhs ], rhs )
6056 end
6157 for rhs , lhs in pairs (config .keymaps .index ) do
6258 ut .push_keymap (M .buf .index , lhs , cmds [rhs ], rhs )
6561
6662--- render whole db as flat list
6763function M .show_index ()
68- if ut .check_command " ZenMode" then
69- vim .cmd " ZenMode"
70- end
7164 db :update_index ()
7265 local lines = {}
7366 lines [1 ] = M .show_hint ()
7467 for i , entry in ipairs (db .index ) do
7568 lines [i + 1 ] = format .entry_name (entry )
7669 end
7770 M .show (lines , M .buf .index , ut .highlight_index )
78- M .state .rendered_once = true
71+ M .state .index_rendered = true
7972end
8073
81- --- @param index integer
82- function M .show_entry (index )
83- local entry = M .get_entry (index )
84- M .show (format .entry (entry , db :get (entry )), M .buf .entry [2 ], ut .highlight_entry )
74+ local function apply_formatter (buf )
8575 local ok , conform = pcall (require , " conform" )
8676 if ok then
87- vim .api .nvim_set_option_value (" modifiable" , true , { buf = M . buf . entry [ 2 ] })
88- conform .format { bufnr = M . buf . entry [ 2 ] }
89- vim .api .nvim_set_option_value (" modifiable" , false , { buf = M . buf . entry [ 2 ] })
77+ vim .api .nvim_set_option_value (" modifiable" , true , { buf = buf })
78+ conform .format { bufnr = buf }
79+ vim .api .nvim_set_option_value (" modifiable" , false , { buf = buf })
9080 end
81+ end
82+
83+ --- @param index integer
84+ function M .show_entry (index )
85+ local entry = M .get_entry (index )
86+ M .show (format .entry (entry , db :get (entry )), M .buf .entry , ut .highlight_entry )
87+ apply_formatter (M .buf .entry )
9188 entry .tags .unread = nil
9289 db :save ()
9390end
0 commit comments