From 407771183e9d70b7e4b8ed9e2d773c9bc8e7af14 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 29 Apr 2021 12:16:03 -0500 Subject: Massively refactor - Redefine as much as possible as `setup' forms - Reorganize into "Setup", "Basics", and "Packages" sections - Within each section, alphabetize sexps - Also (mostly) alphabetize acdw- files - (Not the ones that are almost completely others' code) - Sidebar: Why is this not a thing in elisp!? Should write a function - Break karthink's thing into another library `acdw-re' - Add a function to `acdw': `acdw/find-emacs-source' - Should refactor that to better find the source I think everything looks much more better now! --- lisp/acdw.el | 129 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 71 insertions(+), 58 deletions(-) (limited to 'lisp/acdw.el') diff --git a/lisp/acdw.el b/lisp/acdw.el index 54b139c..1093a8d 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -19,7 +19,7 @@ ;;; Code: -;; Utility constants +;;; Variables (defconst acdw/system (pcase system-type ('gnu/linux :home) @@ -28,19 +28,15 @@ "Which computer system is currently being used.") -;; Utility functions +;;; Utility functions -(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)))) +(defun expand-file-name-exists-p (&rest expand-file-name-args) + "Call `expand-file-name' on EXPAND-FILE-NAME-ARGS, returning + its name if it exists, or NIL otherwise." + (let ((file (apply #'expand-file-name expand-file-name-args))) + (if (file-exists-p file) + file + nil))) (defmacro hook-defun (name hooks &rest forms) "Define a function NAME that executes FORMS, and add it to @@ -88,13 +84,17 @@ With a prefix argument, run git pull on the repo first." (when (file-exists-p file) (load-file file)))))) -(defun expand-file-name-exists-p (&rest expand-file-name-args) - "Call `expand-file-name' on EXPAND-FILE-NAME-ARGS, returning - its name if it exists, or NIL otherwise." - (let ((file (apply #'expand-file-name expand-file-name-args))) - (if (file-exists-p file) - file - nil))) +(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." @@ -105,6 +105,9 @@ With a prefix argument, run git pull on the repo first." ,@body) (message "%s... Done." ,message))) + +;;; Specialized functions + (defun acdw/dir (&optional file make-directory) "Place Emacs files in one place. @@ -122,37 +125,6 @@ if MAKE-DIRECTORY is non-nil." file-name) dir))) -(defun acdw/gc-enable () - "Enable the Garbage collector." - (setq gc-cons-threshold (* 800 1024 1024) - gc-cons-percentage 0.1)) - -(defun acdw/gc-disable () - "Functionally disable the Garbage collector." - (setq gc-cons-threshold most-positive-fixnum - gc-cons-percentage 0.8)) - -(defun acdw/sunrise-sunset (sunrise-command sunset-command) - "Run commands at sunrise and sunset." - (let* ((times-regex (rx (* nonl) - (: (any ?s ?S) "unrise") " " - (group (repeat 1 2 digit) ":" - (repeat 1 2 digit) - (: (any ?a ?A ?p ?P) (any ?m ?M))) - (* nonl) - (: (any ?s ?S) "unset") " " - (group (repeat 1 2 digit) ":" - (repeat 1 2 digit) - (: (any ?a ?A ?p ?P) (any ?m ?M))) - (* nonl))) - (ss (sunrise-sunset)) - (_m (string-match times-regex ss)) - (sunrise-time (match-string 1 ss)) - (sunset-time (match-string 2 ss))) - (run-at-time sunrise-time (* 60 60 24) sunrise-command) - (run-at-time sunset-time (* 60 60 24) sunset-command) - (run-at-time "12:00am" (* 60 60 24) sunset-command))) - (defun acdw/find-emacs-dotfiles () "Finds lisp files in `user-emacs-directory' and passes them to `completing-read'." @@ -161,6 +133,30 @@ if MAKE-DIRECTORY is non-nil." (directory-files-recursively user-emacs-directory "\.el$")))) +(defun acdw/find-emacs-source () + "Find where Emacs keeps its source tree." + (pcase acdw/system + (:work (expand-file-name + (concat "~/src/emacs-" emacs-version "/src"))) + (:home (expand-file-name "~/src/pkg/emacs/src/emacs-git/src")) + (:other nil))) + +(defun acdw/gc-disable () + "Functionally disable the Garbage collector." + (setq gc-cons-threshold most-positive-fixnum + gc-cons-percentage 0.8)) + +(defun acdw/gc-enable () + "Enable the Garbage collector." + (setq gc-cons-threshold (* 800 1024 1024) + gc-cons-percentage 0.1)) + +(defun acdw/insert-iso-date (with-time) + "Insert the ISO-8601-formatted date, with optional time." + (interactive "P") + (let ((format (if with-time "%FT%T%z" "%F"))) + (insert (format-time-string format (current-time))))) + (defun acdw/kill-a-buffer (&optional prefix) "Kill a buffer based on the following rules: @@ -179,14 +175,30 @@ Prompt only if there are unsaved changes." (16 (mapc 'kill-buffer (delq (current-buffer) (buffer-list))) (delete-other-windows)))) -(defun acdw/insert-iso-date (with-time) - "Insert the ISO-8601-formatted date, with optional time." - (interactive "P") - (let ((format (if with-time "%FT%T%z" "%F"))) - (insert (format-time-string format (current-time))))) +(defun acdw/sunrise-sunset (sunrise-command sunset-command) + "Run commands at sunrise and sunset." + (let* ((times-regex (rx (* nonl) + (: (any ?s ?S) "unrise") " " + (group (repeat 1 2 digit) ":" + (repeat 1 2 digit) + (: (any ?a ?A ?p ?P) (any ?m ?M))) + (* nonl) + (: (any ?s ?S) "unset") " " + (group (repeat 1 2 digit) ":" + (repeat 1 2 digit) + (: (any ?a ?A ?p ?P) (any ?m ?M))) + (* nonl))) + (ss (sunrise-sunset)) + (_m (string-match times-regex ss)) + (sunrise-time (match-string 1 ss)) + (sunset-time (match-string 2 ss))) + (run-at-time sunrise-time (* 60 60 24) sunrise-command) + (run-at-time sunset-time (* 60 60 24) sunset-command) + (run-at-time "12:00am" (* 60 60 24) sunset-command))) -;; Make `C-z' more useful +;;; Keymaps + (defvar acdw/leader (let ((map (make-sparse-keymap)) (c-z (global-key-binding "\C-z"))) @@ -195,7 +207,8 @@ Prompt only if there are unsaved changes." map)) -;; `acdw/reading-mode' +;;; Minor modes + (define-minor-mode acdw/reading-mode "A mode for reading." :init-value nil -- cgit 1.4.1-21-gabe81