From: Leo Alekseyev <dnquark@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Minor org mode for achieve code folding effects
Date: Tue, 10 Jan 2012 16:47:58 -0600 [thread overview]
Message-ID: <CADzxs1nkW_KO_n7RsTtO_W2nAvyUvoKGy+FgztaRFiFyuh44ug@mail.gmail.com> (raw)
In-Reply-To: <8739bnjmfc.fsf@ucl.ac.uk>
On Tue, Jan 10, 2012 at 3:08 PM, Eric S Fraga <e.fraga@ucl.ac.uk> wrote:
> Giovanni Giorgi <jj@gioorgi.com> writes:
>
>>
>>
>> Hi all,
>> I'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. Check 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
'(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 mode.
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= comment-starter ";")
(setq comment-starter ";;"))
(when (string= 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)
next prev parent reply other threads:[~2012-01-10 22:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-09 15:14 Minor org mode for achieve code folding effects Giovanni Giorgi
2012-01-09 15:23 ` Carsten Dominik
2012-01-10 21:08 ` Eric S Fraga
2012-01-10 22:47 ` Leo Alekseyev [this message]
2012-01-11 14:56 ` Eric S Fraga
2012-01-12 2:12 ` Leo Alekseyev
-- strict thread matches above, loose matches on Subject: below --
2012-01-11 0:34 David Rogoff
2012-01-11 1:21 ` David Rogoff
2012-01-11 6:23 ` Leo Alekseyev
2012-01-11 7:43 ` Tassilo Horn
2012-01-12 22:58 ` David Rogoff
2012-01-16 18:19 ` David Rogoff
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADzxs1nkW_KO_n7RsTtO_W2nAvyUvoKGy+FgztaRFiFyuh44ug@mail.gmail.com \
--to=dnquark@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).