BonfaceKilz / emacs.d

Mirror of: https://git.sr.ht/~bonfacekilz/emacs.d
GNU General Public License v3.0
4 stars 2 forks source link

tangle instructions #2

Open jgarte opened 2 years ago

jgarte commented 2 years ago

Hi Bonface,

How do you deploy your emacs dotfiles to a new machine?

Is there a way to call emacs from the command line with the tangle command?

emacs --tangle init.org > ~/.emacs

or something like that ;()

BonfaceKilz commented 2 years ago

jgart @.***> anaandika:

Hi Bonface,

Ola ola o/.

How do you deploy your emacs dotfiles to a new machine?

For me, I just need a base install of Emacs and git installed somewhere. On a new machine, I do a git pull of my configs in my org file which contains all my configs. Thereafter, I open that file and simply run "org-babel-tangle"; a command that is bound to "C-c C-v C-t".

Note that all my configs are in an org file with a header that looks like:

--8<---------------cut here---------------start------------->8---

+begin_src emacs-lisp :padding no :tangle ~/.emacs.d/init.el :mkdirp yes :noweb yes

--8<---------------cut here---------------end--------------->8---

The most important bit there is the =:mkdirp yes=. This makes sure that that if a dir doesn't exist, GNU Emacs will create it for you.

Is there a way to call emacs from the command line with the tangle command?

emacs --tangle init.org > ~/.emacs

or something like that ;()

There is a better way of doing this. Say you have this org file, "myfile.org" that looks like:

--8<---------------cut here---------------start------------->8--- Test tangling

+begin_src emacs-lisp :padding no :tangle ~/rand/init.el :mkdirp yes :noweb yes

(defvar user-home-directory (concat (expand-file-name "~") "/"))

+end_src

Another tangle:

+begin_src emacs-lisp :padding no :tangle ~/rand/setup/rand.el :mkdirp yes :noweb yes

(defvar user-home-directory (concat (expand-file-name "~") "/"))

+end_src

--8<---------------cut here---------------end--------------->8---

and you want to tangle it from the CLI. I propose you have an emacs scriptfile, "test.el" (use a better name) that looks like:

--8<---------------cut here---------------start------------->8---

!/home/bonface/.guix-profile/bin/emacs --script

;; The subdirectory ~/.emacs.d is to be added to the top-level elisp ;; file search.

;; Org-Mode, Org-Babel, and the tangle library are required, if we are ;; to proceed further. (require 'org-install) (require 'org) (require 'ob-tangle) ;; Load the main configuration and setup file. (require 'ob-emacs-lisp)

(org-babel-tangle-file "/tmp/myfile.org")

--8<---------------cut here---------------end--------------->8---

Now you just run that from your CLI (ensure it's executable):

: ./test.el

So a simple recipe for tangling from your CLI would be to:

  1. Have an org file with all your configs; and
  2. An elisp script file that does all the tangling for you

I you found this useful.

PS: I got useful information of tangling from the CLI here: https://emacs-orgmode.gnu.narkive.com/NaB7zkJz/o-emacs-shell-script-to-tangle-org-babel-at-the-command-line

-- Bonface M. K. D4F09EB110177E03C28E2FE1F5BBAE1E0392253F (hkp://keys.gnupg.net) Free Software Activist Humble GNU Emacs User | Bearer of scheme-y parens Curator: https://upbookclub.com | Twitter: @MunyokiKilyungi