Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Code folder with Emacs

Reply
Thread Tools

Code folder with Emacs

 
 
Grant Edwards
Guest
Posts: n/a
 
      03-20-2008
Has anybody figured out how to do code folding of Python source
files in emacs?

I tried "hide-show" minor mode, but it doesn't really work for
Python code: the only think it knows how to hide/show are
function bodies. It can't do normal things like hide/show a
code block like it can for other languages.

Google also found my "folding mode", but that's based on
user-inserted tokens and isn't syntax aware.

--
Grant

 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      03-21-2008
Grant Edwards schrieb:
> Has anybody figured out how to do code folding of Python source
> files in emacs?
>
> I tried "hide-show" minor mode, but it doesn't really work for
> Python code: the only think it knows how to hide/show are
> function bodies. It can't do normal things like hide/show a
> code block like it can for other languages.
>
> Google also found my "folding mode", but that's based on
> user-inserted tokens and isn't syntax aware.
>


I just recently started hacking in emacs, to enhance the python-mode and
make pdb work with persisten breakpoints (by that I mean BPs that
survive one debug-session).

Code-folding isn't currently on my agenda, but an interesting idea.
given that e.g. ecb already has structural analysis buffers, there are
python-aware code parsers (cedet?)

So it shouldn't be too hard. The only interesting/important thing would
be to integrate it with ecb because I wouldn't want several parse-runs
at once.


BTW, I can highly recommend flymake for running pylint over the sources!
That really helps me a lot these days!

Diez
 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a
 
      03-21-2008
On 2008-03-21, Diez B. Roggisch <> wrote:

>> Has anybody figured out how to do code folding of Python source
>> files in emacs?
>>
>> I tried "hide-show" minor mode, but it doesn't really work for
>> Python code: the only think it knows how to hide/show are
>> function bodies. It can't do normal things like hide/show a
>> code block like it can for other languages.

>
> I just recently started hacking in emacs, to enhance the
> python-mode and make pdb work with persisten breakpoints (by
> that I mean BPs that survive one debug-session).
>
> Code-folding isn't currently on my agenda, but an interesting
> idea. given that e.g. ecb already has structural analysis
> buffers, there are python-aware code parsers (cedet?)


Given the simplicity of python's indentation-defined
block-delimiting, It's hard to understand how hide-show managed
to come up with a "block" definition that works for function
bodies but not for other identically delimited blocks.

> So it shouldn't be too hard. The only interesting/important
> thing would be to integrate it with ecb because I wouldn't
> want several parse-runs at once.


When I have some time, I'm going to take alook at hide-show's
Python support, but my lisp skills are a bit rusty...

--
Grant
 
Reply With Quote
 
Martin Sand Christensen
Guest
Posts: n/a
 
      03-25-2008
>>>>> "Grant" == Grant Edwards <> writes:
Grant> Has anybody figured out how to do code folding of Python source
Grant> files in emacs?

I use outline-minor-mode with the following home baked configuration:

;; Python stuff for outline mode.
(defvar py-outline-regexp "^\\([ \t]*\\)\\(def\\|class\\|if\\|elif\\|else\\|while\\|fo r\\|try\\|except\\|with\\)"
"This variable defines what constitutes a 'headline' to outline mode.")

(defun py-outline-level ()
"Report outline level for Python outlining."
(save-excursion
(end-of-line)
(let ((indentation (progn
(re-search-backward py-outline-regexp)
(match-string-no-properties 1))))
(if (and (> (length indentation) 0)
(string= "\t" (substring indentation 0 1)))
(length indentation)
(/ (length indentation) py-indent-offset)))))
(add-hook 'python-mode-hook
'(lambda ()
(outline-minor-mode 1)
(setq
outline-regexp py-outline-regexp
outline-level 'py-outline-level)))


Martin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Q for Emacs users: code-folding (hideshow) kj Python 7 07-17-2010 12:57 PM
Trouble running Emacs-EPL (to run perl in emacs). Adam Funk Perl Misc 4 01-29-2007 10:42 AM
writing wx code in emacs - how to make easier? Seweryn Kokot Python 1 11-12-2006 04:26 PM
Emacs commands for running Ruby code francisrammeloo@hotmail.com Ruby 2 08-19-2005 05:45 PM
code coverage tool with emacs integration? John J. Lee Python 3 07-28-2003 01:17 AM



Advertisments