summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2021-04-29 17:21:05 -0500
committerCase Duckworth2021-04-29 17:21:05 -0500
commit64739e7e9911a6d398bc2b2a485857313e172ba4 (patch)
treea26656da3d5ca006556911a21ec5b5b27e8bb9a8
parentMassively refactor (diff)
downloademacs-64739e7e9911a6d398bc2b2a485857313e172ba4.tar.gz
emacs-64739e7e9911a6d398bc2b2a485857313e172ba4.zip
Break emacs-git-pull-config out of emacs-refresh
... and rename refresh-emacs to emacs-refresh ...
-rw-r--r--lisp/acdw.el68
1 files changed, 39 insertions, 29 deletions
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."
50 ,@(dolist (hook hook-list hook-defun-add-hook-list) 50 ,@(dolist (hook hook-list hook-defun-add-hook-list)
51 (push `(add-hook ',hook #',func-name) hook-defun-add-hook-list))))) 51 (push `(add-hook ',hook #',func-name) hook-defun-add-hook-list)))))
52 52
53(defun refresh-emacs (&optional git-pull-first) 53(defmacro when-unfocused (name &rest forms)
54 "Define a function NAME, executing FORMS, that fires when Emacs
55is unfocused."
56 (declare (indent 1))
57 (let ((func-name (intern (concat "when-unfocused-" (symbol-name name)))))
58 `(progn
59 (defun ,func-name () "Defined by `when-unfocused'."
60 (when (seq-every-p #'null
61 (mapcar #'frame-focus-state (frame-list)))
62 ,@forms))
63 (add-function :after after-focus-change-function #',func-name))))
64
65(defmacro with-message (message &rest body)
66 "Execute BODY, messaging 'MESSAGE...' before and 'MESSAGE... Done.' after."
67 (declare (indent 1))
68 ;; Wrap a progn inside a prog1 to return the return value of the body.
69 `(prog1
70 (progn (message "%s..." ,message)
71 ,@body)
72 (message "%s... Done." ,message)))
73
74
75;;; Emacs configuration functions
76
77(defun emacs-git-pull-config (&optional remote branch)
78 "`git-pull' emacs configuration from REMOTE and BRANCH.
79
80REMOTE defaults to 'origin', BRANCH to 'main'."
81 (let ((remote (or remote "origin"))
82 (branch (or branch "main")))
83 (with-message (format "Pulling Emacs's configuration from %s" branch)
84 (shell-command (concat "git -C "
85 "\"" (expand-file-name user-emacs-directory) "\""
86 " pull " remote " " branch)
87 (get-buffer-create "*emacs-git-pull-config-output*")
88 (get-buffer-create "*emacs-git-pull-config-error*")))))
89
90(defun emacs-reload (&optional git-pull-first)
54 "Reload Emacs's configuration files. 91 "Reload Emacs's configuration files.
55 92
56With a prefix argument, run git pull on the repo first." 93With a prefix argument, run git pull on the repo first."
57 (interactive "P") 94 (interactive "P")
58 (when git-pull-first 95 (when git-pull-first
59 (with-message "Pulling Emacs's configuration" 96 (emacs-git-pull-config))
60 (shell-command (concat "git -C "
61 "\"" (expand-file-name user-emacs-directory) "\""
62 " pull")
63 (get-buffer-create "*refresh-emacs-output*")
64 (get-buffer-create "*refresh-emacs-error*"))))
65
66 (let ((init-files (append 97 (let ((init-files (append
67 ;; Load lisp libraries first, in case their functionality 98 ;; Load lisp libraries first, in case their functionality
68 ;; is used by {early-,}init.el 99 ;; is used by {early-,}init.el
@@ -84,27 +115,6 @@ With a prefix argument, run git pull on the repo first."
84 (when (file-exists-p file) 115 (when (file-exists-p file)
85 (load-file file)))))) 116 (load-file file))))))
86 117
87(defmacro when-unfocused (name &rest forms)
88 "Define a function NAME, executing FORMS, that fires when Emacs
89is unfocused."
90 (declare (indent 1))
91 (let ((func-name (intern (concat "when-unfocused-" (symbol-name name)))))
92 `(progn
93 (defun ,func-name () "Defined by `when-unfocused'."
94 (when (seq-every-p #'null
95 (mapcar #'frame-focus-state (frame-list)))
96 ,@forms))
97 (add-function :after after-focus-change-function #',func-name))))
98
99(defmacro with-message (message &rest body)
100 "Execute BODY, messaging 'MESSAGE...' before and 'MESSAGE... Done.' after."
101 (declare (indent 1))
102 ;; Wrap a progn inside a prog1 to return the return value of the body.
103 `(prog1
104 (progn (message "%s..." ,message)
105 ,@body)
106 (message "%s... Done." ,message)))
107
108 118
109;;; Specialized functions 119;;; Specialized functions
110 120