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 --- sx-question-print.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'sx-question-print.el') 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: -- 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(-) (limited to 'sx-question-print.el') 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 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(+) (limited to 'sx-question-print.el') 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 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(-) (limited to 'sx-question-print.el') 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(-) (limited to 'sx-question-print.el') 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(-) (limited to 'sx-question-print.el') 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(-) (limited to 'sx-question-print.el') 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 (limited to 'sx-question-print.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(-) (limited to 'sx-question-print.el') 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(-) (limited to 'sx-question-print.el') 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(-) (limited to 'sx-question-print.el') 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 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(-) (limited to 'sx-question-print.el') 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 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(-) (limited to 'sx-question-print.el') 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 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(-) (limited to 'sx-question-print.el') 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(-) (limited to 'sx-question-print.el') 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 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(-) (limited to 'sx-question-print.el') 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 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(-) (limited to 'sx-question-print.el') 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 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(-) (limited to 'sx-question-print.el') 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 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(-) (limited to 'sx-question-print.el') 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 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(-) (limited to 'sx-question-print.el') 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 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(-) (limited to 'sx-question-print.el') 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