* Re: Minor org mode for achieve code folding effects
@ 2012-01-11 0:34 David Rogoff
2012-01-11 1:21 ` David Rogoff
2012-01-12 22:58 ` David Rogoff
0 siblings, 2 replies; 12+ messages in thread
From: David Rogoff @ 2012-01-11 0:34 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1138 bytes --]
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?
Thanks!
David
[-- Attachment #2: Type: text/html, Size: 1536 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Minor org mode for achieve code folding effects
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
2012-01-12 22:58 ` David Rogoff
1 sibling, 1 reply; 12+ messages in thread
From: David Rogoff @ 2012-01-11 1:21 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1913 bytes --]
> David Rogoff <mailto: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?
>
This works, but is probably not the best way to do it:
(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 "##"))
(when (eq major-mode 'verilog-mode)
(setq comment-starter "\\s-*//")) ;; for verilog-mode, define
comment-starter as any amount of whitespace followed by "//". This
allows indented comments as outline levels
(concat comment-starter " [*]+ ")))
[-- Attachment #2.1: Type: text/html, Size: 3730 bytes --]
[-- Attachment #2.2: postbox-contact.jpg --]
[-- Type: image/jpeg, Size: 1189 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Minor org mode for achieve code folding effects
2012-01-11 1:21 ` David Rogoff
@ 2012-01-11 6:23 ` Leo Alekseyev
2012-01-11 7:43 ` Tassilo Horn
0 siblings, 1 reply; 12+ messages in thread
From: Leo Alekseyev @ 2012-01-11 6:23 UTC (permalink / raw)
To: emacs-orgmode; +Cc: Tassilo Horn
[-- 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 --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Minor org mode for achieve code folding effects
2012-01-11 6:23 ` Leo Alekseyev
@ 2012-01-11 7:43 ` Tassilo Horn
0 siblings, 0 replies; 12+ messages in thread
From: Tassilo Horn @ 2012-01-11 7:43 UTC (permalink / raw)
To: Leo Alekseyev; +Cc: emacs-orgmode
Leo Alekseyev <dnquark@gmail.com> writes:
> 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.
Yes, I was satisfied with having different colors. But thanks a lot for
the improved version!
Bye,
Tassilo
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Minor org mode for achieve code folding effects
2012-01-11 0:34 Minor org mode for achieve code folding effects David Rogoff
2012-01-11 1:21 ` David Rogoff
@ 2012-01-12 22:58 ` David Rogoff
2012-01-16 18:19 ` David Rogoff
1 sibling, 1 reply; 12+ messages in thread
From: David Rogoff @ 2012-01-12 22:58 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1982 bytes --]
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.
I have all this working and it's great. But... This is using
outline-minor-mode. Like Giovanni, who started this thread, I'm used
to orgmode, which is a little different although it uses outline mode.
I tried hacking the code to use orgstruct-mode, which is the minor mode
version of orgmode. I got a little figured out, but got lost. I would
think all of Tassilo's code to automatically set up outline-regexp would
still be valid, but I'm not doing something right. I saw Carsten's
message to look at the visibility cycling and understand that, but the
keymaps are not working right and the outline-regexp isn't being set
right. I've worked around the latter with a quick function I can call
from the file buffer. However, I don't know what's going on with the
keymap. It looks right. For example, c-h k TAB gives this:
<tab> runs the command orgstruct-hijacker-command-102, which is an
interactive Lisp function.
It is bound to <tab>.
(orgstruct-hijacker-command-102 ARG)
In Structure, run `org-cycle'.
Outside of structure, run the binding of `[(tab)]' or ` '.
However, it doesn't seem to recognize when it's in a structure. M-x
org-cycle works as does M-x org-global-cycle.
I only need this for emacs-lisp-mode and verilog-mode so I simplified
Tassilo's code like this:
(when (eq major-mode 'emacs-lisp-mode)
(setq outline-regexp ";; [*]+ "))
(when (eq major-mode 'verilog-mode)
(setq outline-regexp "\\s-*// [*]+ "))
Help Please!
Thanks!
David
[-- Attachment #2: Type: text/html, Size: 2585 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Minor org mode for achieve code folding effects
2012-01-12 22:58 ` David Rogoff
@ 2012-01-16 18:19 ` David Rogoff
0 siblings, 0 replies; 12+ messages in thread
From: David Rogoff @ 2012-01-16 18:19 UTC (permalink / raw)
To: emacs-orgmode
David Rogoff <david <at> therogoffs.com> writes:
> 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.
>
> I have all this working and it's great. But... This is using outline-minor-
mode. Like Giovanni, who started this thread, I'm used to orgmode, which is a
little different although it uses outline mode. I tried hacking the code to use
orgstruct-mode, which is the minor mode version of orgmode. I got a little
figured out, but got lost.
> I would think all of Tassilo's code to automatically set up outline-regexp
would still be valid, but I'm not doing something right. I saw Carsten's message
to look at the visibility cycling and understand that, but the keymaps are not
working right and the outline-regexp isn't being set right. I've worked around
the latter with a quick function I can call from the file buffer. However, I
don't know what's going on with the keymap. It looks right. For example, c-h k
TAB gives this:
> <tab> runs the command orgstruct-hijacker-command-102, which is an
interactive Lisp function. It is bound to <tab>.
> (orgstruct-hijacker-command-102 ARG)
> In Structure, run `org-cycle'.
> Outside of structure, run the binding of `[(tab)]' or ` '.
>
> However, it doesn't seem to recognize when it's in a structure. M-x org-cycle
works as does M-x org-global-cycle.
>
> I only need this for emacs-lisp-mode and verilog-mode so I simplified
Tassilo's code (for now) like this:
>
> (when (eq major-mode 'emacs-lisp-mode)
> (setq outline-regexp ";; [*]+ "))
> (when (eq major-mode 'verilog-mode)
> (setq outline-regexp "\\s-*// [*]+ "))
Anyone?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Minor org mode for achieve code folding effects
@ 2012-01-09 15:14 Giovanni Giorgi
2012-01-09 15:23 ` Carsten Dominik
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Giovanni Giorgi @ 2012-01-09 15:14 UTC (permalink / raw)
To: Emacs orgmode
[-- Attachment #1: Type: text/plain, Size: 661 bytes --]
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.
I have found this article using outline mode:
http://stackoverflow.com/questions/1085170/how-to-achieve-code-folding-effects-in-emacs
but frankly I find it difficult to use because navigation is too
difficult. (I have also excluded folding mode).
Org Mode has a very
nice navigation and key bindings, and I know it better then
outline.
There is a way to get a minor org-mode for replacing the above
outline configuration?
I am ready to experiment, if I need to patch
things...
---
Gio's Blog http://gioorgi.com
[-- Attachment #2: Type: text/html, Size: 873 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Minor org mode for achieve code folding effects
2012-01-09 15:14 Giovanni Giorgi
@ 2012-01-09 15:23 ` Carsten Dominik
2012-01-10 21:08 ` Eric S Fraga
2012-01-11 14:56 ` Eric S Fraga
2 siblings, 0 replies; 12+ messages in thread
From: Carsten Dominik @ 2012-01-09 15:23 UTC (permalink / raw)
To: Giovanni Giorgi; +Cc: Emacs orgmode
On Jan 9, 2012, at 4:14 PM, Giovanni Giorgi wrote:
> 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.
>
> I have found this article using outline mode:
> http://stackoverflow.com/questions/1085170/how-to-achieve-code-folding-effects-in-emacs
>
> but frankly I find it difficult to use because navigation is too difficult. (I have also excluded folding mode).
>
>
> Org Mode has a very nice navigation and key bindings, and I know it better then outline.
> There is a way to get a minor org-mode for replacing the above outline configuration?
> I am ready to experiment, if I need to patch things...
Start by reading the FAQ:
http://orgmode.org/worg/org-faq.html#use-visibility-cycling-in-outline-mode
- Carsten
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Minor org mode for achieve code folding effects
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
2 siblings, 1 reply; 12+ messages in thread
From: Eric S Fraga @ 2012-01-10 21:08 UTC (permalink / raw)
To: emacs-orgmode
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:
(org) Working With Source Code
or, within that section, the subsection
(org) Extracting source code
--
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.92.1
: using Org-mode version 7.8.03 (release_7.8.03.73.gd2b3d)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Minor org mode for achieve code folding effects
2012-01-10 21:08 ` Eric S Fraga
@ 2012-01-10 22:47 ` Leo Alekseyev
0 siblings, 0 replies; 12+ messages in thread
From: Leo Alekseyev @ 2012-01-10 22:47 UTC (permalink / raw)
To: emacs-orgmode
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)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Minor org mode for achieve code folding effects
2012-01-09 15:14 Giovanni Giorgi
2012-01-09 15:23 ` Carsten Dominik
2012-01-10 21:08 ` Eric S Fraga
@ 2012-01-11 14:56 ` Eric S Fraga
2012-01-12 2:12 ` Leo Alekseyev
2 siblings, 1 reply; 12+ messages in thread
From: Eric S Fraga @ 2012-01-11 14:56 UTC (permalink / raw)
To: Giovanni Giorgi; +Cc: Emacs orgmode
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.
Giovanni,
I wonder, having thought about this some more, whether using org mode is
the correct solution? (as much as I like org!) There are other
solutions that may work /out of the box/ as you want. This is *emacs*
we are talking about after all!
For instance, when I was doing a lot of Java programming, I used
hideshow.el all the time to hide block and function bodies. Works very
well (although the default key bindings are annoying to me). Have a
look! It's a standard package in emacs, at least in Emacs 24 but much
earlier than that I believe.
There's a small add-on called hideshow-org.el which may be useful as
well:
,----
| ;;; hideshow-org.el - Provides org-mode like hide and show for hideshow.el
| ;;
| ;; Copyright (C) 2009 Shane Celis
| ;;
| ;; Author: Shane Celis <shane (at) gnufoo (dot) org>
`----
Have a search for that; if you can't find it, I can send you my copy but
there may be a more up to date one on the web somewhere...
HTH,
eric
--
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.90.1
: using Org-mode version 7.8.03 (release_7.8.03.76.ga9c15)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Minor org mode for achieve code folding effects
2012-01-11 14:56 ` Eric S Fraga
@ 2012-01-12 2:12 ` Leo Alekseyev
0 siblings, 0 replies; 12+ messages in thread
From: Leo Alekseyev @ 2012-01-12 2:12 UTC (permalink / raw)
To: Giovanni Giorgi, Emacs orgmode
> For instance, when I was doing a lot of Java programming, I used
> hideshow.el all the time to hide block and function bodies. Works very
> well (although the default key bindings are annoying to me). Have a
> look! It's a standard package in emacs, at least in Emacs 24 but much
> earlier than that I believe.
>
> There's a small add-on called hideshow-org.el which may be useful as
> well:
Having read the OP, I'll second Eric's vote for hideshow-org. It's a
better solution for folding functions. However, the combination of
org/outline-minor-mode/Tassilo's code works well for splitting a file
into foldable sections. Incidentally, you can use both of these
methods at the same time; they don't conflict too much.
--l
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2012-01-16 18:19 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).