summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-07-03 13:16:59 +0300
committerThanos Apollo <[email protected]>2023-07-03 13:16:59 +0300
commit363d40ceb4f91cfba0fdcaa273cf63f556d4aeb2 (patch)
treeeacf81e40b220841035b37e17de89d506251f20a
parent234be14ffcee0cfe180a9459a35e8a6c80b3a8b8 (diff)
Add yeetube-update-info and variable-watchers
Update yeetube-player and yeetube-download-directory displayed in *Yeetube Search* buffer each time user changes their values
-rw-r--r--yeetube.el29
1 files changed, 29 insertions, 0 deletions
diff --git a/yeetube.el b/yeetube.el
index deb010a..d9ce3fb 100644
--- a/yeetube.el
+++ b/yeetube.el
@@ -229,5 +229,34 @@ then run this command interactively."
"\n~C-c C-o~ -> Open In Browser\n"
"\n~q~ -> Quit\n")))
+(defun yeetube-update-info (symbol-name new-value operation where)
+ "Update information for SYMBOL-NAME with NEW-VALUE.
+
+SYMBOL-NAME is the name of the symbol to update.
+NEW-VALUE is the new value for the symbol.
+OPERATION is the operation to perform (e.g., insert or replace).
+WHERE indicates where in the buffer the update should happen.
+
+OPERATION & WHERE are required to work with 'add-variable-watcher."
+ (when (get-buffer "*Yeetube Search*")
+ (let ((to-change
+ (pcase symbol-name
+ ('yeetube-player "Yeetube Player:")
+ ('yeetube-download-directory "Download Directory:"))))
+ (switch-to-buffer (get-buffer "*Yeetube Search*"))
+ (setq-local buffer-read-only nil)
+ (goto-char (point-min))
+ (search-forward to-change)
+ (beginning-of-visual-line)
+ (kill-visual-line)
+ (insert
+ (format "%s %s" to-change new-value))
+ (setq-local buffer-read-only t)
+ (switch-to-buffer (other-buffer)))))
+
+;; Variable to watch
+(add-variable-watcher 'yeetube-download-directory #'yeetube-update-info)
+(add-variable-watcher 'yeetube-player #'yeetube-update-info)
+
(provide 'yeetube)
;;; yeetube.el ends here