A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/neovim/neovim/commit/71ac00ccb523383411b907b5fdf00a376e24a6f0 below:

add nvim_get_option_value · neovim/neovim@71ac00c · GitHub

@@ -133,107 +133,18 @@ do -- window option accessor

133 133

vim.wo = new_win_opt_accessor(nil)

134 134

end

135 135 136 -

--[[

137 -

Local window setter

138 - 139 -

buffer options: does not get copied when split

140 -

nvim_set_option(buf_opt, value) -> sets the default for NEW buffers

141 -

this sets the hidden global default for buffer options

142 - 143 -

nvim_buf_set_option(...) -> sets the local value for the buffer

144 - 145 -

set opt=value, does BOTH global default AND buffer local value

146 -

setlocal opt=value, does ONLY buffer local value

147 - 148 -

window options: gets copied

149 -

does not need to call nvim_set_option because nobody knows what the heck this does⸮

150 -

We call it anyway for more readable code.

151 - 152 - 153 -

Command global value local value

154 -

:set option=value set set

155 -

:setlocal option=value - set

156 -

:setglobal option=value set -

157 -

--]]

158 -

local function set_scoped_option(k, v, set_type)

159 -

local info = options_info[k]

160 - 161 -

-- Don't let people do setlocal with global options.

162 -

-- That is a feature that doesn't make sense.

163 -

if set_type == SET_TYPES.LOCAL and is_global_option(info) then

164 -

error(string.format("Unable to setlocal option: '%s', which is a global option.", k))

165 -

end

166 - 167 -

-- Only `setlocal` skips setting the default/global value

168 -

-- This will more-or-less noop for window options, but that's OK

169 -

if set_type ~= SET_TYPES.LOCAL then

170 -

a.nvim_set_option(k, v)

171 -

end

172 - 173 -

if is_window_option(info) then

174 -

if set_type ~= SET_TYPES.GLOBAL then

175 -

a.nvim_win_set_option(0, k, v)

176 -

end

177 -

elseif is_buffer_option(info) then

178 -

if set_type == SET_TYPES.LOCAL

179 -

or (set_type == SET_TYPES.SET and not info.global_local) then

180 -

a.nvim_buf_set_option(0, k, v)

181 -

end

182 -

end

183 -

end

184 - 185 -

--[[

186 -

Local window getter

187 - 188 -

Command global value local value

189 -

:set option? - display

190 -

:setlocal option? - display

191 -

:setglobal option? display -

192 -

--]]

193 -

local function get_scoped_option(k, set_type)

194 -

local info = assert(options_info[k], "Must be a valid option: " .. tostring(k))

195 - 196 -

if set_type == SET_TYPES.GLOBAL or is_global_option(info) then

197 -

return a.nvim_get_option(k)

198 -

end

199 - 200 -

if is_buffer_option(info) then

201 -

local was_set, value = pcall(a.nvim_buf_get_option, 0, k)

202 -

if was_set then return value end

203 - 204 -

if info.global_local then

205 -

return a.nvim_get_option(k)

206 -

end

207 - 208 -

error("buf_get: This should not be able to happen, given my understanding of options // " .. k)

209 -

end

210 - 211 -

if is_window_option(info) then

212 -

local ok, value = pcall(a.nvim_win_get_option, 0, k)

213 -

if ok then

214 -

return value

215 -

end

216 - 217 -

local global_ok, global_val = pcall(a.nvim_get_option, k)

218 -

if global_ok then

219 -

return global_val

220 -

end

221 - 222 -

error("win_get: This should never happen. File an issue and tag @tjdevries")

223 -

end

224 - 225 -

error("This fallback case should not be possible. " .. k)

226 -

end

227 - 228 136

-- vim global option

229 137

-- this ONLY sets the global option. like `setglobal`

230 -

vim.go = make_meta_accessor(a.nvim_get_option, a.nvim_set_option)

138 +

vim.go = make_meta_accessor(

139 +

function(k) return a.nvim_get_option_value(k, {scope = "global"}) end,

140 +

function(k, v) return a.nvim_set_option_value(k, v, {scope = "global"}) end

141 +

)

231 142 232 143

-- vim `set` style options.

233 144

-- it has no additional metamethod magic.

234 145

vim.o = make_meta_accessor(

235 -

function(k) return get_scoped_option(k, SET_TYPES.SET) end,

236 -

function(k, v) return set_scoped_option(k, v, SET_TYPES.SET) end

146 +

function(k) return a.nvim_get_option_value(k, {}) end,

147 +

function(k, v) return a.nvim_set_option_value(k, v, {}) end

237 148

)

238 149 239 150

---@brief [[

@@ -389,6 +300,10 @@ local convert_value_to_vim = (function()

389 300

}

390 301 391 302

return function(name, info, value)

303 +

if value == nil then

304 +

return vim.NIL

305 +

end

306 + 392 307

local option_type = get_option_type(name, info)

393 308

assert_valid_value(name, value, valid_types[option_type])

394 309

@@ -671,15 +586,19 @@ local create_option_metatable = function(set_type)

671 586

}, option_mt)

672 587

end

673 588 674 -

-- TODO(tjdevries): consider supporting `nil` for set to remove the local option.

675 -

-- vim.cmd [[set option<]]

589 +

local scope

590 +

if set_type == SET_TYPES.GLOBAL then

591 +

scope = "global"

592 +

elseif set_type == SET_TYPES.LOCAL then

593 +

scope = "local"

594 +

end

676 595 677 596

option_mt = {

678 597

-- To set a value, instead use:

679 598

-- opt[my_option] = value

680 599

_set = function(self)

681 600

local value = convert_value_to_vim(self._name, self._info, self._value)

682 -

set_scoped_option(self._name, value, set_type)

601 +

a.nvim_set_option_value(self._name, value, {scope = scope})

683 602 684 603

return self

685 604

end,

@@ -716,7 +635,7 @@ local create_option_metatable = function(set_type)

716 635 717 636

set_mt = {

718 637

__index = function(_, k)

719 -

return make_option(k, get_scoped_option(k, set_type))

638 +

return make_option(k, a.nvim_get_option_value(k, {scope = scope}))

720 639

end,

721 640 722 641

__newindex = function(_, k, v)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4