X-Git-Url: https://git.ganneff.de//index.cgi?p=emacs.git;a=blobdiff_plain;f=.emacs.d%2Finit.el;h=968b93d25aeb5527f8272bd7379248ffc2ad5440;hp=f078c1f09e07fa6d50d24dc6ed545ff096e63a3e;hb=3449bd86e43e169239bd779b3a68c7c5220ea3ca;hpb=fb8dec7f117e72cb82a3e4e38276841adc285a34;ds=sidebyside diff --git a/.emacs.d/init.el b/.emacs.d/init.el index f078c1f..968b93d 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -18,8 +18,12 @@ ;; a config change takes longer, but as that only happens when I change ;; something in the .org files - I don't care. -(let ((file-name-handler-alist nil)) - +(eval-and-compile + (defvar jj--file-name-handler-alist file-name-handler-alist) + (setq gc-cons-threshold most-positive-fixnum + gc-cons-percentage 0.6 + file-name-handler-alist nil)) + ;; Go go go (unless noninteractive (message "Emacs is powering up... Be patient, Master %s!" (getenv "USER"))) @@ -28,15 +32,23 @@ ;; seconds), so save the start time (defvar emacs-load-start-time (current-time)) +;; If we are starting a daemon, load each and every package. If not, +;; default use-package is to delay package loading, which is good when +;; interactively starting emacs. +(if (daemonp) + (setq use-package-always-demand t)) ; Much larger threshold for garbage collection prevents it to run too often. -(setq gc-cons-threshold 480000000) +;(setq gc-cons-threshold 480000000) ;; Set a high number of lines for the message buffer so stuff doesn't "scroll out" (setq message-log-max 16384) -;; Set path to (my, recent) Org-Mode version -(add-to-list 'load-path (concat (file-name-directory (or load-file-name (buffer-file-name))) "elisp/org/")) +;; Don't load old .elc files when the .el file is newer +(setq load-prefer-newer t) + +;; ;; Set path to (my, recent) Org-Mode version +;; (add-to-list 'load-path (concat (file-name-directory (or load-file-name (buffer-file-name))) "elisp/org/")) ;; org-mode can load modules when it loads itself, lets tell it which ones we want. ; org-checklist (setq org-modules (quote @@ -51,7 +63,81 @@ (require 'ob-tangle) ;; And finally, let org-babel do its work. All the rest of the emacs ;; initialization comes from initjj.org -(org-babel-load-file (expand-file-name "initjj.org" (file-name-directory (or load-file-name (buffer-file-name)))))) +;(org-babel-load-file (expand-file-name "initjj.org" (file-name-directory (or load-file-name (buffer-file-name)))))) + +(defun my-tangle-section-canceled () + "Checks if the previous section header was CANC" + (save-excursion + (if (re-search-backward "^\\*+\\s-+\\(.*?\\)?\\s-*$" nil t) + (progn + ;; (message "FOUND '%s'" (match-string 1)) + (string-prefix-p "CANC" (match-string 1))) + nil))) + +(defun my-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 CANC" + (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 (my-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 ";; *- lexical-binding: t; -*-\n") + (insert (format ";; Don't edit this file, edit %s instead ...\n\n" orgfile)) + ;; (insert (apply 'concat (reverse body-list))) + (apply 'insert (reverse body-list))) + (message "Wrote %s ..." elfile) + (byte-compile-file elfile))) + + +(let ((orgfile (expand-file-name "initjj.org" (file-name-directory (or load-file-name (buffer-file-name))))) + (elfile (expand-file-name "initjj.el" (file-name-directory (or load-file-name (buffer-file-name)))))) + (when (or (not (file-exists-p elfile)) + (file-newer-than-file-p orgfile elfile)) + (my-tangle-config-org orgfile elfile)) + (load-file elfile)) ; And back done a bit with it, startup is over -(setq gc-cons-threshold 800000) +;(setq gc-cons-threshold (* 100 1024 1024)) + +;; Don't keep gc-cons-threshold too high. It helps to stave off the GC while +;; Emacs starts up, but afterwards it causes stuttering and random freezes. So +;; reset it to a reasonable default. +(setq gc-cons-threshold 16777216 + gc-cons-percentage 0.1 + file-name-handler-alist jj--file-name-handler-alist) +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(package-selected-packages (quote (notmuch validate use-package paradox keyfreq)))) +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + )