From 97a0d11c657fcb3a7369e62ab4c7b5ee676444ea Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sat, 15 Nov 2014 17:29:40 -0500 Subject: Fix use of `rx' macro It needs to be evaluated. --- sx-question-mode.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index 32cd112..03647bc 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -345,11 +345,11 @@ HEADER is given `sx-question-mode-header' face, and value is given FACE. (when sx-question-mode-bullet-appearance (font-lock-add-keywords ;; Bullet items. nil - `(((rx line-start (0+ blank) (group-n 1 (any "*+-")) blank) + `((,(rx line-start (0+ blank) (group-n 1 (any "*+-")) blank) 1 '(face nil display ,sx-question-mode-bullet-appearance) prepend)))) (font-lock-add-keywords ;; Highlight usernames. nil - `(((rx (or blank line-start) + `((,(rx (or blank line-start) (group-n 1 (and "@" (1+ (or (syntax word) (syntax symbol))))) symbol-end) 1 font-lock-builtin-face))) -- cgit v1.2.3 From 35ed7285e9271da388ed23416a27d40fd90807e3 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 16 Nov 2014 22:28:19 -0500 Subject: Set question data when printing the question --- sx-question-mode.el | 1 + 1 file changed, 1 insertion(+) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index 32cd112..fdb6487 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -192,6 +192,7 @@ Second \"%s\" is replaced with the comment." (defun sx-question-mode--print-question (question) "Print a buffer describing QUESTION. QUESTION must be a data structure returned by `json-read'." + (setq sx-question-mode--data question) ;; Clear the overlays (mapc #'delete-overlay sx-question-mode--overlays) (setq sx-question-mode--overlays nil) -- cgit v1.2.3 From 2e527f3e3c4802602c9f1cff659f0c36a39fce2f Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 16 Nov 2014 22:28:50 -0500 Subject: Add function to browse-url in question-mode --- sx-question-mode.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index fdb6487..9653485 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -545,6 +545,7 @@ Letters do not insert themselves; instead, they are commands. `(("n" sx-question-mode-next-section) ("p" sx-question-mode-previous-section) ("g" sx-question-mode-refresh) + ("v" sx-question-mode-visit) ("q" quit-window) (" " scroll-up-command) (,(kbd "S-SPC") scroll-down-command) @@ -555,18 +556,29 @@ Letters do not insert themselves; instead, they are commands. (,(kbd "") backward-button) ([return] push-button))) +(defun sx-question-mode-visit () + "Visit the currently displayed question." + (interactive) + (sx-question-mode--ensure-mode) + (sx-assoc-let sx-question-mode--data + (browse-url .link))) + (defun sx-question-mode-refresh () "Refresh currently displayed question. Queries the API for any changes to the question or its answers or comments, and redisplays it." (interactive) - (unless (derived-mode-p 'sx-question-mode) - (error "Not in `sx-question-mode'")) + (sx-question-mode--ensure-mode) (sx-assoc-let sx-question-mode--data (sx-question-mode--display (sx-question-get-question sx-question-list--current-site .question_id) (selected-window)))) +(defun sx-question-mode--ensure-mode () + "Ensures we are in question mode, erroring otherwise." + (unless (derived-mode-p 'sx-question-mode) + (error "Not in `sx-question-mode'"))) + (provide 'sx-question-mode) ;;; sx-question-mode.el ends here -- cgit v1.2.3 From 7052a69347e965ac94ea691c8bfe88a1f3825855 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 17 Nov 2014 11:32:57 +0000 Subject: Set text property sx-question-mode--data-here It holds the data of current section, which is a question or answer for now. This means the data of thing-at-point is always immediately available through get-text-property. --- sx-question-mode.el | 116 +++++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 56 deletions(-) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index 9653485..2c4adb3 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -221,67 +221,71 @@ QUESTION must be a data structure returned by `json-read'." (defun sx-question-mode--print-section (data) "Print a section corresponding to DATA. DATA can represent a question or an answer." - (sx-assoc-let data - (insert sx-question-mode-header-title - (apply - #'propertize - ;; Questions have title - (or .title - ;; Answers don't - sx-question-mode-answer-title) - ;; Section level - 'sx-question-mode--section (if .title 1 2) - ;; face, action and help-echo - sx-question-mode--title-properties)) - ;; Sections can be hidden with overlays - (sx-question-mode--wrap-in-overlay - '(sx-question-mode--section-content t) - (sx-question-mode--insert-header - ;; Author - sx-question-mode-header-author - (sx-question-mode--propertize-display-name .owner) - 'sx-question-mode-author - ;; Date - sx-question-mode-header-date - (concat - (sx-time-seconds-to-date .creation_date) - (when .last_edit_date - (format sx-question-mode-last-edit-format - (sx-time-since .last_edit_date) - (sx-question-mode--propertize-display-name .last_editor)))) - 'sx-question-mode-date) - (when .title - ;; Tags - (sx-question-mode--insert-header - sx-question-mode-header-tags - (mapconcat #'sx-question--tag-format .tags " ") - 'sx-question-mode-tags)) - ;; Body - (insert "\n" - (propertize sx-question-mode-separator - 'face 'sx-question-mode-header - 'sx-question-mode--section 4)) + ;; This makes `data' accessible through + ;; `(get-text-property (point) 'sx-question-mode--data-here)' + (sx-question-mode--wrap-in-text-property + (list 'sx-question-mode--data-here data) + (sx-assoc-let data + (insert sx-question-mode-header-title + (apply + #'propertize + ;; Questions have title + (or .title + ;; Answers don't + sx-question-mode-answer-title) + ;; Section level + 'sx-question-mode--section (if .title 1 2) + ;; face, action and help-echo + sx-question-mode--title-properties)) + ;; Sections can be hidden with overlays (sx-question-mode--wrap-in-overlay - '(face sx-question-mode-content-face) + '(sx-question-mode--section-content t) + (sx-question-mode--insert-header + ;; Author + sx-question-mode-header-author + (sx-question-mode--propertize-display-name .owner) + 'sx-question-mode-author + ;; Date + sx-question-mode-header-date + (concat + (sx-time-seconds-to-date .creation_date) + (when .last_edit_date + (format sx-question-mode-last-edit-format + (sx-time-since .last_edit_date) + (sx-question-mode--propertize-display-name .last_editor)))) + 'sx-question-mode-date) + (when .title + ;; Tags + (sx-question-mode--insert-header + sx-question-mode-header-tags + (mapconcat #'sx-question--tag-format .tags " ") + 'sx-question-mode-tags)) + ;; Body (insert "\n" - (sx-question-mode--fill-and-fontify - .body_markdown) (propertize sx-question-mode-separator - 'face 'sx-question-mode-header)))) - ;; Comments - (when .comments - (insert "\n" - (apply #'propertize - sx-question-mode-comments-title - 'face 'sx-question-mode-title-comments - 'sx-question-mode--section 3 - sx-question-mode--title-properties)) - (sx-question-mode--wrap-in-overlay - '(sx-question-mode--section-content t) - (insert "\n") + 'face 'sx-question-mode-header + 'sx-question-mode--section 4)) (sx-question-mode--wrap-in-overlay '(face sx-question-mode-content-face) - (mapc #'sx-question-mode--print-comment .comments)))))) + (insert "\n" + (sx-question-mode--fill-and-fontify + .body_markdown) + (propertize sx-question-mode-separator + 'face 'sx-question-mode-header)))) + ;; Comments + (when .comments + (insert "\n" + (apply #'propertize + sx-question-mode-comments-title + 'face 'sx-question-mode-title-comments + 'sx-question-mode--section 3 + sx-question-mode--title-properties)) + (sx-question-mode--wrap-in-overlay + '(sx-question-mode--section-content t) + (insert "\n") + (sx-question-mode--wrap-in-overlay + '(face sx-question-mode-content-face) + (mapc #'sx-question-mode--print-comment .comments))))))) (defun sx-question-mode--propertize-display-name (author) "Return display_name of AUTHOR with `sx-question-mode-author' face." -- cgit v1.2.3 From 34d28e79f4a6049dc4ceb44397a2ca0725cecd5f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 17 Nov 2014 11:33:53 +0000 Subject: Define -visit to use answer link if available. --- sx-question-mode.el | 18 +++++++++++++++++- sx-question.el | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index 2c4adb3..20d93c4 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -324,6 +324,16 @@ Return the result of BODY." (push ov sx-question-mode--overlays)) result)) +(defmacro sx-question-mode--wrap-in-text-property (properties &rest body) + "Execute BODY and PROPERTIES to any inserted text. +Return the result of BODY." + (declare (indent 1) + (debug t)) + `(let ((p (point-marker)) + (result (progn ,@body))) + (add-text-properties p (point) ,properties) + result)) + (defun sx-question-mode--insert-header (&rest args) "Insert HEADER and VALUE. HEADER is given `sx-question-mode-header' face, and value is given FACE. @@ -564,7 +574,13 @@ Letters do not insert themselves; instead, they are commands. "Visit the currently displayed question." (interactive) (sx-question-mode--ensure-mode) - (sx-assoc-let sx-question-mode--data + (sx-assoc-let + ;; This allows us to visit the thing-at-point. Which could be a + ;; question or an answer. We use `append', so that if one + ;; doesn't have a `link' item we can fallback to + ;; `sx-question-mode--data'. + (append (get-text-property (point) 'sx-question-mode--data-here) + sx-question-mode--data) (browse-url .link))) (defun sx-question-mode-refresh () diff --git a/sx-question.el b/sx-question.el index fc44bd8..6ef9484 100644 --- a/sx-question.el +++ b/sx-question.el @@ -34,11 +34,13 @@ question.answers question.last_editor question.accepted_answer_id + question.link user.display_name comment.owner comment.body_markdown comment.body answer.last_editor + answer.link answer.owner answer.body_markdown answer.comments) -- cgit v1.2.3 From 2149a4c2375e9c73c85c7375565affe3212b6710 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 18 Nov 2014 19:50:48 +0000 Subject: QUICK-FIX: Link regexp Fixes #74 --- sx-question-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index fa58512..089ee12 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -443,7 +443,7 @@ If ID is nil, use ID2 instead." (save-match-data (goto-char (point-min)) (when (search-forward-regexp - (format (rx line-start (0+ blank) "[%s]:" (1+ blank) + (format (rx line-start (0+ blank) "[%s]:" (0+ blank) (group-n 1 (1+ (not blank)))) (or id id2)) nil t) -- cgit v1.2.3