1
1
-- module represents a lua module for the plugin
2
2
local types = require (" types" )
3
- local carbon = {}
3
+ local Carbon = {}
4
4
5
5
-- map some known filetypes to carbon.now.sh supported languages
6
6
--- list of supported languages: https://github.com/carbon-app/carbon/blob/2cbdcd0cc23d2d2f23736dd3cfbe94134b141191/lib/constants.js#L624-L1048
@@ -11,7 +11,7 @@ local language_map = {
11
11
12
12
-- default config
13
13
--- @type cn.ConfigSchema
14
- carbon .config = {
14
+ Carbon .config = {
15
15
base_url = " https://carbon.now.sh/" ,
16
16
open_cmd = " xdg-open" ,
17
17
options = {
@@ -28,6 +28,8 @@ carbon.config = {
28
28
watermark = false ,
29
29
width = " 680" ,
30
30
window_theme = types .WindowThemes .sharp ,
31
+ padding_horizontal = " 0px" ,
32
+ padding_vertical = " 0px" ,
31
33
},
32
34
}
33
35
68
70
--- @nodiscard
69
71
--- validate config param values and create the query params table
70
72
local function get_carbon_now_snapshot_uri (code )
71
- local opts = carbon .config .options
73
+ local opts = Carbon .config .options
72
74
local ft = vim .bo .filetype
73
75
74
76
-- carbon.now.sh parameters
@@ -87,6 +89,8 @@ local function get_carbon_now_snapshot_uri(code)
87
89
wm = opts .watermark ,
88
90
tb = opts .titlebar ,
89
91
code = code ,
92
+ pv = opts .padding_vertical ,
93
+ ph = opts .padding_horizontal ,
90
94
}
91
95
92
96
return encode_params (params )
98
102
--- available an exception will be raised.
99
103
local function get_open_command ()
100
104
-- default launcher
101
- if vim .fn .executable (carbon .config .open_cmd ) then
102
- return carbon .config .open_cmd
105
+ if vim .fn .executable (Carbon .config .open_cmd ) then
106
+ return Carbon .config .open_cmd
103
107
end
104
108
105
109
-- alternative launcher
@@ -127,12 +131,12 @@ local function create_snapshot(opts)
127
131
-- create Uri
128
132
if opts .args ~= " " then
129
133
query_params = get_carbon_now_snapshot_uri ()
130
- url = carbon .config .base_url .. " /" .. opts .args .. " ?" .. query_params
134
+ url = Carbon .config .base_url .. " /" .. opts .args .. " ?" .. query_params
131
135
else
132
136
local range = vim .api .nvim_buf_get_lines (0 , opts .line1 - 1 , opts .line2 , false )
133
137
local code = table.concat (range , " \n " , 1 , # range )
134
138
query_params = get_carbon_now_snapshot_uri (code )
135
- url = carbon .config .base_url .. " ?" .. query_params
139
+ url = Carbon .config .base_url .. " ?" .. query_params
136
140
end
137
141
138
142
-- launch the Uri
149
153
150
154
--- initialization function for the carbon plugin commands
151
155
--- @param params cn.ConfigSchema ?
152
- carbon .setup = function (params )
153
- carbon .config = vim .tbl_deep_extend (" force" , {}, carbon .config , params or {})
156
+ Carbon .setup = function (params )
157
+ Carbon .config = vim .tbl_deep_extend (" force" , {}, Carbon .config , params or {})
154
158
create_commands ()
155
159
end
156
160
157
- return carbon
161
+ return Carbon
0 commit comments