From 8d4d84839e23ac513025000f8882203450063c69 Mon Sep 17 00:00:00 2001
From: Case Duckworth
Date: Sun, 14 Mar 2021 19:18:32 -0500
Subject: Change `:map-after' behavior

---
 lisp/acdw.el | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

(limited to 'lisp')

diff --git a/lisp/acdw.el b/lisp/acdw.el
index 84fcb99..e25de43 100644
--- a/lisp/acdw.el
+++ b/lisp/acdw.el
@@ -145,20 +145,37 @@ otherwise it's wrapped in `kbd'.
 The following keywords are recognized:
 
 :after ARGS .. call `autoload' on COMMAND using ARGS before
-	       binding the key.  ARGS can be just the filename to
-	       load; in that case it's wrapped in a list.  
+    binding the key.  ARGS can be just the filename to
+    load; in that case it's wrapped in a list.  
+
 :map KEYMAP .. define KEY in KEYMAP instead of the
-	       default `acdw/bind-default-map'."
+   default `acdw/bind-default-map'.  If `:after' is also supplied,
+   run `autoload' on KEYMAP (except when using `:map-after', see).
+
+:map-after FILE .. run the underlying `define-key' command in an
+  `with-eval-after-load'.  For the rare occasion when the keymap is
+  defined in a different file than the command it binds (looking
+  at you, `org-mode')."
   (let ((after (when-let (sym (plist-get args :after))
 		 (if (not (listp sym))
 		     (list sym)
 		   sym)))
+	(map-after (plist-get args :map-after))
 	(keymap (or (plist-get args :map) acdw/bind-default-map))
 	(keycode (if (vectorp key) key (kbd key)))
 	(command-list))
-    (push `(define-key ,keymap ,keycode ',command) command-list)
+    (let ((define-key-command `(define-key ,keymap ,keycode ',command)))
+      (if map-after
+	  (push `(with-eval-after-load ,map-after
+		   ,define-key-command)
+		command-list)
+	(push define-key-command command-list)))
     (when after
-      (push `(autoload ',command ,@after) command-list))
+      (unless (fboundp command)
+	(push `(autoload ',command ,@after) command-list))
+      (unless (or map-after
+		  (eq keymap acdw/bind-default-map))
+	(push `(autoload ',keymap ,(car after) nil nil 'keymap) command-list)))
     `(progn
        ,@command-list)))
 
-- 
cgit 1.4.1-21-gabe81