From 64739e7e9911a6d398bc2b2a485857313e172ba4 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 29 Apr 2021 17:21:05 -0500 Subject: Break emacs-git-pull-config out of emacs-refresh ... and rename refresh-emacs to emacs-refresh ... --- lisp/acdw.el | 68 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 29 deletions(-) (limited to 'lisp/acdw.el') diff --git a/lisp/acdw.el b/lisp/acdw.el index 1093a8d..dcb3967 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -50,19 +50,50 @@ each hook in HOOKS." ,@(dolist (hook hook-list hook-defun-add-hook-list) (push `(add-hook ',hook #',func-name) hook-defun-add-hook-list))))) -(defun refresh-emacs (&optional git-pull-first) +(defmacro when-unfocused (name &rest forms) + "Define a function NAME, executing FORMS, that fires when Emacs +is unfocused." + (declare (indent 1)) + (let ((func-name (intern (concat "when-unfocused-" (symbol-name name))))) + `(progn + (defun ,func-name () "Defined by `when-unfocused'." + (when (seq-every-p #'null + (mapcar #'frame-focus-state (frame-list))) + ,@forms)) + (add-function :after after-focus-change-function #',func-name)))) + +(defmacro with-message (message &rest body) + "Execute BODY, messaging 'MESSAGE...' before and 'MESSAGE... Done.' after." + (declare (indent 1)) + ;; Wrap a progn inside a prog1 to return the return value of the body. + `(prog1 + (progn (message "%s..." ,message) + ,@body) + (message "%s... Done." ,message))) + + +;;; Emacs configuration functions + +(defun emacs-git-pull-config (&optional remote branch) + "`git-pull' emacs configuration from REMOTE and BRANCH. + +REMOTE defaults to 'origin', BRANCH to 'main'." + (let ((remote (or remote "origin")) + (branch (or branch "main"))) + (with-message (format "Pulling Emacs's configuration from %s" branch) + (shell-command (concat "git -C " + "\"" (expand-file-name user-emacs-directory) "\"" + " pull " remote " " branch) + (get-buffer-create "*emacs-git-pull-config-output*") + (get-buffer-create "*emacs-git-pull-config-error*"))))) + +(defun emacs-reload (&optional git-pull-first) "Reload Emacs's configuration files. With a prefix argument, run git pull on the repo first." (interactive "P") (when git-pull-first - (with-message "Pulling Emacs's configuration" - (shell-command (concat "git -C " - "\"" (expand-file-name user-emacs-directory) "\"" - " pull") - (get-buffer-create "*refresh-emacs-output*") - (get-buffer-create "*refresh-emacs-error*")))) - + (emacs-git-pull-config)) (let ((init-files (append ;; Load lisp libraries first, in case their functionality ;; is used by {early-,}init.el @@ -84,27 +115,6 @@ With a prefix argument, run git pull on the repo first." (when (file-exists-p file) (load-file file)))))) -(defmacro when-unfocused (name &rest forms) - "Define a function NAME, executing FORMS, that fires when Emacs -is unfocused." - (declare (indent 1)) - (let ((func-name (intern (concat "when-unfocused-" (symbol-name name))))) - `(progn - (defun ,func-name () "Defined by `when-unfocused'." - (when (seq-every-p #'null - (mapcar #'frame-focus-state (frame-list))) - ,@forms)) - (add-function :after after-focus-change-function #',func-name)))) - -(defmacro with-message (message &rest body) - "Execute BODY, messaging 'MESSAGE...' before and 'MESSAGE... Done.' after." - (declare (indent 1)) - ;; Wrap a progn inside a prog1 to return the return value of the body. - `(prog1 - (progn (message "%s..." ,message) - ,@body) - (message "%s... Done." ,message))) - ;;; Specialized functions -- cgit 1.4.1-21-gabe81