Emacs? (was Re: total idiot question: +=, .=, etc...)

Alex Rice alex at mindlube.com
Thu Jun 24 22:09:29 EDT 1999


Preston Landers <planders at mail.utexas.edu> writes:

> I'm thinking of doing a similar thing in (X)Emacs.  It's my editor of
> choice though I've never actually *programmed* something into emacs
> itself.  I'm wondering if anyone's already done a similar thing so I
> can spare the trouble (and the learning exercise, bah.)  
> 
> I'm thinking the best way might be to hook in to abbrev mode or
> something... I guess I have some homework to do in this area.  I was
> just wondering if someone's already done something like this. 

Not that I know of -- and that doesn't mean much --, but since I'm
always willing to learn more about Emacs (wink-wink, nudge-nudge),
here are some macros that kind of approximate it...

In Emacs, creating a macro is easy: C-x( [type stuff here] C-x)
Binding the macros to sensible keystrokes seems to be the hard part in
this case. I challenge you to find a way to integrate these into
emacs's python-mode. :-)

Put this in your .emacs

8< cut

;; Macros for Python  
;; Alex Rice <alex at mindlube.com>

(defalias '++
  (read-kbd-macro "C-SPC ESC b ESC w ESC f = C-y +1 C-e"))
(defalias '--
  (read-kbd-macro "C-SPC ESC b ESC w ESC f = C-y -1 C-e"))
(defalias '+=
  (read-kbd-macro "C-SPC ESC b ESC w ESC f = C-y + C-e"))
(defalias '-=
  (read-kbd-macro "C-SPC ESC b ESC w ESC f = C-y - C-e"))
(defalias '*=
  (read-kbd-macro "C-SPC ESC b ESC w ESC f = C-y * C-e"))
(defalias '/=
  (read-kbd-macro "C-SPC ESC b ESC w ESC f = C-y / C-e"))

8< cut

Now for example typing

spam M-x++

yields

spam=spam+1 

BTW, _Learning GNU Emacs_ by O'Reilly & Assoc is a good gentle intro
to Emacs if you are like me and sometimes can't figure it out just
from the Info browser.

Cheers,

Alex Rice




More information about the Python-list mailing list