Simplify confpkg edits

This commit is contained in:
Kiana Sheibani 2024-04-01 23:19:28 -04:00
parent 148f98afbc
commit b2c948fa15
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -214,7 +214,10 @@ If you're reading the raw org file instead of the published version, the code fo
(insert-file-contents buffer-file-name) (insert-file-contents buffer-file-name)
(goto-char (point-min)) (goto-char (point-min))
(re-search-forward "^;;; Code:\n") (re-search-forward "^;;; Code:\n")
(let (prepared) (let ((comment-start ";")
(comment-padding " ")
(comment-end "")
statements)
(while (re-search-forward "(\\(package!\\|unpin!\\)" nil t) (while (re-search-forward "(\\(package!\\|unpin!\\)" nil t)
(let* ((start (copy-marker (match-beginning 0))) (let* ((start (copy-marker (match-beginning 0)))
(end (progn (goto-char start) (end (progn (goto-char start)
@ -222,27 +225,29 @@ If you're reading the raw org file instead of the published version, the code fo
(if (looking-at "[\t ]*;.*") (if (looking-at "[\t ]*;.*")
(line-end-position) (line-end-position)
(point)))) (point))))
(contents (buffer-substring start end)) (contents (buffer-substring start end)))
paste-start paste-end
(comment-start ";")
(comment-padding " ")
(comment-end ""))
(plist-put confpkg :package-statements (plist-put confpkg :package-statements
(nconc (plist-get confpkg :package-statements) (nconc (plist-get confpkg :package-statements)
(list contents))) (list contents)))
(delete-region start (1+ end)) (delete-region start (1+ end))
(re-search-backward "^;;; Code:") (re-search-backward "^;;; Code:")
(beginning-of-line) (beginning-of-line)
(unless prepared (unless statements
(insert ";; Package statement:\n") (insert ";; Package statements:\n")
(setq prepared t)) (setq statements t))
(setq paste-start (point))
(insert contents) (insert contents)
(setq paste-end (point)) (unless (string-suffix-p "\n" contents)
(comment-region paste-start paste-end 2) (insert "\n"))
(goto-char start))) (goto-char start)))
(when prepared (when statements
(re-search-backward "^;;; Code:") (re-search-backward "^;;; Code:")
(comment-region
(save-excursion
(re-search-backward "^;; Package statements:")
(forward-line)
(point))
(point)
2)
(insert ";;\n"))) (insert ";;\n")))
(when (buffer-modified-p) (when (buffer-modified-p)
(write-region nil nil buffer-file-name) (write-region nil nil buffer-file-name)