Skip to content

Commit

Permalink
Fix keymap to allow coexistence of L2U methods
Browse files Browse the repository at this point in the history
with this all L2U input methods can be used at once without issues
(hopefully)
  • Loading branch information
carlobaldassi committed Dec 11, 2018
1 parent 197e0e7 commit b644d80
Show file tree
Hide file tree
Showing 4 changed files with 7,122 additions and 3,304 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Unicode symbols (e.g. `α`). By default, these substitutions must be triggered e
be activated, and a method based on keymap is also available.

This feature also works in command mode, e.g. when searching the files with the `/` or `?` commands, but the
as-you-type mode is not available (the keymap-based version is though, and it also works with some Vim
as-you-type mode is not available (the keymap-based version works though, and it also works with some Vim
commands like `f` and `t`).

By default, this feature is only active when editing Julia files. However, it can be also enabled with
Expand Down Expand Up @@ -112,10 +112,8 @@ and a LaTeX sequence can unambiguously be identified.
For example, if you type `a \neq b` the `\neq` will be changed to `` right after the space, before you input
the `b`.

This does not interfere with the <kbd>Tab</kbd> mapping discussed above. It only works in insert mode.

The `g:latex_to_unicode_auto` setting can also be changed from the Vim command-line, but you will
also need to give the command `:call LaTeXtoUnicode#Init()` for the change to take effect.
This does not interfere with the <kbd>Tab</kbd> mapping discussed above. It only works in insert mode, and it
doesn't work with emojis.

This feature is not available with Vim versions lower then 7.4.

Expand All @@ -124,14 +122,16 @@ This feature is not available with Vim versions lower then 7.4.
A different susbstitution mode based on keymaps can be activated with `:let g:latex_to_unicode_keymap = 1`,
e.g. by putting it into your `.vimrc` file. This works similarly to the as-you-type method described above,
but it has the advantage that it works under more circumstances, e.g. in command-line mode when searching with
`/` or `?`, and when using the `f` and `t` commands.
The disadvantages are that you don't see the whole sequence as you're typing it, and no suggestions or partial
completions are available, thus you need to know the substitutions (see `:help L2U`), and to type them
correctly in full.
`/` or `?`, and when using the `f` and `t` commands; plus it works with emojis too.
The main disadvantage is that you don't see the whole sequence as you're typing it, and you can't fix mistakes
with backspace, for example.
Another difference is that there is a timeout like for any other mapping.
In any case, it is possible to use this method in parallel with the other two methods, they don't interfere.
So if you have the <kbd>Tab</kbd> mapping (discussed above) activated, you still get to see completions and
suggestions. If you have the as-you-type substitution active, and you make a mistake, you can simply press
backspace and keep going, at least in insert mode, and so on.

If you use this method, it is advisable to disable the other two methods, setting both `g:latex_to_unicode_tab`
and `g:latex_to_unicode_auto` to `0`.
This feature might with Vim versions lower then 7.4, but it hasn't been tested.

### LaTeX-to-Unicode on other file types

Expand Down
28 changes: 13 additions & 15 deletions doc/julia-vim-L2U.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ available:
for a character with |f| or |t|, as explained in |language-mapping|. See
|julia-vim-L2U-keymap|.

The first two methods are independent and can be used together without issues.
The third one is best used by its own, disabling the other two, to avoid
confusion.
All of these methods are independent and can be used together without issues.

The default configuration is to use the first method, and it's only active
when editing Julia files. It only works in |Insert| and |Command-line| modes.
Expand All @@ -75,12 +73,13 @@ It is possible to enable it with other file types, see
regardless of the file type, see |julia-vim-L2U-enable-disable|.

In |Command-line| mode, e.g. when searching with the |/| or |?| commands, the
default behavior is very similar, but slightly more limited, see
|julia-vim-L2U-cmdmode|.
default behavior is very similar to the default |Insert| mode behavior, but
slightly more limited, see |julia-vim-L2U-cmdmode|.

These features only work as described with Vim version 7.4 or higher. Tab
completion can still be made available on lower Vim versions, see
|julia-vim-L2U-workaround|.
|julia-vim-L2U-workaround|. The keymap mode might work but it hasn't been
tested.

See |julia-vim| for the general reference about the other features of the
julia-vim plug-in.
Expand Down Expand Up @@ -198,16 +197,17 @@ uses |keymap| to generate the mappings. This has the advantage that it works
in more circumstances, e.g. in |Command-line| mode or when searching within a
line with |f| or |t| (since it uses |language-mapping| underneath). It can
also be easily turned on or off like any other keymap (see |i_CTRL-^| and
|c_CTRL-^|).
The disadvantages are that you don't see the whole sequence as you're typing
it, and no suggestions or partial completions are available, thus you need to
know the substitutions (see |julia-vim-L2U-reference|), and to type them
correctly in full.
|c_CTRL-^|). It also works with emojis.
The disadvantage is that you don't see the whole sequence as you're typing
it, and you can't fix mistakes with backspace, for example.
Another difference is that there is a |timeout| like for any other mapping.

