Skip to content

Emoji REPL completion #10709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ Library improvements

* Other improvements

* You can now tab complete Emoji characters from the REPL, with `\:name:<tab>` ([#10709)

* `gc_enable`, `gc_disable` returns previous GC state.

* `assert`, `@assert` now throws an `AssertionError` exception type ([#9734]).
Expand Down
2 changes: 1 addition & 1 deletion base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ end
function complete_line(c::LatexCompletions, s)
partial = bytestring_beforecursor(LineEdit.buffer(s))
full = LineEdit.input_string(s)
ret, range, should_complete = latex_completions(full, endof(partial))[2]
ret, range, should_complete = bslash_completions(full, endof(partial))[2]
return ret, partial[range], should_complete
end

Expand Down
29 changes: 20 additions & 9 deletions base/REPLCompletions.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module REPLCompletions

export completions, shell_completions, latex_completions
export completions, shell_completions, bslash_completions

using Base.Meta

Expand Down Expand Up @@ -236,6 +236,7 @@ function complete_methods(ex_org::Expr)
end

include("latex_symbols.jl")
include("emoji_symbols.jl")

const non_identifier_chars = [" \t\n\r\"\\'`\$><=:;|&{}()[],+-*/?%^~"...]
const whitespace_chars = [" \t\n\r"...]
Expand All @@ -253,17 +254,26 @@ function afterusing(string::ByteString, startpos::Int)
return ismatch(r"^\b(using|import)\s*(\w+\s*,\s*)*\w*$", str[fr:end])
end

function latex_completions(string, pos)
function bslash_completions(string, pos)
slashpos = rsearch(string, '\\', pos)
if rsearch(string, whitespace_chars, pos) < slashpos && !(1 < slashpos && (string[prevind(string, slashpos)]=='\\'))
# latex symbol substitution
if (rsearch(string, whitespace_chars, pos) < slashpos &&
!(1 < slashpos && (string[prevind(string, slashpos)]=='\\')))
# latex / emoji symbol substitution
s = string[slashpos:pos]
latex = get(latex_symbols, s, "")
if !isempty(latex) # complete an exact match
return (true, ([latex], slashpos:pos, true))
else
# return possible matches; these cannot be mixed with regular
# Julian completions as only latex symbols contain the leading \
end
emoji = get(emoji_symbols, s, "")
if !isempty(emoji)
return (true, ([emoji], slashpos:pos, true))
end
# return possible matches; these cannot be mixed with regular
# Julian completions as only latex / emoji symbols contain the leading \
if startswith(s, "\\:") # emoji
emoji_names = filter(k -> startswith(k, s), keys(emoji_symbols))
return (true, (sort!(collect(emoji_names)), slashpos:pos, true))
else # latex
latex_names = filter(k -> startswith(k, s), keys(latex_symbols))
return (true, (sort!(collect(latex_names)), slashpos:pos, true))
end
Expand All @@ -290,9 +300,10 @@ function completions(string, pos)
(success || inc_tag==:cmd) && return sort(paths), r, success
end

ok, ret = latex_completions(string, pos)
ok, ret = bslash_completions(string, pos)
ok && return ret
# Make sure that only latex_completions is working on strings

# Make sure that only bslash_completions is working on strings
inc_tag==:string && return UTF8String[], 0:-1, false

if inc_tag == :other && should_method_complete(partial)
Expand Down
Loading