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-question-list.el | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sx-question-list.el') 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) -- 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(-) (limited to 'sx-question-list.el') 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 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(-) (limited to 'sx-question-list.el') 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 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(-) (limited to 'sx-question-list.el') 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 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(-) (limited to 'sx-question-list.el') 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 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(-) (limited to 'sx-question-list.el') 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 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(-) (limited to 'sx-question-list.el') 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 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(-) (limited to 'sx-question-list.el') 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 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(-) (limited to 'sx-question-list.el') 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