diff options
author | Sean Allred <code@seanallred.com> | 2014-11-02 18:25:41 -0500 |
---|---|---|
committer | Sean Allred <code@seanallred.com> | 2014-11-02 18:25:41 -0500 |
commit | 0ecf1dcfb01be97e0d98416dc8e0e2bc1664daeb (patch) | |
tree | 04741375a35e87c25a5e3da91c153e15c483b2c6 /stack-core.el | |
parent | 6766f1175ac3fad1a2928ff1f798e9c11caf465d (diff) | |
parent | e089914f96caf5e1a74acb75995634c34455a290 (diff) |
Merge pull request #6 from vermiculus/precompiled-filters
Precompiled filters
Diffstat (limited to 'stack-core.el')
-rw-r--r-- | stack-core.el | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/stack-core.el b/stack-core.el index 9a535cd..c2aff15 100644 --- a/stack-core.el +++ b/stack-core.el @@ -44,6 +44,10 @@ ;;; Constants and Customizable Options +(defcustom stack-cache-directory + (expand-file-name ".stackmode" user-emacs-directory) + "Directory containined cached files and precompiled filters.") + (defconst stack-core-api-version "2.2" "The current version of the API.") @@ -241,5 +245,33 @@ entire response as a complex alist." cons-cell)))) data)))) +(defun stack-cache-get-file-name (filename) + "Expands FILENAME in the context of `stack-cache-directory'." + (expand-file-name filename stack-cache-directory)) + +(defun stack-cache-get (cache) + "Return the data within CACHE. + +As with `stack-cache-set', CACHE is a file name within the +context of `stack-cache-directory'." + (unless (file-exists-p stack-cache-directory) + (mkdir stack-cache-directory)) + (let ((file (stack-cache-get-file-name cache))) + (when (file-exists-p file) + (with-temp-buffer + (insert-file-contents (stack-cache-get-file-name cache)) + (read (buffer-string)))))) + +(defun stack-cache-set (cache data) + "Set the content of CACHE to DATA. + +As with `stack-cache-get', CACHE is a file name within the +context of `stack-cache-directory'." + (unless (file-exists-p stack-cache-directory) + (mkdir stack-cache-directory)) + (write-region (prin1-to-string data) nil + (stack-cache-get-file-name cache)) + data) + (provide 'stack-core) ;;; stack-core.el ends here |