emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Leo Alekseyev <dnquark@gmail.com>
To: emacs-orgmode@gnu.org
Cc: Tassilo Horn <tassilo@member.fsf.org>
Subject: Re: Minor org mode for achieve code folding effects
Date: Wed, 11 Jan 2012 00:23:01 -0600	[thread overview]
Message-ID: <CADzxs1nFjQw4jYyOd_U8j7FawOfphJKdxBuNowAV28TvTCcP_g@mail.gmail.com> (raw)
In-Reply-To: <4F0CE424.7020409@therogoffs.com>


[-- Attachment #1.1: Type: text/plain, Size: 3141 bytes --]

On Tue, Jan 10, 2012 at 7:21 PM, David Rogoff <david@therogoffs.com> wrote:

>
>
>   David Rogoff <david@therogoffs.com>
>  January 10, 2012 4:34 PM
>  Carlos Russo <mestre.adamastor <at> gmail.com> writes:
> 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.
>
>  This is great info! I was just looking for this in the last couple of
> days and appreciate everyone's code since it's way beyond my elisp
> abilities.
> I like this a lot more than the folding.el I had been using since I
> already use orgmode.  However, I've got a question:
>
> I'm using this with verilog-mode which uses "// " to start comments.  The
> problem is that when I indent my file, the comments indent too and it seems
> that output-minor-mode (and, I assume, orgmode) only recognize headings
> that start in column 0.  How/where can I change this so it will recognize
> any line that is whitepace followed by the comment-start?
>
>
>  I've done a little bit of digging into how Tassilo's code works, and
realized that it's somewhat broken in the following way: if a mode provides
its own outline-level function, chances are, his code will break (this is
why c-mode doesn't work).  Even if default outline-level is used, it will
determine the level incorrectly since it just counts characters in the
current outline regex.  Thus, with the ouline regexp set to something like
"## * " this function will say that you are on outline level 5.  This might
lead to some unexpected behavior.  Long story short, here is the fixed code
that provides and sets proper outline level:

  (defun th-outline-regexp ()
   "Calculate the outline regexp for the current mode."
   (let ((comment-starter (replace-regexp-in-string
                           "[[:space:]]+" "" comment-start)))
     (setq comment-starter (replace-regexp-in-string "*" "[*]"
comment-starter))
     (when (string= comment-starter ";")
       (setq comment-starter ";;"))
     (when (string= comment-starter "#")
       (setq comment-starter "##"))
     (concat "\\(" comment-starter "\\)" "\\( [*]+ \\)")))

  (defun th-lva-outline-level ()
    "Calculates appropriate outline level by counting the stars in the
regex"
    (let ((stars-regex "[*]+") (outline-start-string (match-string 2)))
       ;; ideally, second group obtained by (match-string 2) will be just
the stars
      (if (string-match stars-regex outline-start-string)
          (- (match-end 0) (match-beginning 0))
        0)))

  (defun th-outline-minor-mode-init ()
   (interactive)
   (unless (eq major-mode 'latex-mode)
     (setq outline-regexp (th-outline-regexp))
     (setq outline-level 'th-lva-outline-level)
     (font-lock-add-keywords
      nil
      th-outline-minor-mode-font-lock-keywords)
      (font-lock-fontify-buffer)))

[-- Attachment #1.2: Type: text/html, Size: 4974 bytes --]

[-- Attachment #2: postbox-contact.jpg --]
[-- Type: image/jpeg, Size: 1189 bytes --]

  reply	other threads:[~2012-01-11  6:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-11  0:34 Minor org mode for achieve code folding effects David Rogoff
2012-01-11  1:21 ` David Rogoff
2012-01-11  6:23   ` Leo Alekseyev [this message]
2012-01-11  7:43     ` Tassilo Horn
2012-01-12 22:58 ` David Rogoff
2012-01-16 18:19   ` David Rogoff
  -- strict thread matches above, loose matches on Subject: below --
2012-01-09 15:14 Giovanni Giorgi
2012-01-09 15:23 ` Carsten Dominik
2012-01-10 21:08 ` Eric S Fraga
2012-01-10 22:47   ` Leo Alekseyev
2012-01-11 14:56 ` Eric S Fraga
2012-01-12  2:12   ` Leo Alekseyev

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=CADzxs1nFjQw4jYyOd_U8j7FawOfphJKdxBuNowAV28TvTCcP_g@mail.gmail.com \
    --to=dnquark@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=tassilo@member.fsf.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).