I'm working with the readline module, and I'm trying to set a key combination to process the current command line by calling a known function, *and* enter the command line.
Something along the lines of:
* execute function spam() in some context where it can access the current command line as a string
* enter the command line
Function spam() may or may not modify the command line.
Here is what I have got so far: I can discard the current line and call a function:
Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote:
> I'm working with the readline module, and I'm trying to set a key > combination to process the current command line by calling a known > function, *and* enter the command line.
> Something along the lines of:
> * execute function spam() in some context where it can access > the current command line as a string
> * enter the command line
> Function spam() may or may not modify the command line.
> Here is what I have got so far: I can discard the current line and call a > function:
Why dont you grow yourself some usable neurons instead ? Don't you realize now stackoverflow.com is starting
to hurt your capacity to cogitate on your own or have you not realized this yet?
Cheers,
Etienne
-- Etienne Robillard
Green Tea Hackers Club
Fine Software Carpentry For The Rest Of Us!
http://gthc.org/ e...@gthcfoundation.org
On Sun, Oct 14, 2012 at 12:44 AM, Etienne Robillard
<animelo...@gmail.com> wrote:
> Why dont you grow yourself some usable neurons instead ? Don't you realize now stackoverflow.com is starting
> to hurt your capacity to cogitate on your own or have you not realized this yet?
Excuse me?
I'm not overly familiar with readline, so perhaps there is a really
obvious way to do what Steven's trying to do, but this post does not
appear to be the result of a lack of thinking.
If it really IS that obvious to you, post a link to appropriate
documentation without the rudeness... that way it'll be useful to
everyone, not just cathartic to you.
Chris Angelico <ros...@gmail.com> wrote:
> Excuse me?
> I'm not overly familiar with readline, so perhaps there is a really
> obvious way to do what Steven's trying to do, but this post does not
> appear to be the result of a lack of thinking.
> If it really IS that obvious to you, post a link to appropriate
> documentation without the rudeness... that way it'll be useful to
> everyone, not just cathartic to you.
> On Sun, 14 Oct 2012 00:47:52 +1100
> Chris Angelico <ros...@gmail.com> wrote:
>> Excuse me?
>> I'm not overly familiar with readline, so perhaps there is a really
>> obvious way to do what Steven's trying to do, but this post does not
>> appear to be the result of a lack of thinking.
>> If it really IS that obvious to you, post a link to appropriate
>> documentation without the rudeness... that way it'll be useful to
>> everyone, not just cathartic to you.
> whatever. i don't feel much like replying to idiots today
Then simply don't. Much better then replying in such a rude way.
I leave the question of who is being an idiot here as an exercise to the reader.
-- "Too often we hold fast to the cliches of our forebears. We subject all
facts to a prefabricated set of interpretations. Too often we enjoy the
comfort of opinion without the discomfort of thought."
-- John F Kennedy
<joshua.landau...@gmail.com> wrote:
> With two irritants (including 88888), is it not advisable that python-list
> gets an admin to block these accounts? Even if it does nothing more than
> slow them, that's something.
That's what killfiles are for. You have two options:
The first option is not perfect, as you'll still see replies that
quote such people's posts. The second has a few issues with local law
enforcement, but other than that, is a very effective means of
avoiding seeing their posts.
> With two irritants (including 88888), is it not advisable that python-list
> gets an admin to block these accounts? Even if it does nothing more than
> slow them, that's something.
Most irritants are mere amateurs compared to Ilias Lazaridis. I wonder if he's *STILL* researching?
<joshua.landau...@gmail.com> wrote:
> On 13 October 2012 22:44, Chris Angelico <ros...@gmail.com> wrote:
>> On Sun, Oct 14, 2012 at 8:31 AM, Joshua Landau
>> <joshua.landau...@gmail.com> wrote:
>> > With two irritants (including 88888), is it not advisable that
>> > python-list
>> > gets an admin to block these accounts? Even if it does nothing more than
>> > slow them, that's something.
>> That's what killfiles are for. You have two options:
>> The first option is not perfect, as you'll still see replies that
>> quote such people's posts. The second has a few issues with local law
>> enforcement, but other than that, is a very effective means of
>> avoiding seeing their posts.
> The first's no good for protecting the newbies though. If troll flames
> newbie, then I want to be able to assure newbie that he's not done anything
> wrong or stupid.
> The second is a bit better, definitely, but what I'm wanting is to delegate
> these tasks to python-list's admins. I'm lazy, see.
Agreed, defending newbies is important. But not everyone gets
frustrated at trolls. Those who don't, don't bother to killfile them,
and can respond in defense of the newbies. Also, if two or three
non-trolls respond to the original post, the angry troll is only one
of several, which helps dilute the problem a bit. Still not a
solution, but it helps.
> On 13 October 2012 23:13, Mark Lawrence <breamore...@yahoo.co.uk> wrote:
>> On 13/10/2012 22:31, Joshua Landau wrote:
>>> With two irritants (including 88888), is it not advisable that python-list
>>> gets an admin to block these accounts? Even if it does nothing more than
>>> slow them, that's something.
>> Most irritants are mere amateurs compared to Ilias Lazaridis. I wonder if
>> he's *STILL* researching?
> On 13/10/2012 23:26, Joshua Landau wrote:
>> On 13 October 2012 23:13, Mark Lawrence <breamore...@yahoo.co.uk> wrote:
>>> On 13/10/2012 22:31, Joshua Landau wrote:
>>>> With two irritants (including 88888), is it not advisable that
>>>> python-list
>>>> gets an admin to block these accounts? Even if it does nothing more
>>>> than
>>>> slow them, that's something.
>>> Most irritants are mere amateurs compared to Ilias Lazaridis. I
>>> wonder if
>>> he's *STILL* researching?
Yes a real pro. Trolling will never become an Olympic sport as the guy's so good nobody can compete with him. (If he was American they'd still have a World Series though :) Throw his name plus Eclipse, Netbeans and banned into your search engine of choice and enjoy, but beware that to really endulge yourself please stock up on vast quantities of caffeine and sandwiches first cos you'll need them. For example this http://web.archiveorange.com/archive/v/7IfPlywrYZb0gAgMsPa1 points to this http://www.tfeb.org/lisp/mad-people.html
Steven D'Aprano wrote:
> I'm working with the readline module, and I'm trying to set a key
> combination to process the current command line by calling a known
> function, *and* enter the command line.
> Something along the lines of:
> * execute function spam() in some context where it can access
> the current command line as a string
> * enter the command line
> Function spam() may or may not modify the command line.
> (P.S. I'm aware of IPython, I want to get this working in the standard
> CPython interpreter.)
If IPython does what you want why don't you have a look at the source?
Anyway, here's what I came up with (no warranties as it was all trial-and-
error):
In article <k5j5sk$ms...@ger.gmane.org>, Peter Otten <__pete...@web.de> wrote:
> Steven D'Aprano wrote: > > I'm working with the readline module, and I'm trying to set a key
> > combination to process the current command line by calling a known
> > function, *and* enter the command line.
[...]
> Anyway, here's what I came up with (no warranties as it was all trial-and-
> error):
[...]
Keep in mind that the Python readline module may be linked to either the GPL-licensed GNU readline or the BSD-licensed editline (libedit) library (the default on newer OS X systems and probably on *BSD systems) and they have different command strings. Note the warning here:
Ned Deily wrote:
> In article <k5j5sk$ms...@ger.gmane.org>, Peter Otten <__pete...@web.de>
> wrote:
>> Steven D'Aprano wrote:
>> > I'm working with the readline module, and I'm trying to set a key
>> > combination to process the current command line by calling a known
>> > function, *and* enter the command line.
> [...]
>> Anyway, here's what I came up with (no warranties as it was all
>> trial-and- error):
> [...]
> Keep in mind that the Python readline module may be linked to either the
> GPL-licensed GNU readline or the BSD-licensed editline (libedit) library
> (the default on newer OS X systems and probably on *BSD systems) and
> they have different command strings. Note the warning here:
On Tue, 16 Oct 2012 10:30:01 +0200, Peter Otten wrote:
> Steven D'Aprano wrote:
>> I'm working with the readline module, and I'm trying to set a key
>> combination to process the current command line by calling a known
>> function, *and* enter the command line.
>> Something along the lines of:
>> * execute function spam() in some context where it can access
>> the current command line as a string
>> * enter the command line
>> Function spam() may or may not modify the command line.
>> (P.S. I'm aware of IPython, I want to get this working in the standard
>> CPython interpreter.)
> If IPython does what you want why don't you have a look at the source?
Well, I was hoping for a pure Python solution, rather than having to troll through who knows how many thousands of lines of code in a language I can barely read.
> Anyway, here's what I came up with (no warranties as it was all
> trial-and- error):
> $ cat readline_callback.py
> import ctypes
Ah, ctypes.
Well, I guess I have some interesting study ahead of me, to make head or tail of your solution. Thank you!
> On Tue, 16 Oct 2012 10:30:01 +0200, Peter Otten wrote:
>> Steven D'Aprano wrote:
>>> I'm working with the readline module, and I'm trying to set a key
>>> combination to process the current command line by calling a known
>>> function, *and* enter the command line.
>>> Something along the lines of:
>>> * execute function spam() in some context where it can access
>>> the current command line as a string
>>> * enter the command line
>>> Function spam() may or may not modify the command line.
>>> (P.S. I'm aware of IPython, I want to get this working in the standard
>>> CPython interpreter.)
>> If IPython does what you want why don't you have a look at the source?
> Well, I was hoping for a pure Python solution, rather than having to
> troll through who knows how many thousands of lines of code in a language
> I can barely read.
Are you confusing IPython, the pure Python REPL for CPython, for IronPython, the C# implementation of Python?
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
On Tue, 16 Oct 2012 13:20:24 +0100, Robert Kern wrote:
> On 10/16/12 12:27 PM, Steven D'Aprano wrote:
>> Well, I was hoping for a pure Python solution, rather than having to
>> troll through who knows how many thousands of lines of code in a
>> language I can barely read.
> Are you confusing IPython, the pure Python REPL for CPython,
IPython is pure Python?
Well, you learn something new everyday. Or at least I do.
I guess that means that I can look forward to trolling through 250 or so Python modules instead of C code :)
<steve+comp.lang.pyt...@pearwood.info> wrote:
> On Tue, 16 Oct 2012 10:30:01 +0200, Peter Otten wrote:
>> Steven D'Aprano wrote:
>>> I'm working with the readline module, and I'm trying to set a key
>>> combination to process the current command line by calling a known
>>> function, *and* enter the command line.
>>> Something along the lines of:
>>> * execute function spam() in some context where it can access
>>> the current command line as a string
>>> * enter the command line
I'm working on the dictionary now,but I came up with this, which uses
a list as the key, and accepts the params to perform the function:
import subprocess as sub
key_list = ['print_something','espeak']
for line in key_list:
if str(line) == key:
params = raw_input("Enter Params: ")
eval("%s('%s')" % (key,params))
I keep getting the function performed in the dict. I'll figure it out
eventually, I know I've done it before, and it might be a lambda
solution...not sure.
But the above could be refined more, it just uses a list, and key/params.
On Tue, Oct 16, 2012 at 10:36 AM, Peter Otten <__pete...@web.de> wrote:
> Dwight Hutto wrote:
> I knew I'd eventually regret putting "on topic" into the subject...
I didn't write that. If you're referring to OT, it means Off Topic,
and a response would be appreciated. And you can call me David, I go
by my middle name.
In article <k5jcbs$eu...@ger.gmane.org>, Peter Otten <__pete...@web.de> wrote:
> Ned Deily wrote:
> > Keep in mind that the Python readline module may be linked to either the
> > GPL-licensed GNU readline or the BSD-licensed editline (libedit) library
> > (the default on newer OS X systems and probably on *BSD systems) and
> > they have different command strings. Note the warning here:
> I think you are a Mac user. If so, can the snippet I posted be generalised > to work with libedit?
Isn't it hairy enough??
Here's how to make tab complete work with both; it gives an idea of the libedit commands:
import rlcompleter
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else: # GNU readline format
readline.parse_and_bind("tab: complete")
The documentation of the command syntax is in the .editrc man pages, for example: