emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-style folding for a .emacs
@ 2009-07-13 21:23 Scot Becker
  2009-07-13 22:56 ` Eric S Fraga
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Scot Becker @ 2009-07-13 21:23 UTC (permalink / raw)
  To: Org-mode ml

Does anyone have a recipe for easy org-style folding of an elisp file?
 I'd like to divide my .emacs into segments to make it easier to
oversee and navigate.

Scot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: org-style folding for a .emacs
  2009-07-13 21:23 org-style folding for a .emacs Scot Becker
@ 2009-07-13 22:56 ` Eric S Fraga
  2009-07-13 23:07 ` Michael Zeller
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Eric S Fraga @ 2009-07-13 22:56 UTC (permalink / raw)
  To: Scot Becker; +Cc: Org-mode ml

At Mon, 13 Jul 2009 22:23:51 +0100,
Scot Becker wrote:
> 
> Does anyone have a recipe for easy org-style folding of an elisp file?
>  I'd like to divide my .emacs into segments to make it easier to
> oversee and navigate.
> 
> Scot

Scot,

I use hideshow (part of the standard Emacs distribution from 22.x
onwards, I believe) together with hideshow-org (by Shane Celis).  I've
not used it with elisp (mostly with Java) but I believe it should do
what you want.

eric

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: org-style folding for a .emacs
  2009-07-13 21:23 org-style folding for a .emacs Scot Becker
  2009-07-13 22:56 ` Eric S Fraga
@ 2009-07-13 23:07 ` Michael Zeller
  2009-07-14 11:55   ` Sébastien Vauban
  2009-07-13 23:26 ` Dan Davison
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Michael Zeller @ 2009-07-13 23:07 UTC (permalink / raw)
  To: Scot Becker; +Cc: Org-mode ml

Scot,

I've found a similar solution in a previous thread:
http://thread.gmane.org/gmane.emacs.orgmode/12094/focus=12105

In summary, add the following to your ~/.emacs.el:

  ;; outline-minor-mode
(defun prompt-for-outline-regexp (new-regexp)
  "ask the user for a local value of outline-regexp in this buffer"
  (interactive "Outline regexp: ")
  (set (make-local-variable 'outline-regexp) new-regexp)
)

(global-set-key (kbd "<f9>") 'prompt-for-outline-regexp) 

(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-start ";")
     (setq comment-starter ";;"))
   (concat "^" comment-starter "\\*+")))

(defun th-outline-minor-mode-init ()
 (interactive)
 (setq outline-regexp (th-outline-regexp)))

(add-hook 'outline-minor-mode-hook
          'th-outline-minor-mode-init)

(global-set-key [M-tab] 'org-cycle)
(global-set-key [M-left] 'hide-body)
(global-set-key [M-right] 'show-all)
(global-set-key [M-up] 'outline-previous-heading)
(global-set-key [M-down] 'outline-next-heading)
(global-set-key [C-M-left] 'hide-sublevels)
(global-set-key [C-M-right] 'show-children)
(global-set-key [C-M-up] 'outline-previous-visible-heading)
(global-set-key [C-M-down] 'outline-next-visible-heading)

and add the following as the top line of your ~/.emacs.el:

; -*- mode: emacs-lisp; mode: outline-minor; -*-

Now you can add ;;* and ;;**, etc as headings in your .emacs.el and
cycle using M-tab, M-left and M-right will collapse or expand all
headings respectively. I am guessing you mean to make segments such as
;;* SHORTCUTS and ;;* VARIABLES, this will do that, but not too much
more.

I haven't tried hideshow before, but this solution has worked for me in
other modes, particularly in R-mode, where you use #*, #**, etc,
instead. Just remember to activate outline-minor-mode.

Thanks go to Tassilo Horn,
~Michael Zeller

Scot Becker <scot.becker@gmail.com> writes:

> Does anyone have a recipe for easy org-style folding of an elisp file?
>  I'd like to divide my .emacs into segments to make it easier to
> oversee and navigate.
>
> Scot
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: org-style folding for a .emacs
  2009-07-13 21:23 org-style folding for a .emacs Scot Becker
  2009-07-13 22:56 ` Eric S Fraga
  2009-07-13 23:07 ` Michael Zeller
@ 2009-07-13 23:26 ` Dan Davison
  2009-07-14 11:01   ` Scot Becker
  2009-07-16  1:02 ` Daniel Clemente
  2009-07-16 19:50 ` Bastien
  4 siblings, 1 reply; 15+ messages in thread
From: Dan Davison @ 2009-07-13 23:26 UTC (permalink / raw)
  To: Scot Becker; +Cc: Org-mode ml

Scot Becker <scot.becker@gmail.com> writes:

Hi Scot,

> Does anyone have a recipe for easy org-style folding of an elisp file?
>  I'd like to divide my .emacs into segments to make it easier to
> oversee and navigate.

As you're probably aware, outline-minor-mode can be used for folding
source code in whatever language. By playing with outline-regexp, a
variety of effects can be achieved. However, a much more powerful option
would be to embed the code in an org file: literate programming with
org. Code comments would be moved into the org-file, where they would be
joined by the org bestiary of hyperlinks, tags, TODO items, etc etc
etc. As it stands, org already provides excellent support for working
with source code blocks. One of the aims that Eric Schulte and I have
for org-babel[1] is to provide extra support for literate programming.

For an emacs config file, a simple solution -- that is available now --
is to strip out ('tangle') the code and then load the resulting .el file
as normal. This can be done with org-babel-tangle. Below are an example
of a toy .emacs.org file, and the .emacs.el that results after M-x
org-babel-tangle. The org-babel configuration code that is required is
in the second code block below.

Org-babel is under development. One reason for mentioning it is that the
basic functionality is up and running; another is that we'd be very
happy to have others join the project, and to receive ideas and patches
from the list.

Dan

Footnotes:

[1] http://github.com/eschulte/org-babel/tree/master

NB Although the implementation in org-babel is independent, Eric Neilsen
has also worked on tangle/untangle functions for org-mode, and posted on
that recently.

.emacs.org
--8<---------------cut here---------------start------------->8---
* org config
#+begin_src emacs-lisp
(add-to-list 'load-path "/usr/local/src/org-mode/lisp")
(require 'org-install)
#+end_src

* org-babel config
  Download/clone the org-babel code from [[http://github.com/eschulte/org-babel/tree/master][org-babel on github]]
#+begin_src emacs-lisp
(add-to-list 'load-path "~/src/org-babel/lisp")
(require 'org-babel-init)
(setq org-babel-tangle-langs
      '(("python" . ("py" "#!/usr/bin/env python"))
	("R" . ("R" "#!/usr/bin/env R"))
	("sh" . ("sh" "#!/usr/bin/env bash"))
	("emacs-lisp" . ("el" ""))))
#+end_src
--8<---------------cut here---------------end--------------->8---


.emacs.el:
--8<---------------cut here---------------start------------->8---

;; generated by org-babel-tangle

;; [[file:~/src/org-babel/.emacs.org::*org%20config][block-1]]
(add-to-list 'load-path "/usr/local/src/org-mode/lisp")
(require 'org-install)
;; block-1 ends here

;; [[file:~/src/org-babel/.emacs.org::*org%20babel%20config][block-2]]
(add-to-list 'load-path "~/src/org-babel/lisp")
(require 'org-babel-init)
(setq org-babel-tangle-langs
      '(("python" . ("py" "#!/usr/bin/env python"))
	("R" . ("R" "#!/usr/bin/env R"))
	("sh" . ("sh" "#!/usr/bin/env bash"))
	("emacs-lisp" . ("el" ""))))
;; block-2 ends here
--8<---------------cut here---------------end--------------->8---


>
> Scot
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: org-style folding for a .emacs
  2009-07-13 23:26 ` Dan Davison
@ 2009-07-14 11:01   ` Scot Becker
  2009-07-15  5:17     ` Eric Schulte
  0 siblings, 1 reply; 15+ messages in thread
From: Scot Becker @ 2009-07-14 11:01 UTC (permalink / raw)
  To: Dan Davison; +Cc: Org-mode ml

Thanks Eric, Michael and Dan, for the assistance.

Both options look good (outline-minor-mode and a literate org file).

 My first draft of this request for help actually included
consideration of a  "literate" org file, but I deleted it, since I
thought it would be too complex, and your work (Dan) was too far from
finished to be usable by someone of Not A Lot of Time.  If I can make
it work, this does sound even more powerful than the
outline-minor-mode solution.  I had two reasons for the request: first
it was just to have a modular init file without actually making it
modular (i.e. by folding it org-like), the second was to make an init
file that might be of use to others, especially Emacs beginners, for
which an org-rich literate solution would be nice, both for its
folding and for links to the full range of things that org supports
(or can be made to support).

Thanks all for the examples.  I'll give it a try.

Scot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: org-style folding for a .emacs
  2009-07-13 23:07 ` Michael Zeller
@ 2009-07-14 11:55   ` Sébastien Vauban
  2009-07-15  3:12     ` Michael Zeller
  0 siblings, 1 reply; 15+ messages in thread
From: Sébastien Vauban @ 2009-07-14 11:55 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello Michael,

>> Does anyone have a recipe for easy org-style folding of an elisp file? I'd
>> like to divide my .emacs into segments to make it easier to oversee and
>> navigate.

I asked myself this question a couple of days ago. Telepathy. For real.
Good it has been asked, and answered.

In my case, I am very interested as well by the literate programming approach.
But I will comment on this later.


> In summary, add the following to your ~/.emacs.el:
>
> (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-start ";")
>      (setq comment-starter ";;"))
>    (concat "^" comment-starter "\\*+")))
>
> (defun th-outline-minor-mode-init ()
>  (interactive)
>  (setq outline-regexp (th-outline-regexp)))
>
> (add-hook 'outline-minor-mode-hook
>           'th-outline-minor-mode-init)
>
> and add the following as the top line of your ~/.emacs.el:
>
> ; -*- mode: emacs-lisp; mode: outline-minor; -*-
>
> Now you can add ;;* and ;;**, etc as headings in your .emacs.el and
> cycle using M-tab, M-left and M-right will collapse or expand all
> headings respectively. I am guessing you mean to make segments such as
> ;;* SHORTCUTS and ;;* VARIABLES, this will do that, but not too much
> more.

Done.

Though, is there a way to get the font used for org-levels in the Emacs config
file?  That would really greatly improve the readability, then!

Best regards,
  Seb

-- 
Sébastien Vauban



_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Re: org-style folding for a .emacs
  2009-07-14 11:55   ` Sébastien Vauban
@ 2009-07-15  3:12     ` Michael Zeller
  2009-07-15 15:52       ` Sébastien Vauban
  0 siblings, 1 reply; 15+ messages in thread
From: Michael Zeller @ 2009-07-15  3:12 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

Seb,

> Though, is there a way to get the font used for org-levels in the Emacs config
> file?  That would really greatly improve the readability, then!

Try changing th-outline-minor-mode-init to:

