01.使用 Org Mode 管理 Emacs 配置

Emacs 的配置文件是 Emacs Lisp 脚本。在社区中,有一种更加幽雅的高级配置方式,使用 Org Mode 文件作为 Emacs 配置文件。


org-babel 配置文件

~/.emacs.d/init.el 是 Emacs 的默认配置文件路径。

我们引入一个新的 Org Mode 文件:~/.emacs.d/emacs-config.org

并通过 org-babel-load-file 函数,实现加载 Org Mode 的配置文件。

根据《A minimal emacs setup with orgmode - Invalid Input》,一个可工作的最小配置文件集合如下:

;; add MELPA package server
(require 'package)

(add-to-list 'package-archives 
  '("melpa" . "http://melpa.milkbox.net/packages/"))

(unless package-archive-contents
  (package-refresh-contents))

(package-initialize)

;; if not yet installed, install package use-package
(unless (package-installed-p 'use-package)
  (package-install 'use-package))

;; load org package and our emacs-config.org file
(require 'org)
(org-babel-load-file "~/.emacs.d/emacs-config.org") 

Org Mode 配置文件模板

根据《A minimal emacs setup with orgmode - Invalid Input》在 emacs-config.org 中,以 Org 的语法一边编写描述,一边编写配置代码,模板样例如下:

#+TITLE: Emacs configuration
#+DESCRIPTION: An org-babel based emacs configuration
#+LANGUAGE: en
#+PROPERTY: results silent

* Remove startup welcome screen
The code block below toggle off the welcome startup screen.

#+BEGIN_SRC emacs-lisp
(custom-set-variables
  '(inhibit-startup-screen t))
#+END_SRC

网络资源


本文作者:Maeiee

本文链接:01.使用 Org Mode 管理 Emacs 配置

版权声明:如无特别声明,本文即为原创文章,版权归 Maeiee 所有,未经允许不得转载!


喜欢我文章的朋友请随缘打赏,鼓励我创作更多更好的作品!