From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leo Alekseyev Subject: Re: Minor org mode for achieve code folding effects Date: Tue, 10 Jan 2012 16:47:58 -0600 Message-ID: References: <868da41d9950ca4a287a97c02084c28c@mail.webfaction.com> <8739bnjmfc.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:47124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkkU5-0006s3-Q9 for emacs-orgmode@gnu.org; Tue, 10 Jan 2012 17:48:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RkkU4-0000mh-EB for emacs-orgmode@gnu.org; Tue, 10 Jan 2012 17:48:01 -0500 Received: from mail-pw0-f41.google.com ([209.85.160.41]:44205) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkkU4-0000mZ-9E for emacs-orgmode@gnu.org; Tue, 10 Jan 2012 17:48:00 -0500 Received: by pbdd2 with SMTP id d2so132205pbd.0 for ; Tue, 10 Jan 2012 14:47:59 -0800 (PST) In-Reply-To: <8739bnjmfc.fsf@ucl.ac.uk> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org On Tue, Jan 10, 2012 at 3:08 PM, Eric S Fraga wrote: > Giovanni Giorgi writes: > >> >> >> Hi all, >> =A0I'd like to edit some ruby/python/shell script using >> functions folding. >> >> I'd like to get a way to fold functions or method. > > Carsten has already given you one possible solution; another is to use > org + babel with tangling to have each function or method within a > separate headline in an org document. =A0Check out the manual I have used both Carsten's and Eric's solution, as well as hideshow-org (https://github.com/secelis/hideshow-org), which works rather well and deserves a mention. Expanding a bit on Carsten's post: Tassilo Horn wrote some convenience functions to set the outline minor mode regexps to correspond to the current comment syntax. Thus, if I'm (for instance) in shell-script mode, # * and # ** become the outline level 1 and 2 markers. One issue with this approach is that you might prefer finer control over what sections appear folded and what sections appear visible by default. To deal with this, I hacked org.el watch for special visibility-control markers in the heading line, so that e.g. * A heading ending with tilde-tilde like so ~~ would appear always visible. I hope to come up with a better solution for this in the future. The other issue is that Tassilo's code is currently broken for c-mode (possibly due to conflating *'s in /* comment syntax with *'s in the outline header level syntax). If you can fix it, that would be useful :) The code: (require 'outline) (add-hook 'outline-minor-mode-hook =09 '(lambda () (define-key outline-minor-mode-map (kbd "TAB") 'org-cycle) (define-key outline-minor-mode-map [(tab)] 'org-cycle) (define-key outline-minor-mode-map [(shift tab)] 'org-global-cycle) (define-key outline-minor-mode-map [backtab] 'org-global-cycle))) ;; Tassilo Horn's outline-minor-mode enhancement: derive regex from comment syntax (defvar th-outline-minor-mode-font-lock-keywords '((eval . (list (concat "^\\(?:" outline-regexp "\\).*") 0 '(outline-font-lock-face) t t))) "Additional expressions to highlight in Orgstruct Mode and Outline minor m= ode. The difference to `outline-font-lock-keywords' is that this will overwrite other highlighting.") (defun th-outline-regexp () "Calculate the outline regexp for the current mode." (let ((comment-starter (replace-regexp-in-string "[[:space:]]+" "" comment-start))) (when (string=3D comment-starter ";") (setq comment-starter ";;")) (when (string=3D comment-starter "#") (setq comment-starter "##")) (concat comment-starter " [*]+ "))) (defun th-outline-minor-mode-init () (interactive) (unless (eq major-mode 'latex-mode) (setq outline-regexp (th-outline-regexp)) (font-lock-add-keywords nil th-outline-minor-mode-font-lock-keywords) (font-lock-fontify-buffer))) (add-hook 'outline-minor-mode-hook 'th-outline-minor-mode-init)