From eb80441f498a79e46022b95b236c5bac85993d6c Mon Sep 17 00:00:00 2001
From: Bruno BELANYI <bruno@belanyi.fr>
Date: Mon, 15 Jul 2024 20:40:37 +0100
Subject: [PATCH] home: vim: numbertoggle: use lua callbacks

Use `vim.opt` because those are local options (i.e: similar to `set` it
defaults to setting it locally, `vim.opt_local` is not necessary).
---
 modules/home/vim/plugin/numbertoggle.lua | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/modules/home/vim/plugin/numbertoggle.lua b/modules/home/vim/plugin/numbertoggle.lua
index 1f97fc8..8042710 100644
--- a/modules/home/vim/plugin/numbertoggle.lua
+++ b/modules/home/vim/plugin/numbertoggle.lua
@@ -7,17 +7,28 @@ local numbertoggle = vim.api.nvim_create_augroup("numbertoggle", { clear = true
 vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" }, {
     pattern = "*",
     group = numbertoggle,
-    command = "if &nu | setlocal rnu | endif",
+    callback = function()
+        if vim.opt.number:get() then
+            vim.opt.relativenumber = true
+        end
+    end,
 })
 vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost", "InsertEnter", "WinLeave" }, {
     pattern = "*",
     group = numbertoggle,
-    command = "if &nu | setlocal nornu | endif",
+    callback = function()
+        if vim.opt.number:get() then
+            vim.opt.relativenumber = false
+        end
+    end,
 })
 
 -- Never show the sign column in a terminal buffer
 vim.api.nvim_create_autocmd({ "TermOpen" }, {
     pattern = "*",
     group = numbertoggle,
-    command = "setlocal nonu nornu",
+    callback = function()
+        vim.opt.number = false
+        vim.opt.relativenumber = false
+    end,
 })