Factor out the JSON string generation
This commit is contained in:
		| @@ -64,8 +64,8 @@ | ||||
|     'emacs-mule) | ||||
|   "Coding system of the file `org-clock-waybar-filename'.") | ||||
|  | ||||
| (defun org-clock-waybar--get-clocked-task-json (buffer) | ||||
|   "Save the currently clocked-in task’s data to BUFFER. | ||||
| (defun org-clock-waybar--get-clocked-task-json () | ||||
|   "Get the currently clocked-in task’s data as a stringified JSON object. | ||||
|  | ||||
| The output is in JSON format constructed in a way so Waybar can process it. | ||||
| If there is no clocked in task, alt becomes empty and text will be set to the | ||||
| @@ -75,25 +75,24 @@ value of `org-clock-waybar-not-clocked-in-text'." | ||||
|         (title (when org-clock-current-task | ||||
|                  (substring-no-properties org-clock-current-task))) | ||||
|         (output (json-new-object))) | ||||
|     (with-current-buffer buffer | ||||
|       (setq output (json-add-to-object | ||||
|                     output | ||||
|                     "text" | ||||
|                     (if title | ||||
|                         title | ||||
|                       org-clock-waybar-not-clocked-in-text))) | ||||
|       (setq output (json-add-to-object output "alt" (if category category ""))) | ||||
|       (setq output (json-add-to-object output "tooltip" "")) | ||||
|       (setq output (json-add-to-object output "class" "")) | ||||
|       (setq output (json-add-to-object output "percentage" "")) | ||||
|       (insert (json-encode output))))) | ||||
|     (setq output (json-add-to-object | ||||
|                   output | ||||
|                   "text" | ||||
|                   (if title | ||||
|                       title | ||||
|                     org-clock-waybar-not-clocked-in-text))) | ||||
|     (setq output (json-add-to-object output "alt" (if category category ""))) | ||||
|     (setq output (json-add-to-object output "tooltip" "")) | ||||
|     (setq output (json-add-to-object output "class" "")) | ||||
|     (setq output (json-add-to-object output "percentage" "")) | ||||
|     (json-encode output))) | ||||
|  | ||||
| (defun org-clock-waybar-save-task () | ||||
|   "Save the current clocked in task to `org-clock-waybar-filename'." | ||||
|   (with-temp-buffer | ||||
|     (erase-buffer) | ||||
|     (set-buffer-file-coding-system org-clock-waybar-filename-coding-system) | ||||
|     (org-clock-waybar--get-clocked-task-json (current-buffer)) | ||||
|     (insert (org-clock-waybar--get-clocked-task-json)) | ||||
|     (write-file org-clock-waybar-filename))) | ||||
|  | ||||
| (defun org-clock-waybar-setup () | ||||
|   | ||||
		Reference in New Issue
	
	Block a user