12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- ;; __ __ _ __ _ _ _ _ _
- ;; \ \ / /__ | |/ _| ___( )___ (_)_ __ (_) |_ ___| |
- ;; \ \ /\ / / _ \| | |_ / _ \// __| | | '_ \| | __| / _ \ |
- ;; \ V V / (_) | | _| __/ \__ \ | | | | | | |_ | __/ |
- ;; \_/\_/ \___/|_|_| \___| |___/ |_|_| |_|_|\__(_)___|_|
-
-
- ;; Disable file name handler for performance during startup
- (defvar wolfe/file-name-handler-alist file-name-handler-alist)
- (setq file-name-handler-alist nil
- ;; Set garbage collect high to speed up startup
- gc-cons-threshold most-positive-fixnum
- gc-cons-percentage 0.6
- ;; Ignore advice warnings
- ad-redefinition-action 'accept)
-
- (add-hook 'emacs-startup-hook
- (lambda () (setq gc-cons-threshold 16777216
- gc-cons-percentage 0.1
- file-name-handler-alist wolfe/file-name-handler-alist
- ad-redefinition-action 'warn)))
-
- (require 'package)
- ;; Setup package sources
- (setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
- ("melpa" . "http://melpa.org/packages/")
- ("org" . "http://orgmode.org/elpa/")))
- (setq package-enable-at-startup nil)
- (setq package-pinned-packages '((use-package . "melpa")))
- (package-initialize)
-
- ;; Bootstrap use-package
- (unless (package-installed-p 'use-package)
- (package-refresh-contents)
- (package-install 'use-package))
- (require 'use-package)
- (setq use-package-always-ensure t)
-
- ;; Use latest org before calling babel
- (use-package-pin-package 'org "org")
- (use-package org
- :ensure org-plus-contrib)
-
- (defun init/tangle-section-canceled ()
- "Return t if the current section header was CANCELED, else nil."
- (save-excursion
- (if (re-search-backward "^\\*+\\s-+\\(.*?\\)?\\s-*$" nil t)
- (string-prefix-p "CANCELED" (match-string 1))
- nil)))
-
- (defun init/tangle-config-org (orgfile elfile)
- "This function will write all source blocks from =config.org= into
- =config.el= that are ...
-
- - not marked as :tangle no
- - have a source-code of =emacs-lisp=
- - doesn't have the todo-marker CANCELED"
- (let* ((body-list ())
- (gc-cons-threshold most-positive-fixnum)
- (org-babel-src-block-regexp (concat
- ;; (1) indentation (2) lang
- "^\\([ \t]*\\)#\\+begin_src[ \t]+\\([^ \f\t\n\r\v]+\\)[ \t]*"
- ;; (3) switches
- "\\([^\":\n]*\"[^\"\n*]*\"[^\":\n]*\\|[^\":\n]*\\)"
- ;; (4) header arguments
- "\\([^\n]*\\)\n"
- ;; (5) body
- "\\([^\000]*?\n\\)??[ \t]*#\\+end_src")))
- (with-temp-buffer
- (insert-file-contents orgfile)
- (goto-char (point-min))
- (while (re-search-forward org-babel-src-block-regexp nil t)
- (let ((lang (match-string 2))
- (args (match-string 4))
- (body (match-string 5))
- (canc (init/tangle-section-canceled)))
- (when (and (string= lang "emacs-lisp")
- (not (string-match-p ":tangle\\s-+no" args))
- (not canc))
- (add-to-list 'body-list body)))))
- (with-temp-file elfile
- (insert (format ";;; -*- lexical-binding: t -*-\n" orgfile))
- (apply 'insert (reverse body-list)))
- (message "Wrote %s ..." elfile)))
-
- (let ((orgfile (concat user-emacs-directory "README.org"))
- (elfile (concat user-emacs-directory "README.el")))
- (when (or (not (file-exists-p elfile))
- (file-newer-than-file-p orgfile elfile))
- (init/tangle-config-org orgfile elfile))
- (load-file elfile))
|