(defun th-outline-minor-mode-init ()
 (interactive)
 (setq outline-regexp (th-outline-regexp))
 ;; highlight the headings
 ;; see http://www.gnu.org/software/emacs/manual/html_node/emacs/Font-Lock.html
 ;; use M-x customize-apropos face to customize faces
 ;; to find the corresponding face for each outline level see org-faces.el
 (let ((heading-1-regexp (concat (substring outline-regexp 0 -1) "\\{1\\} \\(.*\\)"))
       (heading-2-regexp (concat (substring outline-regexp 0 -1) "\\{2\\} \\(.*\\)"))
       (heading-3-regexp (concat (substring outline-regexp 0 -1) "\\{3,\\} \\(.*\\)")))
   (font-lock-add-keywords
    nil
    `((,heading-1-regexp 1 font-lock-function-name-face t)
      (,heading-2-regexp 1 font-lock-variable-name-face t)
      (,heading-3-regexp 1 font-lock-keyword-face       t)))))

That should atleast highlight the first three headings properly and make
it more readable. I'm not quite sure how to make it cycle through the 8
colors like org-mode does.

Hope that helps,
~Michael Zeller

Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:

> Hello Michael,
>
>>> Does anyone have a recipe for easy org-style folding of an elisp file? I'd
>>> like to divide my .emacs into segments to make it easier to oversee and
>>> navigate.
>
> I asked myself this question a couple of days ago. Telepathy. For real.
> Good it has been asked, and answered.
>
> In my case, I am very interested as well by the literate programming approach.
> But I will comment on this later.
>
>
>> In summary, add the following to your ~/.emacs.el:
>>
>> (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-start ";")
>>      (setq comment-starter ";;"))
>>    (concat "^" comment-starter "\\*+")))
>>
>> (defun th-outline-minor-mode-init ()
>>  (interactive)
>>  (setq outline-regexp (th-outline-regexp)))
>>
>> (add-hook 'outline-minor-mode-hook
>>           'th-outline-minor-mode-init)
>>
>> and add the following as the top line of your ~/.emacs.el:
>>
>> ; -*- mode: emacs-lisp; mode: outline-minor; -*-
>>
>> Now you can add ;;* and ;;**, etc as headings in your .emacs.el and
>> cycle using M-tab, M-left and M-right will collapse or expand all
>> headings respectively. I am guessing you mean to make segments such as
>> ;;* SHORTCUTS and ;;* VARIABLES, this will do that, but not too much
>> more.
>
> Done.
>
> Though, is there a way to get the font used for org-levels in the Emacs config
> file?  That would really greatly improve the readability, then!
>
> Best regards,
>   Seb

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: org-style folding for a .emacs
  2009-07-14 11:01   ` Scot Becker
@ 2009-07-15  5:17     ` Eric Schulte
  2009-07-15 21:02       ` Sébastien Vauban
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Schulte @ 2009-07-15  5:17 UTC (permalink / raw)
  To: Scot Becker; +Cc: Dan Davison, Org-mode ml

Scot Becker <scot.becker@gmail.com> writes:

> Thanks Eric, Michael and Dan, for the assistance.
>
> Both options look good (outline-minor-mode and a literate org file).
>
>  My first draft of this request for help actually included
> consideration of a  "literate" org file, but I deleted it, since I
> thought it would be too complex, and your work (Dan) was too far from
> finished to be usable by someone of Not A Lot of Time.  If I can make
> it work, this does sound even more powerful than the
> outline-minor-mode solution. 

Hi Scot,

I've added some simplifying functions to the literate programming
functionality of org-babel.  It should now be easy to embed your elisp
initialization into org-mode files.  Specifically there is now a new
`org-babel-load-file' function which can load the elisp portions of
org-mode files in the same manner as the normal `load-file' command.

To use this you need to clone the latest version of org-babel[1], and
then add the following to your emacs initialization (this worked for me
when a base emacs "emacs -Q").

--8<---------------cut here---------------start------------->8---
(add-to-list 'load-path "~/path/to/org/lisp")
(add-to-list 'load-path "~/path/to/org-babel/lisp")
(require 'org-babel-init)
;; now you can load your org-mode files with embedded elisp
(org-babel-load-file "~/path/to/org-mode-file.org")
;; for example
(org-babel-load-file "~/path/to/org-babel/test-tangle.org")
--8<---------------cut here---------------end--------------->8---

Hopefully this will provide the literate programming functionality
without too much trouble.

Cheers -- Eric

> I had two reasons for the request: first it was just to have a modular
> init file without actually making it modular (i.e. by folding it
> org-like), the second was to make an init file that might be of use to
> others, especially Emacs beginners, for which an org-rich literate
> solution would be nice, both for its folding and for links to the full
> range of things that org supports (or can be made to support).
>
> Thanks all for the examples.  I'll give it a try.
>
> Scot
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

Footnotes: 
[1]  git clone git://github.com/eschulte/org-babel.git

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: org-style folding for a .emacs
  2009-07-15  3:12     ` Michael Zeller
@ 2009-07-15 15:52       ` Sébastien Vauban
  0 siblings, 0 replies; 15+ messages in thread
From: Sébastien Vauban @ 2009-07-15 15:52 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello Michael,

>>>> Does anyone have a recipe for easy org-style folding of an elisp file?
>>>> I'd like to divide my .emacs into segments to make it easier to oversee
>>>> and navigate.
>>
>> I asked myself this question a couple of days ago. Telepathy. For real.
>> Good it has been asked, and answered.
>>
>>> In summary, add the following to your ~/.emacs.el:
>>>
>>> (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-start ";")
>>>      (setq comment-starter ";;"))
>>>    (concat "^" comment-starter "\\*+")))
>>>
>>> [...]
>>>
>>> (add-hook 'outline-minor-mode-hook
>>>           'th-outline-minor-mode-init)
>>>
>>> and add the following as the top line of your ~/.emacs.el:
>>>
>>> ; -*- mode: emacs-lisp; mode: outline-minor; -*-
>>>
>>> Now you can add ;;* and ;;**, etc as headings in your .emacs.el.
>>
>> Done. Though, is there a way to get the font used for org-levels in the
>> Emacs config file? That would really greatly improve the readability, then!
>
> Try changing th-outline-minor-mode-init to:
>
> (defun th-outline-minor-mode-init ()
>  (interactive)
>  (setq outline-regexp (th-outline-regexp))
>  ;; highlight the headings
>  ;; see http://www.gnu.org/software/emacs/manual/html_node/emacs/Font-Lock.html
>  ;; use M-x customize-apropos face to customize faces
>  ;; to find the corresponding face for each outline level see org-faces.el
>  (let ((heading-1-regexp (concat (substring outline-regexp 0 -1) "\\{1\\} \\(.*\\)"))
>        (heading-2-regexp (concat (substring outline-regexp 0 -1) "\\{2\\} \\(.*\\)"))
>        (heading-3-regexp (concat (substring outline-regexp 0 -1) "\\{3,\\} \\(.*\\)")))
>    (font-lock-add-keywords
>     nil
>     `((,heading-1-regexp 1 font-lock-function-name-face t)
>       (,heading-2-regexp 1 font-lock-variable-name-face t)
>       (,heading-3-regexp 1 font-lock-keyword-face       t)))))
>
> That should atleast highlight the first three headings properly and make
> it more readable. I'm not quite sure how to make it cycle through the 8
> colors like org-mode does.

You know what?  You really are wonderful ;-)  This is making my month...

Though, I slightly adapted your code (that was in what's possible for me) so
that I get exactly the same faces as within a real Org file:

--8<---------------cut here---------------start------------->8---
(defun th-outline-minor-mode-init ()
  (interactive)
  (setq outline-regexp (th-outline-regexp))

  ;; highlight the headings
  ;; see http://www.gnu.org/software/emacs/manual/html_node/emacs/Font-Lock.html
  ;; use M-x customize-apropos face to customize faces
  ;; to find the corresponding face for each outline level see org-faces.el
  (let ((heading-1-regexp (concat (substring outline-regexp 0 -1) "\\{1\\} \\(.*\\)"))
        (heading-2-regexp (concat (substring outline-regexp 0 -1) "\\{2\\} \\(.*\\)"))
        (heading-3-regexp (concat (substring outline-regexp 0 -1) "\\{3\\} \\(.*\\)"))
        (heading-4-regexp (concat (substring outline-regexp 0 -1) "\\{4,\\} \\(.*\\)"))
        )
    (font-lock-add-keywords
     nil
     `((,heading-1-regexp 1 'org-level-1 t)
       (,heading-2-regexp 1 'org-level-2 t)
       (,heading-3-regexp 1 'org-level-3 t)
       (,heading-4-regexp 1 'org-level-4 t)))))
--8<---------------cut here---------------end--------------->8---

That way, having those faces defined (inspired by the resistors color code):

--8<---------------cut here---------------start------------->8---
(org-level-1 ((t (:foreground "cornflower blue" :weight bold :height 1.8 :family "Arial"))))
(org-level-2 ((t (:foreground "LimeGreen" :weight bold :height 1.6 :family "Arial"))))
(org-level-3 ((t (:foreground "orange" :weight bold :height 1.3 :family "Arial"))))
--8<---------------cut here---------------end--------------->8---

I get a much, much, much more readable emacs file -- nice, moreover as mine is
really huge!


> Hope that helps,

Oohhh yeeeessss!

Best regards,
  Seb

-- 
Sébastien Vauban



_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: org-style folding for a .emacs
  2009-07-15  5:17     ` Eric Schulte
@ 2009-07-15 21:02       ` Sébastien Vauban
  2009-07-16 23:31         ` Eric Schulte
  0 siblings, 1 reply; 15+ messages in thread
From: Sébastien Vauban @ 2009-07-15 21:02 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello Eric,

"Eric Schulte" wrote:
> I've added some simplifying functions to the literate programming
> functionality of org-babel.  It should now be easy to embed your elisp
> initialization into org-mode files.  Specifically there is now a new
> `org-babel-load-file' function which can load the elisp portions of
> org-mode files in the same manner as the normal `load-file' command.
>
> To use this you need to clone the latest version of org-babel[1], and
> then add the following to your emacs initialization (this worked for me
> when a base emacs "emacs -Q").
>
> (add-to-list 'load-path "~/path/to/org/lisp")
> (add-to-list 'load-path "~/path/to/org-babel/lisp")
> (require 'org-babel-init)
> ;; now you can load your org-mode files with embedded elisp
> (org-babel-load-file "~/path/to/org-mode-file.org")
> ;; for example
> (org-babel-load-file "~/path/to/org-babel/test-tangle.org")
>
> Hopefully this will provide the literate programming functionality
> without too much trouble.

I'm a heavy user of "literate programming" for rapports I write for clients
(in fact, for me, first, but I give them to our clients as well).

Up to a couple of months ago, I was doing literate programming via LaTeX and
nuweb, from Windows as my nuweb binary was just available for that platform.
So, writing a `.w' file from which I extract a `.tex' one and the source code.

Then, the last time I did it, I switched to doing such reports under Ubuntu,
with the noweb package. That is a `.nw' file which is "compiled" to a `.tex',
and which is as well outputting all my code.

This is nice, and works well. But, now, I am trying as hard as possible to
avoid writing LaTeX directly and let Org do the work for me. So, if I can use
Org to create my `.tex' file and the source code from it as well (did I
understand correctly?), then that will be wonderful.

Do you have examples or a tiny tutorial about this?

Best regards,
  Seb

PS- Excellent you're looking at this, because I thought I was the latest
    "literate programmer" on earth. All the mailing lists about that are
    dying.

-- 
Sébastien Vauban



_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: org-style folding for a .emacs
  2009-07-13 21:23 org-style folding for a .emacs Scot Becker
                   ` (2 preceding siblings ...)
  2009-07-13 23:26 ` Dan Davison
@ 2009-07-16  1:02 ` Daniel Clemente
  2009-07-16 19:50 ` Bastien
  4 siblings, 0 replies; 15+ messages in thread
From: Daniel Clemente @ 2009-07-16  1:02 UTC (permalink / raw)
  To: Scot Becker; +Cc: Org-mode ml

El lun, jul 13 2009 a les 23:23, Scot Becker va escriure:
> Does anyone have a recipe for easy org-style folding of an elisp file?
>  I'd like to divide my .emacs into segments to make it easier to
> oversee and navigate.


I did this without needing to change variables or define new functions. Just add at the first line:

; -*- mode: emacs-lisp; mode:outline-minor; outline-regexp:";;;;* [^ 	\n]" -*-

(Reopen the file to activate that).

And then start headings with ;;; (that's level 1), for instance: 

;;; a
; something else
;;;; a.1
; bla
;; this is still a normal comment

;;; b


Cycle with C-tab, C-S-tab, …


-- Daniel

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: org-style folding for a .emacs
  2009-07-13 21:23 org-style folding for a .emacs Scot Becker
                   ` (3 preceding siblings ...)
  2009-07-16  1:02 ` Daniel Clemente
@ 2009-07-16 19:50 ` Bastien
  4 siblings, 0 replies; 15+ messages in thread
From: Bastien @ 2009-07-16 19:50 UTC (permalink / raw)
  To: Scot Becker; +Cc: Org-mode ml

Hi Scot,

Scot Becker <scot.becker@gmail.com> writes:

> Does anyone have a recipe for easy org-style folding of an elisp file?
>  I'd like to divide my .emacs into segments to make it easier to
> oversee and navigate.

I use this (original idea from Tassilo IIRC):

--8<---------------cut here---------------start------------->8---
;;; Use orgstruct-mode in emacs-lisp-mode buffers

(add-hook 'emacs-lisp-mode-hook 'orgstruct-mode)

(defun org-cycle-global ()
  (interactive)
  (org-cycle t))

(defun org-cycle-local ()
  (interactive)
  (save-excursion
    (move-beginning-of-line nil)
    (org-cycle)))

(global-set-key (kbd "C-M-]") 'org-cycle-global)
(global-set-key (kbd "M-]") 'org-cycle-local)
--8<---------------cut here---------------end--------------->8---

-- 
 Bastien

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Re: org-style folding for a .emacs
  2009-07-15 21:02       ` Sébastien Vauban
@ 2009-07-16 23:31         ` Eric Schulte
  2009-07-28 14:39           ` Sébastien Vauban
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Schulte @ 2009-07-16 23:31 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

Hi Sébastien,

Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:

> Hello Eric,
>
> "Eric Schulte" wrote:
>> I've added some simplifying functions to the literate programming
>> functionality of org-babel.  It should now be easy to embed your elisp
>> initialization into org-mode files.  Specifically there is now a new
>> `org-babel-load-file' function which can load the elisp portions of
>> org-mode files in the same manner as the normal `load-file' command.
>>
>> To use this you need to clone the latest version of org-babel[1], and
>> then add the following to your emacs initialization (this worked for me
>> when a base emacs "emacs -Q").
>>
>> (add-to-list 'load-path "~/path/to/org/lisp")
>> (add-to-list 'load-path "~/path/to/org-babel/lisp")
>> (require 'org-babel-init)
>> ;; now you can load your org-mode files with embedded elisp
>> (org-babel-load-file "~/path/to/org-mode-file.org")
>> ;; for example
>> (org-babel-load-file "~/path/to/org-babel/test-tangle.org")
>>
>> Hopefully this will provide the literate programming functionality
>> without too much trouble.
>
> I'm a heavy user of "literate programming" for rapports I write for clients
> (in fact, for me, first, but I give them to our clients as well).
>
> Up to a couple of months ago, I was doing literate programming via LaTeX and
> nuweb, from Windows as my nuweb binary was just available for that platform.
> So, writing a `.w' file from which I extract a `.tex' one and the source code.
>
> Then, the last time I did it, I switched to doing such reports under Ubuntu,
> with the noweb package. That is a `.nw' file which is "compiled" to a `.tex',
> and which is as well outputting all my code.
>
> This is nice, and works well. But, now, I am trying as hard as possible to
> avoid writing LaTeX directly and let Org do the work for me. So, if I can use
> Org to create my `.tex' file and the source code from it as well (did I
> understand correctly?), then that will be wonderful.
>
> Do you have examples or a tiny tutorial about this?
>

There are two small examples which should be helpful.  First grab a copy
of the org-babel code [1].  Then load org-babel [2].

To demonstrate extraction of code, open "test-tangle.org" file in the
base of the org-babel directory and run `org-babel-tangle'.  This should
create a couple of source-code files in the same directory.

To demonstrate creation of documents, open the "test-export.org" file in
the base of the org-babel directory, and export it as you would any
other org-mode file.  The "exports" header argument controls how
source-code blocks are exported, with the following options

- none :: no part of the source-code block is exported in the document
- results :: only the output of the evaluated block is exported
- code :: the code itself is exported
- both :: both the code and results are exported

>
> Best regards,
>   Seb
>
> PS- Excellent you're looking at this, because I thought I was the latest
>     "literate programmer" on earth. All the mailing lists about that are
>     dying.

While I find the notion of literate programming very appealing, I have
no practical experience with it.  The literate programming functionality
in org-babel was inspired by talking with Eric Neilsen and by the sense
that literate programming fit with org-babel's focus on code blocks.

As you are actually familiar with literate programming and tools like
noweb, I would be very interested to hear your thoughts on the current
and potential future literate programming implementations in org-babel.

Best -- Eric

Footnotes: 
[1]  git clone git://github.com/eschulte/org-babel.git

[2]  
(add-to-list 'load-path "~/path/to/org-babel/lisp")
(require 'org-babel-init)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: org-style folding for a .emacs
  2009-07-16 23:31         ` Eric Schulte
@ 2009-07-28 14:39           ` Sébastien Vauban
  2009-07-30  0:51             ` Eric Schulte
  0 siblings, 1 reply; 15+ messages in thread
From: Sébastien Vauban @ 2009-07-28 14:39 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Eric,

"Eric Schulte" wrote:
> Sébastien Vauban <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>> I'm a heavy user of "literate programming" for rapports I write for clients
>> (in fact, for me, first, but I give them to our clients as well).
>>
>> Up to a couple of months ago, I was doing literate programming via LaTeX
>> and nuweb, from Windows as my nuweb binary was just available for that
>> platform. So, writing a `.w' file from which I extract a `.tex' one and the
>> source code.
>>
>> Then, the last time I did it, I switched to doing such reports under
>> Ubuntu, with the noweb package. That is a `.nw' file which is "compiled" to
>> a `.tex', and which is as well outputting all my code.

I'll describe my editing process in a separate thread (that will be called
"Literate Programming with Org").


>> This is nice, and works well. But, now, I am trying as hard as possible to
>> avoid writing LaTeX directly and let Org do the work for me. So, if I can
>> use Org to create my `.tex' file and the source code from it as well (did I
>> understand correctly?), then that will be wonderful.
>>
>> Do you have examples or a tiny tutorial about this?
>
> There are two small examples which should be helpful.  First grab a copy
> of the org-babel code [1].  Then load org-babel [2].
>
> To demonstrate extraction of code, open "test-tangle.org" file in the
> base of the org-babel directory and run `org-babel-tangle'.  This should
> create a couple of source-code files in the same directory.

OK.


> To demonstrate creation of documents, open the "test-export.org" file in
> the base of the org-babel directory, and export it as you would any
> other org-mode file.  The "exports" header argument controls how
> source-code blocks are exported, with the following options
>
> - none :: no part of the source-code block is exported in the document
> - results :: only the output of the evaluated block is exported
> - code :: the code itself is exported
> - both :: both the code and results are exported

I have this error showing up:

--8<---------------cut here---------------start------------->8---
executing Ruby source code block
apply: Searching for program: no such file or directory, irb
--8<---------------cut here---------------end--------------->8---


>> PS- Excellent you're looking at this, because I thought I was the latest
>>     "literate programmer" on earth. All the mailing lists about that are
>>     dying.
>
> While I find the notion of literate programming very appealing, I have
> no practical experience with it.  The literate programming functionality
> in org-babel was inspired by talking with Eric Neilsen and by the sense
> that literate programming fit with org-babel's focus on code blocks.
>
> As you are actually familiar with literate programming and tools like
> noweb, I would be very interested to hear your thoughts on the current
> and potential future literate programming implementations in org-babel.

For sure. I'll be more than happy to describe what I do. In case we all can
come to something (much) better than the current way I do things.

Seb

-- 
Sébastien Vauban



_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Re: org-style folding for a .emacs
  2009-07-28 14:39           ` Sébastien Vauban
@ 2009-07-30  0:51             ` Eric Schulte
  0 siblings, 0 replies; 15+ messages in thread
From: Eric Schulte @ 2009-07-30  0:51 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:

> Hi Eric,
>
> "Eric Schulte" wrote:
>> Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:

[...]

>> To demonstrate creation of documents, open the "test-export.org" file in
>> the base of the org-babel directory, and export it as you would any
>> other org-mode file.  The "exports" header argument controls how
>> source-code blocks are exported, with the following options
>>
>> - none :: no part of the source-code block is exported in the document
>> - results :: only the output of the evaluated block is exported
>> - code :: the code itself is exported
>> - both :: both the code and results are exported
>
> I have this error showing up:
>
> executing Ruby source code block
> apply: Searching for program: no such file or directory, irb
>

Hi Sébastien,

The problem here is that org-babel panics when trying to evaluate ruby
code blocks because you don't have the required ruby executables
available on your system.  Probably the best way to deal with this is to
remove ruby from the list of languages supported by babel by adding the
following in your initialization file [1].  Eventually we will need to
find a better way of allowing users to selectively add languages to
org-babel.

> >
>>> PS- Excellent you're looking at this, because I thought I was the latest
>>>     "literate programmer" on earth. All the mailing lists about that are
>>>     dying.
>>
>> While I find the notion of literate programming very appealing, I have
>> no practical experience with it.  The literate programming functionality
>> in org-babel was inspired by talking with Eric Neilsen and by the sense
>> that literate programming fit with org-babel's focus on code blocks.
>>
>> As you are actually familiar with literate programming and tools like
>> noweb, I would be very interested to hear your thoughts on the current
>> and potential future literate programming implementations in org-babel.
>
> For sure. I'll be more than happy to describe what I do. In case we all can
> come to something (much) better than the current way I do things.
>

Wonderful.  Thanks for sharing your experience.

Thanks -- Eric

>
> Seb

Footnotes: 
[1]  

--8<---------------cut here---------------start------------->8---
(setq org-babel-interpreters (delete "ruby" org-babel-interpreters))
--8<---------------cut here---------------end--------------->8---

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2009-07-31 16:46 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-13 21:23 org-style folding for a .emacs Scot Becker
2009-07-13 22:56 ` Eric S Fraga
2009-07-13 23:07 ` Michael Zeller
2009-07-14 11:55   ` Sébastien Vauban
2009-07-15  3:12     ` Michael Zeller
2009-07-15 15:52       ` Sébastien Vauban
2009-07-13 23:26 ` Dan Davison
2009-07-14 11:01   ` Scot Becker
2009-07-15  5:17     ` Eric Schulte
2009-07-15 21:02       ` Sébastien Vauban
2009-07-16 23:31         ` Eric Schulte
2009-07-28 14:39           ` Sébastien Vauban
2009-07-30  0:51             ` Eric Schulte
2009-07-16  1:02 ` Daniel Clemente
2009-07-16 19:50 ` Bastien

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).