From: "Gustav Wikström" <gustav.erik@gmail.com>
To: Andrea Crotti <andrea.crotti.0@gmail.com>
Cc: Org Mode List <emacs-orgmode@gnu.org>
Subject: Re: back to a multiple-file configuration
Date: Mon, 12 Dec 2011 08:43:29 +0100 [thread overview]
Message-ID: <CA+SyOP_TNbhpw-xGarfYCxz-kkwmwQtTbMxq8FQY7Mrp-5kOBQ@mail.gmail.com> (raw)
In-Reply-To: <4EE3C93E.3020708@gmail.com>
[-- 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 --]
next prev parent reply other threads:[~2011-12-12 7:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2011-12-17 11:45 ` Andrea Crotti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CA+SyOP_TNbhpw-xGarfYCxz-kkwmwQtTbMxq8FQY7Mrp-5kOBQ@mail.gmail.com \
--to=gustav.erik@gmail.com \
--cc=andrea.crotti.0@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.