In order to use this method, set |g:latex_to_unicode_keymap| to `1`.
If you do so, it is advisable to disable the other two methods,
setting both |g:latex_to_unicode_tab| and |g:latex_to_unicode_auto| to `0`.
You can use it in parallel with the other methods, they don't interfere. For
example, typing a partial sequence and pressing <Tab> still triggers
completions and suggestions if |g:latex_to_unicode_tab| is active.

If you use this feature, it's also useful to set |lCursor|.

------------------------------------------------------------------------------
LATEX TO UNICODE ON DIFFERENT FILE TYPES *julia-vim-L2U-file-types*
Expand Down Expand Up @@ -337,8 +337,6 @@ g:latex_to_unicode_keymap
in your |.vimrc| file. You can change this setting at any
moment while editing, but you need to invoke
|LaTeXtoUnicode#Init()| for the change to take effect.
It's advisable to disable |g:latex_to_unicode_tab| and
|g:latex_to_unicde_auto| if you use this.

*g:latex_to_unicode_file_types*
g:latex_to_unicode_file_types
Expand Down
44 changes: 37 additions & 7 deletions keymap/generate_L2U_keymap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

const filename = "latex2unicode_utf-8"

# We want to avoid situations in which the user types e.g. \delt and pauses,
# and the result is "∇t" because "\del" gets recognized and then there is some leftover "t".
# This allows us to get completions with <Tab> for example.
function fix_completions(completions::Dict{String,String})
allinputs = sort!(collect(keys(completions)))
new_completions = copy(completions)

for input in allinputs
chars = completions[input]
l = length(input)
longer = filter(x->startswith(x, input)&&length(x)>l, allinputs)
n = length(longer)
n == 0 && continue
new_completions[input * "<Tab>"] = chars
for other in longer
for j = (l+1):(length(other)-1)
haskey(new_completions, other[1:j]) && continue
new_completions[other[1:j]] = other[1:j]
end
end
end
return new_completions
end

function unicode_data()
file = normpath(Sys.BINDIR, "..", "..", "doc", "UnicodeData.txt")
names = Dict{UInt32, String}()
Expand All @@ -27,12 +51,18 @@ function table_entries(completions::Dict{String,String}, unicode_dict)
unicode = String[]
desc = String[]

for (input, chars) in sort!(collect(completions), by = last)
for (input, chars) in sort!(collect(completions))
code_points, unicode_names, characters = String[], String[], String[]
for char in chars
push!(code_points, "<char-0x$(uppercase(string(UInt32(char), base = 16, pad = 5)))>")
push!(unicode_names, get(unicode_dict, UInt32(char), "(No Unicode name)"))
push!(characters, isempty(characters) ? fix_combining_chars(char) : "$char")
if startswith(chars, "\\")
push!(code_points, replace(chars, "\\" => "\\\\"))
push!(unicode_names, "(Incomplete sequence)")
push!(characters, "")
else
for char in chars
push!(code_points, "<char-0x$(uppercase(string(UInt32(char), base = 16, pad = 5)))>")
push!(unicode_names, get(unicode_dict, UInt32(char), "(No Unicode name)"))
push!(characters, isempty(characters) ? fix_combining_chars(char) : "$char")
end
end
push!(latex, replace(input, "\\"=>"\\\\"))
push!(code, join(code_points))
Expand All @@ -56,10 +86,10 @@ open("$filename.vim","w") do f

latex, code, unicode, desc =
table_entries(
merge(
fix_completions(merge(
REPL.REPLCompletions.latex_symbols,
REPL.REPLCompletions.emoji_symbols
),
)),
unicode_data()
)

Expand Down
Loading

0 comments on commit b644d80

Please sign in to comment.