ob-bitfield
ob-bitfield copied to clipboard
Generate bitfield diagrams using org-babel
ob-bitfield
Generate bitfield diagrams using the Python bitfield package and org-babel.
Installation
ob-bitfield
can be installed from MELPA with M-x package-install ob-bitfield
. Before using it, make sure to install the required dependencies.
You can then enable the package in one of the following ways:
(org-babel-do-load-languages
'org-babel-load-languages
'((bitfield . t)))
- Add
(require 'ob-bitfield)
to your Emacs init file - If using
use-package
, you can add this to your init file:
(use-package ob-bitfield
:after org)
Required Dependencies
Install the bitfield Python package:
pip install bit_field[JSON5]
Imagemagick is also required if you would like to generate images other than SVGs. On Debian/Ubuntu this can be installed with sudo apt install imagemagick
, and on macOS it can be installed with brew install imagemagick
.
Usage
Create a bitfield
source block, for example:
#+begin_src bitfield :lanes 2 :file out.png
[
{ "name": "IPO", "bits": 8, "attr": "RO" },
{ "bits": 7 },
{ "name": "BRK", "bits": 5, "attr": "RW", "type": 4 },
{ "name": "CPK", "bits": 1 },
{ "name": "Clear", "bits": 3 },
{ "bits": 8 }
]
#+end_src
Use org-babel-execute-src-block
(C-c C-c
) to execute the source block. The results will look as follows:
#+RESULTS:
[[file:out.png]]
You can view the image inline with org-toggle-inline-images
(C-c C-x C-v
).
If :file
does not end in the ".svg" extension, then Imagemagick is used to convert it to the specified file type.
Header Arguments
By default, :results
is set to file graphics
and :exports
is set to results
.
:file
is the only required header argument.
Most arguments from the bitfield package are supported. If an argument is not specified, the default value from the package is used. The full list of supported arguments is:
-
:lanes
-
:vspace
-
:hspace
-
:bits
-
:fontfamily
-
:fontweight
-
:fontsize
-
:compact