emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* back to a multiple-file configuration
@ 2011-12-10 18:31 Andrea Crotti
  2011-12-10 21:03 ` Andrea Crotti
  0 siblings, 1 reply; 4+ messages in thread
From: Andrea Crotti @ 2011-12-10 18:31 UTC (permalink / raw)
  To: Org Mode List

For quite a long time I had my emacs configuration in a big org-mode
file (https://github.com/AndreaCrotti/Emacs-configuration).

The file has is more than 3500 lines now, and I think the experiment has
failed in a sense.  The problem is that this even if this style is great
to produce nice documents and add a lot of useful text, is quite bad to
actually write modular code.

I rely quite heavily on the order in which things are declared for
example, instead of having different libraries to load.

So I guess I will switch to a multiple files structure again, which is
more "programmer friendly in a sense".
Anyone else had similar experiences?

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

* Re: back to a multiple-file configuration
  2011-12-10 18:31 back to a multiple-file configuration Andrea Crotti
@ 2011-12-10 21:03 ` Andrea Crotti
  2011-12-12  7:43   ` Gustav Wikström
  0 siblings, 1 reply; 4+ messages in thread
From: Andrea Crotti @ 2011-12-10 21:03 UTC (permalink / raw)
  To: Org Mode List

On 12/10/2011 06:31 PM, Andrea Crotti wrote:
> For quite a long time I had my emacs configuration in a big org-mode
> file (https://github.com/AndreaCrotti/Emacs-configuration).
>
> The file has is more than 3500 lines now, and I think the experiment has
> failed in a sense.  The problem is that this even if this style is great
> to produce nice documents and add a lot of useful text, is quite bad to
> actually write modular code.
>
> I rely quite heavily on the order in which things are declared for
> example, instead of having different libraries to load.
>
> So I guess I will switch to a multiple files structure again, which is
> more "programmer friendly in a sense".
> Anyone else had similar experiences?

It's quite a hard task to migrate more than 3500 lines :S
This little function is helping a lot, I replace all the :tangle yes
setting the right destination name for the given block,
so at least I do the first big transiction with org-babel..

(defun ca-replace-with-file (fname)
         (interactive "sWith String:?\n")
         (let ((fname (format "modules/ca-%s.el" fname)))
           (query-replace ":tangle yes" (concat ":tangle " fname))
         ))

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

* Re: back to a multiple-file configuration
  2011-12-10 21:03 ` Andrea Crotti
@ 2011-12-12  7:43   ` Gustav Wikström
  2011-12-17 11:45     ` Andrea Crotti
  0 siblings, 1 reply; 4+ messages in thread
From: Gustav Wikström @ 2011-12-12  7:43 UTC (permalink / raw)
  To: Andrea Crotti; +Cc: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 8650 bytes --]

I've also had this problem, but this related to the use of multiple
computers and more than one OS that all needed some specific tweaks to be
able to run. I'm also using org-babel for my init. A section from my
init.org follows below (warning for wall of text). Maybe this relates to
your thoughts and if so lets hope it adds some value.

8<--------------------------------------------------------------------------------------------------------------------------->8

** Initialization
*** Instructions
To make literate programming work i need to first bootstrap these
settings. I'm using this system on multiple machines and OS'es there
are some other initializations that also has to be made.

The initialization of the emacs-settings can be subdivided into two
main parts:
1. Bootstraping org-mode literate programming.
2. Loading source-files:
   1. OS-specific settings.
   2. Loading computer-specific settings.
   3. Loading the default settings.
   4. Loading computer-specific settings that overrides default
      settings.

This setup makes the system very dynamic, although it might become
difficult to maintain... We'll see about that though.

The code for the initialization follows in this file. It has to be
manually folded, the first time run anyways. (Running C-c C-v t in the
buffer whilst in emacs).
*** Bootstraping
The bootstraping of org-mode literate programing is taken from
http://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming,
with some minor modicifations.
#+begin_src emacs-lisp :tangle yes
  (setq dotfiles-dir
        (file-name-directory
         (or (buffer-file-name) load-file-name)))

  (setq src-dir (expand-file-name "src" dotfiles-dir))
  (setq org-dir (expand-file-name
                 "lisp" (expand-file-name
                         "org" src-dir)))
  (setq org-contrib-dir (expand-file-name
                         "lisp" (expand-file-name
                                 "contrib" (expand-file-name
                                            ".." org-dir))))
  (add-to-list 'load-path src-dir)
  (add-to-list 'load-path org-dir)
  (add-to-list 'load-path org-contrib-dir)
  (require 'org-install)
  (require 'ob-tangle)
#+end_src

After this, and given that i have org installed in the right folder
given the above, code written inside org-mode documents can be called
with the function =org-babel-load-file=. This is used in the next
section, [[*Loading of settings][Loading of settings]].
*** Code tangling hook
If any of the literate-files are updated, I want to automatically
compile them when they are tangled the next time.

This, however, does not work with symbolic links. Thus, my setup using
Dropbox to sync the files between my computers and symbolically
linking these files to my home-folders will not update automatically
anyways. This is (kind of) solved, see the next section.
#+begin_src emacs-lisp :tangle yes
  (add-hook 'org-babel-post-tangle-hook
      (lambda () (progn (eval-buffer (get-file-buffer (buffer-file-name)))
                        (byte-compile-file (buffer-file-name)))))
#+end_src
*** Code tangling function
This is my temporary solution to the symbolic-link problem discussed
in the section above. First the function delete all files that have
been previously tangled. After that it tangles all ".org" files in the
dotfiles-dir which also automatically compiles them due to the
[[*Code%20tangling%20hook][Code
tangling hook]].

This function can be called at any time.
#+begin_src emacs-lisp :tangle yes
  (defun gw/tangle ()
    "Tangles all the org-files in ~/.emacs.d/
  It is a help-function when one of the source-documents are updated
  in Dropbox and the local setup also needs to be updated."
    (interactive)
    (mapc (lambda (file)
            (delete-file (expand-file-name file dotfiles-dir)))
          (directory-files dotfiles-dir nil ".*\.\\(el\\|elc\\)$"))
    (mapc (lambda (file)
            (find-file (expand-file-name file dotfiles-dir))
            (org-babel-tangle)
            (kill-buffer))
          (directory-files dotfiles-dir nil ".*\.org$")))
#+end_src
*** Loading of settings
**** Introduction
The loading process is one single step. It checks which OS is in use
and then load the files given this system.

Add files to the org-files list if more are needed.
#+begin_src emacs-lisp :tangle yes
  (let* ((org-files (list (expand-file-name "emacs.org" dotfiles-dir)
                          (expand-file-name "custom_end.org" dotfiles-dir)))
         (windows-file (expand-file-name "windows.org" dotfiles-dir))
         (linux-file (expand-file-name "linux.org" dotfiles-dir))
         (custom-start (expand-file-name "custom_start.org" dotfiles-dir)))
    (cond
     ((eq system-type 'windows-nt)
      (if (file-exists-p windows-file)
          (mapc #'org-babel-load-file (cons windows-file
                                            (cons custom-start
org-files)))))
     ((eq system-type 'gnu/linux)
      (if (file-exists-p linux-file)
          (mapc #'org-babel-load-file (cons linux-file
                                            (cons custom-start
org-files)))))))
#+end_src
**** OS-specific settings
As stated earlier, I run emacs on multiple systems and keep these
settings synced between the platforms using Dropbox. I have machines
running both Windows, Linux and Mac and these need some customizations
in order to work correctly.

The need for this methodology originally arose from problems with
fileencoding on different systems, where I needed to use Latin-1 to
load paths with non-ASCII characters on windows but wanted UTF-8 to be
the default encoding when editing.

 A search on the Internet resulted in the following:
- http://www.dotemacs.de/multiemacs.html
-
http://stackoverflow.com/questions/1817257/how-to-determine-operating-system-in-elisp
-
http://stackoverflow.com/questions/2382249/how-to-choose-system-type-in-emacs

The settings for the respective systems can be found here:
- [[file:windows.org][windows.org]]
- [[file:linux.org][linux.org]]
**** Main settings
The main part of the customizations during the loading-process resides
in [[file:emacs.org][emacs.org]].
**** Computer-specific settings
The cumputer-specific settings are maintained by two
configuration-files. One ([[file:custom_start.org][custom_start.org]]) that
is loaded directly
after the initialization and one that is loaded as a final stage
([[file:custom_end.org][custom_end.org]]). These files are supposed to be
local to the machine
they are on. [[file:custom_start.org][custom_start.org]] is mostly used to
set system-paths and
define system-specific functions. [[file:custom_end.org][custom_end.org]]
is used to override
the default settings made in either the OS-specific settings or the
main settings.

Make sure that the source-files uses the correct encoding, if the
system is windows the fileencoding should be latin-1 and if the system
is linux it should be utf-8. This can be set by adding the following
string to the top of the document:
: # -*- coding: latin-1 -*-

At the very least one variables is needed in [[file:custom_start.org][
custom_start.org]] because
of it's use later in the loading process:
- gw/gtd-root

8<--------------------------------------------------------------------------------------------------------------------------->8


Kind regards
Gustav

On Sat, Dec 10, 2011 at 10:03 PM, Andrea Crotti
<andrea.crotti.0@gmail.com>wrote:

> On 12/10/2011 06:31 PM, Andrea Crotti wrote:
> > For quite a long time I had my emacs configuration in a big org-mode
> > file (https://github.com/AndreaCrotti/Emacs-configuration).
> >
> > The file has is more than 3500 lines now, and I think the experiment has
> > failed in a sense.  The problem is that this even if this style is great
> > to produce nice documents and add a lot of useful text, is quite bad to
> > actually write modular code.
> >
> > I rely quite heavily on the order in which things are declared for
> > example, instead of having different libraries to load.
> >
> > So I guess I will switch to a multiple files structure again, which is
> > more "programmer friendly in a sense".
> > Anyone else had similar experiences?
>
> It's quite a hard task to migrate more than 3500 lines :S
> This little function is helping a lot, I replace all the :tangle yes
> setting the right destination name for the given block,
> so at least I do the first big transiction with org-babel..
>
> (defun ca-replace-with-file (fname)
>         (interactive "sWith String:?\n")
>         (let ((fname (format "modules/ca-%s.el" fname)))
>           (query-replace ":tangle yes" (concat ":tangle " fname))
>         ))
>
>

[-- Attachment #2: Type: text/html, Size: 12280 bytes --]

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

* Re: back to a multiple-file configuration
  2011-12-12  7:43   ` Gustav Wikström
@ 2011-12-17 11:45     ` Andrea Crotti
  0 siblings, 0 replies; 4+ messages in thread
From: Andrea Crotti @ 2011-12-17 11:45 UTC (permalink / raw)
  To: Gustav Wikström; +Cc: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 1219 bytes --]

On 12/12/2011 07:43 AM, Gustav Wikström wrote:
> I've also had this problem, but this related to the use of multiple
> computers and more than one OS that all needed some specific tweaks to
> be able to run. I'm also using org-babel for my init. A section from
> my init.org <http://init.org> follows below (warning for wall of
> text). Maybe this relates to your thoughts and if so lets hope it adds
> some value.
>
>

Thanks for sharing..
Well my conclusion is that is just a bad idea.
Literate programming is great but for other things, as for example
scientific work very dense
of hard to grasp concepts.

If I need many lines to explain some elisp function it normally means
that it's really badly written,
and I just need to rewrite it better.
One thing which is much harder with the single org file is to have
different kind of profiles.

The only way would be to actually tangle to some files and load them on
demand when needed,
but then there is no point in using org-babel in the first place..
And then it's really hard to debug, because since they are not separate
modules is was
almost impossible to understand what was going on, now that I switched
to many smaller
files I solved all my latent problems..

[-- Attachment #2: Type: text/html, Size: 1787 bytes --]

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

end of thread, other threads:[~2011-12-17 11:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-10 18:31 back to a multiple-file configuration Andrea Crotti
2011-12-10 21:03 ` Andrea Crotti
2011-12-12  7:43   ` Gustav Wikström
2011-12-17 11:45     ` Andrea Crotti

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