aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2015-01-07 14:44:24 -0200
committerArtur Malabarba <bruce.connor.am@gmail.com>2015-01-07 15:48:31 -0200
commit304217c1ac70ee7dc6f7e4c16410fca73b11c515 (patch)
tree7dcb48a805ee12484e7762f73a55a6806a82c16f
parent3b86d82a1a199a98bdb1bae8cc991807afa6a035 (diff)
Move user-printing to sx-user
-rw-r--r--sx-question-print.el34
-rw-r--r--sx-user.el73
2 files changed, 74 insertions, 33 deletions
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 <bruce.connor.am@gmail.com>
+
+;; 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 <http://www.gnu.org/licenses/>.
+
+;;; 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: