Skip to content

Instantly share code, notes, and snippets.

@masutaka
Last active April 24, 2019 21:30
Show Gist options
  • Save masutaka/82159e0ddc3387334b4a58364f9a83dc to your computer and use it in GitHub Desktop.
Save masutaka/82159e0ddc3387334b4a58364f9a83dc to your computer and use it in GitHub Desktop.
Generate helm-github-stars-cache-file asynchronously
(defun my-lisp-load (filename)
"Load lisp from FILENAME"
(let ((fullname (expand-file-name (concat "spec/" filename) user-emacs-directory))
lisp)
(when (file-readable-p fullname)
(with-temp-buffer
(progn
(insert-file-contents fullname)
(setq lisp
(condition-case nil
(read (current-buffer))
(error ()))))))
lisp))
;;; helm-github-stars.el
(setq helm-github-stars-token (my-lisp-load "helm-github-stars-token"))
(setq helm-github-stars-name-length 50)
(setq helm-github-stars-refetch-time 0.5)
(defun my-lisp-load (filename)
"Load lisp from FILENAME"
(let ((fullname (expand-file-name (concat "spec/" filename) user-emacs-directory))
lisp)
(when (file-readable-p fullname)
(with-temp-buffer
(progn
(insert-file-contents fullname)
(setq lisp
(condition-case nil
(read (current-buffer))
(error ()))))))
lisp))
;;; helm-github-stars.el
(require 'helm-github-stars)
(defvar my-helm-github-stars-interval (* 3 60 60)
"Number of seconds to call `my-helm-github-stars-async-generate-cache-file'.")
(defvar my-helm-github-stars-timer nil
"Timer object for GitHub Stars caching will be stored here.
DO NOT SET VALUE MANUALLY.")
(setq helm-github-stars-name-length 50)
(defun my-helm-github-stars-async-generate-cache-file ()
"Generate `helm-github-stars-cache-file' in the child emacs process"
(async-start
;; START-FUNC
`(lambda ()
(let ((start-time (current-time)))
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(require 'helm-github-stars)
(setq helm-github-stars-token ,(my-lisp-load "helm-github-stars-token"))
(hgs/generate-cache-file)
start-time))
;; FINISH-FUNC
(lambda (start-time)
(let ((now (current-time)))
(message "[GH] Success to GET my GitHub Stars and Repos (%0.1fsec) at %s."
(time-to-seconds (time-subtract now start-time))
(format-time-string "%Y-%m-%d %H:%M:%S" now))))))
(defun my-helm-github-stars-set-timer ()
"Set helm-github-stars timer."
(setq my-helm-github-stars-timer
(run-at-time "0 sec"
my-helm-github-stars-interval
#'my-helm-github-stars-async-generate-cache-file)))
(defun my-helm-github-stars-cancel-timer ()
"Cancel helm-github-stars timer."
(when my-helm-github-stars-timer
(cancel-timer my-helm-github-stars-timer)
(setq my-helm-github-stars-timer nil)))
(my-helm-github-stars-set-timer)
@masutaka
Copy link
Author

See also my init.el

@masutaka
Copy link
Author

async.el is very coooool!!!

@masutaka
Copy link
Author

masutaka commented Oct 19, 2017

Of course helm-github-stars.el is good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment