My personal dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

init.el 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ;; __ __ _ __ _ _ _ _ _
  2. ;; \ \ / /__ | |/ _| ___( )___ (_)_ __ (_) |_ ___| |
  3. ;; \ \ /\ / / _ \| | |_ / _ \// __| | | '_ \| | __| / _ \ |
  4. ;; \ V V / (_) | | _| __/ \__ \ | | | | | | |_ | __/ |
  5. ;; \_/\_/ \___/|_|_| \___| |___/ |_|_| |_|_|\__(_)___|_|
  6. ;; Disable file name handler for performance during startup
  7. (defvar wolfe/file-name-handler-alist file-name-handler-alist)
  8. (setq file-name-handler-alist nil
  9. ;; Set garbage collect high to speed up startup
  10. gc-cons-threshold most-positive-fixnum
  11. gc-cons-percentage 0.6
  12. ;; Ignore advice warnings
  13. ad-redefinition-action 'accept)
  14. (add-hook 'emacs-startup-hook
  15. (lambda () (setq gc-cons-threshold 16777216
  16. gc-cons-percentage 0.1
  17. file-name-handler-alist wolfe/file-name-handler-alist
  18. ad-redefinition-action 'warn)))
  19. (require 'package)
  20. ;; Setup package sources
  21. (setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
  22. ("melpa" . "http://melpa.org/packages/")
  23. ("org" . "http://orgmode.org/elpa/")))
  24. (setq package-enable-at-startup nil)
  25. (setq package-pinned-packages '((use-package . "melpa")))
  26. (package-initialize)
  27. ;; Bootstrap use-package
  28. (unless (package-installed-p 'use-package)
  29. (package-refresh-contents)
  30. (package-install 'use-package))
  31. (require 'use-package)
  32. (setq use-package-always-ensure t)
  33. ;; Use latest org before calling babel
  34. (use-package-pin-package 'org "org")
  35. (use-package org
  36. :ensure org-plus-contrib)
  37. (defun init/tangle-section-canceled ()
  38. "Return t if the current section header was CANCELED, else nil."
  39. (save-excursion
  40. (if (re-search-backward "^\\*+\\s-+\\(.*?\\)?\\s-*$" nil t)
  41. (string-prefix-p "CANCELED" (match-string 1))
  42. nil)))
  43. (defun init/tangle-config-org (orgfile elfile)
  44. "This function will write all source blocks from =config.org= into
  45. =config.el= that are ...
  46. - not marked as :tangle no
  47. - have a source-code of =emacs-lisp=
  48. - doesn't have the todo-marker CANCELED"
  49. (let* ((body-list ())
  50. (gc-cons-threshold most-positive-fixnum)
  51. (org-babel-src-block-regexp (concat
  52. ;; (1) indentation (2) lang
  53. "^\\([ \t]*\\)#\\+begin_src[ \t]+\\([^ \f\t\n\r\v]+\\)[ \t]*"
  54. ;; (3) switches
  55. "\\([^\":\n]*\"[^\"\n*]*\"[^\":\n]*\\|[^\":\n]*\\)"
  56. ;; (4) header arguments
  57. "\\([^\n]*\\)\n"
  58. ;; (5) body
  59. "\\([^\000]*?\n\\)??[ \t]*#\\+end_src")))
  60. (with-temp-buffer
  61. (insert-file-contents orgfile)
  62. (goto-char (point-min))
  63. (while (re-search-forward org-babel-src-block-regexp nil t)
  64. (let ((lang (match-string 2))
  65. (args (match-string 4))
  66. (body (match-string 5))
  67. (canc (init/tangle-section-canceled)))
  68. (when (and (string= lang "emacs-lisp")
  69. (not (string-match-p ":tangle\\s-+no" args))
  70. (not canc))
  71. (add-to-list 'body-list body)))))
  72. (with-temp-file elfile
  73. (insert (format ";;; -*- lexical-binding: t -*-\n" orgfile))
  74. (apply 'insert (reverse body-list)))
  75. (message "Wrote %s ..." elfile)))
  76. (let ((orgfile (concat user-emacs-directory "README.org"))
  77. (elfile (concat user-emacs-directory "README.el")))
  78. (when (or (not (file-exists-p elfile))
  79. (file-newer-than-file-p orgfile elfile))
  80. (init/tangle-config-org orgfile elfile))
  81. (load-file elfile))