]> git.eshelyaron.com Git - dotfiles.git/commitdiff
Update Emacs configuration
authorEshel Yaron <me@eshelyaron.com>
Sun, 23 Jul 2023 17:04:22 +0000 (20:04 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sun, 23 Jul 2023 17:04:22 +0000 (20:04 +0300)
.emacs.d/init.el

index 1feeb3f144f1581f981719b49b05d5d9a4a4e687..f2379662fa96649e04ca73c9f265c636dfc1b336 100644 (file)
                       ef-frost
                       ef-kassio
                       ef-light
+                      ef-maris-dark
+                      ef-maris-light
                       ef-night
                       ef-spring
                       ef-summer
@@ -1349,6 +1351,84 @@ as the initial input for completion, and return that directory."
      ;; read feeds list from a separate file
      elfeed-feeds (esy/feeds))))
 
+(esy/init-step currency
+  "Track currency exchange rates."
+
+  (defvar esy/eur-to-ils-rates nil)
+
+  (add-to-list 'savehist-additional-variables
+               'esy/eur-to-ils-rates)
+
+  (defun esy/update-eur-to-ils-rate ()
+    (require 'dom)
+    (let* ((time (float-time))
+           (from "EUR")
+           (to "ILS")
+           (amount 1)
+           (url (url-parse-make-urlobj "https"
+                                       nil
+                                       nil
+                                       "www.x-rates.com"
+                                       nil
+                                       (concat "/calculator/?"
+                                               (url-build-query-string `(("from" ,from)
+                                                                         ("to" ,to)
+                                                                         ("amount" ,amount)))))))
+      (url-retrieve url
+                    (lambda (_)
+                      (goto-char (point-min))
+                      (search-forward "\n\n")
+                      (push (cons time
+                                  (string-to-number (caddar (dom-by-class (libxml-parse-html-region (point))
+                                                                          "ccOutputRslt"))))
+                            esy/eur-to-ils-rates))
+                    nil t)))
+
+  (run-at-time t 300 #'esy/update-eur-to-ils-rate)
+
+  (defun esy/plot-eur-to-ils-rates (height width)
+    (require 'svg)
+    (let* ((svg (svg-create width height
+                            :stroke "green"))
+           (time (float-time))
+           (frame (* 60 60 24))
+           (data (named-let loop ((rates esy/eur-to-ils-rates)
+                                  (acc nil)
+                                  (min most-positive-fixnum)
+                                  (max most-negative-fixnum))
+                   (if rates
+                       (let ((x (* (/ (+ frame (- (caar rates) time))
+                                      frame)
+                                   width)))
+                         (if (< 0 x)
+                             (let ((val (cdar rates)))
+                               (loop (cdr rates)
+                                     (cons (cons x (cdar rates)) acc)
+                                     (min val min)
+                                     (max val max)))
+                           (list acc min max)))
+                     (list acc min max))))
+           (points (nth 0 data))
+           (min (nth 1 data))
+           (max (nth 2 data))
+           (normalized-points (mapcar (lambda (xy)
+                                        (cons (car xy)
+                                              (- height (* height
+                                                           (/ (- (cdr xy) min)
+                                                              (- max min))))))
+                                      points)))
+      (svg-polyline svg normalized-points :fill-color "none")
+      (svg-image svg)))
+
+  (defun esy/plot-eur-rates ()
+    (interactive)
+    (with-current-buffer-window "EUR to ILS" nil nil
+      (insert-image (esy/plot-eur-to-ils-rates 300 500))
+      (insert "\n")))
+
+  (push '(:eval (concat "1€=" (number-to-string (cdar esy/eur-to-ils-rates)) "₪ "))
+        global-mode-string))
+
 (dolist (step (sort esy/init-step-times (lambda (l r) (time-less-p (cdr r) (cdr l)))))
   (message "%f %s"
            (float-time (cdr step))