emacs php folding

I found myself needing code folding in PHP5 again, and switched to TextMate for a few days. But it just doesn't handle things right ... nice UI, but it inserts a <% %> every time I press ^x which drove me nuts. So I worked out how to make code folding for PHP5 work in Aquamacs, and here it is (for your .emacs).

(defun show-onelevel ()
"show entry and children in outline mode"
(interactive)
(show-entry)
(show-children))
;;
(defun cjm-outline-bindings ()
"sets shortcut bindings for outline minor mode"
(interactive)
(local-set-key [?\C-,] 'hide-sublevels)
(local-set-key [?\C-.] 'show-all)
(local-set-key [C-up] 'outline-previous-visible-heading)
(local-set-key [C-down] 'outline-next-visible-heading)
(local-set-key [C-left] 'hide-subtree)
(local-set-key [C-right] 'show-onelevel)
(local-set-key [M-up] 'outline-backward-same-level)
(local-set-key [M-down] 'outline-forward-same-level)
(local-set-key [M-left] 'hide-subtree)
(local-set-key [M-right] 'show-subtree))
;;
(add-hook 'outline-minor-mode-hook
'cjm-outline-bindings)
;;
(add-hook 'php-mode-user-hook
'(lambda ()
(outline-minor-mode)
(setq outline-regexp " *\\(public funct\\|private funct\\|funct\\|class\\|#head\\)")
(hide-sublevels 1)))
;;
(add-hook 'python-mode-hook
'(lambda ()
(outline-minor-mode)
(setq outline-regexp " *\\(def \\|clas\\|#hea\\)")
(hide-sublevels 1)))

Did I mention it's just crude enough to work for me?

Comments

Thanks

Thanks, I been looking for something like this and it works great!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <code> <br> <h2> <h3> <h4> <h5> <h6>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.