From 6353891e14a9b9977b055061ac71608a7acbe564 Mon Sep 17 00:00:00 2001 From: MitchMarq42 Date: Mon, 6 Feb 2023 15:35:09 -0900 Subject: [PATCH] Fix hugo-compile so it works again --- lisp/mitch-packages.el | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/lisp/mitch-packages.el b/lisp/mitch-packages.el index 79c7317..c5bb710 100644 --- a/lisp/mitch-packages.el +++ b/lisp/mitch-packages.el @@ -671,25 +671,35 @@ See https://emacs.stackexchange.com/questions/2538/how-to-define-additional-mode (defun hugo-dir-above (dir) "Return path of Hugo project root above or at DIR. Return nil if DIR is not in a hugo project at all." - (named-let hda-internal ((dir dir)) - (if (eq dir nil) nil - (if (file-exists-p (expand-file-name "config.toml" dir)) dir - (hda-internal (file-name-directory (string-trim-right dir "/"))))))) - (defun hugo-compile (dir) + (require 'subr-x) + (let ((thisdir dir)) + (let ((lexical-binding t)) + (if (eq thisdir nil) nil + (if (file-exists-p (expand-file-name "config.toml" thisdir)) + thisdir + (let ((updir (file-name-directory (string-trim-right thisdir "/")))) + (hugo-dir-above updir))))))) + ;; (hugo-dir-above "~/.local/git/mitchmarq42.github.io/content-org/") + (defun hugo-compile (&optional dir) + (interactive) + (if (bound-and-true-p dir) nil + (setq dir default-directory)) (let ((hugo-dir (hugo-dir-above dir))) (if hugo-dir - (if (string-match-p default-directory "/content-org$") - (org-hugo-export-wim-to-md-after-save) + (progn + (if (string-match-p (rx bol (* any) "/content-org" (opt "/") eol) + default-directory) + (org-hugo-export-wim-to-md-after-save)) (let* ((default-directory hugo-dir) (buffer (get-buffer-create "*hugo*"))) (with-current-buffer buffer - (compilation-mode) - (if (zerop (let ((inhibit-read-only t)) - (shell-command "hugo" buffer))) - (message "Hugo re-generated!") - (error "Hugo Failed, better change something!")))))))) - (add-hook 'after-save-hook - (lambda () (hugo-compile default-directory)))) + ;; (compilation-mode) + (let* ((inhibit-read-only t) + (status-code (call-process-shell-command "hugo" nil buffer))) + (if (zerop status-code) + (message "Hugo re-generated!") + (error "Hugo exited %s, better change something!" status-code))))))))) + (add-hook 'after-save-hook #'hugo-compile)) ;; fake indentation, other than the other fake indentation ;; (elpaca-use-package adaptive-wrap