biome: termux workarounds

This commit is contained in:
Pavel Korytov 2024-04-06 16:51:54 +03:00
parent d393ddbb70
commit f5a590fbba
3 changed files with 41 additions and 4 deletions

View file

@ -17,6 +17,21 @@ The package is available on MELPA. Install it however you normally install packa
Or clone the repository, add it to =load-path=, and =require= the package. Or clone the repository, add it to =load-path=, and =require= the package.
** Issues with termux?
I've been trying to run this package on termux and had some issues.
First, for some reason =request.el= throws the successfully parsed response as error. Use this as a workaround:
#+begin_src emacs-lisp
(setq biome-api-try-parse-error-as-response t)
#+end_src
Second, somehow the =<tab>= is not the same as the =<TAB>= key. The following might be neccessary:
#+begin_src emacs-lisp
(setq biome-query-tab-key "<TAB>")
#+end_src
Be sure to add that before the package initialization.
* Usage * Usage
The main entry point is =M-x biome=. Each item under "Open Meteo Data" corresponds to a particular endpoint of the service. For instance, =M-x biome ww= is a generic weather forecast. Check out the [[https://open-meteo.com/en/docs][API docs]] for more detailed descriptions. The main entry point is =M-x biome=. Each item under "Open Meteo Data" corresponds to a particular endpoint of the service. For instance, =M-x biome ww= is a generic weather forecast. Check out the [[https://open-meteo.com/en/docs][API docs]] for more detailed descriptions.

View file

@ -45,6 +45,14 @@
("Flood" . "https://flood-api.open-meteo.com/v1/flood")) ("Flood" . "https://flood-api.open-meteo.com/v1/flood"))
"Default URLs for Open Meteo API.") "Default URLs for Open Meteo API.")
(defcustom biome-api-try-parse-error-as-response nil
"Try to parse error responses as normal ones.
This is a workaround for my termux setup, somehow request' gives
the parsed response to the error callback there."
:group 'biome
:type 'boolean)
(defcustom biome-api-urls biome-api--default-urls (defcustom biome-api-urls biome-api--default-urls
"URLs of the Open Meteo API." "URLs of the Open Meteo API."
:type `(alist :type `(alist
@ -91,7 +99,7 @@ QUERY is a form as defined by `biome-query-current'."
\\{biome-api-error-mode-map}" \\{biome-api-error-mode-map}"
(read-only-mode 1)) (read-only-mode 1))
(defun biome-api--show-error (error-thrown response) (defun biome-api--show-error (error-thrown response &optional err)
"Show ERROR-THROWN and RESPONSE in a buffer." "Show ERROR-THROWN and RESPONSE in a buffer."
(let ((buffer (generate-new-buffer "*biome-api-error*"))) (let ((buffer (generate-new-buffer "*biome-api-error*")))
(with-current-buffer buffer (with-current-buffer buffer
@ -100,6 +108,11 @@ QUERY is a form as defined by `biome-query-current'."
(propertize "Error: " 'face 'font-lock-warning-face) (propertize "Error: " 'face 'font-lock-warning-face)
(prin1-to-string error-thrown) (prin1-to-string error-thrown)
"\n") "\n")
(when err
(insert
(propertize "Pasing error: " 'face 'font-lock-warning-face)
(error-message-string err)
"\n"))
(condition-case nil (condition-case nil
(insert (propertize "Reason: " 'face 'font-lock-warning-face) (insert (propertize "Reason: " 'face 'font-lock-warning-face)
(alist-get 'reason (request-response-data response)) (alist-get 'reason (request-response-data response))
@ -125,8 +138,12 @@ called with QUERY and the data returned by the API as arguments."
(lambda (&key data &allow-other-keys) (lambda (&key data &allow-other-keys)
(funcall callback (copy-tree query) data))) (funcall callback (copy-tree query) data)))
:error :error
(cl-function (lambda (&key error-thrown response &allow-other-keys) (cl-function
(biome-api--show-error error-thrown response)))))) (lambda (&key error-thrown response &allow-other-keys)
(if biome-api-try-parse-error-as-response
(condition-case err
(funcall callback (copy-tree query) (request-response-data response))
(error (biome-api--show-error error-thrown response err)))))))))
(defun biome-api-get-multiple (queries callback) (defun biome-api-get-multiple (queries callback)
"Get data from Open Meteo API. "Get data from Open Meteo API.

View file

@ -84,6 +84,11 @@ The format is: (name latitude longitude)."
(string :tag "Column name"))) (string :tag "Column name")))
:group 'biome) :group 'biome)
(defcustom biome-query-tab-key "<tab>"
"Key used for TAB."
:type 'string
:group 'biome)
(defconst biome-query-groups '("daily" "hourly" "minutely_15" "hourly") (defconst biome-query-groups '("daily" "hourly" "minutely_15" "hourly")
"Name of groups. "Name of groups.
@ -629,7 +634,7 @@ OBJ is an instance of `biome-query--transient-group-switch'."
(transient-define-infix biome-query--transient-group-switch-infix () (transient-define-infix biome-query--transient-group-switch-infix ()
:class 'biome-query--transient-group-switch :class 'biome-query--transient-group-switch
:key "<tab>" :key biome-query-tab-key
:description "Switch group") :description "Switch group")
;; Layout generation ;; Layout generation