summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Junke <christophe.junke@parrot.com>2018-11-30 15:34:58 +0100
committerChristophe Junke <christophe.junke@parrot.com>2018-11-30 15:42:16 +0100
commitc4c2c355d23fb0420058343754e68901dc8c3c28 (patch)
tree933ecb398e6a24e8c835394005c0e2b6205118d4
parentb38f4505e6b594f19bd771d3ab78f7051961afdb (diff)
downloadparrot-c4c2c355d23fb0420058343754e68901dc8c3c28.tar.gz
Open the right alchemy popup
Works from magit, dired, etc.
-rw-r--r--parrot-alchemy.el22
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))
(org-mode))
+(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
+exists."
+ (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.
;;;###autoload
(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