From 6cc0a9871c7160f769d4ebe60ff9d945ac931449 Mon Sep 17 00:00:00 2001 From: Peter Tillemans Date: Sun, 11 Aug 2024 11:36:44 +0200 Subject: [PATCH] simplified and better monitoring of init scripts --- early-init.el | 2 + init.org | 144 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 103 insertions(+), 43 deletions(-) diff --git a/early-init.el b/early-init.el index 34490db..229028e 100644 --- a/early-init.el +++ b/early-init.el @@ -82,6 +82,7 @@ ;; this is a good time to check if the crafted-emacs repo is fresh ;; - we just updated the init.org file so we expect changes. ;; - or this is the initial tangling and we need the repo to exist. + (message "checking crafted emacs repo...") (check-crafted-emacs-fresh-repo) ))) @@ -95,3 +96,4 @@ (load (expand-file-name "modules/crafted-package-config" crafted-emacs-home)) (load (expand-file-name "modules/crafted-early-init-config" crafted-emacs-home)) +(message "early-init done") diff --git a/init.org b/init.org index 670fb21..5b60b6d 100644 --- a/init.org +++ b/init.org @@ -1,6 +1,6 @@ #+TITLE: My Emacs Configuration #+PROPERTY: header-args :tangle yes -#+PROPERTY: header-args:emacs-lisp :lexical yes :tangle yes :comments both :padline yes +#+PROPERTY: header-args:emacs-lisp :lexical yes :tangle yes :comments nil :padline yes * Literate Configuration for Emacs @@ -39,6 +39,7 @@ one to use. - [[https://github.com/TheBB/dotemacs/blob/master/init.el][Eivind Fonn's init.el]] * First Things First + ** Make tangled file read-only Add a preamble to the file to ensure some global settings, most @@ -73,7 +74,7 @@ Also immediately set lexical binding mode. "Report the time since the file was init script was started. If SUFFIX is provided, it is appended to the message." - (message "Loading init... (%.3fs) %s" + (message "%.3fs: %s" (float-time (time-subtract (current-time) emacs-start-time)) suffix)) @@ -111,7 +112,7 @@ then load it. #+BEGIN_SRC emacs-lisp (defun pti-reload-dir-locals-for-current-buffer () - "reload dir locals for the current buffer" + "Reload dir locals for the current buffer." (interactive) (let ((enable-local-variables :all)) (hack-dir-local-variables-non-file-buffer))) @@ -128,29 +129,37 @@ there is no easy way to get the latest version of a project provided. This functions uses the releases API to get the latest metadata and get the version number from the JSON. -#+BEGIN_SRC emacs-lisp - (defun pti-with-latest-github-version (repo f) +#+BEGIN_SRC emacs-lisp + (require 'url) + (defun pti-latest-github-release (repo) "Return the latest version of the releases for REPO. - The repo should be in the form of 'owner/repo'. The function F - will be called with the version in format 'vX.Y.Z' as the only argument." - (url-retrieve - (format "https://api.github.com/repos/%s/releases/latest" repo) - (lambda (events) - (message "Events: %s" events) - (goto-char url-http-end-of-headers) - (let ((json-object-type 'plist) - (json-key-type 'symbol) - (json-array-type 'vector)) - (let ((result (json-read))) - (message "Latest version: %s" (plist-get result 'name)) - (funcall f (plist-get result 'name)) - ))))) + The repo should be in the form of `owner/repo'." + (with-temp-buffer + (url-insert-file-contents + (format "https://api.github.com/repos/%s/releases/latest" repo)) + (let ((result (json-read))) + (cdr (assoc 'name result))))) #+END_SRC +#+RESULTS: +: pti-latest-github-release + +#+BEGIN_SRC emacs-lisp :results value + (pti-latest-github-release "plantuml/plantuml") +#+END_SRC + +#+RESULTS: +: v1.2024.6 + * Crafted Emacs +#+BEGIN_SRC emacs-lisp +(report-time-since-load "Crafted Emacs") +#+END_SRC + + When I could not solve the persistent slowness I experienced on Windows using Doom Emacs, I wanted to switch to a more hands-on minimal Emacs configuration. I just watched the 'Rational Emacs' @@ -181,7 +190,7 @@ Lists and installs a variety of packages and includes custom configurations for (require 'crafted-writing-packages) (require 'crafted-ui-packages) -(message "loading packages") +(report-time-since-load "loading packages") (crafted-package-install-selected-packages) (elpaca-wait) @@ -198,6 +207,11 @@ Lists and installs a variety of packages and includes custom configurations for : pti-org-config * Integration with Environment + +#+BEGIN_SRC emacs-lisp +(report-time-since-load "Integration with Environment") +#+END_SRC + ** Set default Coding System to Use UTF-8 Everywhere Ensures UTF-8 is the default coding system everywhere. @@ -332,6 +346,11 @@ It provides a minor-mode * Editor Features + +#+BEGIN_SRC emacs-lisp +(report-time-since-load "Editor Features") +#+END_SRC + ** Evil Vim Keybindings I configure all my apps to use vim keybindings if possible to maximise @@ -626,7 +645,7 @@ whether to put it under writing, comms or programming as it is equally )) (ellama-sessions-directory (expand-file-name "~/Dropbox/ellama-sessions")) :config - (message "Ellama is available")) + (report-time-since-load "Ellama is available")) #+END_SRC It seems the *gpt-4o* model provides better responses. I should @@ -708,6 +727,11 @@ Emacs' direnv module gives first class support to Emacs projects so they use the This enables direnv globally. * Writing and Planning + +#+BEGIN_SRC emacs-lisp +(report-time-since-load "Writing and Planning") +#+END_SRC + ** Org Mode *** Mixed Pitch Support by Default in Org @@ -832,20 +856,15 @@ interactive to manually install the latest version if needed. This function is interactive to make it easy to upgrade to the latest, current version with `M-x pti-download-latest-plantuml'." (interactive) - (pti-with-latest-github-version - "plantuml/plantuml" - - - (lambda (version) - (let ((url (format - "https://github.com/plantuml/plantuml/releases/download/%s/plantuml-%s.jar" - version (substring version 1)))) - (message "Downloading PlantUML version %s from %s" version url) - (url-copy-file - url - (concat user-emacs-directory "plantuml.jar") - )))) - ) + (let* ((version (pti-latest-github-release "plantuml/plantuml")) + (url (format + "https://github.com/plantuml/plantuml/releases/download/%s/plantuml-%s.jar" + version (substring version 1)))) + (message "Downloading PlantUML version %s from %s" version url) + (url-copy-file + url + (concat user-emacs-directory "plantuml.jar") + t))) (let ((plantuml-jar (concat user-emacs-directory "plantuml.jar"))) (if (not (file-exists-p plantuml-jar)) @@ -1428,7 +1447,13 @@ We can add a list of queries **** TODO explain what denote-dired-mode-in-directories does. * Programming + +#+BEGIN_SRC emacs-lisp +(report-time-since-load "Programming") +#+END_SRC + ** Programming Support Infrastructure + *** Integration with LSP Servers for language support #+BEGIN_SRC emacs-lisp ;; configure eglot-mode @@ -1471,6 +1496,18 @@ We can add a list of queries #+END_SRC +*** Flymake Support + +#+BEGIN_SRC emacs-lisp + (after-load 'flymake + (evil-define-key 'normal flymake-mode-map + (kbd "]d") #'flymake-goto-next-error + (kbd "[d") #'flymake-goto-prev-error + )) + +#+END_SRC + + *** Use Treesitter parser support #+BEGIN_SRC emacs-lisp @@ -1498,6 +1535,7 @@ We can add a list of queries (tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src") (typescript "https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src") (yaml "https://github.com/ikatyang/tree-sitter-yaml"))) + :hook ((prog . treesit-inspect-mode))) @@ -1691,7 +1729,7 @@ see also [[https://www.masteringemacs.org/article/how-to-get-started-tree-sitter (if (not (file-exists-p archive)) (url-copy-file download-url archive)) (call-process "tar" nil "*snam-install*" t "-C" jdtls-dir "-xzvf" archive ) - (message "jdtls installed at %s" jdtls-prog))) + (report-time-since-load "jdtls installed at %s" jdtls-prog))) (with-eval-after-load 'eglot (progn (setenv "JAVA_HOME" (getenv "GUIX_PROFILE")) @@ -1798,11 +1836,11 @@ Map the keymap consistently to the eglot mappings. (let ((default-directory (expand-file-name snam-vscode-js-debug-dir))) (vc-git-clone "https://github.com/microsoft/vscode-js-debug.git" "." nil) - (message "git repository created") + (report-time-since-load "git repository created") (call-process "npm" nil "*snam-install*" t "install") - (message "npm dependencies installed") + (report-time-since-load "npm dependencies installed") (call-process "npx" nil "*snam-install*" t "gulp" "dapDebugServer") - (message "vscode-js-debug installed"))) + (report-time-since-load "vscode-js-debug installed"))) (setq snam-codelldb-dir (file-name-concat user-emacs-directory "dape/codelldb")) (defun snam-install-codelldb () @@ -1819,9 +1857,9 @@ Map the keymap consistently to the eglot mappings. (release-url (concat "https://github.com/vadimcn/codelldb/releases/download/v" version "/codelldb-" arch "-" os ".vsix"))) (mkdir default-directory t) (url-copy-file release-url "codelldb.zip" t) - (message "codelldb archive downloaded") + (report-time-since-load "codelldb archive downloaded") (call-process "unzip" nil "*snam-install*" t "codelldb.zip") - (message "codelldb installed") + (report-time-since-load "codelldb installed") )) ;; configure dape (dap-mode) @@ -1938,7 +1976,7 @@ the moment. #+BEGIN_SRC emacs-lisp (use-package gitlab-ci-mode - :ensure (:host gitlab.com :repo "ptillemans/gitlab-ci-mode" :branch "fixes_2024") + :ensure (:host gitlab :repo "ptillemans/gitlab-ci-mode" :branch "fixes_2024") :mode "\\.gitlab-ci\\.yml\\'" :custom (gitlab-ci-url "https://gitlab.melexis.com") @@ -1949,6 +1987,11 @@ the moment. : [nil 26292 38256 549743 nil elpaca-process-queues nil nil 11000 nil] * Communication and Interwebs + +#+BEGIN_SRC emacs-lisp +(report-time-since-load "Communication and Interwebs") +#+END_SRC + ** ERC configuration Set up ERC, an IRC client for Emacs, to automatically join specific channels and log in: #+BEGIN_SRC emacs-lisp @@ -2016,7 +2059,7 @@ I like to have my IRC channels on workspace 5 in *i3*. (call-process "i3" nil nil nil "move window to workspace 5") (snam-erc) (call-process "i3" nil nil nil "workspace 5") - (message "Waiting to connect to IRC...") + (report-time-since-load "Waiting to connect to IRC...") (dotimes (i 12) (unless (member channel (mapcar 'buffer-name (erc-channel-list nil))) (sleep-for 0.25))) @@ -2105,6 +2148,11 @@ The commands this package offers: as apparently is was abused too much. * Finishing Touches + +#+BEGIN_SRC emacs-lisp +(report-time-since-load "Finishing Touches") +#+END_SRC + ** Tell the module system that *init.el* is available Indicates the ~init.el~ file is provided by and ends here: #+BEGIN_SRC emacs-lisp @@ -2112,6 +2160,11 @@ Indicates the ~init.el~ file is provided by and ends here: ;;; init.el ends here #+END_SRC * Future + +#+BEGIN_SRC emacs-lisp +(report-time-since-load "Future") +#+END_SRC + ** TODO Decide about general keybindings. The *general* package offers enhanced support for *evil* keybindings, notably it integrates with *use-package* to define keybindings which @@ -2123,6 +2176,11 @@ enough value but I just removed it, so it'll have to wait a bit. see [[https://github.com/gicrisf/ox-zola][ox-zola]] for exporting org-mode to zola markdown. * Final Words +#+BEGIN_SRC emacs-lisp +(report-time-since-load "Final Words") +#+END_SRC + + This is the end of the configuration file. Add a variable so the file is tangling itself each time it is saved.