From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?ISO-8859-1?Q?Gustav_Wikstr=F6m?= Subject: Re: back to a multiple-file configuration Date: Mon, 12 Dec 2011 08:43:29 +0100 Message-ID: References: <4EE3A56F.9090407@gmail.com> <4EE3C93E.3020708@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8f2358e171c41604b3e04afe Return-path: Received: from eggs.gnu.org ([140.186.70.92]:39732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ra0Xu-00069n-Ms for emacs-orgmode@gnu.org; Mon, 12 Dec 2011 02:43:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ra0Xr-00046m-7G for emacs-orgmode@gnu.org; Mon, 12 Dec 2011 02:43:34 -0500 Received: from mail-iy0-f169.google.com ([209.85.210.169]:52088) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ra0Xq-00046b-Tm for emacs-orgmode@gnu.org; Mon, 12 Dec 2011 02:43:31 -0500 Received: by iahk25 with SMTP id k25so9817866iah.0 for ; Sun, 11 Dec 2011 23:43:30 -0800 (PST) In-Reply-To: <4EE3C93E.3020708@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Andrea Crotti Cc: Org Mode List --e89a8f2358e171c41604b3e04afe Content-Type: text/plain; charset=ISO-8859-1 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 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)) > )) > > --e89a8f2358e171c41604b3e04afe Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I've also had this problem, but this related to the use of multiple com= puters 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.=A0A section from my init.org follows below (warning for wall of tex= t).=A0Maybe this relates to your thoughts and if so lets hope it adds some = value.

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

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

The initialization of the emacs-settings can be subdivi= ded into two
main parts:
1. Bootstraping org-mode liter= ate programming.
2. Loading source-files:
=A0 =A01. OS-= specific settings.
=A0 =A02. Loading computer-specific settings.
=A0 =A03. Load= ing the default settings.
=A0 =A04. Loading computer-specific set= tings that overrides default
=A0 =A0 =A0 settings.

=
This setup makes the system very dynamic, although it might beco= me
difficult to maintain... We'll see about that though.
The code for the initialization follows in this file. It has t= o be
manually folded, the first time run anyways. (Running C-c C-= v t in the
buffer whilst in emacs).
*** Bootstraping
The boot= straping of org-mode literate programing is taken from
with some minor modicifations.
#+begin_src emacs-lisp :tangl= e yes
=A0 (setq dotfiles-dir
=A0 =A0 =A0 =A0 (file-name= -directory
=A0 =A0 =A0 =A0 =A0(or (buffer-file-name) load-file-na= me)))
=A0=A0
=A0 (setq src-dir (expand-file-name "src" dotfil= es-dir))
=A0 (setq org-dir (expand-file-name=A0
=A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0"lisp" (expand-file-name
= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"org" src-dir)= ))
=A0 (setq org-contrib-dir (expand-file-name
=A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"lisp" (expand-file-name
=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&qu= ot;contrib" (expand-file-name
=A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ".." = org-dir))))
=A0 (add-to-list 'load-path src-dir)
=A0 (add-to-list &#= 39;load-path org-dir)
=A0 (add-to-list 'load-path org-contrib= -dir)
=A0 (require 'org-install)
=A0 (require '= ob-tangle)
#+end_src

After this, and given that i have o= rg installed in the right folder
given the above, code written in= side org-mode documents can be called
with the function =3Dorg-ba= bel-load-file=3D. 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 wa= nt to automatically
compile them when they are tangled the next t= ime.

This, however, does not work with symbolic links. Thus,= my setup using
Dropbox to sync the files between my computers an= d symbolically
linking these files to my home-folders will not up= date automatically
anyways. This is (kind of) solved, see the next section.
#+b= egin_src emacs-lisp :tangle yes
=A0 (add-hook 'org-babel-post= -tangle-hook
=A0 =A0 =A0 (lambda () (progn (eval-buffer (get-file= -buffer (buffer-file-name)))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (byte-compile-file (bu= ffer-file-name)))))
#+end_src
*** Code tangling functio= n
This is my temporary solution to the symbolic-link problem disc= ussed
in the section above. First the function delete all files t= hat have
been previously tangled. After that it tangles all ".org" fi= les in the
dotfiles-dir which also automatically compiles them du= e to the [[*Code%20tangling%20hook][Code
tangling hook]].

This function can be called at any time.
#+be= gin_src emacs-lisp :tangle yes
=A0 (defun gw/tangle ()
= =A0 =A0 "Tangles all the org-files in ~/.emacs.d/
=A0 It is = a help-function when one of the source-documents are updated
=A0 in Dropbox and the local setup also needs to be updated."
=A0 =A0 (interactive)
=A0 =A0 (mapc (lambda (file)
=A0 =A0 =A0 =A0 =A0 =A0 (delete-file (expand-file-name file dotfiles-dir= )))
=A0 =A0 =A0 =A0 =A0 (directory-files dotfiles-dir nil ".= *\.\\(el\\|elc\\)$"))
=A0 =A0 (mapc (lambda (file)
=A0 =A0 =A0 =A0 =A0 =A0 (find-f= ile (expand-file-name file dotfiles-dir))
=A0 =A0 =A0 =A0 =A0 =A0= (org-babel-tangle)
=A0 =A0 =A0 =A0 =A0 =A0 (kill-buffer))=A0
=A0 =A0 =A0 =A0 =A0 (directory-files dotfiles-dir nil ".*\.org$= ")))
#+end_src
*** Loading of settings
**** Introductio= n
The loading process is one single step. It checks which OS is i= n 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
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (expand-file-name = "custom_end.org" dotfiles-d= ir)))
=A0 =A0 =A0 =A0 =A0(windows-file (expand-file-name "windows.org" dotfiles-dir))
=A0 =A0 =A0 =A0 =A0(linux-file (expand-file-name "linux.org" dotfiles-dir))
=A0 =A0 =A0 =A0 = =A0(custom-start (expand-file-name "custom_start.org" dotfiles-dir)))
=A0 =A0 (cond
=A0 =A0 =A0((eq system-type 'windows-nt)
=A0 =A0 =A0 (if (file-exists-p windows-file)
=A0 =A0 =A0= =A0 =A0 (mapc #'org-babel-load-file (cons windows-file=A0
= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 (cons custom-start org-files)))))
=A0 =A0 =A0((eq system-type 'gnu/linux)
=A0 =A0 =A0 (if = (file-exists-p linux-file)
=A0 =A0 =A0 =A0 =A0 (mapc #'org-ba= bel-load-file (cons linux-file=A0
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (cons custom-start= org-files)))))))
#+end_src
**** OS-specific settings
As stated earl= ier, I run emacs on multiple systems and keep these
settings sync= ed between the platforms using Dropbox. I have machines
running b= oth 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 wi= th non-ASCII characters on windows but wanted UTF-8 to be
the default encoding when editing.

=A0A searc= h on the Internet resulted in the following:

The settings for the respective systems can be found he= re:
- [[file:linux.org][linux.org= ]]
**** Main settings
The main part of the customizations durin= g the loading-process resides
in [[file:emacs.org][emacs.org]].
**** Computer-specific settings
The cumputer-specific settings ar= e 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.o= rg][custom_start.org]] is mostl= y 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-f= iles uses the correct encoding, if the
system is windows the file= encoding 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 i= n [[file:custom_start.org][custom_start.org]] because
of it's use later in the loading process:
- gw/gtd-root<= /div>

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


Kind regards
Gustav

<= div class=3D"gmail_quote">On Sat, Dec 10, 2011 at 10:03 PM, Andrea Crotti <= span dir=3D"ltr"><andrea.cr= otti.0@gmail.com> wrote:
On 1= 2/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 h= as
> failed in a sense. =A0The problem is that this even if this style is g= reat
> to produce nice documents and add a lot of useful text, is quite bad t= o
> 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)
=A0 =A0 =A0 =A0 (interactive "sWith String:?\n")
=A0 =A0 =A0 =A0 (let ((fname (format "modules/ca-%s.el" fname)))=
=A0 =A0 =A0 =A0 =A0 (query-replace ":tangle yes" (concat ":= tangle " fname))
=A0 =A0 =A0 =A0 ))


--e89a8f2358e171c41604b3e04afe--