Skip to content

Commit

Permalink
biome: improve presets
Browse files Browse the repository at this point in the history
  • Loading branch information
SqrtMinusOne committed Mar 10, 2024
1 parent 36efbc1 commit db0784e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
7 changes: 6 additions & 1 deletion biome-multi.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)]
Expand Down
18 changes: 12 additions & 6 deletions biome-query.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
25 changes: 21 additions & 4 deletions biome.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)))
Expand All @@ -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)
Expand Down

0 comments on commit db0784e

Please sign in to comment.