Advertisement
emacstest

Untitled

Oct 26th, 2014
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.70 KB | None | 0 0
  1. ;; eval this buffer and then start modifying the data in the table below.
  2. ;;
  3. ;; ------------
  4. ;; Alpha   | 50
  5. ;; Beta    | 35
  6. ;; Gamma   | 64
  7. ;; Delta   | 20
  8. ;; Epsilon | 80
  9. ;;
  10. ;; ----------------------------------------------------------------------
  11.      
  12. ;; ----------------------------------------------------------------------
  13.  
  14. (defun my-chart-update ()
  15.   (interactive)
  16.   (save-excursion
  17.     (let (data label)
  18.       (goto-char (point-min))
  19.       (search-forward "--------")
  20.       (forward-line)
  21.       (while (looking-at ";;\\s-*\\(\\w+\\)\\s-*|\\s-*\\([0-9.]+\\)")
  22.         (push (match-string 1) label)
  23.         (push (match-string 2) data)
  24.         (forward-line))
  25.  
  26.       (let ((url (format "http://chart.googleapis.com/chart?chs=500x250&chd=t:%s&chl=%s"
  27.                          (mapconcat 'identity (reverse data) ",")
  28.                          (mapconcat 'identity (reverse label) "|"))))
  29.  
  30.         (when (not (equal my-chart-last-data url))
  31.           (setq my-chart-last-data url)
  32.  
  33.           (search-forward "--------")
  34.           (forward-line)
  35.           (delete-region (point)
  36.                          (save-excursion
  37.                            (search-forward "--------")
  38.                            (line-beginning-position)))
  39.           (dolist (type '("p" "lc" "bhs"))
  40.             (insert-image
  41.              (with-current-buffer
  42.                  (url-retrieve-synchronously
  43.                   (let ((url (concat url "&cht=" type)))
  44.                     ;; a little ugly hack, because it's just a prototype
  45.                     (if (equal "bhs" type)
  46.                         (concat (replace-regexp-in-string
  47.                                  "chl=[^&]+"
  48.                                  (concat "chxl=1:|" (mapconcat 'identity
  49.                                                                label
  50.                                                                "|"))
  51.                                  url)
  52.                                 "&chxt=x,y")
  53.                       url)))
  54.                                                
  55.                (goto-char (point-min))
  56.                (search-forward "\n\n")
  57.                (create-image (buffer-substring (point) (point-max)) 'png t)))
  58.             (insert " "))
  59.           (insert "\n"))))))
  60.    
  61. (setq my-chart-update-delay 1)
  62.  
  63. (setq my-chart-buffer-tick (buffer-modified-tick))
  64.  
  65. (setq my-chart-last-data "")
  66.  
  67. (defun my-chart-update-monitor ()
  68.   (when (and (not (equal my-chart-buffer-tick (buffer-modified-tick)))
  69.              (sit-for my-chart-update-delay))
  70.     (setq my-chart-buffer-tick (buffer-modified-tick))
  71.     (my-chart-update)
  72.     (message "")))
  73.  
  74. (add-hook 'post-command-hook 'my-chart-update-monitor nil t)
  75.  
  76. (my-chart-update)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement