From: ruby@... Date: 2016-08-06T01:01:47+00:00 Subject: [ruby-core:76750] [Ruby trunk Feature#12659] Readline: expose rl_char_is_quoted_p setting Issue #12659 has been reported by George Brocklehurst. ---------------------------------------- Feature #12659: Readline: expose rl_char_is_quoted_p setting https://bugs.ruby-lang.org/issues/12659 * Author: George Brocklehurst * Status: Open * Priority: Normal * Assignee: ---------------------------------------- I maintain an interactive Git shell [1] built in Ruby, which made extensive use of the `Readline` module. We found we outgrew the functionality provided by the module, so we built our own `Gitsh::LineEditor` module using Ruby's `Readline` module as a starting point and adding more GNU Readline features to it. I'd like to contribute the features I add back upstream to Ruby. This is the first of them. This patch exposes `rl_char_is_quoted_p` [2] as `Readline.quoting_detection_proc`. `rl_char_is_quoted_p` is used to specify a function that determines if a character is escaped. It's called with completer word break characters that would normally indicate the boundary between two arguments, so that Readline can determine how much text to pass to the completion proc. For example, if we were implementing a Unix shell in Ruby using `Readline`, and a user typed `ls some\ fil` by default we'd get `"fil"` passed to our completion proc, but what we'd really want would be `"some\ fil"`. Setting `rl_char_is_quoted_p` allows us to implement this behaviour. The C function we assign to `rl_char_is_quoted_p` is called with a char array and an index into it, we convert those into a Ruby string and character index and pass them on to the proc. The implementation accounts for multibyte characters. There are tests included in the patch that demonstrate the feature, and here's a simple program that uses it: ~~~ ruby require "readline" completion_text = nil Readline.completion_proc = -> (text) do completion_text = text ["completed"] end Readline.completer_word_break_characters = " " Readline.completer_quote_characters = "\"'" Readline.quoting_detection_proc = -> (text, index) do index > 0 && text[index-1] == "\\" end while line = Readline.readline("> ") do p line p completion_text completion_text = nil end ~~~ This is my first contribution to Ruby, so I'm sure there'll be some changes I need to make before it's accepted. I hope to be able to follow up with a few more Readline features as I build more gitsh features. Thanks to my colleague Adam Sharp for pairing with me on the multibyte string support. [1]: https://github.com/thoughtbot/gitsh [2]: https://cnswww.cns.cwru.edu/php/chet/readline/readline.html#IDX364 ---Files-------------------------------- readline_quoting_detection_proc.patch (9.29 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: