From 48bee50fe6c4a6ed9dd2bf8c90d11036346ebfbc Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sat, 30 Mar 2024 17:28:29 -0400 Subject: [PATCH] Update confpkg to comment all package statements The original code only commented package statements at the beginning, which I thought was a bit restrictive. --- config.org | 60 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/config.org b/config.org index 8cd0c39..c5b7795 100644 --- a/config.org +++ b/config.org @@ -202,29 +202,37 @@ If you're reading the raw org file instead of the published version, the code fo (setq buffer-file-name (plist-get confpkg :file)) (insert-file-contents buffer-file-name) (goto-char (point-min)) - (while (re-search-forward "^;;; Code:\n[[:space:]\n]*(\\(package!\\|unpin!\\)[[:space:]\n]+\\([^[:space:]]+\\)\\b" nil t) - (plist-put confpkg :package-statements - (nconc (plist-get confpkg :package-statements) - (list (match-string 2)))) - (let* ((start (progn (beginning-of-line) (point))) - (end (progn (forward-sexp 1) - (if (looking-at "[\t ]*;.*") - (line-end-position) - (point)))) - (contents (buffer-substring start end)) - paste-start paste-end - (comment-start ";") - (comment-padding " ") - (comment-end "")) - (delete-region start (1+ end)) + (re-search-forward "^;;; Code:\n") + (let (prepared) + (while (re-search-forward "(\\(package!\\|unpin!\\)" nil t) + (let* ((start (copy-marker (match-beginning 0))) + (end (progn (goto-char start) + (forward-sexp 1) + (if (looking-at "[\t ]*;.*") + (line-end-position) + (point)))) + (contents (buffer-substring start end)) + paste-start paste-end + (comment-start ";") + (comment-padding " ") + (comment-end "")) + (plist-put confpkg :package-statements + (nconc (plist-get confpkg :package-statements) + (list contents))) + (delete-region start (1+ end)) + (re-search-backward "^;;; Code:") + (beginning-of-line) + (unless prepared + (insert ";; Package statement:\n") + (setq prepared t)) + (setq paste-start (point)) + (insert contents) + (setq paste-end (point)) + (comment-region paste-start paste-end 2) + (goto-char start))) + (when prepared (re-search-backward "^;;; Code:") - (beginning-of-line) - (insert ";; Package statement:\n") - (setq paste-start (point)) - (insert contents) - (setq paste-end (point)) - (insert "\n;;\n") - (comment-region paste-start paste-end 2))) + (insert ";;\n"))) (when (buffer-modified-p) (write-region nil nil buffer-file-name) (set-buffer-modified-p nil))))) @@ -237,7 +245,7 @@ If you're reading the raw org file instead of the published version, the code fo (insert (format ";;; config.el -*- lexical-binding: t; -*- -;; SPDX-FileCopyrightText: © 2020-%s %s <%s> +;; SPDX-FileCopyrightText: © 2023-%s %s <%s> ;; SPDX-License-Identifier: MIT ;; Generated at %s from the literate configuration. @@ -354,7 +362,7 @@ If you're reading the raw org file instead of the published version, the code fo (org-fold-core-ignore-fragility-checks (org-babel-map-executables nil (when (and (eq (org-element-type (org-element-context)) 'babel-call) - (equal (org-element-property :call (org-element-context)) "confpkg")) + (equal (org-element-property :call (org-element-context)) "confpkg")) (org-babel-remove-result) (org-entry-delete nil "header-args:emacs-lisp"))))) @@ -1967,7 +1975,7 @@ Flymake normally uses italics for warnings, but my italics font being cursive ma And just to make sure nothing else accidentally starts running: -#+begin_src emacs-lisp :tangle packages.el :noweb-ref none +#+begin_src emacs-lisp :tangle packages.el (package! flycheck :disable t) (package! flyspell :disable t) #+end_src @@ -3329,7 +3337,7 @@ A full week-long agenda is usually too cluttered for me to read, so I'll narrow The Org agenda is a very nice feature, but by default it doesn't really provide enough customization to fit my needs. I like to have nice categories to make parsing my todos easier, so we'll use ~org-super-agenda~: -#+begin_src emacs-lisp :tangle packages.el :noweb-ref none +#+begin_src emacs-lisp :tangle packages.el (package! org-super-agenda) #+end_src