From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leo Alekseyev Subject: Re: Minor org mode for achieve code folding effects Date: Wed, 11 Jan 2012 00:23:01 -0600 Message-ID: References: <4F0CD92F.9030004@therogoffs.com> <4F0CE424.7020409@therogoffs.com> Mime-Version: 1.0 Content-Type: multipart/related; boundary=e89a8ff1cceceb3b1c04b63aa914 Return-path: Received: from eggs.gnu.org ([140.186.70.92]:53114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkraT-00044H-JM for emacs-orgmode@gnu.org; Wed, 11 Jan 2012 01:23:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RkraR-0005Kl-Rq for emacs-orgmode@gnu.org; Wed, 11 Jan 2012 01:23:05 -0500 Received: from mail-pz0-f41.google.com ([209.85.210.41]:53868) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkraR-0005Kh-HE for emacs-orgmode@gnu.org; Wed, 11 Jan 2012 01:23:03 -0500 Received: by dakl33 with SMTP id l33so260795dak.0 for ; Tue, 10 Jan 2012 22:23:02 -0800 (PST) In-Reply-To: <4F0CE424.7020409@therogoffs.com> 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 Cc: Tassilo Horn --e89a8ff1cceceb3b1c04b63aa914 Content-Type: multipart/alternative; boundary=e89a8ff1cceceb3b1304b63aa913 --e89a8ff1cceceb3b1304b63aa913 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Jan 10, 2012 at 7:21 PM, David Rogoff wrote: > > > David Rogoff > January 10, 2012 4:34 PM > Carlos Russo 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))) --e89a8ff1cceceb3b1304b63aa913 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Tue, Jan 10, 2012 at 7:21 PM, David R= ogoff <david@t= herogoffs.com> wrote:


=20 January 10, 2012= =20 4:34 PM
Carlos Russo <mestre.adamastor <at> gmail.com> writes:
I have used both Carsten's and Eric&#= 39;s=20 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<= br> functions to set the outline minor mode regexps to correspond to the
current comment syntax.=A0 Thus, if I'm (for instance) in shell-script<= br> 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=20 days and appreciate everyone's code since it's way beyond my elisp= =20 abilities.
I like this a lot more than the folding.el I had been using since I=20 already use orgmode.=A0 However, I've got a question:

I'm using this with verilog-mode which uses "// " to start co= mments.=A0=20 The problem is that when I indent my file, the comments indent too and=20 it seems that output-minor-mode (and, I assume, orgmode) only recognize=20 headings that start in column 0.=A0 How/where can I change this so it will recognize any line that is whitepace followed by the comment-start?


=A0I've done a lit= tle bit of digging into how Tassilo's code works,=20 and realized that it's somewhat broken in the following way: if a mode= =20 provides its own outline-level function, chances are, his code will=20 break (this is why c-mode doesn't work).=A0 Even if default outline-lev= el=20 is used, it will determine the level incorrectly since it just counts=20 characters in the current outline regex.=A0 Thus, with the ouline regexp=20 set to something like "## * " this function will say that you are= on=20 outline level 5.=A0 This might lead to some unexpected behavior.=A0 Long=20 story short, here is the fixed code that provides and sets proper=20 outline level:

=A0 (defun th-outline-regexp ()
=A0=A0 "Calculate the outline regexp for the current mode."
=A0=A0 (let ((comment-starter (replace-regexp-in-string
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 "[[:space:]]+" "" comment-start)))
=A0=A0=A0=A0 (setq comment-starter (replace-regexp-in-string "*" = "[*]" comment-starter))
=A0=A0=A0=A0 (when (string=3D comment-starter ";")
=A0=A0=A0=A0=A0=A0 (setq comment-starter ";;"))
=A0=A0=A0=A0 (when (string=3D comment-starter "#")
=A0=A0=A0=A0=A0=A0 (setq comment-starter "##"))
=A0=A0=A0=A0 (concat "\\(" comment-starter "\\)" "= \\( [*]+ \\)")))
=A0
=A0 (defun th-lva-outline-level ()
=A0=A0=A0 "Calculates appropriate outline level by counting the stars = in the regex"
=A0=A0=A0 (let ((stars-regex "[*]+") (outline-start-string (match= -string 2)))
=A0=A0=A0=A0=A0=A0 ;; ideally, second group obtained by (match-string 2) wi= ll be just the stars
=A0=A0=A0=A0=A0 (if (string-match stars-regex outline-start-string)
=A0=A0=A0=A0=A0=A0=A0=A0=A0 (- (match-end 0) (match-beginning 0))
=A0=A0=A0=A0=A0=A0=A0 0)))
=A0
=A0 (defun th-outline-minor-mode-init ()
=A0=A0 (interactive)
=A0=A0 (unless (eq major-mode 'latex-mode)
=A0=A0=A0=A0 (setq outline-regexp (th-outline-regexp))
=A0=A0=A0=A0 (setq outline-level 'th-lva-outline-level)
=A0=A0=A0=A0 (font-lock-add-keywords
=A0=A0=A0=A0=A0 nil
=A0=A0=A0=A0=A0 th-outline-minor-mode-font-lock-keywords)
=A0=A0=A0=A0=A0 (font-lock-fontify-buffer)))
=A0
--e89a8ff1cceceb3b1304b63aa913-- --e89a8ff1cceceb3b1c04b63aa914 Content-Type: image/jpeg; x-apple-mail-type=stationery; name="postbox-contact.jpg" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: cc242eba6511fe91_0.1.1 /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkI CQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQ EBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCAAZABkDAREA AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA AAF9AQIDAAQRBRIhMUEG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