Mailing List Archive

Quick fix to add "+="
Any one knows a quick fix to add "+=" function. I am really getting
tired of typing long names twice.

Thanks a lot!
Fuming
Quick fix to add "+=" [ In reply to ]
On Fri, 16 Apr 1999 17:26:44 -0400, Fuming Wang <fmwang@mediaone.net> wrote:
>Any one knows a quick fix to add "+=" function. I am really getting
>tired of typing long names twice.

Heh. I can't wait to see the other replies... :)

+= has been left out of the language for a good reason, and thus it's
probably not likely that there's an easy way to add it. I think you
will have to recompile the interpreter to get it to do what you want,
and even then, I don't think that you really want what it would do.

Surely there's some discussion about += in dejanews which would provide
more enlightenment that I can.

Later,
Blake.
Quick fix to add "+=" [ In reply to ]
I have searched dejanews. They don't like the "+=" characters. Could you
be more specific about how to modify the interpreter? I desperate
here.:)

Thanks,
Fuming

Blake Winton wrote:
>
> On Fri, 16 Apr 1999 17:26:44 -0400, Fuming Wang <fmwang@mediaone.net> wrote:
> >Any one knows a quick fix to add "+=" function. I am really getting
> >tired of typing long names twice.
>
> Heh. I can't wait to see the other replies... :)
>
> += has been left out of the language for a good reason, and thus it's
> probably not likely that there's an easy way to add it. I think you
> will have to recompile the interpreter to get it to do what you want,
> and even then, I don't think that you really want what it would do.
>
> Surely there's some discussion about += in dejanews which would provide
> more enlightenment that I can.
>
> Later,
> Blake.
Quick fix to add "+=" [ In reply to ]
Your editor is your friend:

Just use a macro in your favorite editor, which grabs the left
word of the curser postion and expands it into
<word>=<word>+
Trigger the macro with "+=" and you type excactly what you
always type, just the result is more python like.

For vim, the following does the trick (without the special word matching caps
new vim versions provide. the ":noh is for people using hlsearch in
vim 5.x version.)


:map!^[:s/\([a-zA-Z_][a-zA-Z0-9_]*\)$/\1=\1+/^M:noh^MA

Bernhard


On Fri, 16 Apr 1999 22:12:48 -0400, Fuming Wang <fmwang@mediaone.net> wrote:
>I have searched dejanews. They don't like the "+=" characters. Could you
>be more specific about how to modify the interpreter? I desperate
>here.:)

>Blake Winton wrote:
>> On Fri, 16 Apr 1999 17:26:44 -0400, Fuming Wang <fmwang@mediaone.net> wrote:
>> >Any one knows a quick fix to add "+=" function. I am really getting
>> >tired of typing long names twice.
>>
>> += has been left out of the language for a good reason, and thus it's
>> probably not likely that there's an easy way to add it. I think you
>> will have to recompile the interpreter to get it to do what you want,
>> and even then, I don't think that you really want what it would do.
Quick fix to add "+=" [ In reply to ]
[Fuming Wang]
> I have searched dejanews. They don't like the "+=" characters. Could you
> be more specific about how to modify the interpreter? I desperate
> here.:)

There's a Python ToDo entry open on this; it may (or may not) be introduced
in Python2; last time this went around was late last August, in thread "Why
no += operator, please?"; modifying the interpreter was an absurd
suggestion, although that's what it would take; in the meantime, use an
editor with word completion (e.g. Guido's IDLE environment, included with
1.5.2, has this), and/or factor by hand, e.g. not

a.b.c.d.e.f.g.h.i.j = a.b.c.d.e.f.g.h.i + 1

but

x = a.b.c.d.e.f.g.h.i
x.j = x.j + 1

can't-wait-for-a-resumption-of-the-assignment-expression-thread<wink>-ly
y'rs - tim
Quick fix to add "+=" [ In reply to ]
Hi,

On 17 Apr 1999, Bernhard Reiter wrote:

> Your editor is your friend:
>
> Just use a macro in your favorite editor, which grabs the left
> word of the curser postion and expands it into
> <word>=<word>+
> Trigger the macro with "+=" and you type excactly what you
> always type, just the result is more python like.
>
> For vim, the following does the trick (without the special word matching caps
> new vim versions provide. the ":noh is for people using hlsearch in
> vim 5.x version.)
>
>
> :map!^[:s/\([a-zA-Z_][a-zA-Z0-9_]*\)$/\1=\1+/^M:noh^MA
>
> Bernhard
>

This works for me, except I got "no mapping found" when I enter the
suggested command. I am using vim 5.3. Is this the problem?

Thanks!
Fuming
Quick fix to add "+=" [ In reply to ]
On Tue, 20 Apr 1999 05:06:00 -0700, Fuming Wang <fuming@sup.phys.washington.edu> wrote:

>On 17 Apr 1999, Bernhard Reiter wrote:
>> For vim, the following does the trick (without the special word matching caps
>> new vim versions provide. the ":noh is for people using hlsearch in
>> vim 5.x version.)
>>
>> :map!^[:s/\([a-zA-Z_][a-zA-Z0-9_]*\)$/\1=\1+/^M:noh^MA


>This works for me, except I got "no mapping found" when I enter the
>suggested command. I am using vim 5.3. Is this the problem?

uh, I have been not precise enough and just outlined the idea.

:map! += ^[:s/\([a-zA-Z_][a-zA-Z0-9_]*\)$/\1=\1+/^M:noh^MA

Where ":" means go into vim Commandmode
"^[" means Esc, you have to enter it pressing Ctrl-v and then Esc
"^M" means "Return', you have to enter pressing Ctrl-v and then Return

Does that help? :)
Bernhard