From 58ebae60c392f2887de79b9c080f1baece63137c Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sun, 23 Jul 2023 20:04:22 +0300 Subject: [PATCH] Update Emacs configuration --- .emacs.d/init.el | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 1feeb3f..f237966 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -471,6 +471,8 @@ 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)) -- 2.39.2