Skip to content

Commit ad6a3ea

Browse files
committed
Merge pull request #10709 from JuliaLang/jcb/emoji
Emoji REPL completion
2 parents 9b0d15b + a1dedb4 commit ad6a3ea

File tree

5 files changed

+897
-13
lines changed

5 files changed

+897
-13
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ Library improvements
161161

162162
* Other improvements
163163

164+
* You can now tab complete Emoji characters from the REPL, with `\:name:<tab>` ([#10709)
165+
164166
* `gc_enable`, `gc_disable` returns previous GC state.
165167

166168
* `assert`, `@assert` now throws an `AssertionError` exception type ([#9734]).

base/REPL.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ end
286286
function complete_line(c::LatexCompletions, s)
287287
partial = bytestring_beforecursor(LineEdit.buffer(s))
288288
full = LineEdit.input_string(s)
289-
ret, range, should_complete = latex_completions(full, endof(partial))[2]
289+
ret, range, should_complete = bslash_completions(full, endof(partial))[2]
290290
return ret, partial[range], should_complete
291291
end
292292

base/REPLCompletions.jl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module REPLCompletions
22

3-
export completions, shell_completions, latex_completions
3+
export completions, shell_completions, bslash_completions
44

55
using Base.Meta
66

@@ -236,6 +236,7 @@ function complete_methods(ex_org::Expr)
236236
end
237237

238238
include("latex_symbols.jl")
239+
include("emoji_symbols.jl")
239240

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

256-
function latex_completions(string, pos)
257+
function bslash_completions(string, pos)
257258
slashpos = rsearch(string, '\\', pos)
258-
if rsearch(string, whitespace_chars, pos) < slashpos && !(1 < slashpos && (string[prevind(string, slashpos)]=='\\'))
259-
# latex symbol substitution
259+
if (rsearch(string, whitespace_chars, pos) < slashpos &&
260+
!(1 < slashpos && (string[prevind(string, slashpos)]=='\\')))
261+
# latex / emoji symbol substitution
260262
s = string[slashpos:pos]
261263
latex = get(latex_symbols, s, "")
262264
if !isempty(latex) # complete an exact match
263265
return (true, ([latex], slashpos:pos, true))
264-
else
265-
# return possible matches; these cannot be mixed with regular
266-
# Julian completions as only latex symbols contain the leading \
266+
end
267+
emoji = get(emoji_symbols, s, "")
268+
if !isempty(emoji)
269+
return (true, ([emoji], slashpos:pos, true))
270+
end
271+
# return possible matches; these cannot be mixed with regular
272+
# Julian completions as only latex / emoji symbols contain the leading \
273+
if startswith(s, "\\:") # emoji
274+
emoji_names = filter(k -> startswith(k, s), keys(emoji_symbols))
275+
return (true, (sort!(collect(emoji_names)), slashpos:pos, true))
276+
else # latex
267277
latex_names = filter(k -> startswith(k, s), keys(latex_symbols))
268278
return (true, (sort!(collect(latex_names)), slashpos:pos, true))
269279
end
@@ -290,9 +300,10 @@ function completions(string, pos)
290300
(success || inc_tag==:cmd) && return sort(paths), r, success
291301
end
292302

293-
ok, ret = latex_completions(string, pos)
303+
ok, ret = bslash_completions(string, pos)
294304
ok && return ret
295-
# Make sure that only latex_completions is working on strings
305+
306+
# Make sure that only bslash_completions is working on strings
296307
inc_tag==:string && return UTF8String[], 0:-1, false
297308

298309
if inc_tag == :other && should_method_complete(partial)

0 commit comments

Comments
 (0)