1
1
local M = {}
2
2
3
+ local rtl_keymaps = {
4
+ ' arabic_utf-8' ,
5
+ ' arabic' ,
6
+ ' hebrew_cp1255' ,
7
+ ' hebrew_iso-8859-7' ,
8
+ ' hebrew_utf-8' ,
9
+ ' hebrew' ,
10
+ ' persian-iranian_utf-8' ,
11
+ ' persian' ,
12
+ ' thaana' ,
13
+ }
14
+
3
15
-- Handler for buffers with bidi mode enabled
4
16
M .active_bufs = {}
5
17
106
118
107
119
-- Initialize plugin
108
120
function M .setup (opts )
121
+ -- Set options
122
+ vim .o .allowrevins = true
123
+
124
+ -- Set user options
109
125
M .options = vim .tbl_deep_extend (' force' , default_opts , opts or {})
110
126
111
127
-- Create autocommands
@@ -126,6 +142,25 @@ function M.setup(opts)
126
142
desc = ' Temporarily disable Bidi-Mode when writing buffer contents' ,
127
143
})
128
144
145
+ -- Automatically enter `revins` depending on language and `rightleft`
146
+ -- For `rightleft` buffers, LTR languages are `revins`.
147
+ -- For `norightleft` buffers, RTL languages are `revins`.
148
+ vim .api .nvim_create_autocmd (' OptionSet' , {
149
+ callback = function (opts )
150
+ local buf_base_dir = M .active_bufs [tostring (opts .buf )]
151
+ if vim .tbl_contains (rtl_keymaps , vim .v .option_new ) then
152
+ -- NOTE: `revins` is a global option,
153
+ -- so if a local option is wanted,
154
+ -- might need to use `InsertCharPre` and check the buffer.
155
+ vim .o .revins = true
156
+ else
157
+ vim .o .revins = false
158
+ end
159
+ end ,
160
+ group = M .augroup ,
161
+ desc = ' Automatically enter `revins` depending on language and `rightleft`' ,
162
+ })
163
+
129
164
-- Generate user commands
130
165
if M .options .create_user_commands then
131
166
-- Enable Bidi-Mode in current buffer
0 commit comments