From 382fd490f71e00cc293e2ab98cfb7b7b1c59c201 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Fri, 27 Feb 2015 17:48:59 -0300 Subject: Print a header for closed questions. --- sx-question-print.el | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sx-question-print.el b/sx-question-print.el index 5799c96..32a0813 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -136,6 +136,11 @@ the editor's name." "Face used for accepted answers in the question buffer." :group 'sx-question-mode-faces) +(defface sx-question-mode-closed + '((t :box 2 :inherit font-lock-warning-face)) + "Face used for closed question header in the question buffer." + :group 'sx-question-mode-faces) + (defcustom sx-question-mode-answer-accepted-title "Accepted Answer" "Title used at the start of accepted \"Answer\" section." :type 'string @@ -206,8 +211,10 @@ QUESTION must be a data structure returned by `json-read'." (mapc #'delete-overlay sx--overlays) (setq sx--overlays nil) ;; Print everything - (sx-question-mode--print-section question) (sx-assoc-let question + (when .closed_reason + (sx-question-mode--print-close-reason .closed_reason .closed_date)) + (sx-question-mode--print-section question) (mapc #'sx-question-mode--print-section (cl-remove-if #'sx--deleted-p @@ -218,6 +225,15 @@ QUESTION must be a data structure returned by `json-read'." (goto-char (point-min)) (sx-question-mode-next-section)) +(defun sx-question-mode--print-close-reason (reason date) + "Print a header explaining REASON and DATE. +DATE is an integer." + (insert "\n " + (propertize + (format "Closed %s ago because %s" reason (sx-time-since date)) + 'face 'sx-question-mode-closed) + "\n\n")) + (defun sx-question-mode--print-section (data) "Print a section corresponding to DATA. DATA can represent a question or an answer." -- cgit v1.2.3 From e63a29e71d645e67275cb962ec0839e61da90863 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Fri, 27 Feb 2015 17:59:54 -0300 Subject: Add mode-line info for closed questions. --- sx-question-print.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sx-question-print.el b/sx-question-print.el index 32a0813..9e726b4 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -201,6 +201,10 @@ type is not available, images won't work." ;;; Functions ;;;; Printing the general structure +(defconst sx-question-mode--closed-mode-line-string + '(:propertize " [CLOSED] " face font-lock-warning-face) + "String indicating closed questions in the mode-line.") + (defun sx-question-mode--print-question (question) "Print a buffer describing QUESTION. QUESTION must be a data structure returned by `json-read'." @@ -213,6 +217,7 @@ QUESTION must be a data structure returned by `json-read'." ;; Print everything (sx-assoc-let question (when .closed_reason + (add-to-list 'mode-line-format sx-question-mode--closed-mode-line-string) (sx-question-mode--print-close-reason .closed_reason .closed_date)) (sx-question-mode--print-section question) (mapc #'sx-question-mode--print-section -- cgit v1.2.3 From dc106bbfdab8ed87847218e0216cc75f5b10cad1 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 2 Mar 2015 20:37:34 -0300 Subject: Swap date and reason --- sx-question-print.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-question-print.el b/sx-question-print.el index 9e726b4..3309f3a 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -235,7 +235,7 @@ QUESTION must be a data structure returned by `json-read'." DATE is an integer." (insert "\n " (propertize - (format "Closed %s ago because %s" reason (sx-time-since date)) + (format "Closed %s ago because %s" (sx-time-since date) reason) 'face 'sx-question-mode-closed) "\n\n")) -- cgit v1.2.3 From 5ca0e4fe40410555ee38bde39390a501689ef025 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 2 Mar 2015 20:41:00 -0300 Subject: Improved grammar --- sx-question-print.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index 3309f3a..aaa3cd0 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -235,9 +235,9 @@ QUESTION must be a data structure returned by `json-read'." DATE is an integer." (insert "\n " (propertize - (format "Closed %s ago because %s" (sx-time-since date) reason) + (format " Closed %s ago. Reason: %s " (sx-time-since date) reason) 'face 'sx-question-mode-closed) - "\n\n")) + "\n")) (defun sx-question-mode--print-section (data) "Print a section corresponding to DATA. -- cgit v1.2.3 From 40bb7c20c733f2e734b5379d42a924ce76550e8b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 2 Mar 2015 21:10:24 -0300 Subject: Add closed details to filter --- sx-filter.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sx-filter.el b/sx-filter.el index 1ccf611..5848e34 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -111,6 +111,9 @@ return the compiled filter." bounty_amount comments creation_date + closed_reason + closed_date + closed_details answers answer_count score -- cgit v1.2.3 From 5c0f594a5ee0cab2a277fe1a1541b44a492e57fb Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 2 Mar 2015 21:20:43 -0300 Subject: Add details to reason. --- sx-question-print.el | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index aaa3cd0..4de3d72 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -141,6 +141,15 @@ the editor's name." "Face used for closed question header in the question buffer." :group 'sx-question-mode-faces) +(defface sx-question-mode-closed-reason + `((t :box (:line-width 2 :color ,(face-attribute 'sx-question-mode-closed + :foreground nil t)) + :inherit sx-question-mode-title)) + "Face used for closed question header in the question buffer. +Aesthetically, it's important that the color of this face's :box +attribute match the color of the face `sx-question-mode-closed'." + :group 'sx-question-mode-faces) + (defcustom sx-question-mode-answer-accepted-title "Accepted Answer" "Title used at the start of accepted \"Answer\" section." :type 'string @@ -218,7 +227,7 @@ QUESTION must be a data structure returned by `json-read'." (sx-assoc-let question (when .closed_reason (add-to-list 'mode-line-format sx-question-mode--closed-mode-line-string) - (sx-question-mode--print-close-reason .closed_reason .closed_date)) + (sx-question-mode--print-close-reason .closed_reason .closed_date .closed_details)) (sx-question-mode--print-section question) (mapc #'sx-question-mode--print-section (cl-remove-if @@ -230,14 +239,31 @@ QUESTION must be a data structure returned by `json-read'." (goto-char (point-min)) (sx-question-mode-next-section)) -(defun sx-question-mode--print-close-reason (reason date) +(defun sx-question-mode--print-close-reason (reason date &optional details) "Print a header explaining REASON and DATE. -DATE is an integer." - (insert "\n " - (propertize - (format " Closed %s ago. Reason: %s " (sx-time-since date) reason) - 'face 'sx-question-mode-closed) - "\n")) +DATE is an integer. + +DETAILS, when given is an alist further describing the close." + (let ((l (point))) + (let-alist details + (insert "\n " + (propertize (format " %s as %s, %s ago. " + (if .on_hold "Put on hold" "Closed") + reason + (sx-time-since date)) + 'face 'sx-question-mode-closed) + "\n") + (when .description + (insert (replace-regexp-in-string "<[^>]+>" "" .description) + "\n"))) + (save-excursion + (goto-char l) + (search-forward " as " nil 'noerror) + (setq l (point)) + (skip-chars-forward "^,") + (let ((ov (make-overlay l (point)))) + (overlay-put ov 'face 'sx-question-mode-closed-reason) + (push ov sx--overlays))))) (defun sx-question-mode--print-section (data) "Print a section corresponding to DATA. -- cgit v1.2.3