-
-
Save hanachin/1732203 to your computer and use it in GitHub Desktop.
binan-clock.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 拾って来るサーバの指定など | |
(defvar binan-clock-root-url "http://www.bijint.com/binan/") | |
(defvar binan-clock-server-image-dir-path "/tokei_images/") | |
(defvar binan-clock-server-file-name-format "%H%M.jpg") | |
;; 保存するディレクトリや名前 | |
(defvar binan-clock-tmp-image-dir "/tmp") | |
(defvar binan-clock-local-file-name-format "binan%H%M.jpg") | |
(defvar binan-clock-current-image nil) | |
(defvar binan-clock-buffer-name "*BinanClock*") | |
(defvar binan-clock-get-image-timer nil) | |
(defvar binan-clock-view-image-timer nil) | |
(defun binan-clock-image-full-path (file-name) | |
(expand-file-name (concat binan-clock-tmp-image-dir "/" file-name))) | |
(defun binan-clock-local-file-name (time) | |
"画像の名前を生成する関数" | |
(format-time-string binan-clock-local-file-name-format time)) | |
(defun binan-clock-server-file-name (time) | |
"画像の名前を生成する関数" | |
(format-time-string binan-clock-server-file-name-format time)) | |
(defun binan-clock-image-url (time) | |
"画像のURLを生成する関数" | |
(concat binan-clock-root-url | |
"/" | |
binan-clock-server-image-dir-path | |
"/" | |
(binan-clock-server-file-name time))) | |
(defun binan-clock-get-image (&optional time) | |
"指定したサーバから画像を非同期で拾って来る" | |
(let ((time (or time (current-time))) | |
(command (concat "wget -q -b --referer=" binan-clock-root-url " " | |
(binan-clock-image-url time) " " | |
"-O " (concat binan-clock-tmp-image-dir "/" (binan-clock-local-file-name time))))) | |
(shell-command command))) | |
; (setq time (or time (current-time))) | |
; (setq command ) | |
(defun binan-clock-get-image-sync (&optional time) | |
"指定したサーバから画像を拾って来る。非同期じゃないよ" | |
(setq time (or time (current-time))) | |
(call-process "wget" nil "*Messages*" t | |
"-q" | |
(concat "--referer=" binan-clock-root-url) | |
(binan-clock-image-url time) | |
"-O" (concat binan-clock-tmp-image-dir "/" (binan-clock-local-file-name time)))) | |
(defun binan-clock-get-image-start-timer () | |
"画像を拾うアクションを1分毎に実行するよ" | |
(run-at-time "0 sec" 60 'binan-clock-get-image (time-add (current-time) (seconds-to-time 60)))) | |
(defun binan-clock-view-image-start-timer () | |
"画像を表示するアクションを1秒毎に実行するよ" | |
(run-at-time "0 sec" 1 'binan-clock-view-image)) | |
(defun binan-clock-stop-timer | |
"タイマー止めちゃうよ。動作確認してないよ" | |
(interactive) | |
(cancel-timer binan-clock-get-image-timer) | |
(cancel-timer binan-clock-view-image-timer)) | |
(defun binan-clock-view-image () | |
"バッファに拾ってきた画像を表示するよ" | |
(setq time (current-time)) | |
(setq file-name (binan-clock-local-file-name time)) | |
(setq binan-full-path (binan-clock-image-full-path file-name)) | |
(unless (file-exists-p binan-full-path) | |
(binan-clock-get-image-sync time)) | |
(unless (eq binan-clock-current-image file-name) | |
(with-current-buffer binan-clock-buffer-name | |
(save-excursion | |
(setq buffer-read-only nil) | |
(erase-buffer) | |
(insert-image (create-image binan-full-path)) | |
(setq binan-clock-current-image file-name) | |
(setq buffer-read-only t) )))) | |
(defun binan-clock-mode () | |
"なんちゃら時計をemacs内に表示するモード" | |
(interactive) | |
(generate-new-buffer binan-clock-buffer-name) | |
(switch-to-buffer binan-clock-buffer-name) | |
(setq buffer-read-only t) | |
(buffer-disable-undo) | |
(setq major-mode 'binan-clock) | |
(setq mode-name "binan-clock") | |
(setq binan-clock-get-image-timer (binan-clock-get-image-start-timer)) | |
(setq binan-clock-get-image-timer (binan-clock-view-image-start-timer))) | |
(provide 'binan-clock) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment