From a8e752a0454e6ce20162a741dd967ed64380225b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 3 Nov 2014 00:45:23 +0000 Subject: Question-list mode --- stack-question-list.el | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 stack-question-list.el (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el new file mode 100644 index 0000000..bee85aa --- /dev/null +++ b/stack-question-list.el @@ -0,0 +1,104 @@ +;;; stack-question-list.el --- Major-mode for navigating questions list. -*- lexical-binding: t; -*- + +;; Copyright (C) 2014 Artur Malabarba + +;; Author: Artur Malabarba +;; Keywords: help, hypermedia, mail, news, tools + + +;; 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 'stack-question) +(require 'tabulated-list) + + +;;; Mode Definition +(define-derived-mode stack-question-list-mode tabulated-list-mode "Question List" + "Major mode for browsing a list of questions from stack-exchange. +Letters do not insert themselves; instead, they are commands. +\\ +\\{stack-question-list}" + (hl-line-mode 1) + (stack-question-list--update-mode-line) + (setq tabulated-list-format + `[("Vote" 4 nil) ("Answ" 4 nil) ("Date" 4 nil) ("Title" 0 nil)]) + (setq tabulated-list-padding 2) + (setq tabulated-list-sort-key (cons "Date" nil)) + (add-hook 'tabulated-list-revert-hook + #'stack-question-list--refresh-question-list nil t) + (add-hook 'tabulated-list-revert-hook + #'stack-question-list--update-mode-line nil t) + (tabulated-list-init-header)) + +(mapc + (lambda (x) (define-key stack-question-list-mode-map + (car x) (cadr x))) + '(("j" stack-question-list-next) + ("k" stack-question-list-previous) + ([RET] stack-question-list-display-question))) + +(defun stack-question-list--update-mode-line () + "Fill the mode-line with useful information." + nil) + +(defun stack-question-list--refresh-question-list () + "" + ;; Obviously this needs to be changed. + (let ((question-list )) + ;; Print the result. + (setq tabulated-list-entries + (mapcar #'stack-question-list--print-info question-list)))) + +(defun stack-question-list--print-info (data) + "Convert `json-read' DATA into tabulated-list format." + ) + +(defun stack-question-list-previous (n) + "Hide this question, move to previous one, display it." + (interactive "p") + (stack-question-list-next (- n))) + +(defun stack-question-list-next (n) + "Hide this question, move to next one, display it." + (interactive "p") + (next-line n) + (stack-question-list-display-question)) + +(defcustom stack-question-list-height 10 + "Height, in lines, of stack-mode's *question-list* buffer." + :type 'integer + :group 'stack-question-list) + +(defun stack-question-list-display-question (&optional data focus) + "Display question given by DATA. +If called interactively (or with DATA being nil), display +question under point. +Also when called interactively (or when FOCUS is non-nil), also +focus the relevant window." + (interactive '(nil t)) + (unless data (setq data (tabulated-list-get-id))) + (unless data (error "No question here!")) + (let ((window stack-question--window)) + (unless (window-live-p window) + (setq window + (split-window-below stack-question-list-height))) + (stack-question--display data window) + (when focus + (select-window window)))) + +(provide 'stack-question-list) +;;; stack-question-list.el ends here -- cgit v1.2.3 From 995b609b129c96d4694e2b9c066fa973ccffc9bc Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 3 Nov 2014 01:52:38 +0000 Subject: Question List Mode is now functional. --- stack-question-list.el | 68 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 19 deletions(-) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index bee85aa..2dc7aa7 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -24,6 +24,15 @@ ;;; Code: (require 'stack-question) (require 'tabulated-list) +(require 'cl-lib) + + +;;; Customization +(defcustom stack-question-list-height 10 + "Height, in lines, of stack-mode's *question-list* buffer." + :type 'integer + :group 'stack-question-list) + ;;; Mode Definition @@ -39,7 +48,7 @@ Letters do not insert themselves; instead, they are commands. (setq tabulated-list-padding 2) (setq tabulated-list-sort-key (cons "Date" nil)) (add-hook 'tabulated-list-revert-hook - #'stack-question-list--refresh-question-list nil t) + #'stack-question-list-refresh nil t) (add-hook 'tabulated-list-revert-hook #'stack-question-list--update-mode-line nil t) (tabulated-list-init-header)) @@ -49,23 +58,34 @@ Letters do not insert themselves; instead, they are commands. (car x) (cadr x))) '(("j" stack-question-list-next) ("k" stack-question-list-previous) - ([RET] stack-question-list-display-question))) + ("g" stack-question-list-refresh) + ([?\r] stack-question-list-display-question))) (defun stack-question-list--update-mode-line () "Fill the mode-line with useful information." nil) -(defun stack-question-list--refresh-question-list () - "" +(defun stack-question-list-refresh (&optional redisplay) + "Update the list of questions. +If REDISPLAY is non-nil, also call `tabulated-list-print'." ;; Obviously this needs to be changed. - (let ((question-list )) + (let ((question-list (stack-test-sample-data "questions"))) ;; Print the result. (setq tabulated-list-entries - (mapcar #'stack-question-list--print-info question-list)))) + (mapcar #'stack-question-list--print-info question-list))) + (when redisplay (tabulated-list-print 'remember))) + +;; (stack-question-list--print-info sample-question-unauthenticated) (defun stack-question-list--print-info (data) "Convert `json-read' DATA into tabulated-list format." - ) + (cl-flet ((ca (x) (cdr (assoc x data)))) + (list + data + (vector (int-to-string (ca 'score)) + (int-to-string (ca 'answer_count)) + (int-to-string (ca 'last_activity_date)) + (ca 'title))))) (defun stack-question-list-previous (n) "Hide this question, move to previous one, display it." @@ -78,11 +98,6 @@ Letters do not insert themselves; instead, they are commands. (next-line n) (stack-question-list-display-question)) -(defcustom stack-question-list-height 10 - "Height, in lines, of stack-mode's *question-list* buffer." - :type 'integer - :group 'stack-question-list) - (defun stack-question-list-display-question (&optional data focus) "Display question given by DATA. If called interactively (or with DATA being nil), display @@ -92,13 +107,28 @@ focus the relevant window." (interactive '(nil t)) (unless data (setq data (tabulated-list-get-id))) (unless data (error "No question here!")) - (let ((window stack-question--window)) - (unless (window-live-p window) - (setq window - (split-window-below stack-question-list-height))) - (stack-question--display data window) - (when focus - (select-window window)))) + (unless (window-live-p stack-question--window) + (setq stack-question--window + (split-window-below stack-question-list-height))) + (stack-question--display data stack-question--window) + (when focus + (select-window stack-question--window))) + +(defvar stack-question-list--buffer nil + "Buffer where the list of questions is displayed.") + +(defun list-questions (no-update) + "Display a list of stack-exchange questions." + (interactive "P") + (unless (buffer-live-p stack-question-list--buffer) + (setq stack-question-list--buffer + (generate-new-buffer "*question-list*"))) + (with-current-buffer stack-question-list--buffer + (stack-question-list-mode) + (stack-question-list-refresh 'redisplay)) + ;; The package menu buffer has keybindings. If the user types + ;; `M-x list-packages', that suggests it should become current. + (switch-to-buffer stack-question-list--buffer)) (provide 'stack-question-list) ;;; stack-question-list.el ends here -- cgit v1.2.3 From b3e37e4c57e02db9a75b34e46e35a8a84f29c7a5 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 3 Nov 2014 02:02:28 +0000 Subject: Make stack-question-list-refresh interactive --- stack-question-list.el | 1 + 1 file changed, 1 insertion(+) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index 2dc7aa7..58def0b 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -68,6 +68,7 @@ Letters do not insert themselves; instead, they are commands. (defun stack-question-list-refresh (&optional redisplay) "Update the list of questions. If REDISPLAY is non-nil, also call `tabulated-list-print'." + (interactive '(t)) ;; Obviously this needs to be changed. (let ((question-list (stack-test-sample-data "questions"))) ;; Print the result. -- cgit v1.2.3 From e9f4cc5ff86f7a91c8bf68270e72fe33bf46b5f8 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 3 Nov 2014 02:05:59 +0000 Subject: Load tests file for now. --- stack-question-list.el | 1 + 1 file changed, 1 insertion(+) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index 58def0b..e50286c 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -25,6 +25,7 @@ (require 'stack-question) (require 'tabulated-list) (require 'cl-lib) +(load "test/tests.el") ;;; Customization -- cgit v1.2.3 From ec157e5674d08538c4d5250b61cd29b20740d05d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 3 Nov 2014 13:22:35 +0000 Subject: Increase default list height to 15 lines --- stack-question-list.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index e50286c..d0f6722 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -29,7 +29,7 @@ ;;; Customization -(defcustom stack-question-list-height 10 +(defcustom stack-question-list-height 15 "Height, in lines, of stack-mode's *question-list* buffer." :type 'integer :group 'stack-question-list) -- cgit v1.2.3 From 6bbbfc51a351d74a21f82a19972d797310c529b8 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 3 Nov 2014 13:22:48 +0000 Subject: Define questionlist faces --- stack-question-list.el | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index d0f6722..584b2b9 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -34,6 +34,59 @@ :type 'integer :group 'stack-question-list) +(defface stack-question-list-parent + '((t :inherit default)) + "" + :group 'stack-question-list-faces) + +(defface stack-question-list-answers + '((((background light)) :foreground "SeaGreen4" + :height 1.0 :inherit stack-question-list-parent) + (((background dark)) :foreground "#D1FA71" + :height 1.0 :inherit stack-question-list-parent) + (t :inherit stack-question-list-parent)) + "" + :group 'stack-question-list-faces) + +(defface stack-question-list-answers-accepted + '((((background light)) :background "YellowGreen" + :inherit stack-question-list-answers) + (((background dark)) :background "DarkOliveGreen" + :inherit stack-question-list-answers) + (t :inherit stack-question-list-answers)) + "" + :group 'stack-question-list-faces) + +(defface stack-question-list-score + '((t :height 1.0 :inherit stack-question-list-parent)) + "" + :group 'stack-question-list-faces) + +(defface stack-question-list-score-upvoted + '((t :weight bold + :inherit stack-question-list-score)) + "" + :group 'stack-question-list-faces) + +(defface stack-question-list-tags + '((t :inherit font-lock-function-name-face)) + "" + :group 'stack-question-list-faces) + +(defface stack-question-list-date + '((t :inherit font-lock-comment-face)) + "" + :group 'stack-question-list-faces) + +(defface stack-question-list-read-question + '((t :height 1.0 :inherit stack-question-list-parent)) + "" + :group 'stack-question-list-faces) + +(defface stack-question-list-unread-question + '((t :weight bold :inherit stack-question-list-read-question)) + "" + :group 'stack-question-list-faces) ;;; Mode Definition -- cgit v1.2.3 From e298e214bfca97456e16b5f8bf6766e9130a4888 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 3 Nov 2014 13:34:48 +0000 Subject: Huge improvements to the question list --- stack-question-list.el | 60 ++++++++++++++++++++++++++++++++++++-------------- stack-question.el | 12 ++++++++++ 2 files changed, 56 insertions(+), 16 deletions(-) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index 584b2b9..dab5504 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -98,9 +98,10 @@ Letters do not insert themselves; instead, they are commands. (hl-line-mode 1) (stack-question-list--update-mode-line) (setq tabulated-list-format - `[("Vote" 4 nil) ("Answ" 4 nil) ("Date" 4 nil) ("Title" 0 nil)]) - (setq tabulated-list-padding 2) - (setq tabulated-list-sort-key (cons "Date" nil)) + [(" V" 3 t :right-align t) + (" A" 3 t :right-align t) + ("Title" 0 stack-question-list--date-sort)]) + (setq tabulated-list-padding 1) (add-hook 'tabulated-list-revert-hook #'stack-question-list-refresh nil t) (add-hook 'tabulated-list-revert-hook @@ -110,8 +111,10 @@ Letters do not insert themselves; instead, they are commands. (mapc (lambda (x) (define-key stack-question-list-mode-map (car x) (cadr x))) - '(("j" stack-question-list-next) - ("k" stack-question-list-previous) + '(("n" stack-question-list-next) + ("p" stack-question-list-previous) + ("j" stack-question-list-view-next) + ("k" stack-question-list-view-previous) ("g" stack-question-list-refresh) ([?\r] stack-question-list-display-question))) @@ -130,29 +133,54 @@ If REDISPLAY is non-nil, also call `tabulated-list-print'." (mapcar #'stack-question-list--print-info question-list))) (when redisplay (tabulated-list-print 'remember))) -;; (stack-question-list--print-info sample-question-unauthenticated) - (defun stack-question-list--print-info (data) "Convert `json-read' DATA into tabulated-list format." (cl-flet ((ca (x) (cdr (assoc x data)))) (list data - (vector (int-to-string (ca 'score)) - (int-to-string (ca 'answer_count)) - (int-to-string (ca 'last_activity_date)) - (ca 'title))))) - -(defun stack-question-list-previous (n) + (vector + (list (int-to-string (ca 'score)) 'face + (if (ca 'upvoted) 'stack-question-list-score-upvoted + 'stack-question-list-score)) + (list (int-to-string (ca 'answer_count)) 'face + (if (stack-question--accepted-answer data) + 'stack-question-list-answers-accepted + 'stack-question-list-answers)) + (concat + (propertize + (stack-core--decode-entities (ca 'title)) + 'face + (if (stack-question--read-p data) + 'stack-question-list-read-question + 'stack-question-list-unread-question)) + (propertize " " 'display "\n ") + (propertize (stack--time-since (ca 'last_activity_date)) + 'face 'stack-question-list-date) + (propertize (concat " [" (mapconcat #'identity (ca 'tags) "] [") "]") + 'face 'stack-question-list-tags) + (propertize " " 'display "\n")))))) + +(defun stack-question-list-view-previous (n) "Hide this question, move to previous one, display it." (interactive "p") - (stack-question-list-next (- n))) + (stack-question-list-view-next (- n))) -(defun stack-question-list-next (n) +(defun stack-question-list-view-next (n) "Hide this question, move to next one, display it." (interactive "p") - (next-line n) + (stack-question-list-next n) (stack-question-list-display-question)) +(defun stack-question-list-next (n) + "Move to the next entry." + (interactive "p") + (forward-line n)) + +(defun stack-question-list-previous (n) + "Move to the previous entry." + (interactive "p") + (stack-question-list-next (- n))) + (defun stack-question-list-display-question (&optional data focus) "Display question given by DATA. If called interactively (or with DATA being nil), display diff --git a/stack-question.el b/stack-question.el index 4c67e09..2b6cd1f 100644 --- a/stack-question.el +++ b/stack-question.el @@ -44,6 +44,18 @@ (page . ,page)) stack-question-browse-filter)) + +;;; Question Properties +(defun stack-question--read-p (question) + "Non-nil if QUESTION has been read since last updated." + ;; @TODO: + (cl-evenp (random))) + +(defun stack-question--accepted-answer (question) + "Return accepted answer in QUESTION, or nil if none." + ;; @TODO: + (cl-evenp (random))) + ;;; Displaying a question (defvar stack-question--window nil -- cgit v1.2.3 From b09dd861782b5926d8ac29459c2c3366bee2e70a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 3 Nov 2014 13:36:42 +0000 Subject: Question list sort-by-date button. --- stack-question-list.el | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index dab5504..bc8ad90 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -102,12 +102,23 @@ Letters do not insert themselves; instead, they are commands. (" A" 3 t :right-align t) ("Title" 0 stack-question-list--date-sort)]) (setq tabulated-list-padding 1) + ;; Sorting by title actually sorts by date. It's what we want, but + ;; it's not terribly intuitive. + (setq tabulated-list-sort-key '("Title" . nil)) (add-hook 'tabulated-list-revert-hook #'stack-question-list-refresh nil t) (add-hook 'tabulated-list-revert-hook #'stack-question-list--update-mode-line nil t) (tabulated-list-init-header)) +(defvar stack-question-list-date-sort-method 'last_activity_date + "Parameter which controls date sorting.") + +(defun stack-question-list--date-sort (x y) + "Non-nil if tabulated-entry X is newer than Y." + (> (cdr (assoc stack-question-list-date-sort-method (car x))) + (cdr (assoc stack-question-list-date-sort-method (car y))))) + (mapc (lambda (x) (define-key stack-question-list-mode-map (car x) (cadr x))) -- cgit v1.2.3 From ffef03c69affa3b247785654c4c2856100044b1e Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 3 Nov 2014 13:37:07 +0000 Subject: Fix test sample. --- stack-question-list.el | 2 +- test/tests.el | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index bc8ad90..8f3f722 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -138,7 +138,7 @@ Letters do not insert themselves; instead, they are commands. If REDISPLAY is non-nil, also call `tabulated-list-print'." (interactive '(t)) ;; Obviously this needs to be changed. - (let ((question-list (stack-test-sample-data "questions"))) + (let ((question-list (stack-test-sample-data "questions" "test"))) ;; Print the result. (setq tabulated-list-entries (mapcar #'stack-question-list--print-info question-list))) diff --git a/test/tests.el b/test/tests.el index 11914bb..efad2d0 100644 --- a/test/tests.el +++ b/test/tests.el @@ -6,13 +6,12 @@ (unintern symbol))))) ;;; Tests -(defvar stack-test-data-dir - (expand-file-name "data-samples/") +(defvar stack-test-data-dir "data-samples/" "") (defun stack-test-sample-data (method &optional directory) - (let ((file (concat stack-test-data-dir - (when directory (concat directory "/")) + (let ((file (concat (when directory (concat directory "/")) + stack-test-data-dir method ".el"))) (when (file-exists-p file) (with-temp-buffer -- cgit v1.2.3 From 4aab65154b3c8f4d58f9e874d8a93eb288432120 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 4 Nov 2014 08:53:01 +0000 Subject: Move " ago" out of stack--time-since --- stack-core.el | 3 +-- stack-question-list.el | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'stack-question-list.el') diff --git a/stack-core.el b/stack-core.el index 6830583..5a90cb3 100644 --- a/stack-core.el +++ b/stack-core.el @@ -296,8 +296,7 @@ context of `stack-cache-directory'." (while (and (car (setq here (pop sts))) (<= (car here) delay))) (concat (format "%.0f" (/ delay (car (cddr here)))) - (cadr here)))) - " ago"))) + (cadr here))))))) (defcustom stack-core-html-entities-plist '(Aacute "Á" aacute "á" Acirc "Â" acirc "â" acute "´" AElig "Æ" aelig "æ" diff --git a/stack-question-list.el b/stack-question-list.el index 8f3f722..1a19b44 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -165,7 +165,7 @@ If REDISPLAY is non-nil, also call `tabulated-list-print'." 'stack-question-list-read-question 'stack-question-list-unread-question)) (propertize " " 'display "\n ") - (propertize (stack--time-since (ca 'last_activity_date)) + (propertize (concat (stack--time-since (ca 'last_activity_date)) " ago") 'face 'stack-question-list-date) (propertize (concat " [" (mapconcat #'identity (ca 'tags) "] [") "]") 'face 'stack-question-list-tags) -- cgit v1.2.3 From 39706412e070cabe201905b9e6980a5a20aae9e0 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 4 Nov 2014 09:02:13 +0000 Subject: Make " ago" into a customizable varible. --- stack-question-list.el | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index 1a19b44..1a23cde 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -144,6 +144,12 @@ If REDISPLAY is non-nil, also call `tabulated-list-print'." (mapcar #'stack-question-list--print-info question-list))) (when redisplay (tabulated-list-print 'remember))) +(defcustom stack-question-list-ago-string " ago" + "String appended to descriptions of the time since something happened. +Used in the questions list to indicate a question was updated \"4d ago\"." + :type 'string + :group 'stack-question-list) + (defun stack-question-list--print-info (data) "Convert `json-read' DATA into tabulated-list format." (cl-flet ((ca (x) (cdr (assoc x data)))) @@ -165,7 +171,8 @@ If REDISPLAY is non-nil, also call `tabulated-list-print'." 'stack-question-list-read-question 'stack-question-list-unread-question)) (propertize " " 'display "\n ") - (propertize (concat (stack--time-since (ca 'last_activity_date)) " ago") + (propertize (concat (stack--time-since (ca 'last_activity_date)) + stack-question-list-ago-string) 'face 'stack-question-list-date) (propertize (concat " [" (mapconcat #'identity (ca 'tags) "] [") "]") 'face 'stack-question-list-tags) -- cgit v1.2.3 From e4ef9753ba024dbc2c96e17a66cbfc1cb871c6cc Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 4 Nov 2014 09:24:04 +0000 Subject: Turn stack-question-list-date-sort-method into a defcustom --- stack-question-list.el | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index 1a23cde..efacb7f 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -111,8 +111,13 @@ Letters do not insert themselves; instead, they are commands. #'stack-question-list--update-mode-line nil t) (tabulated-list-init-header)) -(defvar stack-question-list-date-sort-method 'last_activity_date - "Parameter which controls date sorting.") +(defcustom stack-question-list-date-sort-method 'last_activity_date + "Parameter which controls date sorting." + ;; This should be made into a (choice ...) of constants. + :type 'symbol + ;; Add a setter to protect the value. + :group 'stack-question-list) + (defun stack-question-list--date-sort (x y) "Non-nil if tabulated-entry X is newer than Y." -- cgit v1.2.3 From 33383d630ce43045cd94c2b515df7567063fc885 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 4 Nov 2014 09:35:28 +0000 Subject: Rename -date-sort to -date-more-recent-p --- stack-question-list.el | 9 +++++---- stack-question.el | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index efacb7f..2e354d3 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -100,7 +100,7 @@ Letters do not insert themselves; instead, they are commands. (setq tabulated-list-format [(" V" 3 t :right-align t) (" A" 3 t :right-align t) - ("Title" 0 stack-question-list--date-sort)]) + ("Title" 0 stack-question-list--date-more-recent-p)]) (setq tabulated-list-padding 1) ;; Sorting by title actually sorts by date. It's what we want, but ;; it's not terribly intuitive. @@ -119,10 +119,11 @@ Letters do not insert themselves; instead, they are commands. :group 'stack-question-list) -(defun stack-question-list--date-sort (x y) +(defun stack-question-list--date-more-recent-p (x y) "Non-nil if tabulated-entry X is newer than Y." - (> (cdr (assoc stack-question-list-date-sort-method (car x))) - (cdr (assoc stack-question-list-date-sort-method (car y))))) + (stack-question-list--< + stack-question-list-date-sort-method + (car x) (car y) #'>)) (mapc (lambda (x) (define-key stack-question-list-mode-map diff --git a/stack-question.el b/stack-question.el index 66a4ea3..a7a74df 100644 --- a/stack-question.el +++ b/stack-question.el @@ -58,6 +58,12 @@ ;; @TODO: (cl-evenp (random))) +(defun stack-question--< (property x y &optional pred) + "Non-nil if PROPERTY attribute of question X is less than that of Y. +With optional argument predicate, use it instead of `<'." + (funcall (or pred #'<) + (cdr (assoc property x)) + (cdr (assoc property y)))) ;;; Displaying a question (defvar stack-question--window nil -- cgit v1.2.3 From 6afdb3c647bcec08e4409ed1299ae3ca9f559d0c Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 4 Nov 2014 13:47:44 +0000 Subject: Fix reference to old function. --- stack-question-list.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index 2e354d3..fae4df4 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -121,7 +121,7 @@ Letters do not insert themselves; instead, they are commands. (defun stack-question-list--date-more-recent-p (x y) "Non-nil if tabulated-entry X is newer than Y." - (stack-question-list--< + (stack-question--< stack-question-list-date-sort-method (car x) (car y) #'>)) -- cgit v1.2.3 From 53c9770c8e706b901197f33a9af38bfb1397246c Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 4 Nov 2014 13:54:43 +0000 Subject: Don't decode html entities in the question list This should be done after reading the API response. --- stack-question-list.el | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index fae4df4..63c568f 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -162,20 +162,21 @@ Used in the questions list to indicate a question was updated \"4d ago\"." (list data (vector - (list (int-to-string (ca 'score)) 'face + (list (int-to-string (ca 'score)) + 'face (if (ca 'upvoted) 'stack-question-list-score-upvoted 'stack-question-list-score)) - (list (int-to-string (ca 'answer_count)) 'face + (list (int-to-string (ca 'answer_count)) + 'face (if (stack-question--accepted-answer data) 'stack-question-list-answers-accepted 'stack-question-list-answers)) (concat - (propertize - (stack-core--decode-entities (ca 'title)) - 'face - (if (stack-question--read-p data) - 'stack-question-list-read-question - 'stack-question-list-unread-question)) + (propertize (ca 'title) + 'face + (if (stack-question--read-p data) + 'stack-question-list-read-question + 'stack-question-list-unread-question)) (propertize " " 'display "\n ") (propertize (concat (stack--time-since (ca 'last_activity_date)) stack-question-list-ago-string) -- cgit v1.2.3 From 52122c621bc21d7e254a5c7dd3e5241df7e9d370 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 4 Nov 2014 16:13:57 +0000 Subject: Define prefixed alias for list-questions --- stack-question-list.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'stack-question-list.el') diff --git a/stack-question-list.el b/stack-question-list.el index 63c568f..f565490 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -234,9 +234,9 @@ focus the relevant window." (with-current-buffer stack-question-list--buffer (stack-question-list-mode) (stack-question-list-refresh 'redisplay)) - ;; The package menu buffer has keybindings. If the user types - ;; `M-x list-packages', that suggests it should become current. (switch-to-buffer stack-question-list--buffer)) +(defalias 'stack-list-questions #'list-questions) + (provide 'stack-question-list) ;;; stack-question-list.el ends here -- cgit v1.2.3