emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Feature request: Maintaining multiple init files with one org fi


From: Sven Bretfeld
Subject: Re: [O] Feature request: Maintaining multiple init files with one org file
Date: Mon, 30 Jul 2018 14:15:38 +0200
User-agent: mu4e 0.9.19; emacs 26.1

Hi Eric

So all in all I feel that there is a demand for my suggestion. Orgmode
has the power to yield a real good solution for centralized init file
maintenance, but at the moment we have to help ourselves with
workarounds. Tag-filtering for tangling functions would be the best way
to go in the future. I'm not a programmer, otherwise I would try to
implement this. For now I can only hope that somebody competent would do
it.

For the time being, here is my workaround which I developed inspired by
Amin's approach. I describe everything for whoever else is looking for a
similar solution:

,---- ~/aktuell/emacs/emacs-config.org
|
| * Init File
| ** Hostname Identification
|    This section defines variables for all use cases: Some code is needed
|    only for one machine, some for a sub-group (e.g. all computers
|    running Linux or all computers having large monitors etc.), some for all 
computers.
|
|    #+begin_src emacs-lisp :tangle (if allhosts "~/.emacs")
|    ;; variable for my PC at home
|    (defvar homepc nil) ;; variable for my PC at home
|    (if (string-match (system-name) "hostname-home") ;<--- set your hostname 
here
|                (setq homepc t))
|
|    ;; variable for my PC at office
|    (defvar officepc nil)
|    (if (string-match (system-name) "hostname-office") ;<--- set your hostname 
here
|                (setq officepc t))
|
|    ;; variable for my laptop
|    (defvar laptop nil)
|    (if (string-match (system-name) "hostname-laptop") ;<--- set your hostname 
here
|                (setq laptop t))
|
|    ;; variable for Termux/Android
|    (defvar andr nil)
|    (if (string-match (system-name) "localhost") ;<--- Termux uses "localhost"
|                (setq andr t))
|
|    ;; variable for all desktop machines together (i.e. home+office in my case)
|    (defvar pcs nil)
|    (if (string-match (system-name) "hostname-home\|hostname-office") <--- set 
your hostnames here
|                (setq pcs t))
|
|    ;; variable for all GNU/Linux machines together (home+office+laptop)
|    (defvar allgnu nil)
|    (if (string-match (system-name) 
"hostname-home\|hostname-office\|hostname-laptop") <--- set your hostnames here
|                (setq allgnu t))
|
|    ;; variable for all machines together (home+office+laptop+Android)
|    (defvar allhosts nil)
|    (if (string-match (system-name) 
"hostname-home\|hostname-office\|hostname-laptop\|localhost")
|                (setq allhosts t))
| #+end_src
| ** Startup File
| *** Linux
|     The code in this section is needed for the init files on all
|     computers running GNU/Linux (variable: allgnu)
|  #+begin_src emacs-lisp :tangle (if allgnu "~/.emacs")
|  (defun tangle-init ()
|    "If the current buffer is 'emacs-config.org' the code-blocks are
|  tangled, and the tangled file is compiled."
|    (when (equal (buffer-file-name)
|               (expand-file-name "~/aktuell/emacs/emacs-config.org"));<---put 
name of this file here
|      ;; Avoid running hooks when tangling.
|      (let ((prog-mode-hook nil))
|        (org-babel-tangle))))
|
|  (add-hook 'after-save-hook 'tangle-init)
|  #+end_src
| *** Android
|     The code in this section is needed only for emacs running on Android
|     (variable: andr).
|  #+begin_src emacs-lisp :tangle (if andr "~/.emacs")
|  (defun tangle-init ()
|    "If the current buffer is 'emacs-config.org' the code-blocks are
|  tangled, and the tangled file is compiled."
|    (when (equal (buffer-file-name)
|               (expand-file-name
|  "/sdcard/Aktuell/emacs/emacs-config.org"));<---put name of this file with 
the Android path here
|      ;; Avoid running hooks when tangling.
|      (let ((prog-mode-hook nil))
|        (org-babel-tangle))))
|
|  (add-hook 'after-save-hook 'tangle-init)
|  #+end_src
|
| * Other configurations whatsoever
|   ...
|
`----

Every section of source-code starts with: `#+begin_src emacs-lisp
:tangle' and a lisp expression assigning the following source code
section to one of the defined variables (homepc, officepc, laptop, andr,
pcs, allgnu or allhosts). The code will then end up in the actual init
file (~/.emacs) only if the present machine belongs to the respective
group, i.e. if this variable is non-nil for it. If the variable is nil,
the code section will be ignored on the respective machine. All you have
to do is to sync this file to each machine, visit it on each and save it
again (which triggers the generation of the .emacs file).

Every piece of source code needs to have one of these expressions
(actually "allhosts" could do without, since it is the default case if
you have headline_args set as shown in my initial email). This is a bit
more clumsy than it would be if we could use org tags but it's easier
and clearer than including hundreds of if-conditions to the code itself.

Thank you for all your help,

Sven

Eric S Fraga writes:

> On Sunday, 29 Jul 2018 at 12:42, Sven Bretfeld wrote:
>
> [...]
>
>> At the moment I have a separate .emacs for the tablet and have to
>> remember changing this file, for ex. whenever I include a new file in
>> the org-agenda-files list. This could be much more tidy with an org
>> approach.
>
> The approach I take, trying to use the same init file for 4 quite
> different systems (including termux on Android at one point), is to have
> a very small .emacs for each which sets up system specific variables
> (e.g. paths and default face) and then loads the common init file.  The
> latter is managed/written in org but the .emacs (or equivalently
> .emacs.d/init.el) files for each system are not as they are typically
> just a few lines long.
>
>> I'm trying to use customize as little as possible, since AFAIK there is
>> no way to let customize use an org file instead of a "real" init file.
>
> I also try to minimize the use of customize but I do use it.  For this,
> I make sure that emacs doesn't use the init file for saving
> customization information but uses a custom-file I specify.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]