From 753ee36a9b1dc17804198d461ca660a65eeff0e9 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 27 Nov 2014 18:41:09 -0500 Subject: File header normalization --- sx-auth.el | 3 ++- sx-favorites.el | 3 ++- sx-filter.el | 3 ++- sx-interaction.el | 6 +++++- sx-networks.el | 3 ++- sx-question-list.el | 6 +++++- sx-question-mode.el | 2 +- sx-request.el | 6 +++++- sx-site.el | 3 ++- sx-tab.el | 6 +++++- sx.el | 2 +- 11 files changed, 32 insertions(+), 11 deletions(-) diff --git a/sx-auth.el b/sx-auth.el index b6c0411..bfa805a 100644 --- a/sx-auth.el +++ b/sx-auth.el @@ -1,4 +1,4 @@ -;;; sx-auth.el --- user authentication -*- lexical-binding: t; -*- +;;; sx-auth.el --- user authentication ;; Copyright (C) 2014 Sean Allred @@ -183,4 +183,5 @@ removed those properties." ;; Local Variables: ;; indent-tabs-mode: nil +;; lexical-binding: t ;; End: diff --git a/sx-favorites.el b/sx-favorites.el index d957167..d5c5a4f 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 @@ -79,4 +79,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..d973f2a 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 @@ -86,4 +86,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..a50e718 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 @@ -196,3 +196,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-networks.el b/sx-networks.el index e4660af..dda6dd5 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 @@ -104,4 +104,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..7caa03d 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 @@ -540,3 +540,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 6dc8395..c3e7eac 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 diff --git a/sx-request.el b/sx-request.el index a98af5a..b6c468b 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 @@ -204,3 +204,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: diff --git a/sx-site.el b/sx-site.el index 8bd4fc0..df02f7e 100644 --- a/sx-site.el +++ b/sx-site.el @@ -1,4 +1,4 @@ -;;; sx-site.el --- browsing sites -*- lexical-binding: t; -*- +;;; sx-site.el --- browsing sites ;; Copyright (C) 2014 Sean Allred @@ -70,4 +70,5 @@ api_site_parameter." ;; Local Variables: ;; indent-tabs-mode: nil +;; lexical-binding: t ;; End: diff --git a/sx-tab.el b/sx-tab.el index 154a90f..bbbdb79 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -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 @@ -100,3 +100,7 @@ If SITE is nil, use `sx-tab-default-site'." (provide 'sx-tab) ;;; sx-tab.el ends here + +;; Local Variables: +;; lexical-binding: t +;; End: diff --git a/sx.el b/sx.el index 0fe98c7..b468762 100644 --- a/sx.el +++ b/sx.el @@ -1,4 +1,4 @@ -;;; sx.el --- core functions of the sx package. +;;; sx.el --- core functions ;; Copyright (C) 2014 Sean Allred -- cgit v1.2.3 From 0228524a31cf2e040525302da8cf12e2f749fbbb Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 28 Nov 2014 13:30:11 -0500 Subject: Provide commentaries for each file --- sx-auth.el | 7 +++++++ sx-cache.el | 14 ++++++++++---- sx-encoding.el | 5 +++++ sx-favorites.el | 3 +++ sx-filter.el | 4 ++++ sx-interaction.el | 4 ++++ sx-networks.el | 3 +++ sx-question-list.el | 2 ++ sx-question-mode.el | 3 +++ sx-question.el | 3 +++ sx-site.el | 3 +++ sx-tab.el | 7 ++++++- sx-time.el | 3 ++- 13 files changed, 55 insertions(+), 6 deletions(-) diff --git a/sx-auth.el b/sx-auth.el index bfa805a..427900d 100644 --- a/sx-auth.el +++ b/sx-auth.el @@ -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) 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..36cf03f 100644 --- a/sx-encoding.el +++ b/sx-encoding.el @@ -19,6 +19,11 @@ ;;; 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) diff --git a/sx-favorites.el b/sx-favorites.el index d5c5a4f..44ee19f 100644 --- a/sx-favorites.el +++ b/sx-favorites.el @@ -19,6 +19,9 @@ ;;; Commentary: +;; This file provides logic for retrieving and managing a user's +;; starred questions. + ;;; Code: (require 'sx-method) diff --git a/sx-filter.el b/sx-filter.el index d973f2a..327a8eb 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -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: diff --git a/sx-interaction.el b/sx-interaction.el index a50e718..0e4aae9 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -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: diff --git a/sx-networks.el b/sx-networks.el index dda6dd5..5f5f1c3 100644 --- a/sx-networks.el +++ b/sx-networks.el @@ -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) diff --git a/sx-question-list.el b/sx-question-list.el index 7caa03d..0967d6a 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -19,6 +19,8 @@ ;;; Commentary: +;; Provides question list logic (as used in e.g. `sx-tab-frontpage'). + ;;; Code: (require 'tabulated-list) (require 'cl-lib) diff --git a/sx-question-mode.el b/sx-question-mode.el index c3e7eac..ff13ede 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -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: (require 'markdown-mode) diff --git a/sx-question.el b/sx-question.el index 01ba030..680eaaf 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: diff --git a/sx-site.el b/sx-site.el index df02f7e..1ed469a 100644 --- a/sx-site.el +++ b/sx-site.el @@ -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) diff --git a/sx-tab.el b/sx-tab.el index bbbdb79..16b1737 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -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: diff --git a/sx-time.el b/sx-time.el index e65bb50..8f90747 100644 --- a/sx-time.el +++ b/sx-time.el @@ -19,7 +19,8 @@ ;;; Commentary: -;; +;; This file provides functions for manipulating and displaying +;; timestamps. ;;; Code: -- cgit v1.2.3 From 209546f6af36e6c2bacb9cee92a51e1c782aff1f Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 28 Nov 2014 13:30:44 -0500 Subject: Correct documentation --- sx-auth.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-auth.el b/sx-auth.el index 427900d..cfbae0a 100644 --- a/sx-auth.el +++ b/sx-auth.el @@ -72,7 +72,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 -- cgit v1.2.3 From 4c8a4e83e09b2f9c0bbb5cc75896bcdd543c33cd Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 28 Nov 2014 13:31:08 -0500 Subject: Relate variable with setting function --- sx-auth.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sx-auth.el b/sx-auth.el index cfbae0a..8a52041 100644 --- a/sx-auth.el +++ b/sx-auth.el @@ -43,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) -- cgit v1.2.3 From ab61931b5101f94ed3c7fc5a985e8f34d1a394da Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 28 Nov 2014 13:42:14 -0500 Subject: Update .gitignore --- .gitignore | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index cfaa152..59d35bb 100644 --- a/.gitignore +++ b/.gitignore @@ -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 -- cgit v1.2.3 From 891c7eeb070ccde615cd3371bf9136a3b2287b4f Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 28 Nov 2014 13:42:31 -0500 Subject: Add sections to `sx-encoding.el' --- sx-encoding.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sx-encoding.el b/sx-encoding.el index 36cf03f..ee099bc 100644 --- a/sx-encoding.el +++ b/sx-encoding.el @@ -28,6 +28,9 @@ (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 "∧" @@ -91,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. @@ -136,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 -- cgit v1.2.3 From 3a5afcc8225e52baaaba92c27d1d594eeb1cf729 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Mon, 1 Dec 2014 08:45:50 -0500 Subject: Standardize local variables - Move lexical-binding to top of file; fixes #123 - Use indent-tabs-mode: nil for all files --- sx-auth.el | 3 +-- sx-cache.el | 2 +- sx-encoding.el | 2 +- sx-favorites.el | 3 +-- sx-filter.el | 3 +-- sx-interaction.el | 4 ++-- sx-method.el | 6 +++++- sx-networks.el | 3 +-- sx-question-list.el | 4 ++-- sx-question-mode.el | 4 ++-- sx-question-print.el | 4 ++-- sx-question.el | 3 +-- sx-request.el | 4 ++-- sx-site.el | 3 +-- sx-tab.el | 4 ++-- sx-time.el | 6 +++++- sx.el | 3 +-- 17 files changed, 31 insertions(+), 30 deletions(-) diff --git a/sx-auth.el b/sx-auth.el index 8a52041..bbd84e2 100644 --- a/sx-auth.el +++ b/sx-auth.el @@ -1,4 +1,4 @@ -;;; sx-auth.el --- user authentication +;;; sx-auth.el --- user authentication -*- lexical-binding: t -*- ;; Copyright (C) 2014 Sean Allred @@ -192,5 +192,4 @@ removed those properties." ;; Local Variables: ;; indent-tabs-mode: nil -;; lexical-binding: t ;; End: diff --git a/sx-cache.el b/sx-cache.el index cf48ef5..598a5df 100644 --- a/sx-cache.el +++ b/sx-cache.el @@ -1,4 +1,4 @@ -;;; sx-cache.el --- caching +;;; sx-cache.el --- caching -*- lexical-binding: t -*- ;; Copyright (C) 2014 Sean Allred diff --git a/sx-encoding.el b/sx-encoding.el index ee099bc..c8a7862 100644 --- a/sx-encoding.el +++ b/sx-encoding.el @@ -1,4 +1,4 @@ -;;; sx-encoding.el --- encoding +;;; sx-encoding.el --- encoding -*- lexical-binding: t -*- ;; Copyright (C) 2014 Sean Allred diff --git a/sx-favorites.el b/sx-favorites.el index 44ee19f..9408dd5 100644 --- a/sx-favorites.el +++ b/sx-favorites.el @@ -1,4 +1,4 @@ -;;; sx-favorites.el --- starred questions +;;; sx-favorites.el --- starred questions -*- lexical-binding: t -*- ;; Copyright (C) 2014 Sean Allred @@ -82,5 +82,4 @@ 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 327a8eb..cd919f7 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -1,4 +1,4 @@ -;;; sx-filter.el --- filters +;;; sx-filter.el --- filters -*- lexical-binding: t -*- ;; Copyright (C) 2014 Sean Allred @@ -90,5 +90,4 @@ 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 0e4aae9..aeb6781 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -1,4 +1,4 @@ -;;; sx-interaction.el --- voting, commenting, and other interaction +;;; sx-interaction.el --- voting, commenting, and other interaction -*- lexical-binding: t -*- ;; Copyright (C) 2014 Artur Malabarba @@ -202,5 +202,5 @@ OBJECT can be a question or an answer." ;;; sx-interaction.el ends here ;; Local Variables: -;; lexical-binding: t +;; indent-tabs-mode: nil ;; End: diff --git a/sx-method.el b/sx-method.el index 83455b8..88525a3 100644 --- a/sx-method.el +++ b/sx-method.el @@ -1,4 +1,4 @@ -;;; sx-method.el --- method calls +;;; sx-method.el --- method calls -*- lexical-binding: t -*- ;; Copyright (C) 2014 Sean Allred @@ -114,3 +114,7 @@ Return the entire response as a complex alist." (provide 'sx-method) ;;; sx-method.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx-networks.el b/sx-networks.el index 5f5f1c3..e9bc1c7 100644 --- a/sx-networks.el +++ b/sx-networks.el @@ -1,4 +1,4 @@ -;;; sx-networks.el --- user network information +;;; sx-networks.el --- user network information -*- lexical-binding: t -*- ;; Copyright (C) 2014 Sean Allred @@ -107,5 +107,4 @@ 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 0967d6a..58c233b 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 +;;; sx-question-list.el --- major-mode for navigating questions list -*- lexical-binding: t -*- ;; Copyright (C) 2014 Artur Malabarba @@ -544,5 +544,5 @@ Sets `sx-question-list--site' and then call ;;; sx-question-list.el ends here ;; Local Variables: -;; lexical-binding: t +;; indent-tabs-mode: nil ;; End: diff --git a/sx-question-mode.el b/sx-question-mode.el index 6efa10b..6293ad2 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -1,4 +1,4 @@ -;;; sx-question-mode.el --- major-mode for displaying questions +;;; sx-question-mode.el --- major-mode for displaying questions -*- lexical-binding: t -*- ;; Copyright (C) 2014 Artur Malabarba @@ -228,5 +228,5 @@ query the api." ;;; sx-question-mode.el ends here ;; Local Variables: -;; lexical-binding: t +;; indent-tabs-mode: nil ;; End: diff --git a/sx-question-print.el b/sx-question-print.el index 0959f36..6b1c96e 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -1,4 +1,4 @@ -;;; sx-question-print.el --- Populating the question-mode buffer with content. +;;; sx-question-print.el --- Populating the question-mode buffer with content. -*- lexical-binding: t -*- ;; Copyright (C) 2014 Artur Malabarba @@ -436,5 +436,5 @@ If ID is nil, use FALLBACK-ID instead." ;;; sx-question-print.el ends here ;; Local Variables: -;; lexical-binding: t +;; indent-tabs-mode: nil ;; End: diff --git a/sx-question.el b/sx-question.el index 7b53e2e..a9ff2b1 100644 --- a/sx-question.el +++ b/sx-question.el @@ -1,4 +1,4 @@ -;;; sx-question.el --- question logic +;;; sx-question.el --- question logic -*- lexical-binding: t -*- ;; Copyright (C) 2014 Sean Allred @@ -171,5 +171,4 @@ If no cache exists for it, initialize one with SITE." ;; Local Variables: ;; indent-tabs-mode: nil -;; lexical-binding: t ;; End: diff --git a/sx-request.el b/sx-request.el index 3a8b7a8..653e17c 100644 --- a/sx-request.el +++ b/sx-request.el @@ -1,4 +1,4 @@ -;;; sx-request.el --- requests and url manipulation +;;; sx-request.el --- requests and url manipulation -*- lexical-binding: t -*- ;; Copyright (C) 2014 Sean Allred @@ -200,5 +200,5 @@ false, use the symbol `false'. Each element is processed with ;;; sx-request.el ends here ;; Local Variables: -;; lexical-binding: t +;; indent-tabs-mode: nil ;; End: diff --git a/sx-site.el b/sx-site.el index 1ed469a..250df35 100644 --- a/sx-site.el +++ b/sx-site.el @@ -1,4 +1,4 @@ -;;; sx-site.el --- browsing sites +;;; sx-site.el --- browsing sites -*- lexical-binding: t -*- ;; Copyright (C) 2014 Sean Allred @@ -73,5 +73,4 @@ api_site_parameter." ;; Local Variables: ;; indent-tabs-mode: nil -;; lexical-binding: t ;; End: diff --git a/sx-tab.el b/sx-tab.el index 7394da6..3706780 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -1,4 +1,4 @@ -;;; sx-tab.el --- functions for viewing different tabs +;;; sx-tab.el --- functions for viewing different tabs -*- lexical-binding: t -*- ;; Copyright (C) 2014 Artur Malabarba @@ -114,5 +114,5 @@ If SITE is nil, use `sx-tab-default-site'." ;;; sx-tab.el ends here ;; Local Variables: -;; lexical-binding: t +;; indent-tabs-mode: nil ;; End: diff --git a/sx-time.el b/sx-time.el index 8f90747..3cf26b9 100644 --- a/sx-time.el +++ b/sx-time.el @@ -1,4 +1,4 @@ -;;; sx-time.el --- time +;;; sx-time.el --- time -*- lexical-binding: t -*- ;; Copyright (C) 2014 Sean Allred @@ -78,3 +78,7 @@ See also `sx-time-date-format-year'." (provide 'sx-time) ;;; sx-time.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx.el b/sx.el index b468762..899e9ff 100644 --- a/sx.el +++ b/sx.el @@ -1,4 +1,4 @@ -;;; sx.el --- core functions +;;; sx.el --- core functions -*- lexical-binding: t -*- ;; Copyright (C) 2014 Sean Allred @@ -319,5 +319,4 @@ If FORCE is non-nil, run them even if they've already been run." ;; Local Variables: ;; indent-tabs-mode: nil -;; lexical-binding: t ;; End: -- cgit v1.2.3 From fffae22a181b653c4b3ca1ceba8c7d46f7db50a5 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 4 Jan 2015 16:17:14 -0500 Subject: Update Makefile Clean compiled files before every test. This ensures that the changes made during the current session are applied when re-testing. --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ae11f84..53451ad 100644 --- a/Makefile +++ b/Makefile @@ -20,14 +20,17 @@ VERSIONS = 1 2 3 4 all :: $(VERSIONS) -$(VERSIONS) :: +$(VERSIONS) :: clean evm install emacs-24.$@-bin --skip || true evm use emacs-24.$@-bin emacs --version cask install - rm -rf .sx/ emacs --batch -L . -l ert -l test/tests.el -f ert-run-tests-batch-and-exit +clean: + rm -rf .sx/ + cask clean-elc + install_cask: curl -fsSkL https://raw.github.com/cask/cask/master/go | python -- cgit v1.2.3 From 14eadafd6388281085eb3330b9d7ee29a85ab8b2 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 28 Nov 2014 13:30:11 -0500 Subject: Provide commentaries for each file --- sx-auth.el | 7 +++++++ sx-cache.el | 14 ++++++++++---- sx-encoding.el | 5 +++++ sx-favorites.el | 3 +++ sx-filter.el | 4 ++++ sx-networks.el | 3 +++ sx-question-list.el | 2 ++ sx-question-mode.el | 3 +++ sx-question.el | 3 +++ sx-site.el | 3 +++ sx-tab.el | 7 ++++++- sx-time.el | 3 ++- 12 files changed, 51 insertions(+), 6 deletions(-) diff --git a/sx-auth.el b/sx-auth.el index fca5392..8c317fb 100644 --- a/sx-auth.el +++ b/sx-auth.el @@ -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) diff --git a/sx-cache.el b/sx-cache.el index e68397d..5f37d84 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 795f175..cf7d0f8 100644 --- a/sx-encoding.el +++ b/sx-encoding.el @@ -19,6 +19,11 @@ ;;; 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) diff --git a/sx-favorites.el b/sx-favorites.el index e86e521..17021fc 100644 --- a/sx-favorites.el +++ b/sx-favorites.el @@ -19,6 +19,9 @@ ;;; Commentary: +;; This file provides logic for retrieving and managing a user's +;; starred questions. + ;;; Code: (require 'sx-method) diff --git a/sx-filter.el b/sx-filter.el index 15bd8a1..f64d34b 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -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: diff --git a/sx-networks.el b/sx-networks.el index 58ebff5..f2b0a22 100644 --- a/sx-networks.el +++ b/sx-networks.el @@ -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) diff --git a/sx-question-list.el b/sx-question-list.el index 3354052..0cb1167 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -19,6 +19,8 @@ ;;; Commentary: +;; Provides question list logic (as used in e.g. `sx-tab-frontpage'). + ;;; Code: (require 'tabulated-list) (require 'cl-lib) diff --git a/sx-question-mode.el b/sx-question-mode.el index b13caf3..b3f9eb7 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -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 0e830a6..f3f99bb 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: diff --git a/sx-site.el b/sx-site.el index 2f0a31d..02f618e 100644 --- a/sx-site.el +++ b/sx-site.el @@ -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) diff --git a/sx-tab.el b/sx-tab.el index f97119a..eb2e2de 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -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: diff --git a/sx-time.el b/sx-time.el index e05d95a..c1be881 100644 --- a/sx-time.el +++ b/sx-time.el @@ -19,7 +19,8 @@ ;;; Commentary: -;; +;; This file provides functions for manipulating and displaying +;; timestamps. ;;; Code: -- cgit v1.2.3 From 45376bd7cad5175aa77e2343137856c9ee041e26 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 28 Nov 2014 13:30:44 -0500 Subject: Correct documentation --- sx-auth.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-auth.el b/sx-auth.el index 8c317fb..c142e3d 100644 --- a/sx-auth.el +++ b/sx-auth.el @@ -72,7 +72,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 -- cgit v1.2.3 From d94292227beddbceee8b0bb0c8f6a761764487fe Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 28 Nov 2014 13:31:08 -0500 Subject: Relate variable with setting function --- sx-auth.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sx-auth.el b/sx-auth.el index c142e3d..f35cca1 100644 --- a/sx-auth.el +++ b/sx-auth.el @@ -43,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) -- cgit v1.2.3 From 4b9ca544bcb498f5786f76186e99c638029b3161 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 28 Nov 2014 13:42:14 -0500 Subject: Update .gitignore --- .gitignore | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index cfaa152..59d35bb 100644 --- a/.gitignore +++ b/.gitignore @@ -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 -- cgit v1.2.3 From 7335257fc2bf56e992e92801cf72926f15dc4807 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 28 Nov 2014 13:42:31 -0500 Subject: Add sections to `sx-encoding.el' --- sx-encoding.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sx-encoding.el b/sx-encoding.el index cf7d0f8..dad8a53 100644 --- a/sx-encoding.el +++ b/sx-encoding.el @@ -28,6 +28,9 @@ (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 "∧" @@ -91,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. @@ -136,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 -- cgit v1.2.3 From 1afeaf67be32a8ef1599452d09b4cf7b326d0954 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Mon, 1 Dec 2014 08:45:50 -0500 Subject: Standardize local variables - Move lexical-binding to top of file; fixes #123 - Use indent-tabs-mode: nil for all files --- Makefile | 4 ---- sx-babel.el | 5 ++++- sx-button.el | 6 +++++- sx-compose.el | 6 +++++- sx-favorites.el | 2 +- sx-filter.el | 2 +- sx-inbox.el | 2 +- sx-interaction.el | 2 +- sx-load.el | 2 +- sx-method.el | 6 +++++- sx-notify.el | 2 +- sx-question-list.el | 6 +++++- sx-question-mode.el | 6 +++++- sx-question-print.el | 6 +++++- sx-question.el | 2 +- sx-request.el | 6 +++++- sx-search.el | 6 +++++- sx-switchto.el | 2 +- sx-tab.el | 20 +++++++++++++++----- sx-tag.el | 6 +++++- sx-time.el | 6 +++++- sx.el | 2 +- 22 files changed, 78 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index ae11f84..9d2ebdd 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,3 @@ install_cask: install_evm: curl -fsSkL https://raw.github.com/rejeep/evm/master/go | bash - -# Local Variables: -# indent-tabs-mode: t -# End: diff --git a/sx-babel.el b/sx-babel.el index b30a044..4386172 100644 --- a/sx-babel.el +++ b/sx-babel.el @@ -1,4 +1,4 @@ -;;; sx-babel.el --- Font-locking pre blocks according to language. -*- lexical-binding: t; -*- +;;; sx-babel.el --- font-locking pre blocks according to language -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba @@ -122,3 +122,6 @@ Returns the amount of indentation removed." (provide 'sx-babel) ;;; sx-babel.el ends here +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx-button.el b/sx-button.el index f166164..0824026 100644 --- a/sx-button.el +++ b/sx-button.el @@ -1,4 +1,4 @@ -;;; sx-button.el --- Defining buttons used throughout SX. -*- lexical-binding: t; -*- +;;; sx-button.el --- defining buttons -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba @@ -163,3 +163,7 @@ usually part of a code-block." (provide 'sx-button) ;;; sx-button.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx-compose.el b/sx-compose.el index 8a8637b..c5b8f78 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -1,4 +1,4 @@ -;;; sx-compose.el --- Major-mode for coposing questions and answers. -*- lexical-binding: t; -*- +;;; sx-compose.el --- major-mode for coposing questions and answers -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba @@ -302,3 +302,7 @@ the id property." (provide 'sx-compose) ;;; sx-compose.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx-favorites.el b/sx-favorites.el index 17021fc..e8155ea 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 -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Sean Allred diff --git a/sx-filter.el b/sx-filter.el index f64d34b..4695446 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -1,4 +1,4 @@ -;;; sx-filter.el --- Handles retrieval of filters. -*- lexical-binding: t; -*- +;;; sx-filter.el --- handles retrieval of filters -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Sean Allred diff --git a/sx-inbox.el b/sx-inbox.el index d0be379..01000a6 100644 --- a/sx-inbox.el +++ b/sx-inbox.el @@ -1,4 +1,4 @@ -;;; sx-inbox.el --- Base inbox logic. -*- lexical-binding: t; -*- +;;; sx-inbox.el --- base inbox logic -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba diff --git a/sx-interaction.el b/sx-interaction.el index dc4398e..acb4a77 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 otherwise interacting with questions -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba diff --git a/sx-load.el b/sx-load.el index f1ec7c3..003f965 100644 --- a/sx-load.el +++ b/sx-load.el @@ -1,4 +1,4 @@ -;;; sx-load.el --- Load all files of the sx package. -*- lexical-binding: t; -*- +;;; sx-load.el --- load all files of the SX package -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba diff --git a/sx-method.el b/sx-method.el index bff6d30..84a17db 100644 --- a/sx-method.el +++ b/sx-method.el @@ -1,4 +1,4 @@ -;;; sx-method.el --- Main interface for API method calls. -*- lexical-binding: t; -*- +;;; sx-method.el --- main interface for API method calls -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Sean Allred @@ -144,3 +144,7 @@ Return the entire response as a complex alist." (provide 'sx-method) ;;; sx-method.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx-notify.el b/sx-notify.el index c335427..6dc90b9 100644 --- a/sx-notify.el +++ b/sx-notify.el @@ -1,4 +1,4 @@ -;;; sx-notify.el --- Mode-line notifications. -*- lexical-binding: t; -*- +;;; sx-notify.el --- mode-line notifications -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba diff --git a/sx-question-list.el b/sx-question-list.el index 0cb1167..b9f34a0 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 -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba @@ -608,3 +608,7 @@ Sets `sx-question-list--site' and then call (provide 'sx-question-list) ;;; sx-question-list.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx-question-mode.el b/sx-question-mode.el index b3f9eb7..4eee2af 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -1,4 +1,4 @@ -;;; sx-question-mode.el --- Major-mode for displaying a question. -*- lexical-binding: t; -*- +;;; sx-question-mode.el --- major-mode for displaying a question -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba @@ -274,3 +274,7 @@ query the api." (provide 'sx-question-mode) ;;; sx-question-mode.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx-question-print.el b/sx-question-print.el index 07378e8..e148d5f 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -1,4 +1,4 @@ -;;; sx-question-print.el --- Populating the question-mode buffer with content. -*- lexical-binding: t; -*- +;;; sx-question-print.el --- populating the question-mode buffer with content -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba @@ -468,3 +468,7 @@ font-locking." (provide 'sx-question-print) ;;; sx-question-print.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx-question.el b/sx-question.el index f3f99bb..5222576 100644 --- a/sx-question.el +++ b/sx-question.el @@ -1,4 +1,4 @@ -;;; sx-question.el --- Base question logic. -*- lexical-binding: t; -*- +;;; sx-question.el --- base question logic -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Sean Allred diff --git a/sx-request.el b/sx-request.el index bab53ec..ebc16d2 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 -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Sean Allred @@ -256,3 +256,7 @@ false, use the symbol `false'. Each element is processed with (provide 'sx-request) ;;; sx-request.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx-search.el b/sx-search.el index 2633da9..d47905e 100644 --- a/sx-search.el +++ b/sx-search.el @@ -1,4 +1,4 @@ -;;; sx-search.el --- Searching for questions. -*- lexical-binding: t; -*- +;;; sx-search.el --- searching for questions -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba @@ -110,3 +110,7 @@ prefix argument, the user is asked for everything." (provide 'sx-search) ;;; sx-search.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx-switchto.el b/sx-switchto.el index 76804e4..458586a 100644 --- a/sx-switchto.el +++ b/sx-switchto.el @@ -1,4 +1,4 @@ -;;; sx-switchto.el --- Keymap for navigating between pages. -*- lexical-binding: t; -*- +;;; sx-switchto.el --- keymap for navigating between pages -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba diff --git a/sx-tab.el b/sx-tab.el index eb2e2de..2b3f20a 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -1,4 +1,4 @@ -;;; sx-tab.el --- Functions for viewing different tabs. -*- lexical-binding: t; -*- +;;; sx-tab.el --- functions for viewing different tabs -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba @@ -24,10 +24,16 @@ ;;; Tabs: -;; - frontpage :: the frontpage of a single site - - -;;; Code: +;; - FrontPage :: The standard front page +;; - Newest :: Newest questions +;; - TopVoted :: Top-voted questions +;; - Hot :: Hot questions recently +;; - Week :: Hot questions for the week +;; - Month :: Hot questions for the month +;; - Unanswered :: Unanswered questions +;; - Unanswered My-tags :: Unanswered questions (subscribed tags) +;; - Featured :: Featured questions +;; - Starred :: Favorite questions (require 'sx) (require 'sx-question-list) @@ -271,3 +277,7 @@ belongs to." (provide 'sx-tab) ;;; sx-tab.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx-tag.el b/sx-tag.el index 8c468a6..7ac80c6 100644 --- a/sx-tag.el +++ b/sx-tag.el @@ -1,4 +1,4 @@ -;;; sx-tag.el --- Retrieving list of tags and handling tags. -*- lexical-binding: t; -*- +;;; sx-tag.el --- retrieving list of tags and handling tags -*- lexical-binding: t; -*- ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -84,3 +84,7 @@ Return the list of invalid tags in TAGS." (provide 'sx-tag) ;;; sx-tag.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx-time.el b/sx-time.el index c1be881..1d1267b 100644 --- a/sx-time.el +++ b/sx-time.el @@ -1,4 +1,4 @@ -;;; sx-time.el --- time -*- lexical-binding: t; -*- +;;; sx-time.el --- time -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Sean Allred @@ -78,3 +78,7 @@ See also `sx-time-date-format-year'." (provide 'sx-time) ;;; sx-time.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: diff --git a/sx.el b/sx.el index f77b313..8cfb5dc 100644 --- a/sx.el +++ b/sx.el @@ -1,4 +1,4 @@ -;;; sx.el --- StackExchange client. Ask and answer questions on Stack Overflow, Super User, and the likes. -*- lexical-binding: t; -*- +;;; sx.el --- StackExchange client. Ask and answer questions on Stack Overflow, Super User, and the likes -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Sean Allred -- cgit v1.2.3 From 8a9c0fcae05c714d782cc9c1d4bc2d438abb879c Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 4 Jan 2015 18:04:30 -0500 Subject: Add missing Code: section It was taken out during the merge. --- sx-tab.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sx-tab.el b/sx-tab.el index 2b3f20a..f4e0c3d 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -35,6 +35,8 @@ ;; - Featured :: Featured questions ;; - Starred :: Favorite questions +;;; Code: + (require 'sx) (require 'sx-question-list) (require 'sx-interaction) -- cgit v1.2.3 From 97130cb7154fc494745d6b2a2a347c765403c5f3 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 4 Jan 2015 18:06:16 -0500 Subject: Fix docstrings --- sx-auth.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sx-auth.el b/sx-auth.el index 3cb7217..686aa0c 100644 --- a/sx-auth.el +++ b/sx-auth.el @@ -74,11 +74,11 @@ This variable is set with `sx-auth-authenticate'.") upvote (unanswered my-tags))) "List of methods that require auth. -Methods are of form (METHOD . SUBMETHODS) where SUBMETHODS - is (METHOD METHOD METHOD ...). +Methods are of the form \(METHOD . SUBMETHODS) where SUBMETHODS + is \(METHOD METHOD METHOD ...). If all SUBMETHODS require auth or there are no submethods, form -will be (METHOD . t)") +will be \(METHOD . t)") (defvar sx-auth-filter-auth '(question.upvoted question.downvoted @@ -86,8 +86,8 @@ will be (METHOD . t)") answer.downvoted comment.upvoted) "List of filter types that require auth. -Keywords are of form (OBJECT TYPES) where TYPES is (FILTER FILTER -FILTER).") +Keywords are of the form \(OBJECT TYPES) where TYPES is \(FILTER +FILTER FILTER).") ;;;###autoload (defun sx-authenticate () -- cgit v1.2.3 From 4a32725dfd8275eb1d8b44afc9494e7350a9bf7c Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 21:08:31 -0200 Subject: Fix sx-tab-unanswered-my-tags autoload --- sx-tab.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-tab.el b/sx-tab.el index 6a2552f..92e5921 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -210,7 +210,7 @@ If SITE is nil, use `sx-default-site'." (sx-question-get-questions sx-question-list--site page nil 'unanswered/my-tags))) ;;;###autoload -(autoload 'sx-tab-unanswered +(autoload 'sx-tab-unanswered-my-tags (expand-file-name "sx-tab" (when load-file-name -- cgit v1.2.3 From a812b209b24401827a7020051ac3726358795231 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 21:22:42 -0200 Subject: Use defconst instead of defvar where appropriate. Fix #200 --- sx-auth.el | 64 +++++++++++++++++++++++++++-------------------------- sx-favorites.el | 2 +- sx-filter.el | 2 +- sx-inbox.el | 6 ++--- sx-networks.el | 2 +- sx-notify.el | 2 +- sx-question-list.el | 2 +- sx-question-mode.el | 2 +- sx-site.el | 2 +- sx-tag.el | 2 +- sx-time.el | 2 +- sx.el | 2 +- 12 files changed, 46 insertions(+), 44 deletions(-) diff --git a/sx-auth.el b/sx-auth.el index 686aa0c..cba310d 100644 --- a/sx-auth.el +++ b/sx-auth.el @@ -47,32 +47,33 @@ what you are doing! This variable is set with `sx-auth-authenticate'.") -(defvar sx-auth-method-auth '((me . t) - (inbox . t) - (notifications . t) - (events . t) - (posts (comments add)) - (comments delete - edit - flags - upvote) - (answers accept - delete - downvote - edit - flags - upvote) - (questions answers - add - close - delete - downvote - edit - favorite - flags - render - upvote - (unanswered my-tags))) +(defconst sx-auth-method-auth + '((me . t) + (inbox . t) + (notifications . t) + (events . t) + (posts (comments add)) + (comments delete + edit + flags + upvote) + (answers accept + delete + downvote + edit + flags + upvote) + (questions answers + add + close + delete + downvote + edit + favorite + flags + render + upvote + (unanswered my-tags))) "List of methods that require auth. Methods are of the form \(METHOD . SUBMETHODS) where SUBMETHODS is \(METHOD METHOD METHOD ...). @@ -80,11 +81,12 @@ Methods are of the form \(METHOD . SUBMETHODS) where SUBMETHODS If all SUBMETHODS require auth or there are no submethods, form will be \(METHOD . t)") -(defvar sx-auth-filter-auth '(question.upvoted - question.downvoted - answer.upvoted - answer.downvoted - comment.upvoted) +(defconst sx-auth-filter-auth + '(question.upvoted + question.downvoted + answer.upvoted + answer.downvoted + comment.upvoted) "List of filter types that require auth. Keywords are of the form \(OBJECT TYPES) where TYPES is \(FILTER FILTER FILTER).") diff --git a/sx-favorites.el b/sx-favorites.el index 7fdc772..d98b4c2 100644 --- a/sx-favorites.el +++ b/sx-favorites.el @@ -30,7 +30,7 @@ (require 'sx-networks) (require 'sx-filter) -(defvar sx-favorite-list-filter +(defconst sx-favorite-list-filter (sx-filter-from-nil (question.question_id))) diff --git a/sx-filter.el b/sx-filter.el index 4695446..57c491d 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -107,7 +107,7 @@ return the compiled filter." ;;; Browsing filter -(defvar sx-browse-filter +(defconst sx-browse-filter (sx-filter-from-nil ((question body_markdown bounty_amount diff --git a/sx-inbox.el b/sx-inbox.el index 01000a6..1efceb1 100644 --- a/sx-inbox.el +++ b/sx-inbox.el @@ -28,7 +28,7 @@ ;;; API -(defvar sx-inbox-filter +(defconst sx-inbox-filter '((inbox_item.answer_id inbox_item.body inbox_item.comment_id @@ -91,7 +91,7 @@ These are identified by their links.") "List of notification items which are read. These are identified by their links.") -(defvar sx-inbox--header-line +(defconst sx-inbox--header-line '(" " (:propertize "n p j k" face mode-line-buffer-id) ": Navigate" @@ -106,7 +106,7 @@ These are identified by their links.") ": Quit") "Header-line used on the inbox list.") -(defvar sx-inbox--mode-line +(defconst sx-inbox--mode-line '(" " (:propertize (sx-inbox--notification-p diff --git a/sx-networks.el b/sx-networks.el index 2695689..45eaf05 100644 --- a/sx-networks.el +++ b/sx-networks.el @@ -29,7 +29,7 @@ (require 'sx-site) (require 'sx-filter) -(defvar sx-network--user-filter +(defconst sx-network--user-filter (sx-filter-from-nil ((badge_count bronze silver diff --git a/sx-notify.el b/sx-notify.el index 6dc90b9..0c9a5b8 100644 --- a/sx-notify.el +++ b/sx-notify.el @@ -27,7 +27,7 @@ ;;; mode-line notification -(defvar sx-notify--mode-line +(defconst sx-notify--mode-line '((sx-inbox--unread-inbox (sx-inbox--unread-notifications " [")) (sx-inbox--unread-inbox (:propertize diff --git a/sx-question-list.el b/sx-question-list.el index b9f34a0..c72dc0d 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -228,7 +228,7 @@ and thus not displayed in the list of questions. This is ignored if `sx-question-list--refresh-function' is set.") (make-variable-buffer-local 'sx-question-list--dataset) -(defvar sx-question-list--header-line +(defconst sx-question-list--header-line '(" " (:propertize "n p j k" face mode-line-buffer-id) ": Navigate" diff --git a/sx-question-mode.el b/sx-question-mode.el index f702822..5303ebb 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -178,7 +178,7 @@ property." ;;; Major-mode -(defvar sx-question-mode--header-line +(defconst sx-question-mode--header-line '(" " (:propertize "n p TAB" face mode-line-buffer-id) ": Navigate" diff --git a/sx-site.el b/sx-site.el index 02f618e..9b2ea34 100644 --- a/sx-site.el +++ b/sx-site.el @@ -28,7 +28,7 @@ (require 'sx-cache) (require 'sx-filter) -(defvar sx-site-browse-filter +(defconst sx-site-browse-filter (sx-filter-from-nil ((site site_type name diff --git a/sx-tag.el b/sx-tag.el index 7ac80c6..5e75890 100644 --- a/sx-tag.el +++ b/sx-tag.el @@ -26,7 +26,7 @@ ;;; Getting the list from a site -(defvar sx-tag-filter +(defconst sx-tag-filter (sx-filter-from-nil (tag.name tag.synonyms)) diff --git a/sx-time.el b/sx-time.el index 1d1267b..9fa0037 100644 --- a/sx-time.el +++ b/sx-time.el @@ -26,7 +26,7 @@ (require 'time-date) -(defvar sx-time-seconds-to-string +(defconst sx-time-seconds-to-string ;; (LIMIT NAME VALUE) ;; We use an entry if the number of seconds in question is less than ;; LIMIT, but more than the previous entry's LIMIT. diff --git a/sx.el b/sx.el index 8cfb5dc..3271755 100644 --- a/sx.el +++ b/sx.el @@ -300,7 +300,7 @@ Return the result of BODY." (push ov sx--overlays)) result)) -(defvar sx--ascii-replacement-list +(defconst sx--ascii-replacement-list '(("[:space:]" . "") ("àåáâäãåą" . "a") ("èéêëę" . "e") -- cgit v1.2.3 From ae0fc9a35f3eef1518d1486682962045d82b2a76 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 5 Jan 2015 11:17:19 -0200 Subject: HOTFIX Specify more filters --- sx-filter.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sx-filter.el b/sx-filter.el index 57c491d..d341032 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -113,6 +113,11 @@ return the compiled filter." bounty_amount comments answers + answer_count + score + title + owner + tags last_editor last_activity_date accepted_answer_id @@ -141,6 +146,7 @@ return the compiled filter." last_activity_date link share_link + score owner body_markdown upvoted -- cgit v1.2.3 From 85b4e56d60aaa3420616572c444d6152ed180944 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 5 Jan 2015 11:17:56 -0200 Subject: HOTFIX After composing, don't error if only window --- sx-compose.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-compose.el b/sx-compose.el index f4fcd0a..8a6edc3 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -128,7 +128,7 @@ contents to the API, then calls `sx-compose-after-send-functions'." (when (buffer-live-p buffer) (let ((w (get-buffer-window buffer))) (when (window-live-p w) - (delete-window w))) + (ignore-errors (delete-window w)))) (kill-buffer buffer))) (defun sx-compose--copy-as-kill (buffer _) -- cgit v1.2.3 From 01aac931f90c1251ed6b3c30df672cf3073b16c5 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 23:03:53 -0200 Subject: Implement sx-request-get-data for getting data from the data branch. --- sx-request.el | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sx-request.el b/sx-request.el index ebc16d2..e91ac18 100644 --- a/sx-request.el +++ b/sx-request.el @@ -212,6 +212,35 @@ require authentication. Currently returns nil." '(())) + +;;; Our own generated data +(defvar sx-request--data-url-format + "https://raw.githubusercontent.com/vermiculus/sx.el/data/data/%s.el" + "Url of the \"data\" directory inside the SX `data' branch.") + +(defun sx-request-get-data (file) + "Fetch and return data stored online by SX. +FILE is a string or symbol, the name of the file which holds the +desired data, relative to `sx-request--data-url-format'. For +instance, `tags/emacs' returns the list of tags on Emacs.SE." + (let* ((url-automatic-caching t) + (url-inhibit-uncompression t) + (request-url (format sx-request--data-url-format file)) + (url-request-method "GET") + (url-request-extra-headers + '(("Content-Type" . "application/x-www-form-urlencoded"))) + (response-buffer (url-retrieve-synchronously request-url))) + (if (not response-buffer) + (error "Something went wrong in `url-retrieve-synchronously'") + (with-current-buffer response-buffer + (progn + (goto-char (point-min)) + (if (not (search-forward "\n\n" nil t)) + (error "Headers missing; response corrupt") + (when (looking-at-p "Not Found") (error "Page not found.")) + (prog1 (read (current-buffer)) + (kill-buffer (current-buffer))))))))) + ;;; Support Functions (defun sx-request--build-keyword-arguments (alist &optional kv-sep) -- cgit v1.2.3 From d26df2730db01a4904ad71eb3590b5d90c015767 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 23:16:44 -0200 Subject: Implement sx-tag-list--get --- sx-tag.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sx-tag.el b/sx-tag.el index 5e75890..0f726fd 100644 --- a/sx-tag.el +++ b/sx-tag.el @@ -62,6 +62,23 @@ Returns a list." (mapcar (lambda (x) (cdr (assoc 'name x))) (sx-tag--get-some-tags-containing site string))) + +;;; Getting tags from our data branch. Without the API. +;;;; @TODO: Once the cache is finished, this can probably be made into +;;;; a cache variasble with 1 day expiration time. +(defvar sx-tag-list-alist nil + "Alist where the tag list for each site is stored. +Elements are of the type (SITE . TAG-LIST).") + +(defun sx-tag-list--get (site) + "Retrieve all tags from SITE in a single request. +This does not access the API. Instead, it uses +`sx-request-get-data', which accesses SX's tag cache." + (or (cdr (assoc site sx-tag-list-alist)) + (let ((list (sx-request-get-data (concat "tags/" site)))) + (push (cons site list) sx-tag-list-alist) + list))) + ;;; Check tag validity (defun sx-tag--invalid-name-p (site tags) -- cgit v1.2.3 From 065ef960b3fcf80ea68dbcbbcca8c276a2d09b07 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 5 Jan 2015 00:53:01 -0200 Subject: Move sx--multiple-read to sx-tag-multiple-read --- sx-search.el | 13 ++++--------- sx-tag.el | 33 +++++++++++++++++++++++++++++++++ sx.el | 18 ------------------ 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/sx-search.el b/sx-search.el index d47905e..8614f49 100644 --- a/sx-search.el +++ b/sx-search.el @@ -32,13 +32,11 @@ (require 'sx) (require 'sx-question-list) +(require 'sx-tag) (defvar sx-search--query-history nil "Query history for interactive prompts.") -(defvar sx-search--tag-history nil - "Tags history for interactive prompts.") - ;;; Basic function (defun sx-search-get-questions (site page query &optional tags excluded-tags keywords) @@ -84,15 +82,12 @@ prefix argument, the user is asked for everything." (when (string= query "") (setq query nil)) (when current-prefix-arg - (setq tags (sx--multiple-read - (format "Tags (%s)" - (if query "optional" "mandatory")) - 'sx-search--tag-history)) + (setq tags (sx-tag-multiple-read + site (format "Tags%s" (if query " (optional)" "")))) (when (and (not query) (string= "" tags)) (sx-user-error "Must supply either QUERY or TAGS")) (setq excluded-tags - (sx--multiple-read - "Excluded tags (optional)" 'sx-search--tag-history))) + (sx-tag-multiple-read site "Excluded tags (optional)"))) (list site query tags excluded-tags))) ;; Here starts the actual function diff --git a/sx-tag.el b/sx-tag.el index 0f726fd..41ed9eb 100644 --- a/sx-tag.el +++ b/sx-tag.el @@ -99,6 +99,39 @@ Return the list of invalid tags in TAGS." :site site)))) (cl-remove-if (lambda (x) (member x result)) tags))) + +;;; Prompt the user for tags. +(defvar sx-tag-history nil + "Tags history for interactive prompts.") + +;;; @TODO: Make it so that hitting BACKSPACE with an empty input +;;; deletes a previously submitted tag. +(defun sx-tag-multiple-read (site prompt &optional initial-value) + "Interactively read a list of tags for SITE. +Call `sx-completing-read' multiple times, until input is empty. +Return a list of tags given by the user. + +PROMPT is a string displayed to the user and should not end with +a space nor a colon. INITIAL-VALUE is a list of already-selected +tags." + (let ((completion-list (sx-tag-list--get site)) + (list initial-value) + input) + (while (not (string= + "" + (setq input (sx-completing-read + (concat prompt " [" + (mapconcat #'identity list ",") + "]: ") + completion-list + (lambda (x) (not (member x list))) + nil + 'require-match + nil + 'sx-tag-history)))) + (push input list)) + list)) + (provide 'sx-tag) ;;; sx-tag.el ends here diff --git a/sx.el b/sx.el index 3271755..9924308 100644 --- a/sx.el +++ b/sx.el @@ -176,24 +176,6 @@ All ARGS are passed to `completing-read' or `ido-completing-read'." (apply (if ido-mode #'ido-completing-read #'completing-read) args)) -(defun sx--multiple-read (prompt hist-var) - "Interactively query the user for a list of strings. -Call `read-string' multiple times, until the input is empty. - -PROMPT is a string displayed to the user and should not end with -a space nor a colon. HIST-VAR is a quoted symbol, indicating a -list in which to store input history." - (let (list input) - (while (not (string= - "" - (setq input (read-string - (concat prompt " [" - (mapconcat #'identity list ",") - "]: ") - "" hist-var)))) - (push input list)) - list)) - (defmacro sx-sorted-insert-skip-first (newelt list &optional predicate) "Inserted NEWELT into LIST sorted by PREDICATE. This is designed for the (site id id ...) lists. So the first car -- cgit v1.2.3 From 359a48845905feab401b5dc0783733ff230f8956 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 5 Jan 2015 01:03:58 -0200 Subject: Refactor sx-compose--goto-tag-header --- sx-compose.el | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sx-compose.el b/sx-compose.el index 8a6edc3..ac6700b 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -137,20 +137,25 @@ contents to the API, then calls `sx-compose-after-send-functions'." (with-current-buffer buffer (kill-new (buffer-string))))) +(defun sx-compose--goto-tag-header () + "Move to the \"Tags:\" header. +Match data is set so group 1 encompasses any already inserted +tags. Return a list of already inserted tags." + (goto-char (point-min)) + (unless (search-forward-regexp + "^Tags : *\\([^[:space:]].*\\) *$" + (next-single-property-change (point-min) 'sx-compose-separator) + 'noerror) + (error "No Tags header found")) + (split-string (match-string 1) "[[:space:],;]" + 'omit-nulls "[[:space:]]")) + (defun sx-compose--check-tags () "Check if tags in current compose buffer are valid." (save-excursion - (goto-char (point-min)) - (unless (search-forward-regexp - "^Tags : *\\([^[:space:]].*\\) *$" - (next-single-property-change (point-min) 'sx-compose-separator) - 'noerror) - (error "No Tags header found")) (let ((invalid-tags (sx-tag--invalid-name-p - (split-string (match-string 1) "[[:space:],;]" - 'omit-nulls "[[:space:]]") - sx-compose--site))) + sx-compose--site (sx-compose--goto-tag-header)))) (if invalid-tags ;; If the user doesn't want to create the tags, we return ;; nil and sending is aborted. -- cgit v1.2.3 From 60050b7b773a3bfd5d7ba0bfa53f46c6e1b4dca5 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 5 Jan 2015 01:04:11 -0200 Subject: Implement sx-compose-insert-tags --- sx-compose.el | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/sx-compose.el b/sx-compose.el index ac6700b..e1f6874 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -120,6 +120,21 @@ contents to the API, then calls `sx-compose-after-send-functions'." (run-hook-with-args 'sx-compose-after-send-functions (current-buffer) result))))) +(defun sx-compose-insert-tags () + "Prompt for a tag list for this draft and insert them." + (interactive) + (save-excursion + (let* ((old (sx-compose--goto-tag-header)) + (new + (save-match-data + (mapconcat + #'identity + (sx-tag-multiple-read sx-compose--site "Tags" old) + " ")))) + (if (match-string 1) + (replace-match new :fixedcase nil nil 1) + (insert new))))) + ;;; Functions for use in hooks (defun sx-compose-quit (buffer _) @@ -143,12 +158,13 @@ Match data is set so group 1 encompasses any already inserted tags. Return a list of already inserted tags." (goto-char (point-min)) (unless (search-forward-regexp - "^Tags : *\\([^[:space:]].*\\) *$" + (rx bol "Tags : " (group-n 1 (* not-newline)) eol) (next-single-property-change (point-min) 'sx-compose-separator) 'noerror) (error "No Tags header found")) - (split-string (match-string 1) "[[:space:],;]" - 'omit-nulls "[[:space:]]")) + (save-match-data + (split-string (match-string 1) (rx (any space ",;")) + 'omit-nulls (rx space)))) (defun sx-compose--check-tags () "Check if tags in current compose buffer are valid." -- cgit v1.2.3 From 34ea6829153a1b5b45104c0650a9d0a148491aef Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 5 Jan 2015 11:16:50 -0200 Subject: Fix sx-tag-completing-read --- sx-tag.el | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sx-tag.el b/sx-tag.el index 41ed9eb..b2ad375 100644 --- a/sx-tag.el +++ b/sx-tag.el @@ -108,29 +108,30 @@ Return the list of invalid tags in TAGS." ;;; deletes a previously submitted tag. (defun sx-tag-multiple-read (site prompt &optional initial-value) "Interactively read a list of tags for SITE. -Call `sx-completing-read' multiple times, until input is empty. +Call `sx-completing-read' multiple times, until input is empty, +with completion options given by the tag list of SITE. Return a list of tags given by the user. PROMPT is a string displayed to the user and should not end with a space nor a colon. INITIAL-VALUE is a list of already-selected tags." (let ((completion-list (sx-tag-list--get site)) - (list initial-value) + (list (reverse initial-value)) + (empty-string + (propertize "--\x000-some-string-representing-empty-\x000--" + 'display "DONE")) input) (while (not (string= - "" + empty-string (setq input (sx-completing-read (concat prompt " [" - (mapconcat #'identity list ",") + (mapconcat #'identity (reverse list) ",") "]: ") completion-list - (lambda (x) (not (member x list))) - nil - 'require-match - nil - 'sx-tag-history)))) + nil 'require-match nil 'sx-tag-history + empty-string)))) (push input list)) - list)) + (reverse list))) (provide 'sx-tag) ;;; sx-tag.el ends here -- cgit v1.2.3 From f77495881d218a96a8b875e650a0d8acf0f36354 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 5 Jan 2015 11:23:30 -0200 Subject: Bind sx-compose-insert-tags to "\C-c\C-q" Fix #137 --- sx-compose.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sx-compose.el b/sx-compose.el index e1f6874..ee4f774 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -107,6 +107,9 @@ with the `sx-compose-create' function. (define-key sx-compose-mode-map "\C-c\C-c" #'sx-compose-send) (define-key sx-compose-mode-map "\C-c\C-k" #'sx-compose-quit) +(sx--define-conditional-key + sx-compose-mode-map "\C-c\C-q" #'sx-compose-insert-tags + (ignore-errors (string= "Title: " (substring (buffer-string) 0 7)))) (defun sx-compose-send () "Finish composing current buffer and send it. -- cgit v1.2.3 From 999822d231c92e52ea52f6a467980e6eb6b5e66f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 5 Jan 2015 16:06:09 -0200 Subject: Add process-function arg to request-fallback. Fix #205 --- sx-request.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sx-request.el b/sx-request.el index ebc16d2..0d618d5 100644 --- a/sx-request.el +++ b/sx-request.el @@ -131,6 +131,8 @@ access the response wrapper." (vconcat return-value (cdr (assoc 'items response))))) +;;; NOTE: Whenever this is arglist changes, `sx-request-fallback' must +;;; also change. (defun sx-request-make (method &optional args request-method process-function) "Make a request to the API, executing METHOD with ARGS. You should almost certainly be using `sx-method-call' instead of @@ -204,7 +206,7 @@ the main content of the response is returned." (funcall (or process-function #'sx-request-response-get-items) response))))))) -(defun sx-request-fallback (_method &optional _args _request-method) +(defun sx-request-fallback (_method &optional _args _request-method _process-function) "Fallback method when authentication is not available. This is for UI generation when the associated API call would require authentication. -- cgit v1.2.3 From 51b5f280119745074e9d16042b5608f25cbb6e06 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 5 Jan 2015 16:09:37 -0200 Subject: Turn sx-compose--question-headers into a defconst --- sx-compose.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-compose.el b/sx-compose.el index ee4f774..0e5e35f 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -67,7 +67,7 @@ succeeds.") Is invoked between `sx-compose-before-send-hook' and `sx-compose-after-send-functions'.") -(defvar sx-compose--question-headers +(defconst sx-compose--question-headers (concat #("Title: " 0 7 (intangible t read-only t rear-nonsticky t)) "%s" -- cgit v1.2.3 From e061fb947a02290314be7247d81963e7bfd0987b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 5 Jan 2015 16:31:10 -0200 Subject: Move define-conditional-key to sx.el --- sx-switchto.el | 12 ------------ sx.el | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sx-switchto.el b/sx-switchto.el index 458586a..ed83360 100644 --- a/sx-switchto.el +++ b/sx-switchto.el @@ -54,18 +54,6 @@ ;;; These are keys which depend on context. ;;;; For instance, it makes no sense to have `switch-site' bound to a ;;;; key on a buffer with no `sx-question-list--site' variable. -(defmacro sx--define-conditional-key (keymap key def &rest body) - "In KEYMAP, define key sequence KEY as DEF conditionally. -This is like `define-key', except the definition \"disapears\" -whenever BODY evaluates to nil." - (declare (indent 3) - (debug (form form form &rest sexp))) - `(define-key ,keymap ,key - '(menu-item - ,(format "maybe-%s" (or (car (cdr-safe def)) def)) ignore - :filter (lambda (&optional _) - (when (progn ,@body) ,def))))) - (sx--define-conditional-key sx-switchto-map "s" #'sx-question-list-switch-site (and (boundp 'sx-question-list--site) sx-question-list--site)) diff --git a/sx.el b/sx.el index 9924308..bfc647d 100644 --- a/sx.el +++ b/sx.el @@ -247,6 +247,18 @@ Anything before the (sub)domain is removed." (rx string-start (or (and (0+ word) (optional ":") "//"))) "" url))) +(defmacro sx--define-conditional-key (keymap key def &rest body) + "In KEYMAP, define key sequence KEY as DEF conditionally. +This is like `define-key', except the definition \"disapears\" +whenever BODY evaluates to nil." + (declare (indent 3) + (debug (form form form &rest sexp))) + `(define-key ,keymap ,key + '(menu-item + ,(format "maybe-%s" (or (car (cdr-safe def)) def)) ignore + :filter (lambda (&optional _) + (when (progn ,@body) ,def))))) + ;;; Printing request data (defvar sx--overlays nil -- cgit v1.2.3 From cbd587f6fdcd9936132972e510d4cbd973d3a703 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 5 Jan 2015 16:31:48 -0200 Subject: Add sx-compose--is-question-p variable --- sx-compose.el | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sx-compose.el b/sx-compose.el index 0e5e35f..db76531 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -82,6 +82,10 @@ Is invoked between `sx-compose-before-send-hook' and "Headers inserted when composing a new question. Used by `sx-compose-create'.") +(defvar sx-compose--is-question-p nil + "Non-nil if this `sx-compose-mode' buffer is a question.") +(make-variable-buffer-local 'sx-compose--is-question-p) + (defvar sx-compose--site nil "Site which the curent compose buffer belongs to.") (make-variable-buffer-local 'sx-compose--site) @@ -95,8 +99,11 @@ just implements some extra features related to posting to the API. This mode won't function if `sx-compose--send-function' isn't -set. To make sure you set it correctly, you can create the buffer -with the `sx-compose-create' function. +set. To make sure you set it correctly, you can create the +buffer with the `sx-compose-create' function. + +If creating a question draft, the `sx-compose--is-question-p' +variable should also be set to enable more functionality. \\ \\{sx-compose-mode}" @@ -109,7 +116,7 @@ with the `sx-compose-create' function. (define-key sx-compose-mode-map "\C-c\C-k" #'sx-compose-quit) (sx--define-conditional-key sx-compose-mode-map "\C-c\C-q" #'sx-compose-insert-tags - (ignore-errors (string= "Title: " (substring (buffer-string) 0 7)))) + sx-compose--is-question-p) (defun sx-compose-send () "Finish composing current buffer and send it. @@ -204,6 +211,7 @@ respectively added locally to `sx-compose-before-send-hook' and (with-current-buffer (sx-compose--get-buffer-create site parent) (sx-compose-mode) (setq sx-compose--site site) + (setq sx-compose--is-question-p is-question) (setq sx-compose--send-function (if (consp parent) (sx-assoc-let parent -- cgit v1.2.3 From 023b5511df15df4289783a8701fec2bed95462f1 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 5 Jan 2015 16:32:06 -0200 Subject: Add header-line to compose-buffer --- sx-compose.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sx-compose.el b/sx-compose.el index db76531..67c476e 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -82,6 +82,19 @@ Is invoked between `sx-compose-before-send-hook' and "Headers inserted when composing a new question. Used by `sx-compose-create'.") +(defconst sx-compose--header-line + '(" " + (:propertize "C-c C-c" face mode-line-buffer-id) + ": Finish and Send" + (sx-compose--is-question-p + (" " + (:propertize "C-c C-q" face mode-line-buffer-id) + ": Insert tags")) + " " + (:propertize "C-c C-k" face mode-line-buffer-id) + ": Discard Draft") + "Header-line used on `sx-compose-mode' drafts.") + (defvar sx-compose--is-question-p nil "Non-nil if this `sx-compose-mode' buffer is a question.") (make-variable-buffer-local 'sx-compose--is-question-p) @@ -107,6 +120,7 @@ variable should also be set to enable more functionality. \\ \\{sx-compose-mode}" + (setq header-line-format sx-compose--header-line) (add-hook 'sx-compose-after-send-functions #'sx-compose-quit nil t) (add-hook 'sx-compose-after-send-functions -- cgit v1.2.3 From f099001018a8436f1843002e9192a4bf160e5a76 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 6 Jan 2015 10:43:31 -0500 Subject: Hotfix kill response buffers after request --- sx-request.el | 1 + 1 file changed, 1 insertion(+) diff --git a/sx-request.el b/sx-request.el index 0d618d5..6f95687 100644 --- a/sx-request.el +++ b/sx-request.el @@ -191,6 +191,7 @@ the main content of the response is returned." ;; RESPONSE to 'corrupt or something (response (with-demoted-errors "`json' error: %S" (json-read-from-string data)))) + (kill-buffer response-buffer) (when (and (not response) (string-equal data "{}")) (sx-message "Unable to parse response: %S" response) (error "Response could not be read by `json-read-from-string'")) -- cgit v1.2.3 From 7db38cdcfbcac58722012049aceb365cf8c83d76 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 6 Jan 2015 14:02:09 -0200 Subject: Add creation_date to filters. Affects #206 --- sx-filter.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sx-filter.el b/sx-filter.el index d341032..a3f6861 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -112,6 +112,7 @@ return the compiled filter." ((question body_markdown bounty_amount comments + creation_date answers answer_count score @@ -142,6 +143,7 @@ return the compiled filter." post_id comment_id) (answer answer_id + creation_date last_editor last_activity_date link -- cgit v1.2.3 From 1874b560599f5937c7f9301057a18665a3840150 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 6 Jan 2015 14:07:46 -0200 Subject: HOTFIX. Don't assume the shallow_user has display_name nor reputation. Fix #206 --- sx-question-list.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sx-question-list.el b/sx-question-list.el index c72dc0d..1b7fe5a 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -184,8 +184,8 @@ Also see `sx-question-list-refresh'." " " (let-alist .owner (format "%15s %5s" - (propertize .display_name 'face 'sx-question-list-user) - (propertize (number-to-string .reputation) + (propertize (or .display_name "") 'face 'sx-question-list-user) + (propertize (number-to-string (or .reputation 0)) 'face 'sx-question-list-reputation))) (propertize " " 'display "\n"))))))) -- cgit v1.2.3 From d49e720b6961ea005cdb26e4191b6f51384253ac Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 6 Jan 2015 19:28:15 -0200 Subject: sx-search: Use concat instead of format --- sx-search.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-search.el b/sx-search.el index 8614f49..fa08e56 100644 --- a/sx-search.el +++ b/sx-search.el @@ -83,7 +83,7 @@ prefix argument, the user is asked for everything." (setq query nil)) (when current-prefix-arg (setq tags (sx-tag-multiple-read - site (format "Tags%s" (if query " (optional)" "")))) + site (concat "Tags" (when query " (optional)")))) (when (and (not query) (string= "" tags)) (sx-user-error "Must supply either QUERY or TAGS")) (setq excluded-tags -- cgit v1.2.3 From 5b66d7865fb9f160586c7d579f8df7195804e927 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 6 Jan 2015 19:29:46 -0200 Subject: Typo --- sx.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx.el b/sx.el index bfc647d..8680fc3 100644 --- a/sx.el +++ b/sx.el @@ -249,7 +249,7 @@ Anything before the (sub)domain is removed." (defmacro sx--define-conditional-key (keymap key def &rest body) "In KEYMAP, define key sequence KEY as DEF conditionally. -This is like `define-key', except the definition \"disapears\" +This is like `define-key', except the definition \"disappears\" whenever BODY evaluates to nil." (declare (indent 3) (debug (form form form &rest sexp))) -- cgit v1.2.3 From 9c55ae8efcd7a9b9f940d00f9a14dc439a7c225b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 6 Jan 2015 19:57:22 -0200 Subject: Use site_par instead of site --- sx.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx.el b/sx.el index 3271755..5aec9e5 100644 --- a/sx.el +++ b/sx.el @@ -90,7 +90,7 @@ with a `link' property)." (defun sx--link-to-data (link) "Convert string LINK into data that can be displayed." - (let ((result (list (cons 'site (sx--site link))))) + (let ((result (list (cons 'site_par (sx--site link))))) ;; Try to strip a question or answer ID (when (or ;; Answer -- cgit v1.2.3 From 79dd8ab7ea1c6e54fe2ad7e88b13a7990e2ec5be Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 6 Jan 2015 20:09:54 -0200 Subject: Don't assume .display_name exists. Fix #209 --- sx-question-print.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-question-print.el b/sx-question-print.el index e148d5f..e2db76f 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -276,7 +276,7 @@ DATA can represent a question or an answer." (defun sx-question-mode--propertize-display-name (author) "Return display_name of AUTHOR with `sx-question-mode-author' face." (sx-assoc-let author - (propertize .display_name + (propertize (or .display_name "??") 'face 'sx-question-mode-author))) (defun sx-question-mode--print-comment (comment-data) -- cgit v1.2.3 From a11d7997aa61f6e5bcb5fb6974c25b914b3bd001 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Wed, 7 Jan 2015 00:58:56 -0500 Subject: Use `data' branch for bot data --- bot/sx-bot.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/sx-bot.sh b/bot/sx-bot.sh index 6a5df17..22c7284 100755 --- a/bot/sx-bot.sh +++ b/bot/sx-bot.sh @@ -1,6 +1,6 @@ #!/usr/bin/bash -DESTINATION_BRANCH=gh-pages +DESTINATION_BRANCH=data function notify-done { local title -- cgit v1.2.3 From 8b6487e1158b200e514621b24f02f86cb87d64b8 Mon Sep 17 00:00:00 2001 From: Sebastian Wiesner Date: Wed, 7 Jan 2015 11:24:43 +0100 Subject: Use locate-user-emacs-file It's the standard function for this purpose. --- sx-cache.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sx-cache.el b/sx-cache.el index 3a5bd3b..3e8e08f 100644 --- a/sx-cache.el +++ b/sx-cache.el @@ -34,8 +34,7 @@ ;;; Code: -(defcustom sx-cache-directory - (expand-file-name ".sx" user-emacs-directory) +(defcustom sx-cache-directory (locate-user-emacs-file ".sx") "Directory containing cached data." :type 'directory :group 'sx) -- cgit v1.2.3 From 706a445f831a7864256bbc375ee0d60be5ce2f6e Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 6 Jan 2015 20:52:42 -0200 Subject: Use defconst for button help-echo's --- sx-button.el | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/sx-button.el b/sx-button.el index 4c0666b..2dd20d0 100644 --- a/sx-button.el +++ b/sx-button.el @@ -104,23 +104,29 @@ usually part of a code-block." ;;; Help-echo definitions -(defvar sx-button--help-echo +(defconst sx-button--help-echo (concat "mouse-1, RET" (propertize ": %s -- " 'face 'minibuffer-prompt) "w" (propertize ": copy %s" 'face 'minibuffer-prompt)) "Base help-echo on which others can be written.") -(defvar sx-button--question-title-help-echo +(defconst sx-button--user-help-echo (format sx-button--help-echo - (propertize "hide content" 'face 'minibuffer-prompt) - (propertize "link" 'face 'minibuffer-prompt)) + "visit user page" + "link") + "Help echoed in the minibuffer when point is on a user.") + +(defconst sx-button--question-title-help-echo + (format sx-button--help-echo + "hide content" + "link") "Help echoed in the minibuffer when point is on a section.") -(defvar sx-button--link-help-echo +(defconst sx-button--link-help-echo (format sx-button--help-echo - (propertize "visit %s" 'face 'minibuffer-prompt) - (propertize "URL" 'face 'minibuffer-prompt)) + "visit %s" + "URL") "Help echoed in the minibuffer when point is on a section.") -- cgit v1.2.3 From 17d41cf40e36d0f0a7c48c60a7bf8880b659c438 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 6 Jan 2015 20:53:41 -0200 Subject: Define user button --- sx-button.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sx-button.el b/sx-button.el index 2dd20d0..8309543 100644 --- a/sx-button.el +++ b/sx-button.el @@ -151,6 +151,13 @@ usually part of a code-block." 'action #'sx-button-follow-link :supertype 'sx-button) +(define-button-type 'sx-button-user + 'action #'sx-button-follow-link + 'help-echo sx-button--user-help-echo + ;; We use different faces on diferent parts of the user button. + 'face nil + :supertype 'sx-button) + (define-button-type 'sx-button-comment 'help-echo (concat "mouse-1, RET" (propertize ": write a comment" -- cgit v1.2.3 From f64d2922ed44dcacd3a0fd06eb494e94bd128bbe Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 6 Jan 2015 23:02:59 -0200 Subject: Define sx-format-replacements Use FORMAT-STRING to format the values in ALIST. --- sx.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/sx.el b/sx.el index e080271..6112510 100644 --- a/sx.el +++ b/sx.el @@ -337,6 +337,30 @@ removed from the display name before it is returned." (format "[%s]" (car kar)) (cdr kar) string))) string)) +(defun sx-format-replacements (format alist) + "Use FORMAT-STRING to format the values in ALIST. +ALIST is a list with elements of the form (CHAR . STRING). +The value is a copy of FORMAT-STRING, but with certain constructs +replaced by text as given by ALIST. + +The construct is a `%' character followed by any other character. +The replacement is the STRING corresponding to CHAR in ALIST. + +The %% construct is special, it is replaced with a single %, even +if ALIST contains a different string at the ?% entry." + (let ((alist (cons '(?% . "%") alist))) + (with-temp-buffer + (insert format) + (goto-char (point-min)) + (while (search-forward "%" nil 'noerror) + (delete-char -1) + (unless (eobp) + (insert + (or (cdr (assq (char-after) alist)) + (error "ALIST has no value for `%c'" (char-after)))) + (delete-char 1))) + (buffer-string)))) + (defcustom sx-init-hook nil "Hook run when SX initializes. -- cgit v1.2.3 From 4365d8f3cd693350a722b49b0f791670c16db6a8 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 6 Jan 2015 23:22:52 -0200 Subject: Define sx--format-user Use FORMAT-STRING to format the user object USER. --- sx-question-print.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/sx-question-print.el b/sx-question-print.el index e2db76f..d2c5249 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -402,6 +402,34 @@ URL is used as 'help-echo and 'url properties." 'sx-button-copy url :type 'sx-button-link)) +(defun sx--format-user (format-string user) + "Use FORMAT-STRING to format the user object USER. +The value is a copy of FORMAT-STRING, but with certain constructs +replaced by text that describes the specified USER: + +%d is the display name. +%l is the link to the profile. +%r is the reputation. +%a is the accept rate. + +The returned string is additionally propertized as a button with +the `sx-button-user' category." + (let-alist user + (let* ((link (or .link "")) + (text (sx-format-replacements + format-string + `((?d . ,(or .display_name "Unknown user")) + (?l . ,link) + (?r . ,(number-to-string (or .reputation 0))) + (?a . ,(number-to-string (or .accept_rate 0))))))) + (if link + (insert-text-button text + ;; For visiting and stuff. + 'sx-button-url link + 'sx-button-copy link + :type 'sx-button-user) + text)))) + (defun sx-question-mode-find-reference (id &optional fallback-id) "Find url identified by reference ID in current buffer. If ID is nil, use FALLBACK-ID instead." -- cgit v1.2.3 From 2fed944ba8c3bbf85b4c9eb225ff8a785597521b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 12:45:36 -0200 Subject: Improve sx-format-replacements to take a property-alist --- sx.el | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/sx.el b/sx.el index 6112510..f01a11d 100644 --- a/sx.el +++ b/sx.el @@ -337,14 +337,17 @@ removed from the display name before it is returned." (format "[%s]" (car kar)) (cdr kar) string))) string)) -(defun sx-format-replacements (format alist) +(defun sx-format-replacements (format alist &optional property-alist) "Use FORMAT-STRING to format the values in ALIST. ALIST is a list with elements of the form (CHAR . STRING). The value is a copy of FORMAT-STRING, but with certain constructs replaced by text as given by ALIST. The construct is a `%' character followed by any other character. -The replacement is the STRING corresponding to CHAR in ALIST. +The replacement is the STRING corresponding to CHAR in ALIST. In +addition, if CHAR is also the car of an element in +PROPERTY-ALIST, the cdr of that element should be a list of text +properties which will be applied on the replacement. The %% construct is special, it is replaced with a single %, even if ALIST contains a different string at the ?% entry." @@ -352,12 +355,22 @@ if ALIST contains a different string at the ?% entry." (with-temp-buffer (insert format) (goto-char (point-min)) - (while (search-forward "%" nil 'noerror) - (delete-char -1) - (unless (eobp) - (insert - (or (cdr (assq (char-after) alist)) - (error "ALIST has no value for `%c'" (char-after)))) + (while (search-forward-regexp + (rx "%" (group-n 1 (* (any "-+ #0-9.")))) nil 'noerror) + (let* ((char (char-after)) + ;; Understand flags + (flag (match-string 1)) + (val (cdr-safe (assq char alist)))) + (unless val + (error "Invalid format character: `%%%c'" char)) + ;; Insert first, to preserve text properties. + (insert-and-inherit + (apply #'propertize + (format (concat "%" flag "s") val) + (cdr-safe (assq char property-alist)))) + ;; Delete the specifier body. + (replace-match "") + ;; Delete `char-after'. (delete-char 1))) (buffer-string)))) -- cgit v1.2.3 From 77c0fa3803d3f6827dd6287fdbee70405c7a146a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 14:21:49 -0200 Subject: Change deleted-user to fallback-user --- sx-question-print.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index d2c5249..0bf5479 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -41,10 +41,16 @@ ;;; Faces and Variables -(defcustom sx-question-mode-deleted-user - '((display_name . "(deleted user)")) +(defconst sx-question-mode-fallback-user + '((display_name . "(unknown user)") + (link . "") + (reputation . -1) + (accept_rate . -1)) "The structure used to represent a deleted account." - :type '(alist :options ((display_name string))) + :type '(alist :options ((display_name string) + (link string) + (reputation integer) + (accept_rate integer))) :group 'sx-question-mode) (defface sx-question-mode-header @@ -217,7 +223,7 @@ DATA can represent a question or an answer." (format sx-question-mode-last-edit-format (sx-time-since .last_edit_date) (sx-question-mode--propertize-display-name - (or .last_editor sx-question-mode-deleted-user))))) + (or .last_editor sx-question-mode-fallback-user))))) 'sx-question-mode-date) (sx-question-mode--insert-header sx-question-mode-header-score -- cgit v1.2.3 From 5584905198e5f3b4db68cdd9373b4172885d0d43 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 14:22:28 -0200 Subject: Use fallback user in sx--format-user --- sx-question-print.el | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index 0bf5479..e4b8850 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -420,14 +420,14 @@ replaced by text that describes the specified USER: The returned string is additionally propertized as a button with the `sx-button-user' category." - (let-alist user - (let* ((link (or .link "")) - (text (sx-format-replacements + (sx-assoc-let (append user sx-question-mode-fallback-user) + (let* ((text (sx-format-replacements format-string - `((?d . ,(or .display_name "Unknown user")) - (?l . ,link) - (?r . ,(number-to-string (or .reputation 0))) - (?a . ,(number-to-string (or .accept_rate 0))))))) + `((?d . ,.display_name) + (?l . ,.link) + (?r . ,.reputation) + (?a . ,.accept_rate)) + sx-user-property-alist))) (if link (insert-text-button text ;; For visiting and stuff. -- cgit v1.2.3 From ea5bd0a5a03976b8b5bf62645f1e5623e805db8b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 14:30:33 -0200 Subject: Delete duplicate face definition --- sx-question-print.el | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index e4b8850..0f54e6e 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -73,11 +73,6 @@ :type 'string :group 'sx-question-mode) -(defface sx-question-mode-author - '((t :inherit font-lock-string-face)) - "Face used on the question author in the question buffer." - :group 'sx-question-mode-faces) - (defcustom sx-question-mode-header-author "\nAuthor: " "String used before the question author at the header." :type 'string -- cgit v1.2.3 From 3b86d82a1a199a98bdb1bae8cc991807afa6a035 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 14:31:19 -0200 Subject: Use sx--format-user instead of propertize-display-name --- sx-question-print.el | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index 0f54e6e..0efea98 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -208,7 +208,7 @@ DATA can represent a question or an answer." (sx-question-mode--insert-header ;; Author sx-question-mode-header-author - (sx-question-mode--propertize-display-name .owner) + (sx--format-user .owner) 'sx-question-mode-author ;; Date sx-question-mode-header-date @@ -217,8 +217,7 @@ DATA can represent a question or an answer." (when .last_edit_date (format sx-question-mode-last-edit-format (sx-time-since .last_edit_date) - (sx-question-mode--propertize-display-name - (or .last_editor sx-question-mode-fallback-user))))) + (sx--format-user "%n" .last_editor)))) 'sx-question-mode-date) (sx-question-mode--insert-header sx-question-mode-header-score @@ -274,12 +273,6 @@ DATA can represent a question or an answer." :type 'sx-button-comment) (insert "\n"))))) -(defun sx-question-mode--propertize-display-name (author) - "Return display_name of AUTHOR with `sx-question-mode-author' face." - (sx-assoc-let author - (propertize (or .display_name "??") - 'face 'sx-question-mode-author))) - (defun sx-question-mode--print-comment (comment-data) "Print the comment described by alist COMMENT-DATA. The comment is indented, filled, and then printed according to @@ -292,9 +285,8 @@ The comment is indented, filled, and then printed according to (if (eq .upvoted t) "^" "") " ")) (insert - (format - sx-question-mode-comments-format - (sx-question-mode--propertize-display-name .owner) + (format sx-question-mode-comments-format + (sx--format-user "%n" .owner) (substring ;; We fill with three spaces at the start, so the comment is ;; slightly indented. -- cgit v1.2.3 From 304217c1ac70ee7dc6f7e4c16410fca73b11c515 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 14:44:24 -0200 Subject: Move user-printing to sx-user --- sx-question-print.el | 34 +----------------------- sx-user.el | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 33 deletions(-) create mode 100644 sx-user.el diff --git a/sx-question-print.el b/sx-question-print.el index 0efea98..a8604e0 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -26,6 +26,7 @@ (require 'sx) (require 'sx-question) (require 'sx-babel) +(require 'sx-user) (defgroup sx-question-mode nil "Customization group for sx-question-mode." @@ -93,11 +94,6 @@ "Face used on the question tags in the question buffer." :group 'sx-question-mode-faces) -(defface sx-question-mode-author - '((t :inherit font-lock-variable-name-face)) - "Face used for author names in the question buffer." - :group 'sx-question-mode-faces) - (defface sx-question-mode-score '((t)) "Face used for the score in the question buffer." @@ -395,34 +391,6 @@ URL is used as 'help-echo and 'url properties." 'sx-button-copy url :type 'sx-button-link)) -(defun sx--format-user (format-string user) - "Use FORMAT-STRING to format the user object USER. -The value is a copy of FORMAT-STRING, but with certain constructs -replaced by text that describes the specified USER: - -%d is the display name. -%l is the link to the profile. -%r is the reputation. -%a is the accept rate. - -The returned string is additionally propertized as a button with -the `sx-button-user' category." - (sx-assoc-let (append user sx-question-mode-fallback-user) - (let* ((text (sx-format-replacements - format-string - `((?d . ,.display_name) - (?l . ,.link) - (?r . ,.reputation) - (?a . ,.accept_rate)) - sx-user-property-alist))) - (if link - (insert-text-button text - ;; For visiting and stuff. - 'sx-button-url link - 'sx-button-copy link - :type 'sx-button-user) - text)))) - (defun sx-question-mode-find-reference (id &optional fallback-id) "Find url identified by reference ID in current buffer. If ID is nil, use FALLBACK-ID instead." diff --git a/sx-user.el b/sx-user.el new file mode 100644 index 0000000..975d5ef --- /dev/null +++ b/sx-user.el @@ -0,0 +1,73 @@ +;;; sx-user.el --- handling and printing user information -*- lexical-binding: t; -*- + +;; Copyright (C) 2014 Artur Malabarba + +;; Author: Artur Malabarba + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + + +;;; Code: +(require 'sx) +(require 'sx-button) + +(defgroup sx-user nil + "Customization group for sx-question-mode." + :prefix "sx-user-" + :tag "SX Question Mode" + :group 'sx) + +(defvar sx--user-format-property-alist + '((?d face sx-question-mode-author) + (?r face sx-question-mode-reputation) + (?a face sx-question-mode-accept-rate)) + "Alist relating % constructs with text properties. +See `sx--user-format'.") + +(defun sx--user-format (format-string user) + "Use FORMAT-STRING to format the user object USER. +The value is a copy of FORMAT-STRING, but with certain constructs +replaced by text that describes the specified USER: + +%d is the display name. +%l is the link to the profile. +%r is the reputation. +%a is the accept rate. + +The returned string is additionally propertized as a button with +the `sx-button-user' category." + (sx-assoc-let (append user sx-question-mode-fallback-user) + (let* ((text (sx-format-replacements + format-string + `((?d . ,.display_name) + (?l . ,.link) + (?r . ,.reputation) + (?a . ,.accept_rate)) + sx--format-user-property-alist))) + (if link + (insert-text-button text + ;; For visiting and stuff. + 'sx-button-url link + 'sx-button-copy link + :type 'sx-button-user) + text)))) + +(provide 'sx-user) +;;; sx-user.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: -- cgit v1.2.3 From b61d953576c2e46678777d5838c54a92093485c7 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 14:44:42 -0200 Subject: Change sx-question-mode-header-author to sx-question-mode-header-author-format --- sx-question-print.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index a8604e0..3ae86fc 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -74,8 +74,9 @@ :type 'string :group 'sx-question-mode) -(defcustom sx-question-mode-header-author "\nAuthor: " - "String used before the question author at the header." +(defcustom sx-question-mode-header-author-format "\nAuthor: %n %r" + "String used to display the question author at the header. +% constructs have special meaning here. See `sx--user-format'." :type 'string :group 'sx-question-mode) @@ -201,11 +202,12 @@ DATA can represent a question or an answer." ;; Sections can be hidden with overlays (sx--wrap-in-overlay '(sx-question-mode--section-content t) + ;; Author + (sx--format-user + (propertize sx-question-mode-header-author-format + 'face 'sx-question-mode-header) + .owner) (sx-question-mode--insert-header - ;; Author - sx-question-mode-header-author - (sx--format-user .owner) - 'sx-question-mode-author ;; Date sx-question-mode-header-date (concat -- cgit v1.2.3 From d2e808eae7565cefb95becd05628ae69f2980e25 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 15:08:58 -0200 Subject: Move fallback-user to sx-user, and improve it --- sx-question-print.el | 12 -------- sx-user.el | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 12 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index 3ae86fc..6ab7698 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -42,18 +42,6 @@ ;;; Faces and Variables -(defconst sx-question-mode-fallback-user - '((display_name . "(unknown user)") - (link . "") - (reputation . -1) - (accept_rate . -1)) - "The structure used to represent a deleted account." - :type '(alist :options ((display_name string) - (link string) - (reputation integer) - (accept_rate integer))) - :group 'sx-question-mode) - (defface sx-question-mode-header '((t :inherit font-lock-variable-name-face)) "Face used on the question headers in the question buffer." diff --git a/sx-user.el b/sx-user.el index 975d5ef..d09faf0 100644 --- a/sx-user.el +++ b/sx-user.el @@ -30,6 +30,86 @@ :tag "SX Question Mode" :group 'sx) +(defcustom sx-question-mode-fallback-user + '( + (about_me . "") + (accept_rate . -1) + (account_id . -1) + (age . -1) + (answer_count . -1) + (badge_counts . ((bronze . -1) (silver . -1) (gold . -1))) + (creation_date . -1) + (display_name . "(unknown user)") + (down_vote_count . -1) + (is_employee . :json-false) + (last_access_date . -1) + (last_modified_date . -1) + (link . "") + (location . "") + (profile_image . ":(") + (question_count . -1) + (reputation . -1) + (reputation_change_day . -1) + (reputation_change_month . -1) + (reputation_change_quarter . -1) + (reputation_change_week . -1) + (reputation_change_year . -1) + (timed_penalty_date . -1) + (up_vote_count . -1) + (user_id . -1) + (user_type . does_not_exist) + (view_count . -1) + (website_url . "") + ) + "The structure used to represent missing user information. +NOOTE: SX relies on this variable containing all necessary user +information. You may edit any of its fields, but you'll run into +errors if you remove them." + :type '(alist :options ((about_me string) + (accept_rate integer) + (account_id integer) + (age integer) + (answer_count integer) + (badge_counts alist) + (creation_date integer) + (display_name string) + (down_vote_count integer) + (is_employee boolean) + (last_access_date integer) + (last_modified_date integer) + (link string) + (location string) + (profile_image string) + (question_count integer) + (reputation integer) + (reputation_change_day integer) + (reputation_change_month integer) + (reputation_change_quarter integer) + (reputation_change_week integer) + (reputation_change_year integer) + (timed_penalty_date integer) + (up_vote_count integer) + (user_id integer) + (user_type symbol) + (view_count integer) + (website_url string))) + :group 'sx-user) + +(defface sx-user-name + '((t :inherit font-lock-variable-name-face)) + "Face used for user names." + :group 'sx-user) + +(defface sx-user-reputation + '((t :inherit font-lock-function-name-face)) + "Face used for user reputations." + :group 'sx-user) + +(defface sx-user-accept-rate + '((t)) + "Face used for user accept-rates." + :group 'sx-user) + (defvar sx--user-format-property-alist '((?d face sx-question-mode-author) (?r face sx-question-mode-reputation) -- cgit v1.2.3 From adbf1e311eaafbec2476fe08a5ba81672f25eb79 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 15:09:21 -0200 Subject: Fix some migration left-overs --- sx-question-print.el | 20 +++++++++++--------- sx-user.el | 29 ++++++++++++++++------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index 6ab7698..66ae922 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -34,8 +34,9 @@ :tag "SX Question Mode" :group 'sx) -(defgroup sx-question-mode-faces nil - "Customization group for the faces of `sx-question-mode'." +(defgroup sx-question-mode-faces '((sx-user custom-group)) + "Customization group for the faces of `sx-question-mode'. +Some faces of this mode might be defined in the `sx-user' group." :prefix "sx-question-mode-" :tag "SX Question Mode Faces" :group 'sx-question-mode) @@ -62,7 +63,7 @@ :type 'string :group 'sx-question-mode) -(defcustom sx-question-mode-header-author-format "\nAuthor: %n %r" +(defcustom sx-question-mode-header-author-format "\nAuthor: %d %r" "String used to display the question author at the header. % constructs have special meaning here. See `sx--user-format'." :type 'string @@ -191,10 +192,11 @@ DATA can represent a question or an answer." (sx--wrap-in-overlay '(sx-question-mode--section-content t) ;; Author - (sx--format-user - (propertize sx-question-mode-header-author-format - 'face 'sx-question-mode-header) - .owner) + (insert + (sx--user-format + (propertize sx-question-mode-header-author-format + 'face 'sx-question-mode-header) + .owner)) (sx-question-mode--insert-header ;; Date sx-question-mode-header-date @@ -203,7 +205,7 @@ DATA can represent a question or an answer." (when .last_edit_date (format sx-question-mode-last-edit-format (sx-time-since .last_edit_date) - (sx--format-user "%n" .last_editor)))) + (sx--user-format "%d" .last_editor)))) 'sx-question-mode-date) (sx-question-mode--insert-header sx-question-mode-header-score @@ -272,7 +274,7 @@ The comment is indented, filled, and then printed according to " ")) (insert (format sx-question-mode-comments-format - (sx--format-user "%n" .owner) + (sx--user-format "%d" .owner) (substring ;; We fill with three spaces at the start, so the comment is ;; slightly indented. diff --git a/sx-user.el b/sx-user.el index d09faf0..362f1e3 100644 --- a/sx-user.el +++ b/sx-user.el @@ -25,9 +25,9 @@ (require 'sx-button) (defgroup sx-user nil - "Customization group for sx-question-mode." + "How users are displayed by SX." :prefix "sx-user-" - :tag "SX Question Mode" + :tag "SX User" :group 'sx) (defcustom sx-question-mode-fallback-user @@ -111,12 +111,14 @@ errors if you remove them." :group 'sx-user) (defvar sx--user-format-property-alist - '((?d face sx-question-mode-author) - (?r face sx-question-mode-reputation) - (?a face sx-question-mode-accept-rate)) + '((?d face sx-user-name) + (?r face sx-user-reputation) + (?a face sx-user-accept-rate)) "Alist relating % constructs with text properties. See `sx--user-format'.") + +;;; Formatting function (defun sx--user-format (format-string user) "Use FORMAT-STRING to format the user object USER. The value is a copy of FORMAT-STRING, but with certain constructs @@ -132,16 +134,17 @@ the `sx-button-user' category." (sx-assoc-let (append user sx-question-mode-fallback-user) (let* ((text (sx-format-replacements format-string - `((?d . ,.display_name) - (?l . ,.link) - (?r . ,.reputation) - (?a . ,.accept_rate)) - sx--format-user-property-alist))) - (if link + `((?d . ,\.display_name) + (?n . ,\.display_name) + (?l . ,\.link) + (?r . ,\.reputation) + (?a . ,\.accept_rate)) + sx--user-format-property-alist))) + (if (> 0 (string-width .link)) (insert-text-button text ;; For visiting and stuff. - 'sx-button-url link - 'sx-button-copy link + 'sx-button-url .link + 'sx-button-copy .link :type 'sx-button-user) text)))) -- cgit v1.2.3 From c46dd1cde6d8428a73be0f2e6918b701af541004 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 15:46:13 -0200 Subject: Fix sx-format-replacements replace-match moves point --- sx.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sx.el b/sx.el index f01a11d..4159933 100644 --- a/sx.el +++ b/sx.el @@ -369,7 +369,8 @@ if ALIST contains a different string at the ?% entry." (format (concat "%" flag "s") val) (cdr-safe (assq char property-alist)))) ;; Delete the specifier body. - (replace-match "") + (delete-region (match-beginning 0) + (match-end 0)) ;; Delete `char-after'. (delete-char 1))) (buffer-string)))) -- cgit v1.2.3 From dc98b2bd2a7b805e5d3c8a410bcaf137cd4cf78a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 15:54:53 -0200 Subject: sx-format-replacements: Fix propertizing --- sx.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sx.el b/sx.el index 4159933..d67771b 100644 --- a/sx.el +++ b/sx.el @@ -364,10 +364,10 @@ if ALIST contains a different string at the ?% entry." (unless val (error "Invalid format character: `%%%c'" char)) ;; Insert first, to preserve text properties. - (insert-and-inherit - (apply #'propertize - (format (concat "%" flag "s") val) - (cdr-safe (assq char property-alist)))) + (insert-and-inherit (format (concat "%" flag "s") val)) + (when property-alist + (add-text-properties (match-end 0) (point) + (cdr-safe (assq char property-alist)))) ;; Delete the specifier body. (delete-region (match-beginning 0) (match-end 0)) -- cgit v1.2.3 From 0da0edda16757f2ec16e645288ba2cd49786f169 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 15:55:44 -0200 Subject: Better faces --- sx-user.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sx-user.el b/sx-user.el index 362f1e3..fe620ca 100644 --- a/sx-user.el +++ b/sx-user.el @@ -96,12 +96,12 @@ errors if you remove them." :group 'sx-user) (defface sx-user-name - '((t :inherit font-lock-variable-name-face)) + '((t :inherit font-lock-function-name-face)) "Face used for user names." :group 'sx-user) (defface sx-user-reputation - '((t :inherit font-lock-function-name-face)) + '((t :inherit font-lock-string-face)) "Face used for user reputations." :group 'sx-user) -- cgit v1.2.3 From 5e29ea61e86c399cb966fc2299566d43694c2cfe Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 16:29:09 -0200 Subject: Move @name to sx-user --- sx-user.el | 42 ++++++++++++++++++++++++++++++++++++++++++ sx.el | 33 --------------------------------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/sx-user.el b/sx-user.el index fe620ca..2e8c89a 100644 --- a/sx-user.el +++ b/sx-user.el @@ -148,6 +148,48 @@ the `sx-button-user' category." :type 'sx-button-user) text)))) + +;;; @name conversion +(defconst sx-user--ascii-replacement-list + '(("[:space:]" . "") + ("àåáâäãåą" . "a") + ("èéêëę" . "e") + ("ìíîïı" . "i") + ("òóôõöøőð" . "o") + ("ùúûüŭů" . "u") + ("çćčĉ" . "c") + ("żźž" . "z") + ("śşšŝ" . "s") + ("ñń" . "n") + ("ýÿ" . "y") + ("ğĝ" . "g") + ("ř" . "r") + ("ł" . "l") + ("đ" . "d") + ("ß" . "ss") + ("Þ" . "th") + ("ĥ" . "h") + ("ĵ" . "j") + ("^[:ascii:]" . "")) + "List of replacements to use for non-ascii characters. +Used to convert user names into @mentions.") + +(defun sx-user--@name (user) + "Get the `display_name' of USER prepended with @. +In order to correctly @mention the user, all whitespace is +removed from the display name and a series of unicode conversions +are performed before it is returned +See `sx-user--ascii-replacement-list'. + +If all you need is the @name, this is very slightly faster than +using `sx-user--format'." + (sx-assoc-let user + (if (stringp .display_name) + (concat "@" (sx--recursive-replace + sx-user--ascii-replacement-list .display_name)) + ;; "" + ))) + (provide 'sx-user) ;;; sx-user.el ends here diff --git a/sx.el b/sx.el index d67771b..36ecfca 100644 --- a/sx.el +++ b/sx.el @@ -294,39 +294,6 @@ Return the result of BODY." (push ov sx--overlays)) result)) -(defconst sx--ascii-replacement-list - '(("[:space:]" . "") - ("àåáâäãåą" . "a") - ("èéêëę" . "e") - ("ìíîïı" . "i") - ("òóôõöøőð" . "o") - ("ùúûüŭů" . "u") - ("çćčĉ" . "c") - ("żźž" . "z") - ("śşšŝ" . "s") - ("ñń" . "n") - ("ýÿ" . "y") - ("ğĝ" . "g") - ("ř" . "r") - ("ł" . "l") - ("đ" . "d") - ("ß" . "ss") - ("Þ" . "th") - ("ĥ" . "h") - ("ĵ" . "j") - ("^[:ascii:]" . "")) - "List of replacements to use for non-ascii characters. -Used to convert user names into @mentions.") - -(defun sx--user-@name (user) - "Get the `display_name' of USER prepended with @. -In order to correctly @mention the user, all whitespace is -removed from the display name before it is returned." - (sx-assoc-let user - (when (stringp .display_name) - (concat "@" (sx--recursive-replace - sx--ascii-replacement-list .display_name))))) - (defun sx--recursive-replace (alist string) "Replace each car of ALIST with its cdr in STRING." (if alist -- cgit v1.2.3 From 085c9d8d29aeb060b93db35e0c1076745ac9fe88 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 16:29:20 -0200 Subject: Change sx--user- to sx-user-- --- sx-user.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sx-user.el b/sx-user.el index 2e8c89a..e2aab49 100644 --- a/sx-user.el +++ b/sx-user.el @@ -110,16 +110,16 @@ errors if you remove them." "Face used for user accept-rates." :group 'sx-user) -(defvar sx--user-format-property-alist +(defvar sx-user--format-property-alist '((?d face sx-user-name) (?r face sx-user-reputation) (?a face sx-user-accept-rate)) "Alist relating % constructs with text properties. -See `sx--user-format'.") +See `sx-user--format'.") ;;; Formatting function -(defun sx--user-format (format-string user) +(defun sx-user--format (format-string user) "Use FORMAT-STRING to format the user object USER. The value is a copy of FORMAT-STRING, but with certain constructs replaced by text that describes the specified USER: @@ -139,7 +139,7 @@ the `sx-button-user' category." (?l . ,\.link) (?r . ,\.reputation) (?a . ,\.accept_rate)) - sx--user-format-property-alist))) + sx-user--format-property-alist))) (if (> 0 (string-width .link)) (insert-text-button text ;; For visiting and stuff. -- cgit v1.2.3 From 49ee9fc6aa1702cfaf3f67b193eb7c888d23f8d2 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 16:29:47 -0200 Subject: Typo --- sx-user.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sx-user.el b/sx-user.el index e2aab49..7a07d03 100644 --- a/sx-user.el +++ b/sx-user.el @@ -187,8 +187,7 @@ using `sx-user--format'." (if (stringp .display_name) (concat "@" (sx--recursive-replace sx-user--ascii-replacement-list .display_name)) - ;; "" - ))) + ""))) (provide 'sx-user) ;;; sx-user.el ends here -- cgit v1.2.3 From 74790a11bc19fbdeae054816962b2160461767f4 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 16:36:07 -0200 Subject: Make sx-user--@name take a string. --- sx-user.el | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/sx-user.el b/sx-user.el index 7a07d03..fe05057 100644 --- a/sx-user.el +++ b/sx-user.el @@ -174,20 +174,17 @@ the `sx-button-user' category." "List of replacements to use for non-ascii characters. Used to convert user names into @mentions.") -(defun sx-user--@name (user) - "Get the `display_name' of USER prepended with @. +(defun sx-user--@name (display-name) + "Convert DISPLAY-NAME into an @mention. In order to correctly @mention the user, all whitespace is -removed from the display name and a series of unicode conversions -are performed before it is returned +removed from DISPLAY-NAME and a series of unicode conversions are +performed before it is returned. See `sx-user--ascii-replacement-list'. If all you need is the @name, this is very slightly faster than -using `sx-user--format'." - (sx-assoc-let user - (if (stringp .display_name) - (concat "@" (sx--recursive-replace - sx-user--ascii-replacement-list .display_name)) - ""))) +using `sx-user--format', but it doesn't do any sanity checking." + (concat "@" (sx--recursive-replace + sx-user--ascii-replacement-list display-name))) (provide 'sx-user) ;;; sx-user.el ends here -- cgit v1.2.3 From 09423c2e8f40638a8438cd76783a21d0eb7ed492 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 16:36:35 -0200 Subject: Add %@ support to sx-user--format --- sx-user.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sx-user.el b/sx-user.el index fe05057..c533744 100644 --- a/sx-user.el +++ b/sx-user.el @@ -125,6 +125,7 @@ The value is a copy of FORMAT-STRING, but with certain constructs replaced by text that describes the specified USER: %d is the display name. +%@ is the display name in a format suitable for @mentions. %l is the link to the profile. %r is the reputation. %a is the accept rate. @@ -138,7 +139,10 @@ the `sx-button-user' category." (?n . ,\.display_name) (?l . ,\.link) (?r . ,\.reputation) - (?a . ,\.accept_rate)) + (?a . ,\.accept_rate) + (?@ . ,(when (string-match "%@" format-string) + (sx-user--@name .display_name))) + ) sx-user--format-property-alist))) (if (> 0 (string-width .link)) (insert-text-button text -- cgit v1.2.3 From a582fa9da166983076460ba8a245a86a1330f8fb Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 16:37:53 -0200 Subject: Indentation --- sx-user.el | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/sx-user.el b/sx-user.el index c533744..df7d82f 100644 --- a/sx-user.el +++ b/sx-user.el @@ -155,25 +155,25 @@ the `sx-button-user' category." ;;; @name conversion (defconst sx-user--ascii-replacement-list - '(("[:space:]" . "") - ("àåáâäãåą" . "a") - ("èéêëę" . "e") - ("ìíîïı" . "i") - ("òóôõöøőð" . "o") - ("ùúûüŭů" . "u") - ("çćčĉ" . "c") - ("żźž" . "z") - ("śşšŝ" . "s") - ("ñń" . "n") - ("ýÿ" . "y") - ("ğĝ" . "g") - ("ř" . "r") - ("ł" . "l") - ("đ" . "d") - ("ß" . "ss") - ("Þ" . "th") - ("ĥ" . "h") - ("ĵ" . "j") + '(("[:space:]" . "") + ("àåáâäãåą" . "a") + ("èéêëę" . "e") + ("ìíîïı" . "i") + ("òóôõöøőð" . "o") + ("ùúûüŭů" . "u") + ("çćčĉ" . "c") + ("żźž" . "z") + ("śşšŝ" . "s") + ("ñń" . "n") + ("ýÿ" . "y") + ("ğĝ" . "g") + ("ř" . "r") + ("ł" . "l") + ("đ" . "d") + ("ß" . "ss") + ("Þ" . "th") + ("ĥ" . "h") + ("ĵ" . "j") ("^[:ascii:]" . "")) "List of replacements to use for non-ascii characters. Used to convert user names into @mentions.") -- cgit v1.2.3 From db309722e660c2861fe3a08108cf7352a577a41f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 17:08:25 -0200 Subject: Use sx-user--format in the question list --- sx-question-list.el | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/sx-question-list.el b/sx-question-list.el index 1b7fe5a..fd2c20e 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -111,16 +111,6 @@ "" :group 'sx-question-list-faces) -(defface sx-question-list-reputation - '((t :inherit sx-question-list-date)) - "" - :group 'sx-question-list-faces) - -(defface sx-question-list-user - '((t :inherit font-lock-builtin-face)) - "" - :group 'sx-question-list-faces) - ;;; Backend variables (defvar sx-question-list--print-function #'sx-question-list--print-info @@ -182,11 +172,7 @@ Also see `sx-question-list-refresh'." (propertize (format "%-40s" (mapconcat #'sx-question--tag-format .tags " ")) 'face 'sx-question-list-tags) " " - (let-alist .owner - (format "%15s %5s" - (propertize (or .display_name "") 'face 'sx-question-list-user) - (propertize (number-to-string (or .reputation 0)) - 'face 'sx-question-list-reputation))) + (sx-user--format "%15d %4r" .owner) (propertize " " 'display "\n"))))))) (defvar sx-question-list--pages-so-far 0 -- cgit v1.2.3 From 65000b68e9f8db743081c1a36acd31222b666a56 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 17:08:50 -0200 Subject: Face changes --- sx-user.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sx-user.el b/sx-user.el index df7d82f..44456a0 100644 --- a/sx-user.el +++ b/sx-user.el @@ -96,12 +96,12 @@ errors if you remove them." :group 'sx-user) (defface sx-user-name - '((t :inherit font-lock-function-name-face)) + '((t :inherit font-lock-builtin-face)) "Face used for user names." :group 'sx-user) (defface sx-user-reputation - '((t :inherit font-lock-string-face)) + '((t :inherit font-lock-comment-face)) "Face used for user reputations." :group 'sx-user) -- cgit v1.2.3 From 524bd12ca222d054776a195f8829c75b17699fa3 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 17:10:20 -0200 Subject: Add link and accept_rate to user filter --- sx-filter.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sx-filter.el b/sx-filter.el index a3f6861..af3717f 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -128,8 +128,12 @@ return the compiled filter." question_id share_link) (user display_name + link + accept_rate reputation) (shallow_user display_name + link + accept_rate reputation) (comment owner body_markdown -- cgit v1.2.3 From ff92c3cf289b9109ad4b3b304bad06a40534fda2 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 17:15:22 -0200 Subject: Update doctring --- sx-question-list.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sx-question-list.el b/sx-question-list.el index fd2c20e..884f994 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -128,8 +128,9 @@ change `tabulated-list-format' accordingly.") This is the default printer used by `sx-question-list'. It assumes QUESTION-DATA is an alist containing (at least) the elements: - `site', `score', `upvoted', `answer_count', `title', - `last_activity_date', `tags', `uestion_id'. + `question_id', `site_par', `score', `upvoted', `answer_count', + `title', `bounty_amount', `bounty_amount', `bounty_amount', + `last_activity_date', `tags', `owner'. Also see `sx-question-list-refresh'." (sx-assoc-let question-data -- cgit v1.2.3 From 1509d09a5ed073688a316660b5e3a2222dbebfca Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 17:20:57 -0200 Subject: Fix outdated references --- sx-interaction.el | 2 +- sx-question-print.el | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sx-interaction.el b/sx-interaction.el index 4d71c17..e444248 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -272,7 +272,7 @@ TEXT is a string. Interactively, it is read from the minibufer." (setq text (read-string "Comment text: " (when .comment_id - (concat (sx--user-@name .owner) " ")))) + (concat (sx-user--format "%@" .owner) " ")))) (while (not (sx--comment-valid-p text 'silent)) (setq text (read-string "Comment text (between 16 and 600 characters): " text)))) ;; If non-interactive, `text' could be anything. diff --git a/sx-question-print.el b/sx-question-print.el index 66ae922..37fa238 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -65,7 +65,7 @@ Some faces of this mode might be defined in the `sx-user' group." (defcustom sx-question-mode-header-author-format "\nAuthor: %d %r" "String used to display the question author at the header. -% constructs have special meaning here. See `sx--user-format'." +% constructs have special meaning here. See `sx-user--format'." :type 'string :group 'sx-question-mode) @@ -193,7 +193,7 @@ DATA can represent a question or an answer." '(sx-question-mode--section-content t) ;; Author (insert - (sx--user-format + (sx-user--format (propertize sx-question-mode-header-author-format 'face 'sx-question-mode-header) .owner)) @@ -205,7 +205,7 @@ DATA can represent a question or an answer." (when .last_edit_date (format sx-question-mode-last-edit-format (sx-time-since .last_edit_date) - (sx--user-format "%d" .last_editor)))) + (sx-user--format "%d" .last_editor)))) 'sx-question-mode-date) (sx-question-mode--insert-header sx-question-mode-header-score @@ -274,7 +274,7 @@ The comment is indented, filled, and then printed according to " ")) (insert (format sx-question-mode-comments-format - (sx--user-format "%d" .owner) + (sx-user--format "%d" .owner) (substring ;; We fill with three spaces at the start, so the comment is ;; slightly indented. -- cgit v1.2.3 From 7ea2edd6e54cf4dd257a32555fec4489d510eaf6 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 17:59:51 -0200 Subject: Only display_name and @name are turned into buttons --- sx-button.el | 2 +- sx-user.el | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/sx-button.el b/sx-button.el index 8309543..a459eb4 100644 --- a/sx-button.el +++ b/sx-button.el @@ -155,7 +155,7 @@ usually part of a code-block." 'action #'sx-button-follow-link 'help-echo sx-button--user-help-echo ;; We use different faces on diferent parts of the user button. - 'face nil + 'face 'sx-user-name :supertype 'sx-button) (define-button-type 'sx-button-comment diff --git a/sx-user.el b/sx-user.el index 44456a0..c0f3a78 100644 --- a/sx-user.el +++ b/sx-user.el @@ -95,6 +95,8 @@ errors if you remove them." (website_url string))) :group 'sx-user) + +;;; Text properties (defface sx-user-name '((t :inherit font-lock-builtin-face)) "Face used for user names." @@ -111,7 +113,9 @@ errors if you remove them." :group 'sx-user) (defvar sx-user--format-property-alist - '((?d face sx-user-name) + `((?d button ,(list t) category ,(button-category-symbol 'sx-button-user)) + (?n button ,(list t) category ,(button-category-symbol 'sx-button-user)) + (?@ button ,(list t) category ,(button-category-symbol 'sx-button-user)) (?r face sx-user-reputation) (?a face sx-user-accept-rate)) "Alist relating % constructs with text properties. @@ -130,8 +134,10 @@ replaced by text that describes the specified USER: %r is the reputation. %a is the accept rate. -The returned string is additionally propertized as a button with -the `sx-button-user' category." +The string replaced in each of these construct is also given the +text-properties specified in `sx-user--format-property-alist'. +Specially, %d and %@ are turned into buttons with the +`sx-button-user' category." (sx-assoc-let (append user sx-question-mode-fallback-user) (let* ((text (sx-format-replacements format-string @@ -144,12 +150,11 @@ the `sx-button-user' category." (sx-user--@name .display_name))) ) sx-user--format-property-alist))) - (if (> 0 (string-width .link)) - (insert-text-button text - ;; For visiting and stuff. - 'sx-button-url .link - 'sx-button-copy .link - :type 'sx-button-user) + (if (< 0 (string-width .link)) + (propertize text + ;; For visiting and stuff. + 'sx-button-url .link + 'sx-button-copy .link) text)))) -- cgit v1.2.3 From 39dbc7379da010cc3bae479fa70d9724acf169f5 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 18:01:25 -0200 Subject: Don't propertize when composing a comment --- sx-interaction.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-interaction.el b/sx-interaction.el index e444248..9e96228 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -272,7 +272,7 @@ TEXT is a string. Interactively, it is read from the minibufer." (setq text (read-string "Comment text: " (when .comment_id - (concat (sx-user--format "%@" .owner) " ")))) + (substring-no-properties (sx-user--format "%@ " .owner))))) (while (not (sx--comment-valid-p text 'silent)) (setq text (read-string "Comment text (between 16 and 600 characters): " text)))) ;; If non-interactive, `text' could be anything. -- cgit v1.2.3 From afc89bf0482698163fb0d3faa1b679418e84061d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 18:06:42 -0200 Subject: Fix tests --- test/test-printing.el | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/test-printing.el b/test/test-printing.el index 2857cb7..7eb5853 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -64,10 +64,21 @@ after being run through `sx-question--tag-format'." "Test `sx--user-@name' character substitution" (should (string= - (sx--user-@name '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★"))) + (sx-user--@name "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★") "@hTHssdlrggyynnsssszzzccccuuuuuuooooooooiiiiieeeeeaaaaaaaaj")) (should (string= - (sx--user-@name '((display_name . "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ"))) + (sx-user--@name "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ") + "@HTHssDLRGGYYNNSSSSZZZCCCCUUUUUUOOOOOOOOIIIIiEEEEEAAAAAAAAJ"))) + +(ert-deftest sx-user--format () + "Test various `sx-user--format' features." + (should + (string= + (sx-user--format "%@" '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★"))) + "@hTHssdlrggyynnsssszzzccccuuuuuuooooooooiiiiieeeeeaaaaaaaaj")) + (should + (string= + (sx-user--format "%@" '((display_name . "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ"))) "@HTHssDLRGGYYNNSSSSZZZCCCCUUUUUUOOOOOOOOIIIIiEEEEEAAAAAAAAJ"))) -- cgit v1.2.3 From ad81dcacfe9ddf57f7e4a113fc14b0a1dce0dcdd Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 18:33:46 -0200 Subject: A few more tests --- test/test-printing.el | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/test/test-printing.el b/test/test-printing.el index 7eb5853..2fe1839 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -69,16 +69,31 @@ after being run through `sx-question--tag-format'." (should (string= (sx-user--@name "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ") - "@HTHssDLRGGYYNNSSSSZZZCCCCUUUUUUOOOOOOOOIIIIiEEEEEAAAAAAAAJ"))) + "@HTHssDLRGGYYNNSSSSZZZCCCCUUUUUUOOOOOOOOIIIIiEEEEEAAAAAAAAJ")) + (should-error + (sx-user--@name 2))) (ert-deftest sx-user--format () "Test various `sx-user--format' features." + (let ((user + '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★") + (accept_rate . 90) + (reputation . 10) + (link . "link")))) + (should + (equal (sx-user--format "%l" user) "link")) + (should + (equal + (sx-user--format "%@" user) + "@hTHssdlrggyynnsssszzzccccuuuuuuooooooooiiiiieeeeeaaaaaaaaj")) + (should + (equal + (sx-user--format "%@%%d%%%-30d %9r%l" user) + "@hTHssdlrggyynnsssszzzccccuuuuuuooooooooiiiiieeeeeaaaaaaaaj%d%ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★ 10link"))) (should (string= - (sx-user--format "%@" '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★"))) "@hTHssdlrggyynnsssszzzccccuuuuuuooooooooiiiiieeeeeaaaaaaaaj")) (should (string= (sx-user--format "%@" '((display_name . "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ"))) "@HTHssDLRGGYYNNSSSSZZZCCCCUUUUUUOOOOOOOOIIIIiEEEEEAAAAAAAAJ"))) - -- cgit v1.2.3 From 95e9f6069ba328249c0e8ac86efdc888437ac187 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Wed, 7 Jan 2015 16:00:59 -0500 Subject: Hotfix Travis/Gitter integration It was broken when the repository URL changed -- I just never noticed until now. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d00ab46..067fa62 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ script: notifications: webhooks: urls: - - https://webhooks.gitter.im/e/07063bd143e35f54b1e8 + - https://webhooks.gitter.im/e/77b562dfc62ea5cd545a on_success: change # options: [always|never|change] default: always on_failure: always # options: [always|never|change] default: always on_start: false # default: false -- cgit v1.2.3 From 726b372ee56a367fd2dc366e05667bbd80282962 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 19:12:44 -0200 Subject: Fix unkown owner after creating a comment. --- sx-interaction.el | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sx-interaction.el b/sx-interaction.el index 9e96228..6ecfa38 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -291,10 +291,8 @@ TEXT is a string. Interactively, it is read from the minibufer." ;; The api returns the new DATA. (when (> (length result) 0) (sx--add-comment-to-object - (elt result 0) - (if .post_id - (sx--get-post .post_type .site_par .post_id) - data)) + (sx--add-owner-to-object (list (cons 'display_name "(You)")) (elt result 0)) + (if .post_id (sx--get-post .post_type .site_par .post_id) data)) ;; Display the changes in `data'. (sx--maybe-update-display))))) @@ -344,7 +342,15 @@ OBJECT can be a question or an answer." (list comment))))) ;; No previous comments, add it manually. (setcdr object (cons (car object) (cdr object))) - (setcar object `(comments . [,comment]))))) + (setcar object `(comments . [,comment])))) + object) + +(defun sx--add-owner-to-object (owner object) + "Add `owner' property with value OWNER to OBJECT." + (unless (cdr-safe (assq 'owner object)) + (setcdr object (cons (car object) (cdr object))) + (setcar object `(owner . ,owner))) + object) ;;; Editing -- cgit v1.2.3 From 78c576bb9f784f1c063399f8c97b5f163f586497 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 19:18:30 -0200 Subject: Bad test --- test/test-printing.el | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/test-printing.el b/test/test-printing.el index 2fe1839..4d89b4d 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -90,9 +90,6 @@ after being run through `sx-question--tag-format'." (equal (sx-user--format "%@%%d%%%-30d %9r%l" user) "@hTHssdlrggyynnsssszzzccccuuuuuuooooooooiiiiieeeeeaaaaaaaaj%d%ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★ 10link"))) - (should - (string= - "@hTHssdlrggyynnsssszzzccccuuuuuuooooooooiiiiieeeeeaaaaaaaaj")) (should (string= (sx-user--format "%@" '((display_name . "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ"))) -- cgit v1.2.3 From ae3e8ee9d9f792ff8c543c249f6d26fb22ec7965 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 20:30:34 -0200 Subject: Rename add to ensure --- sx-interaction.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sx-interaction.el b/sx-interaction.el index 6ecfa38..8b72ea5 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -291,7 +291,7 @@ TEXT is a string. Interactively, it is read from the minibufer." ;; The api returns the new DATA. (when (> (length result) 0) (sx--add-comment-to-object - (sx--add-owner-to-object (list (cons 'display_name "(You)")) (elt result 0)) + (sx--ensure-owner-in-object (list (cons 'display_name "(You)")) (elt result 0)) (if .post_id (sx--get-post .post_type .site_par .post_id) data)) ;; Display the changes in `data'. (sx--maybe-update-display))))) @@ -345,7 +345,7 @@ OBJECT can be a question or an answer." (setcar object `(comments . [,comment])))) object) -(defun sx--add-owner-to-object (owner object) +(defun sx--ensure-owner-in-object (owner object) "Add `owner' property with value OWNER to OBJECT." (unless (cdr-safe (assq 'owner object)) (setcdr object (cons (car object) (cdr object))) -- cgit v1.2.3 From a16341cdf93224a399d3b64a8d50c32ce4323f08 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 20:53:34 -0200 Subject: sx--add-answer-to-question-object returns the question --- sx-interaction.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sx-interaction.el b/sx-interaction.el index 8b72ea5..97c68b6 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -445,7 +445,8 @@ context at point. " (append (cdr cell) (list answer)))) ;; No previous comments, add it manually. (setcdr question (cons (car question) (cdr question))) - (setcar question `(answers . [,answer]))))) + (setcar question `(answers . [,answer]))) + question)) (provide 'sx-interaction) ;;; sx-interaction.el ends here -- cgit v1.2.3 From ed981ba21cbd34a6eb0d2f1c67f137a547f8b09e Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 20:53:46 -0200 Subject: Moar tests! --- test/test-printing.el | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/test-printing.el b/test/test-printing.el index 4d89b4d..10b1d06 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -94,3 +94,42 @@ after being run through `sx-question--tag-format'." (string= (sx-user--format "%@" '((display_name . "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ"))) "@HTHssDLRGGYYNNSSSSZZZCCCCUUUUUUOOOOOOOOIIIIiEEEEEAAAAAAAAJ"))) + +(ert-deftest sx-object-modification () + "Test adding things to objects" + (let ((object (list (cons 'owner "me")))) + (should + (equal (sx--ensure-owner-in-object 1 object) + '((owner . "me")))) + (should + (equal object '((owner . "me"))))) + (let ((object (list (cons 'not-owner "me")))) + (should + (equal (sx--ensure-owner-in-object 1 object) + '((owner . 1) (not-owner . "me")))) + (should + (equal object '((owner . 1) (not-owner . "me"))))) + (let ((object (list (cons 'comments [something])))) + (should + (equal (sx--add-comment-to-object "comment" object) + '((comments . [something "comment"])))) + (should + (equal object '((comments . [something "comment"]))))) + (let ((object (list (cons 'not-comments [something])))) + (should + (equal (sx--add-comment-to-object "comment" object) + '((comments . ["comment"]) (not-comments . [something])))) + (should + (equal object '((comments . ["comment"]) (not-comments . [something]))))) + (let ((object (list (cons 'not-answers [something])))) + (should + (equal (sx--add-answer-to-question-object "answer" object) + '((answers . ["answer"]) (not-answers . [something])))) + (should + (equal object '((answers . ["answer"]) (not-answers . [something]))))) + (let ((object (list (cons 'answers [something])))) + (should + (equal (sx--add-answer-to-question-object "answer" object) + '((answers . [something "answer"])))) + (should + (equal object '((answers . [something "answer"])))))) -- cgit v1.2.3 From c14bdb9a4ed4707937255ba27c68aa2dfd02de30 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Wed, 7 Jan 2015 18:18:00 -0500 Subject: Spellcheck --- sx-babel.el | 2 +- sx-button.el | 6 +++--- sx-question.el | 2 +- sx-search.el | 2 +- sx-switchto.el | 2 +- sx.org | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sx-babel.el b/sx-babel.el index 4386172..31c0924 100644 --- a/sx-babel.el +++ b/sx-babel.el @@ -22,7 +22,7 @@ ;; This file contains functions and a variable for font-locking the ;; content of markdown pre blocks according to their language. The ;; main configuration point, for both the user and the developer is -;; the varuable `sx-babel-major-mode-alist', which see. +;; the variable `sx-babel-major-mode-alist', which see. ;;; Code: diff --git a/sx-button.el b/sx-button.el index a459eb4..5a2f052 100644 --- a/sx-button.el +++ b/sx-button.el @@ -23,7 +23,7 @@ ;; buttons, see: ;; http://www.gnu.org/software/emacs/manual/html_node/elisp/Buttons.html ;; -;; Most interactible parts of the SX buffers are buttons. Wherever you +;; Most interactive parts of the SX buffers are buttons. Wherever you ;; are, you can always cycle through all buttons by hitting `TAB', ;; that should help identify what's a button in each buffer. ;; @@ -34,7 +34,7 @@ ;; ;; Buttons can then be inserted in their respective files using ;; `insert-text-button'. Give it the string, the `:type' you defined, -;; and any aditional properties that can only be determined at +;; and any additional properties that can only be determined at ;; creation. Existing text can be transformed into a button with ;; `make-text-button' instead. @@ -154,7 +154,7 @@ usually part of a code-block." (define-button-type 'sx-button-user 'action #'sx-button-follow-link 'help-echo sx-button--user-help-echo - ;; We use different faces on diferent parts of the user button. + ;; We use different faces on different parts of the user button. 'face 'sx-user-name :supertype 'sx-button) diff --git a/sx-question.el b/sx-question.el index b9fc78a..1adbc24 100644 --- a/sx-question.el +++ b/sx-question.el @@ -19,7 +19,7 @@ ;;; Commentary: -;; Thie file provides an API for retrieving questions and defines +;; This file provides an API for retrieving questions and defines ;; additional logic for marking questions as read or hidden. diff --git a/sx-search.el b/sx-search.el index fa08e56..aefd12e 100644 --- a/sx-search.el +++ b/sx-search.el @@ -19,7 +19,7 @@ ;;; Commentary: -;; Implements sarch functionality. The basic function is +;; Implements search functionality. The basic function is ;; `sx-search-get-questions', which returns an array of questions ;; according to a search term. ;; diff --git a/sx-switchto.el b/sx-switchto.el index ed83360..6a195e0 100644 --- a/sx-switchto.el +++ b/sx-switchto.el @@ -33,7 +33,7 @@ (mapc (lambda (x) (define-key sx-switchto-map (car x) (cadr x))) '( - ;; These immitate the site's G hotkey. + ;; These imitate the site's G hotkey. ("a" sx-ask) ("h" sx-tab-frontpage) ("m" sx-tab-meta-or-main) diff --git a/sx.org b/sx.org index 7ccb51b..94780ec 100644 --- a/sx.org +++ b/sx.org @@ -97,7 +97,7 @@ Scrolling past the bottom of the list fetches more questions. - ~sx-init-hook~ :: Run when ~sx-initialize~ is called. - ~sx-compose-before-send-hook~ :: Run before POSTing to the API from a buffer in ~sx-compose-mode~. If any of the functions in this - hook, return nil, the transaction is cancelled. + hook, return nil, the transaction is canceled. - ~sx-compose-after-send-functions~ :: Run after POSTing to the API from a buffer in ~sx-compose-mode~, if the transaction was successful. -- cgit v1.2.3 From 67581dc6879bdbf7b6da9210b092fa7a18d39e4d Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Wed, 7 Jan 2015 18:18:25 -0500 Subject: Use description list appropriately --- sx.org | 77 +++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/sx.org b/sx.org index 94780ec..e206cc2 100644 --- a/sx.org +++ b/sx.org @@ -156,44 +156,45 @@ has a descriptive header explaining its purpose. Still, to help you find your way around, we describe below the current project structure. This list is very loosely ordered form low to high-level. -- ~sx.el~ - Utility functions used throughout the package. Essentially - every file indirectly requires this one. If you're adding a function - that's used by different parts of the package, add it to this file. -- ~sx-time.el~ - Similar to ~sx.el~, but only contains a few - time-related functions. -- ~sx-filter.el~ - Handles retrieval of filters. -- ~sx-cache.el~ - Saves and restores persistent data between sessions. -- ~sx-button.el~ - Defines all button types used throughout the - package. Currently used only by ~sx-question-print.el~. - -- ~sx-request.el~ - Requests and url manipulation. Backend used by - ~sx-method.el~. It shouldn't be necessary to use the functions in - this file outside ~sx-method.el~. -- ~sx-method.el~ - Main interface for API method calls. - -- ~sx-favorites.el~ - Starred questions. -- ~sx-networks.el~ - User network information. -- ~sx-site.el~ - Browsing sites. -- ~sx-auth.el~ - Handles user authentication. - -- ~sx-question.el~ - Base question logic. Holds several functions for - retrieving questions and for processing retrieved questions. Doesn't - do any sort of user interface, that is left for - ~sx-question-list.el~ and ~sx-question-mode.el~. -- ~sx-question-list.el~ - Major-mode for navigating questions list. -- ~sx-question-mode.el~ - User interface for displaying a - question. Creates the buffer and defines the major-mode. -- ~sx-question-print.el~ - Populating the question buffer with - content. Used by ~sx-question-mode.el~ to actually print the content - of a question. -- ~sx-babel.el~ - Font-locking code blocks printed by - ~sx-question-print.el~ according to the language. - -- ~sx-compose.el~ - Major-mode for composing questions and answers. -- ~sx-interaction.el~ - Voting, commenting, and otherwise interacting with questions. -- ~sx-tab.el~ - Functions for viewing different tabs. - -- ~sx-load.el~ - Load all files of the sx package. Designed as an easy way in for users who install the package manually (since they don't have autoloads). +- ~sx.el~ :: Utility functions used throughout the + package. Essentially every file indirectly requires this + one. If you're adding a function that's used by different + parts of the package, add it to this file. +- ~sx-time.el~ :: Similar to ~sx.el~, but only contains a few + time-related functions. +- ~sx-filter.el~ :: Handles retrieval of filters. +- ~sx-cache.el~ :: Saves and restores persistent data between + sessions. +- ~sx-button.el~ :: Defines all button types used throughout the + package. Currently used only by + ~sx-question-print.el~. +- ~sx-request.el~ :: Requests and url manipulation. Back-end used by + ~sx-method.el~. It shouldn't be necessary to use the functions in + this file outside ~sx-method.el~. +- ~sx-method.el~ :: Main interface for API method calls. +- ~sx-favorites.el~ :: Starred questions. +- ~sx-networks.el~ :: User network information. +- ~sx-site.el~ :: Browsing sites. +- ~sx-auth.el~ :: Handles user authentication. +- ~sx-question.el~ :: Base question logic. Holds several functions for + retrieving questions and for processing retrieved + questions. Doesn't do any sort of user interface, that is left + for ~sx-question-list.el~ and ~sx-question-mode.el~. +- ~sx-question-list.el~ :: Major-mode for navigating questions list. +- ~sx-question-mode.el~ :: User interface for displaying a + question. Creates the buffer and defines the major-mode. +- ~sx-question-print.el~ :: Populating the question buffer with + content. Used by ~sx-question-mode.el~ to actually print the + content of a question. +- ~sx-babel.el~ :: Font-locking code blocks printed by + ~sx-question-print.el~ according to the language. +- ~sx-compose.el~ :: Major-mode for composing questions and answers. +- ~sx-interaction.el~ :: Voting, commenting, and otherwise interacting + with questions. +- ~sx-tab.el~ :: Functions for viewing different tabs. +- ~sx-load.el~ :: Load all files of the SX package. Designed as an + easy way in for users who install the package + manually (since they don't have autoloads). * COMMENT Local Variables # LocalWords: StackExchange SX inbox sx API url json inline Org -- cgit v1.2.3 From 1534c4c690697b6ec23dca29dc94837705fe5fc5 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 21:40:32 -0200 Subject: Really fix filling --- sx-question-print.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index e2db76f..1e25d67 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -462,9 +462,11 @@ font-locking." (defun sx-question-mode--skip-references () "If there's a reference ahead, skip it and return non-nil." - (while (looking-at-p (format sx-question-mode--reference-regexp ".+")) + (forward-line 0) + (when (looking-at-p (format sx-question-mode--reference-regexp ".+")) ;; Returns non-nil - (forward-line 1))) + (forward-paragraph 1) + t)) (provide 'sx-question-print) ;;; sx-question-print.el ends here -- cgit v1.2.3 From cd0c7c622865d0ab3b628a96d93537bcfe0e76d9 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 21:48:49 -0200 Subject: Test fill-and-fontify --- test/test-printing.el | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/test-printing.el b/test/test-printing.el index 2857cb7..c477b28 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -71,3 +71,59 @@ after being run through `sx-question--tag-format'." (sx--user-@name '((display_name . "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ"))) "@HTHssDLRGGYYNNSSSSZZZCCCCUUUUUUOOOOOOOOIIIIiEEEEEAAAAAAAAJ"))) +(ert-deftest sx-question-mode--fill-and-fontify () + "Check complicated questions are filled correctly." + (should + (equal + (sx-question-mode--fill-and-fontify + "Creating an account on a new site requires you to log into that site using *the same credentials you used on existing sites.* For instance, if you used the Stack Exchange login method, you'd... + +1. Click the \"Log in using Stack Exchange\" button: + + ![][1] + +2. Enter your username and password (yes, even if you *just did this* to log into, say, Stack Overflow) and press the \"Log In\" button: + + ![][2] + +3. Confirm the creation of the new account: + + ![][3] + + some code block + some code block + some code block + some code block + some code block + some code block + + [1]: http://i.stack.imgur.com/ktFTs.png + [2]: http://i.stack.imgur.com/5l2AY.png + [3]: http://i.stack.imgur.com/22myl.png") + "Creating an account on a new site requires you to log into that site +using *the same credentials you used on existing sites.* For instance, +if you used the Stack Exchange login method, you'd... + +1. Click the \"Log in using Stack Exchange\" button: + + ![][1] + +2. Enter your username and password (yes, even if you *just did this* + to log into, say, Stack Overflow) and press the \"Log In\" button: + + ![][2] + +3. Confirm the creation of the new account: + + ![][3] + + some code block + some code block + some code block + some code block + some code block + some code block + + [1]: http://i.stack.imgur.com/ktFTs.png + [2]: http://i.stack.imgur.com/5l2AY.png + [3]: http://i.stack.imgur.com/22myl.png"))) -- cgit v1.2.3 From b5cc49f539aab7a1685bbcbdb089916ecfd5476f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 22:14:29 -0200 Subject: Change regexps to defconst --- sx-question-print.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index e2db76f..02e14c8 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -322,14 +322,14 @@ where `value' is given `face' as its face. 'face 'markdown-list-face) "String to be displayed as the bullet of markdown list items.") -(defvar sx-question-mode--reference-regexp +(defconst sx-question-mode--reference-regexp (rx line-start (0+ blank) "[%s]:" (0+ blank) (group-n 1 (1+ (not blank)))) "Regexp used to find the url of labeled links. E.g.: [1]: https://...") -(defvar sx-question-mode--link-regexp +(defconst sx-question-mode--link-regexp ;; Done at compile time. (rx "[" (group-n 1 (1+ (not (any "]")))) "]" (or (and "(" (group-n 2 (1+ (not (any ")")))) ")") -- cgit v1.2.3 From 9344809abe4b6b1b73038bd02b466900f1340bc3 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 22:14:51 -0200 Subject: Enable raw links. Fix #214 --- sx-question-print.el | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index 02e14c8..d74a162 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -331,9 +331,13 @@ E.g.: (defconst sx-question-mode--link-regexp ;; Done at compile time. - (rx "[" (group-n 1 (1+ (not (any "]")))) "]" - (or (and "(" (group-n 2 (1+ (not (any ")")))) ")") - (and "[" (group-n 3 (1+ (not (any "]")))) "]"))) + (rx (or (and "[" (group-n 1 (1+ (not (any "]")))) "]" + (or (and "(" (group-n 2 (1+ (not (any ")")))) ")") + (and "[" (group-n 3 (1+ (not (any "]")))) "]"))) + (group-n 4 (and (or (and "http" (opt "s") "://") "") + (+ (any alnum "_%")) + "." + (+ (any alnum "/._%&#?=;")))))) "Regexp matching markdown links.") (defun sx-question-mode--fill-and-fontify (text) @@ -377,6 +381,7 @@ E.g.: (while (search-forward-regexp sx-question-mode--link-regexp nil t) (let* ((text (match-string-no-properties 1)) (url (or (match-string-no-properties 2) + (match-string-no-properties 4) (sx-question-mode-find-reference (match-string-no-properties 3) text))) @@ -384,7 +389,7 @@ E.g.: (when (stringp url) (replace-match "") (sx-question-mode--insert-link - (if sx-question-mode-pretty-links text full-text) + (or (if sx-question-mode-pretty-links text full-text) url) url)))))) (defun sx-question-mode--insert-link (text url) -- cgit v1.2.3 From c54fba393ee1b8fa62708c27f7ea1940d90d1859 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 22:33:55 -0200 Subject: Add latex-mode and c-mode --- sx-babel.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sx-babel.el b/sx-babel.el index 4386172..e115817 100644 --- a/sx-babel.el +++ b/sx-babel.el @@ -34,6 +34,12 @@ ;; @TODO: Make shell-mode work here. Currently errors because it ;; needs a process. `sh-mode' isn't as nice. (,(rx (or "$ " "# ")) sh-mode) + ;; Not sure if leaving out "[{" might lead to false positives. + (,(rx "\\" (+ alnum) (any "[{")) latex-mode) + ;; Right now, this will match a lot of stuff. Once we are capable + ;; of determining major-mode from tags, site, and comments, this + ;; will work as a last case fallback. + (,(rx (or (and "int" (+ space) "main" (* space) "("))) c-mode) ) "List of cons cells determining which major-mode to use when. Each car is a rule and each cdr is a major-mode. The first rule -- cgit v1.2.3 From 2278f45dfc4a21dd1a9c8757d0539e6c460ac43d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 7 Jan 2015 22:51:25 -0200 Subject: Use http instead of https for our data requests --- sx-request.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sx-request.el b/sx-request.el index f892367..9a788ca 100644 --- a/sx-request.el +++ b/sx-request.el @@ -217,8 +217,8 @@ Currently returns nil." ;;; Our own generated data -(defvar sx-request--data-url-format - "https://raw.githubusercontent.com/vermiculus/sx.el/data/data/%s.el" +(defconst sx-request--data-url-format + "http://raw.githubusercontent.com/vermiculus/sx.el/data/data/%s.el" "Url of the \"data\" directory inside the SX `data' branch.") (defun sx-request-get-data (file) -- cgit v1.2.3 From bd471870f800559279738e4f3d7ef3a7993dd951 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 8 Jan 2015 14:15:01 -0200 Subject: Hotfix Add site_url to sx-site-browse-filter. Fix #220 --- sx-site.el | 1 + 1 file changed, 1 insertion(+) diff --git a/sx-site.el b/sx-site.el index 9b2ea34..4dac8e6 100644 --- a/sx-site.el +++ b/sx-site.el @@ -33,6 +33,7 @@ ((site site_type name api_site_parameter + site_url related_sites) (related_site api_site_parameter relation))) -- cgit v1.2.3 From 954e54ba2521dde8f2e3a9349802e24c7d60c7c3 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 8 Jan 2015 14:25:43 -0200 Subject: Don't use sx-favorites--initialize --- sx-favorites.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sx-favorites.el b/sx-favorites.el index d98b4c2..444df29 100644 --- a/sx-favorites.el +++ b/sx-favorites.el @@ -45,8 +45,10 @@ Added as hook to initialization." (or (setq sx-favorites--user-favorite-list (sx-cache-get 'question-favorites)) (sx-favorites-update))) -;; Append to ensure `sx-network--initialize is run before it. -(add-hook 'sx-init--internal-hook #'sx-favorites--initialize 'append) +;; ;; Append to ensure `sx-network--initialize' is run before it. +;; This is removed for now because it performs a lot of API calls and +;; was never used. +;; (add-hook 'sx-init--internal-hook #'sx-favorites--initialize 'append) (defun sx-favorites--retrieve-favorites (site) "Obtain list of starred QUESTION_IDs for SITE." -- cgit v1.2.3 From 7ca84717120848f0172c06b5f124a62753cdf5df Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 8 Jan 2015 15:49:20 -0200 Subject: Require sx-tag --- sx-compose.el | 1 + 1 file changed, 1 insertion(+) diff --git a/sx-compose.el b/sx-compose.el index 67c476e..f734904 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -34,6 +34,7 @@ (require 'markdown-mode) (require 'sx) +(require 'sx-tag) (defgroup sx-compose-mode nil "Customization group for sx-compose-mode." -- cgit v1.2.3 From 5acb70ccce4be466b54e7d0a01df1010e8145aa0 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 8 Jan 2015 15:58:00 -0200 Subject: Hotfix: Go back to https for data --- sx-request.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-request.el b/sx-request.el index 9a788ca..2650c55 100644 --- a/sx-request.el +++ b/sx-request.el @@ -218,7 +218,7 @@ Currently returns nil." ;;; Our own generated data (defconst sx-request--data-url-format - "http://raw.githubusercontent.com/vermiculus/sx.el/data/data/%s.el" + "https://raw.githubusercontent.com/vermiculus/sx.el/data/data/%s.el" "Url of the \"data\" directory inside the SX `data' branch.") (defun sx-request-get-data (file) -- cgit v1.2.3 From 50465fe9cb68978088da2be1a88549892c6b3146 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 8 Jan 2015 16:03:54 -0200 Subject: Don't use .total the total property doubles the time taken for the request, according to https://api.stackexchange.com/docs/paging --- sx-filter.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-filter.el b/sx-filter.el index a3f6861..72ab6b2 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -64,7 +64,7 @@ All wrapper fields are included by default." .page_size .quota_max .quota_remaining - .total) + ) nil none))) ;;; @TODO allow BASE to be a precompiled filter name -- cgit v1.2.3 From 7818811a7ca2666a007007caa8b32be7787e932d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 8 Jan 2015 16:09:54 -0200 Subject: Docs --- sx-filter.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sx-filter.el b/sx-filter.el index 72ab6b2..a35b51d 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -47,7 +47,7 @@ Structure: ;;; Creation (defmacro sx-filter-from-nil (included) - "Creates a filter data structure with INCLUDED fields. + "Create a filter data structure with INCLUDED fields. All wrapper fields are included by default." `(quote ((,@(sx--tree-expand @@ -70,7 +70,7 @@ All wrapper fields are included by default." ;;; @TODO allow BASE to be a precompiled filter name (defun sx-filter-compile (&optional include exclude base) "Compile INCLUDE and EXCLUDE into a filter derived from BASE. -INCLUDE and EXCLUDE must both be lists; BASE should be a string. +INCLUDE and EXCLUDE must both be lists; BASE should be a symbol. Returns the compiled filter as a string." (let ((keyword-arguments @@ -93,7 +93,7 @@ Returns the compiled filter as a string." (defun sx-filter-get (&optional include exclude base) "Return the string representation of the given filter. -If the filter data exist in `sx--filter-alist', that value will +If the filter data exists in `sx--filter-alist', that value will be returned. Otherwise, compile INCLUDE, EXCLUDE, and BASE into a filter with `sx-filter-compile' and push the association onto `sx--filter-alist'. Re-cache the alist with `sx-cache-set' and -- cgit v1.2.3 From 55682ee682c983f66c0a05b63ecb0ab4e5832cba Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 8 Jan 2015 16:10:05 -0200 Subject: Style --- sx-filter.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sx-filter.el b/sx-filter.el index a35b51d..bdbdab9 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -77,10 +77,8 @@ Returns the compiled filter as a string." `((include . ,(if include (sx--thing-as-string include))) (exclude . ,(if exclude (sx--thing-as-string exclude))) (base . ,(if base base))))) - (let ((response (elt (sx-request-make - "filter/create" - keyword-arguments) 0))) - (sx-assoc-let response + (let ((result (elt (sx-request-make "filter/create" keyword-arguments) 0))) + (sx-assoc-let result .filter)))) -- cgit v1.2.3 From 117f78c3e16fa32f82e75f43a7aac24afd9a37d5 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 8 Jan 2015 16:11:54 -0200 Subject: Build filters from default. --- sx-filter.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-filter.el b/sx-filter.el index bdbdab9..0df9b5e 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -65,7 +65,7 @@ All wrapper fields are included by default." .quota_max .quota_remaining ) - nil none))) + nil nil))) ;;; @TODO allow BASE to be a precompiled filter name (defun sx-filter-compile (&optional include exclude base) -- cgit v1.2.3 From 0edc2c089f45672e9390ef98db468e4d690c09df Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 8 Jan 2015 18:27:37 -0200 Subject: Fix test --- test/test-macros.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-macros.el b/test/test-macros.el index 1634603..a43d383 100644 --- a/test/test-macros.el +++ b/test/test-macros.el @@ -41,4 +41,4 @@ .quota_max .quota_remaining .total) - nil none)))) + nil nil)))) -- cgit v1.2.3 From 14f219c69039b681adbb0312973ae481b96a980e Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 11 Jan 2015 19:50:38 -0200 Subject: Hotfix: Less aggressive raw links --- sx-question-print.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index f6cd1dc..e120752 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -334,10 +334,10 @@ E.g.: (rx (or (and "[" (group-n 1 (1+ (not (any "]")))) "]" (or (and "(" (group-n 2 (1+ (not (any ")")))) ")") (and "[" (group-n 3 (1+ (not (any "]")))) "]"))) - (group-n 4 (and (or (and "http" (opt "s") "://") "") - (+ (any alnum "_%")) + (group-n 4 (and (and "http" (opt "s") "://") "" + (>= 2 (any lower numeric "_%")) "." - (+ (any alnum "/._%&#?=;")))))) + (>= 2 (any lower numeric "/._%&#?=;")))))) "Regexp matching markdown links.") (defun sx-question-mode--fill-and-fontify (text) -- cgit v1.2.3 From 72c00ea6a42f2a3f7c1bdb8a1f5c88446d263ae9 Mon Sep 17 00:00:00 2001 From: Sebastian Wiesner Date: Mon, 12 Jan 2015 19:50:47 +0100 Subject: Add missing format call `y-or-n-p` doesn't accept format arguments, so we need to call `format` explicitly. --- sx-compose.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-compose.el b/sx-compose.el index f734904..3047a97 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -200,7 +200,7 @@ tags. Return a list of already inserted tags." (if invalid-tags ;; If the user doesn't want to create the tags, we return ;; nil and sending is aborted. - (y-or-n-p "Following tags don't exist. Create them? %s " invalid-tags) + (y-or-n-p (format "Following tags don't exist. Create them? %s " invalid-tags)) t)))) -- cgit v1.2.3 From 766d008e12d7164053bda6d56f336af442109232 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Wed, 14 Jan 2015 08:41:38 -0500 Subject: Sort answers by score --- sx-question-print.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sx-question-print.el b/sx-question-print.el index e120752..737844a 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -179,7 +179,12 @@ QUESTION must be a data structure returned by `json-read'." ;; Print everything (sx-question-mode--print-section question) (sx-assoc-let question - (mapc #'sx-question-mode--print-section .answers)) + (mapc #'sx-question-mode--print-section + (cl-sort .answers + ;; Highest-voted first. @TODO: custom sorting + (lambda (a b) + (> (cdr (assoc 'score a)) + (cdr (assoc 'score b))))))) (insert "\n\n ") (insert-text-button "Write an Answer" :type 'sx-button-answer) ;; Go up -- cgit v1.2.3 From 7d6583a6da023f0a1f243d01cb2d856e272fc625 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 12 Jan 2015 09:13:21 -0200 Subject: Hotfix: Unused argument page --- sx-inbox.el | 1 + 1 file changed, 1 insertion(+) diff --git a/sx-inbox.el b/sx-inbox.el index 1efceb1..21589fb 100644 --- a/sx-inbox.el +++ b/sx-inbox.el @@ -69,6 +69,7 @@ KEYWORDS are added to the method call along with PAGE. `sx-method-call' is used with `sx-inbox-filter'." (sx-method-call (if notifications 'notifications 'inbox) :keywords keywords + :page page :filter sx-inbox-filter)) -- cgit v1.2.3 From ef5b4639cb8e70f2d4ddd26a7621f1361ccb1af7 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 14 Jan 2015 17:20:11 -0200 Subject: Remove .total from tests too --- test/test-macros.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test-macros.el b/test/test-macros.el index a43d383..5e0eac9 100644 --- a/test/test-macros.el +++ b/test/test-macros.el @@ -39,6 +39,5 @@ .page .page_size .quota_max - .quota_remaining - .total) + .quota_remaining) nil nil)))) -- cgit v1.2.3 From 3328a62d42ff3ca62c31366a4cd0cfd38a3ec663 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 15 Jan 2015 00:01:32 -0500 Subject: Create and implement comparator creation macro This obsoletes `sx--<'. --- sx-question-list.el | 10 +++++----- sx.el | 24 +++++++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/sx-question-list.el b/sx-question-list.el index 1b7fe5a..5909156 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -322,11 +322,11 @@ into consideration. ;; Add a setter to protect the value. :group 'sx-question-list) -(defun sx-question-list--date-more-recent-p (x y) - "Non-nil if tabulated-entry X is newer than Y." - (sx--< - sx-question-list-date-sort-method - (car x) (car y) #'>)) +(sx--create-comparator sx-question-list--date-more-recent-p + "Non-nil if tabulated-entry A is newer than B." + > (lambda (x) + (cdr (assoc sx-question-list-date-sort-method + (car x))))) ;;; Keybinds diff --git a/sx.el b/sx.el index e080271..87907de 100644 --- a/sx.el +++ b/sx.el @@ -259,6 +259,23 @@ whenever BODY evaluates to nil." :filter (lambda (&optional _) (when (progn ,@body) ,def))))) +(defmacro sx--create-comparator (name doc compare-func get-func) + "Define a new comparator called NAME with documentation DOC. +COMPARE-FUNC is a function that takes the return value of +GET-FUNC and performs the actual comparison." + (declare (indent 1) (doc-string 2)) + (let ((gpf (intern (format " %S--get-prop-function" name))) + (cf (intern (format " %S--compare-function" name)))) + ;; Leading space to hide from completion systems + `(progn + ;; In using `defalias', the macro supports both function + ;; symbols and lambda expressions. + (defalias ',gpf ,get-func) + (defalias ',cf ,compare-func) + (defun ,name (a b) + ,doc + (,cf (,gpf a) (,gpf b)))))) + ;;; Printing request data (defvar sx--overlays nil @@ -349,13 +366,6 @@ Run after `sx-init--internal-hook'." This is used internally to set initial values for variables such as filters.") -(defun sx--< (property x y &optional predicate) - "Non-nil if PROPERTY attribute of alist X is less than that of Y. -With optional argument PREDICATE, use it instead of `<'." - (funcall (or predicate #'<) - (cdr (assoc property x)) - (cdr (assoc property y)))) - (defmacro sx-init-variable (variable value &optional setter) "Set VARIABLE to VALUE using SETTER. SETTER should be a function of two arguments. If SETTER is nil, -- cgit v1.2.3 From 8e9983d1c9edab01335e3923bb5b50ad5a91ed1f Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 15 Jan 2015 00:09:31 -0500 Subject: Abstract sorting function --- sx-question-print.el | 6 +----- sx-question.el | 7 +++++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index 737844a..210f99a 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -180,11 +180,7 @@ QUESTION must be a data structure returned by `json-read'." (sx-question-mode--print-section question) (sx-assoc-let question (mapc #'sx-question-mode--print-section - (cl-sort .answers - ;; Highest-voted first. @TODO: custom sorting - (lambda (a b) - (> (cdr (assoc 'score a)) - (cdr (assoc 'score b))))))) + (cl-sort .answers #'sx-answer-higher-score-p))) (insert "\n\n ") (insert-text-button "Write an Answer" :type 'sx-button-answer) ;; Go up diff --git a/sx-question.el b/sx-question.el index b9fc78a..d624f45 100644 --- a/sx-question.el +++ b/sx-question.el @@ -187,6 +187,13 @@ If no cache exists for it, initialize one with SITE." "Formats TAG for display." (concat "[" tag "]")) + +;;; Question Mode Answer-Sorting Functions + +(sx--create-comparator sx-answer-higher-score-p + "Return t if answer A has a higher score than answer B." + #'> (lambda (x) (cdr (assoc 'score x)))) + (provide 'sx-question) ;;; sx-question.el ends here -- cgit v1.2.3 From 9b093f7a7a02e31dc6985619f5277ee945f6f90d Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 15 Jan 2015 00:22:04 -0500 Subject: Small bugfix Everything must now be a proper function. --- sx-question-list.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sx-question-list.el b/sx-question-list.el index 5909156..cb5bc33 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -324,9 +324,9 @@ into consideration. (sx--create-comparator sx-question-list--date-more-recent-p "Non-nil if tabulated-entry A is newer than B." - > (lambda (x) - (cdr (assoc sx-question-list-date-sort-method - (car x))))) + #'> (lambda (x) + (cdr (assoc sx-question-list-date-sort-method + (car x))))) ;;; Keybinds -- cgit v1.2.3 From fe912f7a4871f7beedeafe5f29feb57ca65ecc47 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 15 Jan 2015 00:22:33 -0500 Subject: Abstract sorting function into customizable option --- sx-question-print.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sx-question-print.el b/sx-question-print.el index 210f99a..c19b0c3 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -166,6 +166,15 @@ replaced with the comment." :type 'boolean :group 'sx-question-mode) +(defcustom sx-question-mode-answer-sort-function + #'sx-answer-higher-score-p + "Function used to sort answers in the question buffer." + :type '(choice + (const :tag "Higher-scoring first" sx-answer-higher-score-p) + (const :tag "Older first" sx-answer-older-p) + (const :tag "More active first" sx-answer-more-active-p)) + :group 'sx-question-mode) + ;;; Functions ;;;; Printing the general structure @@ -180,7 +189,7 @@ QUESTION must be a data structure returned by `json-read'." (sx-question-mode--print-section question) (sx-assoc-let question (mapc #'sx-question-mode--print-section - (cl-sort .answers #'sx-answer-higher-score-p))) + (cl-sort .answers sx-question-list--sort-answer-function))) (insert "\n\n ") (insert-text-button "Write an Answer" :type 'sx-button-answer) ;; Go up -- cgit v1.2.3 From 087ff1fdf3c4d42510d59a91659f166763baec57 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 15 Jan 2015 00:22:51 -0500 Subject: Add more sorting functions --- sx-question.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sx-question.el b/sx-question.el index d624f45..7c687e8 100644 --- a/sx-question.el +++ b/sx-question.el @@ -194,6 +194,14 @@ If no cache exists for it, initialize one with SITE." "Return t if answer A has a higher score than answer B." #'> (lambda (x) (cdr (assoc 'score x)))) +(sx--create-comparator sx-answer-older-p + "Return t if answer A was posted later than answer B." + #'< (lambda (x) (cdr (assoc 'creation_date x)))) + +(sx--create-comparator sx-answer-more-active-p + "Return t if answer A was updated after answer B." + #'> (lambda (x) (cdr (assoc 'last_activity_date x)))) + (provide 'sx-question) ;;; sx-question.el ends here -- cgit v1.2.3 From 67f1cd1dc24560a21eef8186590020d26d9e55d7 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 15 Jan 2015 00:26:14 -0500 Subject: Fix letbinding `gpf' used to stand for `get-property-function', but this was abstracted into a `get-function'. The letbinding was never changed. This commit also conveniently allows me to say: Fix #226. --- sx.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sx.el b/sx.el index 87907de..1cfba12 100644 --- a/sx.el +++ b/sx.el @@ -264,17 +264,17 @@ whenever BODY evaluates to nil." COMPARE-FUNC is a function that takes the return value of GET-FUNC and performs the actual comparison." (declare (indent 1) (doc-string 2)) - (let ((gpf (intern (format " %S--get-prop-function" name))) - (cf (intern (format " %S--compare-function" name)))) + (let ((gf (intern (format " %S--get-prop-function" name))) + (cf (intern (format " %S--compare-function" name)))) ;; Leading space to hide from completion systems `(progn ;; In using `defalias', the macro supports both function ;; symbols and lambda expressions. - (defalias ',gpf ,get-func) - (defalias ',cf ,compare-func) + (defalias ',gf ,get-func) + (defalias ',cf ,compare-func) (defun ,name (a b) ,doc - (,cf (,gpf a) (,gpf b)))))) + (,cf (,gf a) (,gf b)))))) ;;; Printing request data -- cgit v1.2.3 From b9eab6419e514fc6e1ce3096892bccd8a8ffb121 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 16 Jan 2015 00:40:26 -0500 Subject: Use assq instead of assoc --- sx-question-list.el | 3 +-- sx-question.el | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/sx-question-list.el b/sx-question-list.el index cb5bc33..41bebda 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -325,8 +325,7 @@ into consideration. (sx--create-comparator sx-question-list--date-more-recent-p "Non-nil if tabulated-entry A is newer than B." #'> (lambda (x) - (cdr (assoc sx-question-list-date-sort-method - (car x))))) + (cdr (assq sx-question-list-date-sort-method (car x))))) ;;; Keybinds diff --git a/sx-question.el b/sx-question.el index 7c687e8..e199966 100644 --- a/sx-question.el +++ b/sx-question.el @@ -192,15 +192,15 @@ If no cache exists for it, initialize one with SITE." (sx--create-comparator sx-answer-higher-score-p "Return t if answer A has a higher score than answer B." - #'> (lambda (x) (cdr (assoc 'score x)))) + #'> (lambda (x) (cdr (assq 'score x)))) (sx--create-comparator sx-answer-older-p "Return t if answer A was posted later than answer B." - #'< (lambda (x) (cdr (assoc 'creation_date x)))) + #'< (lambda (x) (cdr (assq 'creation_date x)))) (sx--create-comparator sx-answer-more-active-p "Return t if answer A was updated after answer B." - #'> (lambda (x) (cdr (assoc 'last_activity_date x)))) + #'> (lambda (x) (cdr (assq 'last_activity_date x)))) (provide 'sx-question) ;;; sx-question.el ends here -- cgit v1.2.3 From 7470438d4455e38e4f7b749579470d4af2b66751 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 16 Jan 2015 00:43:21 -0500 Subject: Change older-p to newer-p Older functions generally have more votes anyway -- new answers need initial the attention. --- sx-question-print.el | 2 +- sx-question.el | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index c19b0c3..031e06b 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -171,7 +171,7 @@ replaced with the comment." "Function used to sort answers in the question buffer." :type '(choice (const :tag "Higher-scoring first" sx-answer-higher-score-p) - (const :tag "Older first" sx-answer-older-p) + (const :tag "Newer first" sx-answer-newer-p) (const :tag "More active first" sx-answer-more-active-p)) :group 'sx-question-mode) diff --git a/sx-question.el b/sx-question.el index e199966..e39634b 100644 --- a/sx-question.el +++ b/sx-question.el @@ -194,9 +194,9 @@ If no cache exists for it, initialize one with SITE." "Return t if answer A has a higher score than answer B." #'> (lambda (x) (cdr (assq 'score x)))) -(sx--create-comparator sx-answer-older-p +(sx--create-comparator sx-answer-newer-p "Return t if answer A was posted later than answer B." - #'< (lambda (x) (cdr (assq 'creation_date x)))) + #'> (lambda (x) (cdr (assq 'creation_date x)))) (sx--create-comparator sx-answer-more-active-p "Return t if answer A was updated after answer B." -- cgit v1.2.3 From 6c4e7c6b95e8bd7d83e5d0f868d9fb3a70c7a974 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 16 Jan 2015 00:45:35 -0500 Subject: Don't define aliases with comparators The aliases were created in the fear that runtime would be slower to interpret the duplicated lambda expressions for get-func. After testing, this was found not to be the case. `funcall' is a much nicer solution. --- sx.el | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/sx.el b/sx.el index 1cfba12..829570f 100644 --- a/sx.el +++ b/sx.el @@ -264,17 +264,14 @@ whenever BODY evaluates to nil." COMPARE-FUNC is a function that takes the return value of GET-FUNC and performs the actual comparison." (declare (indent 1) (doc-string 2)) - (let ((gf (intern (format " %S--get-prop-function" name))) - (cf (intern (format " %S--compare-function" name)))) - ;; Leading space to hide from completion systems - `(progn - ;; In using `defalias', the macro supports both function - ;; symbols and lambda expressions. - (defalias ',gf ,get-func) - (defalias ',cf ,compare-func) - (defun ,name (a b) - ,doc - (,cf (,gf a) (,gf b)))))) + `(progn + ;; In using `defalias', the macro supports both function + ;; symbols and lambda expressions. + (defun ,name (a b) + ,doc + (funcall ,compare-func + (funcall ,get-func a) + (funcall ,get-func b))))) ;;; Printing request data -- cgit v1.2.3 From 389e433953bba4003b102748dbbf5f8a9b421a51 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 16 Jan 2015 08:54:13 -0500 Subject: Hotfix: wrong variable name Fix #234 --- sx-question-print.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-question-print.el b/sx-question-print.el index a25ff52..f9ecfab 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -176,7 +176,7 @@ QUESTION must be a data structure returned by `json-read'." (sx-question-mode--print-section question) (sx-assoc-let question (mapc #'sx-question-mode--print-section - (cl-sort .answers sx-question-list--sort-answer-function))) + (cl-sort .answers sx-question-mode-answer-sort-function))) (insert "\n\n ") (insert-text-button "Write an Answer" :type 'sx-button-answer) ;; Go up -- cgit v1.2.3