diff options
-rw-r--r-- | .gitignore | 12 | ||||
-rw-r--r-- | sx-auth.el | 16 | ||||
-rw-r--r-- | sx-cache.el | 14 | ||||
-rw-r--r-- | sx-encoding.el | 14 | ||||
-rw-r--r-- | sx-favorites.el | 6 | ||||
-rw-r--r-- | sx-filter.el | 7 | ||||
-rw-r--r-- | sx-interaction.el | 10 | ||||
-rw-r--r-- | sx-method.el | 3 | ||||
-rw-r--r-- | sx-networks.el | 6 | ||||
-rw-r--r-- | sx-question-list.el | 8 | ||||
-rw-r--r-- | sx-question-mode.el | 5 | ||||
-rw-r--r-- | sx-question.el | 32 | ||||
-rw-r--r-- | sx-request.el | 22 | ||||
-rw-r--r-- | sx-site.el | 6 | ||||
-rw-r--r-- | sx-tab.el | 20 | ||||
-rw-r--r-- | sx-time.el | 3 | ||||
-rw-r--r-- | sx.el | 2 |
17 files changed, 138 insertions, 48 deletions
@@ -1,12 +1,18 @@ -# Emacs backup files +# Personal Development +.dir-locals.el + +# Backup Files *~ \#*\# # Compiled Elisp *.elc + +# Package Artifacts /.cask/ -.dir-locals.el -/.stackmode/ /url/ +/.sx/ + +# Generated Files /sx.info /sx.texi @@ -1,4 +1,4 @@ -;;; sx-auth.el --- user authentication -*- lexical-binding: t; -*- +;;; sx-auth.el --- user authentication ;; Copyright (C) 2014 Sean Allred @@ -19,6 +19,13 @@ ;;; Commentary: +;; This file handles logic related to authentication. This includes +;; determining if a certain filter requires authentication (via the +;; variable `sx-auth-filter-auth' and function `sx-auth--filter-p'), +;; determining if a method requires authentication (via the variable +;; `sx-auth-method-auth' and function `sx-auth--method-p'), and +;; actually authenticating the user (with `sx-auth-authenticate'). + ;;; Code: (require 'sx) @@ -36,7 +43,9 @@ "Your access token. This is needed to use your account to write questions, make comments, and read your inbox. Do not alter this unless you know -what you are doing!") +what you are doing! + +This variable is set with `sx-auth-authenticate'.") (defvar sx-auth-method-auth '((me . t) (inbox . t) @@ -65,7 +74,7 @@ what you are doing!") upvote (unanswered my-tags))) "List of methods that require auth. -Methods are of form (METHOD SUBMETHODS) where SUBMETHODS +Methods are of form (METHOD . SUBMETHODS) where SUBMETHODS is (METHOD METHOD METHOD ...). If all SUBMETHODS require auth or there are no submethods, form @@ -183,4 +192,5 @@ removed those properties." ;; Local Variables: ;; indent-tabs-mode: nil +;; lexical-binding: t ;; End: diff --git a/sx-cache.el b/sx-cache.el index 51c2267..cf48ef5 100644 --- a/sx-cache.el +++ b/sx-cache.el @@ -19,12 +19,18 @@ ;;; Commentary: -;; All caches are retrieved and set using symbols. The symbol should -;; be the sub-subpackage that is using the cache. For example, -;; `sx-pkg' would use `(sx-cache-get 'pkg)'. +;; This file handles the cache system. All caches are retrieved and +;; set using symbols. The symbol should be the sub-package that is +;; using the cache. For example, `sx-pkg' would use +;; +;; `(sx-cache-get 'pkg)' ;; ;; This symbol is then converted into a filename within -;; `sx-cache-directory'. +;; `sx-cache-directory' using `sx-cache-get-file-name'. +;; +;; Currently, the cache is written at every `sx-cache-set', but this +;; write will eventually be done by some write-all function which will +;; be set on an idle timer. ;;; Code: diff --git a/sx-encoding.el b/sx-encoding.el index 0e66677..ee099bc 100644 --- a/sx-encoding.el +++ b/sx-encoding.el @@ -19,10 +19,18 @@ ;;; Commentary: +;; This file handles decoding the responses we get from the API. They +;; are received either as plain-text or as a `gzip' compressed archive. +;; For this, `sx-encoding-gzipped-p' is used to determine if content +;; has been compressed under `gzip'. + ;;; Code: (require 'cl-lib) + +;;;; HTML Encoding + (defcustom sx-encoding-html-entities-plist '(Aacute "Á" aacute "á" Acirc "Â" acirc "â" acute "´" AElig "Æ" aelig "æ" Agrave "À" agrave "à" alefsym "ℵ" Alpha "Α" alpha "α" amp "&" and "∧" @@ -86,6 +94,9 @@ Return the decoded string." (substring ss 1)))))))) (replace-regexp-in-string "&[^; ]*;" get-function string))) + +;;;; Convenience Functions + (defun sx-encoding-normalize-line-endings (string) "Normalize the line endings for STRING. The API returns strings that use Windows-style line endings. @@ -131,6 +142,9 @@ some cases." (cl-map #'vector #'sx-encoding-clean-content-deep data)) (t data)))) + +;;;; GZIP + (defun sx-encoding-gzipped-p (data) "Check for magic bytes in DATA. Check if the first two bytes of a string in DATA match the magic diff --git a/sx-favorites.el b/sx-favorites.el index d957167..44ee19f 100644 --- a/sx-favorites.el +++ b/sx-favorites.el @@ -1,4 +1,4 @@ -;;; sx-favorites.el --- Starred questions -*- lexical-binding: t; -*- +;;; sx-favorites.el --- starred questions ;; Copyright (C) 2014 Sean Allred @@ -19,6 +19,9 @@ ;;; Commentary: +;; This file provides logic for retrieving and managing a user's +;; starred questions. + ;;; Code: (require 'sx-method) @@ -79,4 +82,5 @@ Writes list to cache QUESTION-FAVORITES." ;; Local Variables: ;; indent-tabs-mode: nil +;; lexical-binding: t ;; End: diff --git a/sx-filter.el b/sx-filter.el index 38084b9..327a8eb 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -1,4 +1,4 @@ -;;; sx-filter.el --- filters -*- lexical-binding: t; -*- +;;; sx-filter.el --- filters ;; Copyright (C) 2014 Sean Allred @@ -19,6 +19,10 @@ ;;; Commentary: +;; This file manages filters and provides an API to compile filters +;; and retrieve them from the cache. See `sx-filter-compile' and +;; `sx-filter-get-var', respectively. + ;;; Code: @@ -86,4 +90,5 @@ return the compiled filter." ;; Local Variables: ;; indent-tabs-mode: nil +;; lexical-binding: t ;; End: diff --git a/sx-interaction.el b/sx-interaction.el index 5f3ece6..0e4aae9 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -1,4 +1,4 @@ -;;; sx-interaction.el --- Voting, commenting, and otherwise interacting with questions. -*- lexical-binding: t; -*- +;;; sx-interaction.el --- voting, commenting, and other interaction ;; Copyright (C) 2014 Artur Malabarba @@ -19,6 +19,10 @@ ;;; Commentary: +;; This file provides voting, commenting, and other interactive +;; facilities. Most functions are scoped relative to `sx--data-here' +;; when called interactively. + ;;; Code: @@ -196,3 +200,7 @@ OBJECT can be a question or an answer." (provide 'sx-interaction) ;;; sx-interaction.el ends here + +;; Local Variables: +;; lexical-binding: t +;; End: diff --git a/sx-method.el b/sx-method.el index 1b20cbf..83455b8 100644 --- a/sx-method.el +++ b/sx-method.el @@ -82,7 +82,8 @@ Return the entire response as a complex alist." (prog1 (format "?site=%s" site) (setq site nil))))) - (call #'sx-request-make)) + (call #'sx-request-make) + parameters) (lwarn "sx-call-method" :debug "A: %S T: %S. M: %S,%s. F: %S" (equal 'warn auth) access-token method-auth full-method filter-auth) (unless access-token diff --git a/sx-networks.el b/sx-networks.el index e4660af..5f5f1c3 100644 --- a/sx-networks.el +++ b/sx-networks.el @@ -1,4 +1,4 @@ -;;; sx-networks.el --- user network information -*- lexical-binding: t; -*- +;;; sx-networks.el --- user network information ;; Copyright (C) 2014 Sean Allred @@ -19,6 +19,9 @@ ;;; Commentary: +;; This file provides logic for retrieving information about the user +;; across the entire network, e.g. their registered sites. + ;;; Code: (require 'sx-method) @@ -104,4 +107,5 @@ list of sites the user is active on." ;; Local Variables: ;; indent-tabs-mode: nil +;; lexical-binding: t ;; End: diff --git a/sx-question-list.el b/sx-question-list.el index 9709b99..0967d6a 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -1,4 +1,4 @@ -;;; sx-question-list.el --- Major-mode for navigating questions list. -*- lexical-binding: t; -*- +;;; sx-question-list.el --- major-mode for navigating questions list ;; Copyright (C) 2014 Artur Malabarba @@ -19,6 +19,8 @@ ;;; Commentary: +;; Provides question list logic (as used in e.g. `sx-tab-frontpage'). + ;;; Code: (require 'tabulated-list) (require 'cl-lib) @@ -540,3 +542,7 @@ Sets `sx-question-list--site' and then call (provide 'sx-question-list) ;;; sx-question-list.el ends here + +;; Local Variables: +;; lexical-binding: t +;; End: diff --git a/sx-question-mode.el b/sx-question-mode.el index 01a980a..6efa10b 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -1,4 +1,4 @@ -;;; sx-question-mode.el --- Creating the buffer that displays questions +;;; sx-question-mode.el --- major-mode for displaying questions ;; Copyright (C) 2014 Artur Malabarba @@ -19,6 +19,9 @@ ;;; Commentary: +;; This file provides a means to print questions with their answers +;; and all comments. See the customizable group `sx-question-mode'. + ;;; Code: (eval-when-compile diff --git a/sx-question.el b/sx-question.el index 01ba030..7b53e2e 100644 --- a/sx-question.el +++ b/sx-question.el @@ -19,6 +19,9 @@ ;;; Commentary: +;; Thie file provides an API for retrieving questions and defines +;; additional logic for marking questions as read or hidden. + ;;; Code: @@ -134,20 +137,21 @@ If no cache exists for it, initialize one with SITE." (defun sx-question--mark-hidden (question) "Mark QUESTION as being hidden." - (let ((site-cell (assoc .site sx-question--user-hidden-list)) - cell) - ;; If question already hidden, do nothing. - (unless (memq .question_id site-cell) - ;; First question from this site. - (push (list .site .question_id) sx-question--user-hidden-list) - ;; Question wasn't present. - ;; Add it in, but make sure it's sorted (just in case we need - ;; it later). - (sx-sorted-insert-skip-first .question_id site-cell >) - ;; This causes a small lag on `j' and `k' as the list gets large. - ;; Should we do this on a timer? - ;; Save the results. - (sx-cache-set 'hidden-questions sx-question--user-hidden-list)))) + (sx-assoc-let question + (let ((site-cell (assoc .site sx-question--user-hidden-list)) + cell) + ;; If question already hidden, do nothing. + (unless (memq .question_id site-cell) + ;; First question from this site. + (push (list .site .question_id) sx-question--user-hidden-list) + ;; Question wasn't present. + ;; Add it in, but make sure it's sorted (just in case we need + ;; it later). + (sx-sorted-insert-skip-first .question_id site-cell >) + ;; This causes a small lag on `j' and `k' as the list gets large. + ;; Should we do this on a timer? + ;; Save the results. + (sx-cache-set 'hidden-questions sx-question--user-hidden-list))))) ;;;; Other data diff --git a/sx-request.el b/sx-request.el index a98af5a..3a8b7a8 100644 --- a/sx-request.el +++ b/sx-request.el @@ -1,4 +1,4 @@ -;;; sx-request.el --- requests and url manipulation -*- lexical-binding: t; -*- +;;; sx-request.el --- requests and url manipulation ;; Copyright (C) 2014 Sean Allred @@ -91,9 +91,8 @@ number of requests left every time it finishes a call." ;;; Making Requests -(defun sx-request-make - (method &optional args request-method) - "Make a request to the API, executing METHOD with ARGS. +(defun sx-request-make (method &optional args request-method) + "Make a request to the API, executing METHOD with ARGS. You should almost certainly be using `sx-method-call' instead of this function. REQUEST-METHOD is one of `GET' (default) or `POST'. @@ -116,8 +115,7 @@ then read with `json-read-from-string'. the main content of the response is returned." (let* ((url-automatic-caching t) (url-inhibit-uncompression t) - (url-request-data (sx-request--build-keyword-arguments args - nil)) + (url-request-data (sx-request--build-keyword-arguments args nil)) (request-url (concat sx-request-api-root method)) (url-request-method request-method) (url-request-extra-headers @@ -168,15 +166,11 @@ Currently returns nil." ;;; Support Functions - -(defun sx-request--build-keyword-arguments (alist &optional - kv-sep need-auth) +(defun sx-request--build-keyword-arguments (alist &optional kv-sep) "Format ALIST as a key-value list joined with KV-SEP. If authentication is needed, include it also or error if it is not available. -If NEED-AUTH is non-nil, authentication is required. - Build a \"key=value&key=value&...\"-style string with the elements of ALIST. If any value in the alist is nil, that pair will not be included in the return. If you wish to pass a notion of @@ -185,7 +179,7 @@ false, use the symbol `false'. Each element is processed with ;; Add API key to list of arguments, this allows for increased quota ;; automatically. (let ((api-key (cons "key" sx-request-api-key)) - (auth (car (sx-cache-get 'auth)))) + (auth (car (sx-cache-get 'auth)))) (push api-key alist) (when auth (push auth alist)) @@ -204,3 +198,7 @@ false, use the symbol `false'. Each element is processed with (provide 'sx-request) ;;; sx-request.el ends here + +;; Local Variables: +;; lexical-binding: t +;; End: @@ -1,4 +1,4 @@ -;;; sx-site.el --- browsing sites -*- lexical-binding: t; -*- +;;; sx-site.el --- browsing sites ;; Copyright (C) 2014 Sean Allred @@ -19,6 +19,9 @@ ;;; Commentary: +;; This file provides various pieces of site logic, such as retrieving +;; the list of sites and the list of a user's favorited questions. + ;;; Code: (require 'sx-method) @@ -70,4 +73,5 @@ api_site_parameter." ;; Local Variables: ;; indent-tabs-mode: nil +;; lexical-binding: t ;; End: @@ -1,4 +1,4 @@ -;;; sx-tab.el --- Functions for viewing different tabs. -*- lexical-binding: t; -*- +;;; sx-tab.el --- functions for viewing different tabs ;; Copyright (C) 2014 Artur Malabarba @@ -19,7 +19,12 @@ ;;; Commentary: -;; +;; This file provides a single macro to define 'tabs' to view lists of +;; questions. + +;;; Tabs: + +;; - frontpage :: the frontpage of a single site ;;; Code: @@ -97,6 +102,17 @@ If SITE is nil, use `sx-tab-default-site'." (lambda (page) (sx-question-get-questions sx-question-list--site page))) +;;;###autoload +(autoload 'sx-tab-frontpage + (expand-file-name + "sx-tab" + (when load-file-name + (file-name-directory load-file-name))) + nil t) (provide 'sx-tab) ;;; sx-tab.el ends here + +;; Local Variables: +;; lexical-binding: t +;; End: @@ -19,7 +19,8 @@ ;;; Commentary: -;; +;; This file provides functions for manipulating and displaying +;; timestamps. ;;; Code: @@ -1,4 +1,4 @@ -;;; sx.el --- core functions of the sx package. +;;; sx.el --- core functions ;; Copyright (C) 2014 Sean Allred |