Skip to content
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

REPL: implement Alt-{u,c,l} to change the case of the next word #23379

Merged
merged 1 commit into from
Aug 25, 2017
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
22 changes: 22 additions & 0 deletions base/repl/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,25 @@ function edit_transpose_words(buf::IOBuffer, mode=:emacs)
end


edit_upper_case(s) = edit_replace_word_right(s, uppercase)
edit_lower_case(s) = edit_replace_word_right(s, lowercase)
edit_title_case(s) = edit_replace_word_right(s, ucfirst)

edit_replace_word_right(s, replace::Function) =
edit_replace_word_right(buffer(s), replace) && refresh_line(s)

function edit_replace_word_right(buf::IOBuffer, replace::Function)
# put the cursor at the beginning of the next word
skipchars(buf, is_non_word_char)
b = position(buf)
char_move_word_right(buf)
e = position(buf)
e == b && return false
newstr = replace(String(buf.data[b+1:e]))
splice_buffer!(buf, b:e-1, newstr)
true
end

edit_clear(buf::IOBuffer) = truncate(buf, 0)

function edit_clear(s::MIState)
Expand Down Expand Up @@ -1531,6 +1550,9 @@ AnyDict(
end,
"^T" => (s,o...)->edit_transpose_chars(s),
"\et" => (s,o...)->edit_transpose_words(s),
"\eu" => (s,o...)->edit_upper_case(s),
"\el" => (s,o...)->edit_lower_case(s),
"\ec" => (s,o...)->edit_title_case(s),
)

const history_keymap = AnyDict(
Expand Down
3 changes: 3 additions & 0 deletions doc/src/manual/interacting-with-julia.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ to do so).
| `^K` | "Kill" to end of line, placing the text in a buffer |
| `^Y` | "Yank" insert the text from the kill buffer |
| `^T` | Transpose the characters about the cursor |
| `meta-u` | Change the next word to uppercase |
| `meta-c` | Change the next word to titlecase |
| `meta-l` | Change the next word to lowercase |
| `^Q` | Write a number in REPL and press `^Q` to open editor at corresponding stackframe or method |


Expand Down
12 changes: 12 additions & 0 deletions test/lineedit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,15 @@ end
@test bufferdata(s) == "begin\n" * ' '^(i-6) * "\n x"
end
end

@testset "change case on the right" begin
buf = IOBuffer()
LineEdit.edit_insert(buf, "aa bb CC")
seekstart(buf)
LineEdit.edit_upper_case(buf)
LineEdit.edit_title_case(buf)
@test String(take!(copy(buf))) == "AA Bb CC"
@test position(buf) == 5
LineEdit.edit_lower_case(buf)
@test String(take!(copy(buf))) == "AA Bb cc"
end