By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,050 Members | 1,019 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,050 IT Pros & Developers. It's quick & easy.

emacs alphabetize methods

P: n/a

Using emacs python-mode with a class

class C:
def method1(self):
pass

def anothermethod(self):
pass

def method2(self):
pass

is there any way to select all the methods and have emacs order them
alphabetically? If not, is there a good too to do so?

Thanks,
John Hunter

Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Not that I am aware of - but this wouldn't be an impossible job to tackle
yourself and provide the results for benefit of the rest of us who uses
Emacs :-)

My suggestion for how to do this (off the top of my head :-)) is to write a
support (Python) program to call from your emacs using Pymacs
(http://pymacs.progiciels-bpi.ca/manu...--buffer.html).

Then you could probably locate the points where your methods start and
finish using services available from the Python Language Services section in
the Python Library Reference (Chapter 18), re-arrange the source code and
then re-insert it back into your Python buffer.

Probably not a very big job at all - if you don't do it then I might well do
it myself one day (but not in the foreseeable future due to other work loads
:-)).

Regards,
Peter

"John Hunter" <jd******@ace.bsd.uchicago.edu> wrote in message
news:ma**************************************@pyth on.org...

Using emacs python-mode with a class

class C:
def method1(self):
pass

def anothermethod(self):
pass

def method2(self):
pass

is there any way to select all the methods and have emacs order them
alphabetically? If not, is there a good too to do so?

Thanks,
John Hunter

Jul 18 '05 #2

P: n/a
"Peter Milliken" <pe****@resmed.com.au> writes:
My suggestion for how to do this (off the top of my head :-)) is to write a
support (Python) program to call from your emacs using Pymacs
(http://pymacs.progiciels-bpi.ca/manu...--buffer.html).


You can just call the program directly and use stdin/stdout:

(defun my-alphabize-region (beg end)
"Sort methods in region alphabetically."
(interactive "r")
;; run command with region as input, and replace it with the output
(shell-command-on-region
beg end
"myCommand" ;<<< Your command here
t t "*errors*"))
(You could do this entirely inside emacs of course.)

--
Johan Bockgård
Jul 18 '05 #3

P: n/a
"John Hunter" <jd******@ace.bsd.uchicago.edu> wrote:

John> Using emacs python-mode with a class
John>
John> class C:
John> def method1(self):
John> pass
John>
John> def anothermethod(self):
John> pass
John>
John> def method2(self):
John> pass
John>
John> is there any way to select all the methods and have emacs order
John> them alphabetically? If not, is there a good too to do so?

Sort of, but there are problems. Emacs does have a sort-paragraphs
function. Python-mode has a py-mark-block command. If you place the
cursor at the start of the "class" line and hit C-c C-k you'll mark the
class. Hit C-n C-x C-x to highlight the block except for the class line
itself then M-x sort-paragraphs RET.

This has a gotcha. The notion of paragraph separator is basically a blank
line. To make this more effective you'd have to modify the
paragraph-separate variable. If you come up with a reasonable value for
Python code, send it along to py*********@python.org and we'll update
python-mode.el.

Skip


Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.