Skip to content

Commit

Permalink
biome: termux workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
SqrtMinusOne committed Apr 6, 2024
1 parent d393ddb commit f5a590f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
15 changes: 15 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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.

** 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
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.

Expand Down
23 changes: 20 additions & 3 deletions biome-api.el
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
("Flood" . "https://flood-api.open-meteo.com/v1/flood"))
"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
"URLs of the Open Meteo API."
:type `(alist
Expand Down Expand Up @@ -91,7 +99,7 @@ QUERY is a form as defined by `biome-query-current'."
\\{biome-api-error-mode-map}"
(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."
(let ((buffer (generate-new-buffer "*biome-api-error*")))
(with-current-buffer buffer
Expand All @@ -100,6 +108,11 @@ QUERY is a form as defined by `biome-query-current'."
(propertize "Error: " 'face 'font-lock-warning-face)
(prin1-to-string error-thrown)
"\n")
(when err
(insert
(propertize "Pasing error: " 'face 'font-lock-warning-face)
(error-message-string err)
"\n"))
(condition-case nil
(insert (propertize "Reason: " 'face 'font-lock-warning-face)
(alist-get 'reason (request-response-data response))
Expand All @@ -125,8 +138,12 @@ called with QUERY and the data returned by the API as arguments."
(lambda (&key data &allow-other-keys)
(funcall callback (copy-tree query) data)))
:error
(cl-function (lambda (&key error-thrown response &allow-other-keys)
(biome-api--show-error error-thrown response))))))
(cl-function
(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)
"Get data from Open Meteo API.
Expand Down
7 changes: 6 additions & 1 deletion biome-query.el
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ The format is: (name latitude longitude)."
(string :tag "Column name")))
: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")
"Name of groups.
Expand Down Expand Up @@ -629,7 +634,7 @@ OBJ is an instance of `biome-query--transient-group-switch'."

(transient-define-infix biome-query--transient-group-switch-infix ()
:class 'biome-query--transient-group-switch
:key "<tab>"
:key biome-query-tab-key
:description "Switch group")

;; Layout generation
Expand Down

0 comments on commit f5a590f

Please sign in to comment.