Add posts/emacs-orgmode-babel-literate-programming.post.

parent 3dd0abef
Pipeline #8811929 passed with stages
in 42 seconds
;;;;;
title: Emacs + Orgmode babel and Literate Programming
tags: void, voidlinux, emacs, babel, literate, programming, literate programming
date: 2017-06-06
author: Lenilson Jose Dias
format: md
;;;;;
Since my last post, I was thinking about remodeling a `dotfiles.org` to a `setup.org`.
This new [orgmode](http://orgmode.org/) is used to apply [Literate Programming](http://www.literateprogramming.com/) and get:
- dotfiles at `$HOME`
- csh files at `$HOME/bin`
- lib files at `$HOME/lib`
All **important** information about this [setup.org](https://github.com/0x7cc/.setup/blob/master/setup.org):
- Purpose
- The Result
- Requirements
Applying Literate Programming Use Emacs + Orgmode babel to convert source code blocks into files with tangle is something very easy.
Bellow an example to create the file: `$HOME/.gitconfig` with a `core` and `user` sections:
```
* git
*** .gitconfig
:PROPERTIES:
:tangle: ~/.gitconfig
:END:
**** Core
#+begin_src conf
[core]
excludesfile = ~/.gitignore
editor = "vim"
autocrlf = input
filemode = false
pager = less -r
#+end_src
**** User
My personal information and GPG key for signing commits.
#+begin_src conf
[user]
name = Lenilson Jose Dias
email = lenilson@gmail.com
signingkey = 5074D5CF
#+end_src
```
It's possible to create shell scripts too:
```
** Setup emacs
:PROPERTIES:
:tangle: ~/bin/setup-emacs
:mkdirp: yes
:shebang: "#!/usr/bin/env csh"
:END:
~$HOME/bin/setup-emacs~ for now clone an Emacs git repository...
#+begin_src sh
rm -rf ~/.emacs.d
git clone https://github.com/0x7cc/.emacs.d ~/.emacs.d
#+end_src
```
This source code block will create a `csh` shell script `$HOME/bin/setup-emacs`.
It's possible create files in a different `file-mode` too:
```
*** msmtp
:PROPERTIES:
:tangle: ~/.msmtprc
:tangle-mode: (identity #o600)
:END:
[[http://msmtp.sourceforge.net/][msmtp]] is a SMTP client. From [[http://jonmorehouse.tumblr.com/post/100650456885/yosemite-mutt][here]]:
#+begin_src conf
# Set default values for all following accounts.
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log
# Gmail
account personal_email
host smtp.gmail.com
port 587
from lenilson@gmail.com
user lenilson@gmail.com
password
account default : personal_email
#+end_src
```
Here with `:tangle-mode: (identity #o600)` will create `$HOME/.msmtprc` with `600` permission mode.
The section [Purpose](https://github.com/0x7cc/.setup/blob/master/setup.org#1-purpose) has some inspiration references like this [video](https://www.youtube.com/watch?v%3DdljNabciEGg) from [@howardabrams](https://twitter.com/howardabrams).
For this project I am using a `Makefile` to set up everything, but you can only call:
```
emacs --batch --eval "(require 'org)(require 'ob-tangle)" --eval '(org-babel-tangle-file "<path to>/setup.org")'
```
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment