[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Minor org mode for achieve code folding effects

From: Leo Alekseyev
Subject: Re: [O] Minor org mode for achieve code folding effects
Date: Wed, 11 Jan 2012 00:23:01 -0600

On Tue, Jan 10, 2012 at 7:21 PM, David Rogoff <address@hidden> wrote:

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))
  (defun th-outline-minor-mode-init ()
   (unless (eq major-mode 'latex-mode)
     (setq outline-regexp (th-outline-regexp))
     (setq outline-level 'th-lva-outline-level)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]