Re: [O] Minor org mode for achieve code folding effects
David Rogoff therogoffs.com> writes: > 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. > > 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: >runs the command orgstruct-hijacker-command-102, which is an interactive Lisp function. It is bound to . > (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?
Re: [O] Minor org mode for achieve code folding effects
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. 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: runs the command orgstruct-hijacker-command-102, which is an interactive Lisp function. It is bound to . (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
Re: [O] Minor org mode for achieve code folding effects
> 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
Re: [O] Minor org mode for achieve code folding effects
Giovanni Giorgi 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 ` 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)
Re: [O] Minor org mode for achieve code folding effects
Leo Alekseyev 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
Re: [O] Minor org mode for achieve code folding effects
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))) <>
Re: [O] Minor org mode for achieve code folding effects
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? 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 " [*]+ ")))
Re: [O] Minor org mode for achieve code folding effects
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? Thanks! David
Re: [O] Minor org mode for achieve code folding effects
On Tue, Jan 10, 2012 at 3:08 PM, Eric S Fraga wrote: > Giovanni Giorgi 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)
Re: [O] Minor org mode for achieve code folding effects
Giovanni Giorgi 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)
Re: [O] Minor org mode for achieve code folding effects
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
[O] Minor org mode for achieve code folding effects
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