diff options
authorChristophe Junke <>2018-11-30 15:34:58 +0100
committerChristophe Junke <>2018-11-30 15:42:16 +0100
commitc4c2c355d23fb0420058343754e68901dc8c3c28 (patch)
parentb38f4505e6b594f19bd771d3ab78f7051961afdb (diff)
Open the right alchemy popup
Works from magit, dired, etc.
1 files changed, 22 insertions, 0 deletions
diff --git a/parrot-alchemy.el b/parrot-alchemy.el
index 8a34a79..047baa9 100644
--- a/parrot-alchemy.el
+++ b/parrot-alchemy.el
@@ -205,6 +205,25 @@
(switch-to-buffer output-buffer))
+(defvar *alchemy-path-relative-popups* nil
+ "Association list from paths to alchemy popups, used to quickly
+ open the right popup based on current directory.")
+(defun alchemy-popup-dwim ()
+ "Start the alchemy popup associated with current directory,
+either default-directory or the buffer's file directory, when it
+ (interactive)
+ (if-let (path (or default-directory (buffer-file-name)))
+ (let ((path (file-truename path)))
+ (if-let (popup (cdr
+ (find-if (lambda (dir) (search dir path))
+ *alchemy-path-relative-popups*
+ :key (lambda (map) (file-truename (car map))))))
+ (call-interactively popup)
+ (message "No alchemy popup found for current directory")))
+ (message "Cannot determine current directory")))
;; Here we use a macro because NAME needs to be known at compile time.
(defmacro alchemy-generate-popup (name product path key)
@@ -216,6 +235,9 @@
;; to reset defvars, does not reach defvar forms inside progns.
(when (boundp ',popup-name)
(makunbound ',popup-name))
+ (pushnew (cons ,path ',popup-name)
+ *alchemy-path-relative-popups*
+ :test 'equalp)
(magit-define-popup ,popup-name ,name
:switches alchemy-specific-switches
:options alchemy-specific-options