From 48928e6c8350a699e9572c2632f049c4b0aeddbf Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 2 Jan 2021 17:35:33 -0600 Subject: Add acdw/when-unfocused Runs a command only if Emacs’ frames are unfocused. Should be run in a after-focus-change-hook. I should probably make a macro or something to really friendlify it. --- config.org | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'config.org') diff --git a/config.org b/config.org index d45c46e..4bd98cd 100644 --- a/config.org +++ b/config.org @@ -89,7 +89,7 @@ doesn't work, I'll call git directly and clone the repo myself. (acdw/bootstrap-straight)) #+END_SRC -** Customize macros +** Ease-of-configuring functions *** Emulate use-package’s =:custom= @@ -120,6 +120,17 @@ doesn't work, I'll call git directly and clone the repo myself. (add-hook 'after-init-hook #'acdw/set-custom-faces)) #+end_src +*** Determine whether any Emacs frame is focused or not + +This comes in handy when I want to garbage collect, say, or save recent files. + + #+begin_src emacs-lisp + (defun acdw/when-unfocused (func &rest args) + "Run FUNC with ARGS only if all frames are out of focus." + (if (seq-every-p #'null (mapcar #'frame-focus-state (frame-list))) + (apply func args))) + #+end_src + ** Clean =.emacs.d= #+BEGIN_SRC emacs-lisp -- cgit 1.4.1-21-gabe81