Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93274 > unrolled thread
| Started by | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| First post | 2015-06-29 04:55 +1000 |
| Last post | 2015-07-09 22:56 -0600 |
| Articles | 6 — 6 participants |
Back to article view | Back to comp.lang.python
Readline -- cannot bind to both Ctrl-tab and tab at the same time? Steven D'Aprano <steve@pearwood.info> - 2015-06-29 04:55 +1000
Re: Readline -- cannot bind to both Ctrl-tab and tab at the same time? Laura Creighton <lac@openend.se> - 2015-06-28 23:22 +0200
Re: Readline -- cannot bind to both Ctrl-tab and tab at the same time? Chris Angelico <rosuav@gmail.com> - 2015-06-29 11:36 +1000
Re: Readline -- cannot bind to both Ctrl-tab and tab at the same time? Tony the Tiger <tony@tiger.invalid> - 2015-07-09 20:03 +0000
Re: Readline -- cannot bind to both Ctrl-tab and tab at the same time? Marko Rauhamaa <marko@pacujo.net> - 2015-07-09 23:42 +0300
Re: Readline -- cannot bind to both Ctrl-tab and tab at the same time? Michael Torrie <torriem@gmail.com> - 2015-07-09 22:56 -0600
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2015-06-29 04:55 +1000 |
| Subject | Readline -- cannot bind to both Ctrl-tab and tab at the same time? |
| Message-ID | <55904328$0$1636$c3e8da3$5496439d@news.astraweb.com> |
I'm trying to use a readline binding for both TAB and Ctrl-TAB, but it's not
working for me. Whichever I install second seems to over-ride the first.
In the Python interactive interpreter under Linux, enter these two lines:
import readline
readline.parse_and_bind('Control-tab: "import"')
Then on the next line, press Ctrl-TAB and readline should insert the
word "import". You don't need to import anything, that's just to prove that
the binding works.
Now enter:
readline.parse_and_bind('tab: "raise"')
and on the next line, press TAB and readline should insert the word "raise".
Again, no need to raise anything.
Try Ctrl-TAB again, and you'll get "raise" instead of "import".
Can anyone else replicate this issue?
Is this a Python issue, a problem with the terminal I am using, or readline
in general?
I have also tried with the alternate syntax:
readline.parse_and_bind(r'"\C-\t": "import"')
but it just silently fails to install the binding at all.
Can anyone else successfully bind two different functions to TAB and
Ctrl-TAB?
--
Steven
[toc] | [next] | [standalone]
| From | Laura Creighton <lac@openend.se> |
|---|---|
| Date | 2015-06-28 23:22 +0200 |
| Message-ID | <mailman.151.1435526571.3674.python-list@python.org> |
| In reply to | #93274 |
I can reproduce this with Python 2.7.9 (default, Mar 1 2015, 12:57:24) on my debian unstable system. On pypy both forms just silently fail to install the binding at all. Since PyPy has its own readline, this is circumstantial evidence that readline is the problem. It's not just you. Laura
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-06-29 11:36 +1000 |
| Message-ID | <mailman.154.1435541792.3674.python-list@python.org> |
| In reply to | #93274 |
On Mon, Jun 29, 2015 at 4:55 AM, Steven D'Aprano <steve@pearwood.info> wrote: > Try Ctrl-TAB again, and you'll get "raise" instead of "import". > > Can anyone else replicate this issue? > > Is this a Python issue, a problem with the terminal I am using, or readline > in general? Confirmed with Python 3.6 on Debian Jessie. Delving into Laura's suggestion that it's a readline problem, I came across this: http://stackoverflow.com/questions/12044574/getting-complete-and-menu-complete-to-work-together Testing with "showkey -a" suggests that tab and ctrl-tab indeed send the same bytes. I wonder if there's a way to change terminal type or fiddle with terminfo to change this? GUI programs obviously don't have this conflation. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Tony the Tiger <tony@tiger.invalid> |
|---|---|
| Date | 2015-07-09 20:03 +0000 |
| Message-ID | <tsAnx.3609$JE3.2939@fx44.am4> |
| In reply to | #93274 |
On Mon, 29 Jun 2015 04:55:37 +1000, Steven D'Aprano wrote:
> readline.parse_and_bind('tab: "raise"')
According to this:
https://docs.python.org/2/library/readline.html
... there shouldn't be any "" within the ''s.
Can you trap the Ctrl key at all?
Is 'Control-tab' the correct name? Python is case sensitive.
/Grrr
--
___ ___
(\_--_/) | _ ._ _|_|_ _ |o _ _ ._
( 9 9 ) |(_)| |\/ |_| |(/_ ||(_|(/_|
stripes are forever - as overripe ferrets
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2015-07-09 23:42 +0300 |
| Message-ID | <87si8x6p1p.fsf@elektro.pacujo.net> |
| In reply to | #93601 |
Skip Montanaro <skip.montanaro@gmail.com>: > It makes perfect sense to me that TAB and Ctrl-TAB would generate the > same keycode, as TAB is itself a control character (Ctrl-I). As the > Ctrl modifier bit is effectively already set, I don't think you can > really set it a second time and be able to detect it. If you input a character stream, that's the case since the characters are Unicode code points. AFAIK, Unicode doesn't have Ctrl-TAB as a separate code point. However, X11 key events come with modifiers. Thus, CAPS-A, LeftShift-A, RightShift-A, CAPS-LeftShift-RightShift-A and the plain A are different key events (provided the physical keyboard plays along). Marko
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2015-07-09 22:56 -0600 |
| Message-ID | <mailman.383.1436504170.3674.python-list@python.org> |
| In reply to | #93608 |
On 07/09/2015 02:42 PM, Marko Rauhamaa wrote: > Skip Montanaro <skip.montanaro@gmail.com>: > >> It makes perfect sense to me that TAB and Ctrl-TAB would generate the >> same keycode, as TAB is itself a control character (Ctrl-I). As the >> Ctrl modifier bit is effectively already set, I don't think you can >> really set it a second time and be able to detect it. > > If you input a character stream, that's the case since the characters > are Unicode code points. AFAIK, Unicode doesn't have Ctrl-TAB as a > separate code point. Yes and readline works on character streams, not with X11. > > However, X11 key events come with modifiers. Thus, CAPS-A, LeftShift-A, > RightShift-A, CAPS-LeftShift-RightShift-A and the plain A are different > key events (provided the physical keyboard plays along). Not relevant to libreadline, unfortunately.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web