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 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