Skip to content

Commit

Permalink
revins automatically toggled for RTL keymaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Cook committed Apr 1, 2023
1 parent 80f4a34 commit 83ca8a8
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lua/bidi.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
local M = {}

local rtl_keymaps = {
'arabic_utf-8',
'arabic',
'hebrew_cp1255',
'hebrew_iso-8859-7',
'hebrew_utf-8',
'hebrew',
'persian-iranian_utf-8',
'persian',
'thaana',
}

-- Handler for buffers with bidi mode enabled
M.active_bufs = {}

Expand Down Expand Up @@ -106,6 +118,10 @@ end

-- Initialize plugin
function M.setup(opts)
-- Set options
vim.o.allowrevins = true

-- Set user options
M.options = vim.tbl_deep_extend('force', default_opts, opts or {})

-- Create autocommands
Expand All @@ -126,6 +142,25 @@ function M.setup(opts)
desc = 'Temporarily disable Bidi-Mode when writing buffer contents',
})

-- Automatically enter `revins` depending on language and `rightleft`
-- For `rightleft` buffers, LTR languages are `revins`.
-- For `norightleft` buffers, RTL languages are `revins`.
vim.api.nvim_create_autocmd('OptionSet', {
callback = function(opts)
local buf_base_dir = M.active_bufs[tostring(opts.buf)]
if vim.tbl_contains(rtl_keymaps, vim.v.option_new) then
-- NOTE: `revins` is a global option,
-- so if a local option is wanted,
-- might need to use `InsertCharPre` and check the buffer.
vim.o.revins = true
else
vim.o.revins = false
end
end,
group = M.augroup,
desc = 'Automatically enter `revins` depending on language and `rightleft`',
})

-- Generate user commands
if M.options.create_user_commands then
-- Enable Bidi-Mode in current buffer
Expand Down

0 comments on commit 83ca8a8

Please sign in to comment.