File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ # Cache Colorscheme
2+
3+ ** Website:** < https://docs.astronvim.com/recipes/colorscheme/#cache-colorscheme >
4+
5+ This plugin specification caches the last chosen colorscheme by the user to persist colorscheme changes without modifying user configuration.
Original file line number Diff line number Diff line change 1+ -- pick a location to cache colorscheme
2+ local colorscheme_cache = vim .fs .joinpath (vim .fn .stdpath " state" --[[ @as string]] , " last_colorscheme" )
3+
4+ --- Execute function with open file
5+ --- @param file string path to file to interact with
6+ --- @param mode openmode the mode in which to open the file
7+ --- @param callback fun ( fd : file* ) the callback to execute with the opened file
8+ --- @param on_error ? fun ( err : string ) the callback to execute if unable to open the file
9+ local function with_file (file , mode , callback , on_error )
10+ local fd , errmsg = io.open (file , mode )
11+ if fd then
12+ callback (fd )
13+ fd :close ()
14+ elseif errmsg and on_error then
15+ on_error (errmsg )
16+ end
17+ end
18+
19+ return {
20+ {
21+ " AstroNvim/astroui" ,
22+ -- @param opts AstroUIOpts
23+ opts = function (_ , opts )
24+ -- read colorscheme cache on open
25+ with_file (colorscheme_cache , " r" , function (file ) opts .colorscheme = file :read " *a" end )
26+ end ,
27+ },
28+ {
29+ " AstroNvim/astrocore" ,
30+ --- @type AstroCoreOpts
31+ opts = {
32+ autocmds = {
33+ -- save colorscheme to cache on change
34+ cache_colorscheme = {
35+ {
36+ event = " ColorScheme" ,
37+ callback = function (args )
38+ if args .match then with_file (colorscheme_cache , " w+" , function (file ) file :write (args .match ) end ) end
39+ end ,
40+ },
41+ },
42+ },
43+ },
44+ },
45+ }
You can’t perform that action at this time.
0 commit comments