About

Welcome to Panela, Matt Harrison's take on mostly Open Source, Linux, Python, innovation in those areas, other buzzwords and Dick Proenneke. It comes complete with the illustrations as needed. Note the opinions expressed here are merely my opinions and not the opinions of my employer.

about Matt

Calendar

««Nov 2009»»
SMTWTFS
1234567
8910
11
12
1314
151617
18
192021
22232425262728
2930

Mailing List

My RSS Feeds








Python and emacs (1): Keyboard macros

posted 2009.01.13 Tue

I'll admit I'm mediocre at emacs. Which is kind of silly because other than a few years of eclipse use it's been my main editor for some 11 years. In an effort to help me start using features I don't normally use, I'm going to go over Jonathon's features of python IDE's in a series of blog posts, but with a focus on emacs. I'm going to base the post's on the features found there, but also might do some other features that I think are handy. If you've got comments, suggestions, by all means let me know. Also, one way to learn is by watching others. Well I can't watch you, but you can drop hints. I've sat in the presence of people who live in a screened session of emacs, and wish I would've taken note of what they did...

Some possible outcomes of this might be updating the content on emacswiki and python wiki both of which seem somewhat disorganized. Another outcome might be a "Teach me how to use emacs...." session in PyCon. (I wouldn't teach it, but would love to see demo's of others using features that I should be using).

Without further ado, here's the first feature on the list:

Keyboard macros

Yes! Emacs has keyboard macros. The documentation included in emacs manual (C-h r) and the emacswiki entry on keyboard macros seem simple enough.

This might seem lame for my first entry, since I'm not really expounding on anything new. But I'll admit, I never use macros. It seems like either a search/replace covers most needs, otherwise if it's something more complicated than that I'll write a script or do it by hand (if it's a one time thing). I'll further admit, that most of these are not even when editing python. So my questions to all emacs gurus out there: When do you find macros nice? When do you use them when python programming?

update - I'm using macros more and finding them useful every so often. Also extremely useful in Python are the rectangle commands. I really only use one ,C-x r t (string-rectangle), which is a great combination for inserts and deletes!. Another use for macros is to simplify creating functions. Today I wanted a command to kill the pdb buffer and restart pdb (since I was doing it a lot). I made a macro for it. I named it (C-x C-k n), then I pasted the macro in my .emacs using M-x insert-kbd-macro, then I bound the command to f11 as listed in the emacswiki macro entry (sub heading One-Key Macros).

tags:      

links: digg this    del.icio.us    reddit




1. Tom left...
2009.01.13 Tue 5:19 pm :: http://badrunner.net

Looking forward to some more emacs articles. I've just started using it again after breaking for a year or so jumping from vim to eclipse to komodo edit amongst others, so any pointers, especially python ones would be great.


2. Steve Holden left...
2009.01.13 Tue 8:48 pm :: http://holdenweb.com/

"""Another outcome might be a "Teach me how to use emacs...." session in PyCon. (I wouldn't teach it, but would love to see demo's of others using features that I should be using)."""

While you may not teach it, you should certainly be the guy at the front of the room. The idea behind "Teach Me" is that you, along with most of the rest of the audience, learn publicly from the cognoscenti in the room, making sure that their output is accessible to everyone. I think a "Teach Me Emacs" session would be a great idea!


3. Chris Lee-Messer left...
2009.01.13 Tue 9:48 pm

I find that with python, I don't need code completion much, but it's still useful at times. pysmell with emacs is pretty cool. It's by Orestis Markou

http://code.google.com/p/pysmell/


4. Tom Ritchford left...
2009.01.14 Wed 1:43 am

I use emacs macros constantly. If you get good at them, you see all sorts of examples - for example, you often need to make the same change to several functions, and if you are careful to make your navigation general, you can do the first one carefully and then use a macro to do the rest.

In fact, when I'm using Eclipse, the only reason I ever duck back into emacs is for the macros!


5. Floris Bruynooghe left...
2009.01.14 Wed 5:48 am :: http://bruynooghe.blogspot.com

A "Teach me how to use Emacs" session would be great! Preferably at euro pycon too.


6. drewp left...
2009.01.17 Sat 11:01 pm

I love dmacro: http://drewp.quickwitretort.com/2006/05/22/0

If your repeated actions can be run right after one another (i.e. you don't have to do an arbitrary move to the next place you want to run the macro), dmacro wins. Just make your loop obvious (e.g. C-s C-s left del del f o o C-s C-s left) and press the "keep repeating that" key.


7. Shawn Willden left...
2009.01.22 Thu 9:55 pm :: http://krisandshawn.blogspot.com

I use keyboard macros all the time. Any time I find myself repeating the same sequence of actions for a second time, and know I'm going to do it a few more, I pay attention to how I can "generalize" the movements to make them macroable, and then the third time I do it, I record. After that it's just C-x e, C-x e -- or even better, C-u 50 C-x e. Keyboard macros rock.