emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* OrgStruct for Python source code
@ 2014-03-19 16:54 Karl Voit
  2014-03-19 17:03 ` Bastien
  0 siblings, 1 reply; 5+ messages in thread
From: Karl Voit @ 2014-03-19 16:54 UTC (permalink / raw)
  To: emacs-orgmode

Hi!

I am evaluating methods to fold Python source code. I stumbled over
orgstruct-mode which looks quite cool to me. My first test with 

    (setq orgstruct-heading-prefix-regexp "^[ ]*##[ ]+\*[ ]")

worked out of the box.

Unfortunately, this attempt requires a comment linke for each
Python-def in order to be able to fold at def-borders.

IMHO it would be very cool if I could come up with a regexp which
folds at the def-definitions like

    (setq orgstruct-heading-prefix-regexp "^[ ]*def .+(.*)\s-*$")

-> optional white spaces followed by "def " and a name. Then the
parenthesis with optional arguments followed by optional
whitespaces.

This should fold all defs. Unfortunately, this does not work at my
side. Did I make a mistake or do I have to limit myself to matching
comment lines only?

Thanks!

-- 
mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
       > get Memacs from https://github.com/novoid/Memacs <

https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: OrgStruct for Python source code
  2014-03-19 16:54 OrgStruct for Python source code Karl Voit
@ 2014-03-19 17:03 ` Bastien
  2014-03-19 19:39   ` Karl Voit
  0 siblings, 1 reply; 5+ messages in thread
From: Bastien @ 2014-03-19 17:03 UTC (permalink / raw)
  To: Karl Voit; +Cc: news1142, emacs-orgmode

Hi Karl,

Karl Voit <devnull@Karl-Voit.at> writes:

> This should fold all defs. Unfortunately, this does not work at my
> side. Did I make a mistake or do I have to limit myself to matching
> comment lines only?

simply turn on orgstruct-mode in a python buffer and try
M-x org-cycle RET on a def: it will fold it.

`orgstruct-heading-prefix-regexp' comes on top of that,
if needed, but as long as `outline-regexp' is properly
set, orgstruct-mode gives you the cycling commands.

For example, this is the bindings I have for emacs-lisp:

(global-set-key (kbd "C-M-]") (lambda () (interactive) (org-cycle t)))

(global-set-key (kbd "M-]")
                (lambda () (interactive)
                  (ignore-errors (end-of-defun) (beginning-of-defun)) (org-cycle)))

HTH,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: OrgStruct for Python source code
  2014-03-19 17:03 ` Bastien
@ 2014-03-19 19:39   ` Karl Voit
  2014-03-20  1:19     ` Ilya Shlyakhter
  0 siblings, 1 reply; 5+ messages in thread
From: Karl Voit @ 2014-03-19 19:39 UTC (permalink / raw)
  To: emacs-orgmode

* Bastien <bzg@gnu.org> wrote:
> Hi Karl,

Hi Bastien!

> simply turn on orgstruct-mode in a python buffer and try
> M-x org-cycle RET on a def: it will fold it.

Oh, even better! :-) Thanks for the pointer!

-- 
mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
       > get Memacs from https://github.com/novoid/Memacs <

https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: OrgStruct for Python source code
  2014-03-19 19:39   ` Karl Voit
@ 2014-03-20  1:19     ` Ilya Shlyakhter
  2014-03-20  1:30       ` Ilya Shlyakhter
  0 siblings, 1 reply; 5+ messages in thread
From: Ilya Shlyakhter @ 2014-03-20  1:19 UTC (permalink / raw)
  To: emacs-orgmode

On 3/19/2014 3:39 PM, Karl Voit wrote:
>I am evaluating methods to fold Python source code.
>> simply turn on orgstruct-mode in a python buffer and try
>> M-x org-cycle RET on a def: it will fold it.

Another option is to use Thorsten Jolitz's excellent outshine mode
( http://orgmode.org/worg/org-tutorials/org-outside-org.html ).

I've written a small extension that allows it to fold language elements:
http://www.broadinstitute.org/~ilya/outshine-python.el

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: OrgStruct for Python source code
  2014-03-20  1:19     ` Ilya Shlyakhter
@ 2014-03-20  1:30       ` Ilya Shlyakhter
  0 siblings, 0 replies; 5+ messages in thread
From: Ilya Shlyakhter @ 2014-03-20  1:30 UTC (permalink / raw)
  To: emacs-orgmode

On 3/19/2014 9:19 PM, Ilya Shlyakhter wrote:

> Another option is to use Thorsten Jolitz's excellent outshine mode
> ( http://orgmode.org/worg/org-tutorials/org-outside-org.html ).
>
> I've written a small extension that allows it to fold language elements:
> http://www.broadinstitute.org/~ilya/outshine-python.el

Apologies, correct link is 
https://github.com/notestaff/outshine/blob/outshine-lang/outshine-lang.el

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-03-20  1:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-19 16:54 OrgStruct for Python source code Karl Voit
2014-03-19 17:03 ` Bastien
2014-03-19 19:39   ` Karl Voit
2014-03-20  1:19     ` Ilya Shlyakhter
2014-03-20  1:30       ` Ilya Shlyakhter

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).