1- --- TODO: lazy load these ...
21local config = require " feed.config"
3- local fetch = require " feed.fetch"
4- local render = require " feed.render"
52local ut = require " feed.utils"
6- local db = require (" feed.db" ).db (config .db_dir )
73
84-- IDEAS:
95-- show random entry
@@ -20,46 +16,19 @@ local cmds = {}
2016-- 6. tag / untag: save to db
2117-- 7. show: its a better name lol
2218
23- cmds .load_opml = {
24- --- load opml file to list of sources
25- --- @param file string
26- impl = function (file )
27- local feedparser = require " feed.feedparser"
28- local feeds = feedparser .parse (file , { type = " opml" })
29- for _ , feed in ipairs (feeds ) do
30- local title = feed .title
31- local xmlUrl = feed .xmlUrl
32- table.insert (config .feeds , { xmlUrl , name = title })
33- end
34- end ,
35- complete = function (lead )
36- local tab = { " abc" , " efg" , " hijk" }
37- return vim .iter (tab ):filter (function (t )
38- return t :find (lead ) ~= nil
39- end )
40- end ,
41- }
42-
43- local function Fee (opts )
44- local fargs = opts .fargs
45- local sub_key = table.remove (fargs , 1 )
46- local sub_cmd = cmds [sub_key ]
47- if not sub_cmd then
48- vim .notify (" Feed: Unknown command: " .. sub_key , vim .log .levels .ERROR )
49- end
50- sub_cmd .impl (fargs , opts )
19+ --- load opml file to list of sources
20+ --- @param filepath string
21+ function cmds .load_opml (filepath )
22+ local opml = require " feed.opml"
23+ local outlines = opml .import (filepath ).outline
24+ local index_opml = opml .import (config .opml )
25+ vim .list_extend (index_opml .outline , outlines )
26+ index_opml :export (config .opml )
5127end
5228
53- vim .api .nvim_create_user_command (" Fee" , Fee , {
54- nargs = " +" ,
55- desc = " Feed comp test" ,
56- complete = function (arg_lead , cmdline , _ )
57- print (arg_lead )
58- end ,
59- })
60-
6129--- index buffer commands
6230function cmds .show_in_browser ()
31+ local render = require " feed.render"
6332 vim .ui .open (render .current_entry ().link )
6433end
6534
@@ -72,41 +41,48 @@ function cmds.show_in_w3m()
7241end
7342
7443local function current_index ()
44+ local render = require " feed.render"
7545 local index = vim .api .nvim_win_get_cursor (0 )[1 ] - 1
7646 render .current_index = index
7747 return index
7848end
7949
8050function cmds .show_in_split ()
51+ local render = require " feed.render"
8152 render .state .in_split = true
8253 vim .cmd (config .split )
8354 vim .cmd (config .split :find " v" and " wincmd k" or " wincmd j" )
8455 render .show_entry (current_index ())
8556end
8657
8758function cmds .show_entry ()
59+ local render = require " feed.render"
8860 render .state .in_entry = true
8961 render .show_entry (current_index ())
9062end
9163
9264function cmds .link_to_clipboard ()
65+ local render = require " feed.render"
9366 vim .fn .setreg (" +" , render .current_entry ().link )
9467end
9568
9669function cmds .tag ()
70+ local render = require " feed.render"
9771 local input = vim .fn .input " Tag: "
9872 render .current_entry ().tags [input ] = true
9973 -- db:save() -- TODO: do it on exit / or only if ":w" , make an option
10074 render .show_index () -- TODO: inefficient??, only rerender the one entry
10175end
10276
10377function cmds .untag ()
78+ local render = require " feed.render"
10479 local input = vim .fn .input " Untag: "
10580 render .current_entry ().tags [input ] = nil
10681 render .show_index ()
10782end
10883
10984function cmds .quit_index ()
85+ local render = require " feed.render"
11086 -- TODO: jump to the buffer before the index
11187 --- TODO: check if in index
11288 if ut .check_command " ZenMode" then
11995
12096--- entry buffer actions
12197function cmds .show_index ()
98+ local render = require " feed.render"
99+ config .og_colorscheme = vim .g .colors_name
122100 if not render .state .in_entry then
123101 if not render .buf .index then
124102 print " reerer"
@@ -138,6 +116,7 @@ function cmds.show_index()
138116end
139117
140118function cmds .show_next ()
119+ local render = require " feed.render"
141120 if render .current_index == # db .index then
142121 return
143122 end
147126
148127-- TODO: properly do 'ring' navigation, ie. wrap around
149128function cmds .show_prev ()
129+ local render = require " feed.render"
150130 if render .current_index == 1 then
151131 return
152132 end
@@ -159,7 +139,9 @@ function cmds.list_feeds()
159139end
160140
161141function cmds .update ()
162- config .opml_t = require (" feed.opml" ).import (config .opml )
142+ local db = require (" feed.db" ).db (config .db_dir )
143+ local fetch = require " feed.fetch"
144+ local opml = require (" feed.opml" ).import (config .opml )
163145 local ok , progress = pcall (require , " fidget.progress" )
164146 local handle
165147 if not ok then
@@ -172,8 +154,8 @@ function cmds.update()
172154 }
173155 end
174156
175- if config . opml_t then
176- config .feeds = vim .list_extend (config .feeds , config . opml_t .outline ) -- TODO: remove duplicates ...
157+ if opml then
158+ config .feeds = vim .list_extend (config .feeds , opml .outline ) -- TODO: remove duplicates ...
177159 end
178160
179161 for _ , link in ipairs (config .feeds ) do
@@ -209,23 +191,15 @@ end
209191
210192--- @param args string[]
211193local function load_command (args )
212- Pr (args )
213194 local cmd = table.remove (args , 1 )
214- return cmds [cmd ](unpack (args ))
195+ if type (cmds [cmd ]) == " table" then
196+ return cmds [cmd ].impl (unpack (args ))
197+ elseif type (cmds [cmd ]) == " function" then
198+ return cmds [cmd ](unpack (args ))
199+ end
215200end
216201
217- local popup = require " plenary.popup"
218-
219202return {
220203 load_command = load_command ,
221204 cmds = cmds ,
222205}
223-
224- -- vim.api.nvim_create_autocmd("VimLeavePre", {
225- -- pattern = "*.md",
226- -- callback = function()
227- -- print "leave!"
228- -- db:save()
229- -- -- autocmds.update()
230- -- end,
231- -- })
0 commit comments