From db0784e243988005f4f45919a90bf323442401cf Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Sun, 10 Mar 2024 22:33:52 +0300 Subject: [PATCH] biome: improve presets --- biome-multi.el | 7 ++++++- biome-query.el | 18 ++++++++++++------ biome.el | 25 +++++++++++++++++++++---- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/biome-multi.el b/biome-multi.el index 63700fa..587015a 100644 --- a/biome-multi.el +++ b/biome-multi.el @@ -25,10 +25,14 @@ ;; Tools for doing multiple queries to Open Meteo. ;;; Code: -(require 'biome-query) (require 'font-lock) (require 'transient) +(require 'biome-query) + +;; XXX Recursive imports T_T +(declare-function biome-preset "biome") + (defvar biome-multi-query-current nil "Current query. @@ -140,6 +144,7 @@ This is a list of forms as defined by `biome-query-current'.") ["Actions" :class transient-row ("RET" "Run" biome-multi-exec) + ("p" "Preset" biome-preset :transient transient--do-replace) ("P" "Generate preset definition" biome-multi--generate-preset) ("R" "Reset" biome-multi-reset :transient t) ("q" "Quit" transient-quit-one)] diff --git a/biome-query.el b/biome-query.el index 67e0b69..3a97e6a 100644 --- a/biome-query.el +++ b/biome-query.el @@ -39,6 +39,10 @@ (require 'biome-api-data) +;; XXX Recursive imports T_T +(declare-function biome-preset "biome") +(declare-function biome-multi "biome") + (defcustom biome-query-max-fields-in-row 20 "Maximum number of fields in a row." :type 'integer @@ -438,7 +442,7 @@ number of options is more than (mapconcat (lambda (choice) (propertize (cdr choice) 'face - (if (eq (car choice) value) + (if (equal (car choice) value) 'transient-value 'transient-inactive-value))) (oref obj options) @@ -1030,14 +1034,16 @@ SECTION is a form as defined in `biome-api-parse--page'." (transient-parse-suffixes 'transient--prefix (cl-loop for (name . params) in biome-api-data - collect `(,(alist-get :key params) - ,name - (lambda () (interactive) - (biome-query--section-open ,name)) - :transient transient--do-stack))))] + collect `(,(alist-get :key params) + ,name + (lambda () (interactive) + (biome-query--section-open ,name)) + :transient transient--do-stack))))] ["Actions" :class transient-row ("r" "Resume" biome-resume :transient transient--do-replace) + ("p" "Preset" biome-preset :transient transient--do-stack) + ("u" "Join multiple queries" biome-multi :transient transient--do-stack) ("q" "Quit" transient-quit-one)] (interactive (list nil)) (unless callback diff --git a/biome.el b/biome.el index 538a664..c44a742 100644 --- a/biome.el +++ b/biome.el @@ -58,7 +58,17 @@ API." :group 'biome) (defcustom biome-presets-alist nil - "Presets for `biome' queries." + "Presets for `biome' queries. + +One item of the list is another list with three elements: +- preset name; +- `:normal' for normal `biome' or `:multi' for `biome-multi'; +- parameters as defined by `biome-query-current' or + `biome-multi-query-current'. +Thus, preset names are the keys of the alist. + +To generate expressions that add stuff to this list, run \"Generate +preset definition\" in `biome' or `biome-multi'." :type '(repeat (list (string :tag "Preset name") @@ -128,7 +138,14 @@ PARAMS as query." (call-interactively #'biome-multi))) (defun biome-preset (preset-def) - "Run PRESET-DEF." + "Run `biome' with a preset. + +PRESET-DEF is one preset as defined by `biome-presets-alist', sans the +name. If run interactively, prompt PRESET-DEF from +`biome-presets-alist'. + +Run \"Generate preset definition\" in `biome' or `biome-multi' to +generate expressions that add stuff to `biome-presets-alist'." (interactive (list (alist-get (completing-read "Preset" biome-presets-alist) biome-presets-alist nil nil #'equal))) @@ -138,10 +155,10 @@ PARAMS as query." (setq biome-query--callback (lambda (query) (biome-api-get query biome-frontend))) - (setq biome-query-current params) + (setq biome-query-current (copy-tree params)) (biome-query--section-open (alist-get :name params))) (:multi - (setq biome-multi-query-current params) + (setq biome-multi-query-current (copy-tree params)) (call-interactively #'biome-multi))))) (provide 'biome)