Coder Social home page Coder Social logo

use-block's Introduction

use-block

The use-block merges all Emacs Lisp source code blocks in Org mode into use-package expressions

Motivation

When you write the Emacs configuration file in Org mode with use-package,

* Org mode configuration
#+begin_src emacs-lisp
(use-package org
  :defer t
  :config
  ;; Many comments about todo, capture, agenda, tag, column, clock, etc.
  (setq ...)
  ...
  )
#+end_src

in spite of Literate Programming, it's unavoidable that comments are embedded into the source code blocks because all the configurations have to be packed into one use-package expression. And it's tiring to surround all blocks with use-package or eval-after-load if all of them are divided into some extent.

Usage

use-block adds two header arguments to the Emacs Lisp source code blocks.

  • :pre-init PACKAGE

    the source code block is evaluated before PACKAGE is loaded.

  • :post-init PACKAGE

    the source code block is evaluated after PACKAGE is loaded.

If you write config.org

# config.org
* Org mode configuration
#+begin_src emacs-lisp
(use-package org
  :defer t
  :mode ("\\.\\(org\\|org_archive\\)\\'" . org-mode))

(use-package org-agenda :defer t)
#+end_src

org-mode startup layout
#+begin_src emacs-lisp :post-init org
(setq org-startup-folded 'content)

(setq org-startup-indented t)
#+end_src

org-agenda keybinds
#+begin_src emacs-lisp :pre-init org-agenda
(bind-key "C-c a" 'org-agenda)
#+end_src

and load by the function use-block-load-file,

(use-block-load-file "config.org")

Emacs Lisp file config.el is exported and loaded.

;; config.el
(use-package org
  :defer t
  :mode ("\\.\\(org\\|org_archive\\)\\' . org-mode)
  :init
  :config
  (setq org-startup-folded 'content)
  (setq org-startup-indented t))

(use-package org-agenda
  :defer t
  :init
  (bind-key "C-c a" 'org-agenda)
  :config)

Note that expressions other than use-package expressions in code blocks without header arguments such as :pre-init and :post-init are exported as is.

use-block's People

Contributors

hyonhyoro avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.