how to use fold(or hideshow) in emacs python-mode

L

Li Daobing

Hello,
I want to use fold-mode or hideshow mode under emacs, but it doesn't
work.
Cound you tell me how to do this?
Thank you.

Li Daobing
 
S

Sean Richards

Li Daobing said:
Hello,
I want to use fold-mode or hideshow mode under emacs, but it doesn't
work.
Cound you tell me how to do this?
Thank you.

You can try this. I use something similar and it works quite well.

--8<--------------------------------------------------------------------

(add-hook 'python-mode-hook 'my-python-hook)

(defun py-outline-level ()
"This is so that `current-column` DTRT in otherwise-hidden text"
;; from ada-mode.el
(let (buffer-invisibility-spec)
(save-excursion
(skip-chars-forward "\t ")
(current-column))))

; this fragment originally came from the web somewhere, but the outline-regexp
; was horribly broken and is broken in all instances of this code floating
; around. Finally fixed by Charl P. Botha <<a href="http://cpbotha.net/">http://cpbotha.net/</a>>
(defun my-python-hook ()
(setq outline-regexp "[^ \t\n]\\|[ \t]*\\(def[ \t]+\\|class[ \t]+\\)")
; enable our level computation
(setq outline-level 'py-outline-level)
; do not use their \C-c@ prefix, too hard to type. Note this overides
;some python mode bindings
(setq outline-minor-mode-prefix "\C-c")
; turn on outline mode
(outline-minor-mode t)
; initially hide all but the headers
(hide-body)
(show-paren-mode 1)
)

--8<--------------------------------------------------------------------

This code was found here -> http://tinyurl.com/7yyqv

Cheers, Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top