From 296c4d7c09cf66b2a97e8871c5a903fda9d0919e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 28 Oct 2022 19:43:06 -0500 Subject: uhhhhh --- lisp/acdw.el | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'lisp/acdw.el') diff --git a/lisp/acdw.el b/lisp/acdw.el index f039540..6e298b2 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -28,6 +28,36 @@ the filesystem, unless INHIBIT-MKDIR is non-nil." (make-directory (file-name-directory file-name) :parents)) file-name)))) +;;; Evaluating things after other things + + +(defun eval-after-init (fn) + "Evaluate FN after inititation, or now if Emacs is initialized. +FN is called with no arguments." + (if after-init-time + (funcall fn) + (add-hook 'after-init-hook fn))) + +(defmacro eval-after (features &rest body) + "Evaluate BODY, but only after loading FEATURES. +FEATURES can be an atom or a list; as an atom it works like +`with-eval-after-load'. The special feature `init' will evaluate +BODY after Emacs is finished initializing." + (declare (indent 1) + (debug (form def-body))) + (unless (listp features) + (setf features (list features))) + (if (null features) + (macroexp-progn body) + (let* ((this (car features)) + (rest (cdr features))) + (cond ((eq this 'init) + `(eval-after-init + (lambda () (eval-after ,rest ,@body)))) + (:else + `(with-eval-after-load ',this + (eval-after ,rest ,@body))))))) + ;;; Convenience functions (defun define-key* (maps &rest keydefs) @@ -58,7 +88,7 @@ not a list, return a one-element list containing OBJECT." (defun add-to-list* (lists &rest things) "Add THINGS to LISTS. LISTS can be one list variable or a list. Each thing of THINGS -can be either a variablel (the thing), or a list of the form +can be either a variable (the thing), or a list of the form (ELEMENT &optional APPEND COMPARE-FN), which is passed to `add-to-list'." (declare (indent 1)) @@ -180,9 +210,10 @@ When joining, this command deletes whitespace." (delete-indentation 1) (funcall (if visual-line-mode #'kill-visual-line #'kill-line) arg))) -(defun other-window|switch-buffer () - "Call `other-window' or `switch-buffer' depending on windows." - (interactive) - (if (one-window-p) - (switch-to-buffer nil) +(defun other-window|switch-buffer (arg) + "Call `other-window' or `switch-buffer' depending on windows. +When called with prefix ARG, unconditionally switch buffer." + (interactive "P") + (if (or arg (one-window-p)) + (switch-to-buffer (other-buffer) nil t) (other-window 1))) -- cgit 1.4.1-21-gabe81