473,408 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

emacs alphabetize methods


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
3 2280
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
"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
IDE
by: Thomas Lindgaard | last post by:
Hello I am probably going to start a war now... but so be it :) I just want to hear what all you guys who eat pythons for breakfast use for python coding. Currently I use Kate, but I would...
81
by: julio | last post by:
Sorry but there is no another way, c# .net and mono are going to rip python, not because python is a bad lenguage, but because is to darn old and it refuses to innovate things, to fix wrong things,...
2
by: John Crouse | last post by:
I have a text file like so: ben amy jerry ann john and would like to alphabetize each line like so:
12
by: Thomas Bartkus | last post by:
Does anyone use emacs together with both WordStar key bindings and python mode? I'm afraid that Wordstar editing key commands are burned R/O into my knuckles! I would like to play with emacs...
7
by: Xah Lee | last post by:
Summary: when encountering ex as a unit in css, FireFox (and iCab) did not take into account the font-family. Detail: http://xahlee.org/js/ff_pre_ex.html Xah xah@xahlee.org ∑...
4
by: emin.shopper | last post by:
Emacs seems to freeze when doing certain shell commands on Microsoft Windows. The following is a simple example with Xemacs: ---------------------------------------------------------- ...
331
by: Xah Lee | last post by:
http://xahlee.org/emacs/modernization.html ] The Modernization of Emacs ---------------------------------------- THE PROBLEM Emacs is a great editor. It is perhaps the most powerful and...
4
by: Richard Szopa | last post by:
Hi All, I am a devoted Emacs user and I write a lot in Python. However, I never managed to get my Emacs configuration right for this purpose. There were some discussions on this, but the threads...
14
by: jmDesktop | last post by:
Hi, I'm trying to learn Python. I using Aquamac an emac implementation with mac os x. I have a program. If I go to the command prompt and type pythong myprog.py, it works. Can the program be...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.