From a77d38b11ec1a2e886fb739f7df3e7bbca1a34c7 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 21:00:26 +0000 Subject: Slight tweak to question-mode-recenter-line So the "add comment" button is visible after navigating to the comments section. --- 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 01a980a..6f5dec3 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -82,7 +82,7 @@ If WINDOW is given, use that to display the buffer." ;; To move between sections, just search for the property. The value ;; of the text-property is the depth of the section (1 for contents, 2 ;; for comments). -(defcustom sx-question-mode-recenter-line 1 +(defcustom sx-question-mode-recenter-line 2 "Screen line to which we recenter after moving between sections. This is used as an argument to `recenter', only used if the end of section is outside the window. -- cgit v1.2.3 From bf56eba935f73c1803ea9964671a36bccb4efa21 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 1 Dec 2014 01:00:06 +0000 Subject: Define and use sx-question-mode-display-buffer-function --- sx-question-mode.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index 01a980a..6423ad8 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -30,6 +30,14 @@ ;;; Displaying a question +(defcustom sx-question-mode-display-buffer-function #'switch-to-buffer + "Function used to display the question buffer. +Called, for instance, when hitting \\`\\[sx-question-list-display-question]' on an entry in the +question list. +This is not used when navigating the question list with `\\[sx-question-list-view-next]." + :type 'function + :group 'sx-question-mode) + (defvar sx-question-mode--window nil "Window where the content of questions is displayed.") @@ -71,7 +79,8 @@ If WINDOW is given, use that to display the buffer." ;; No window, but the buffer is already being displayed somewhere. ((get-buffer-window sx-question-mode--buffer 'visible)) ;; Neither, so we create the window. - (t (switch-to-buffer sx-question-mode--buffer))) + (t (funcall sx-question-mode-display-buffer-function + sx-question-mode--buffer))) sx-question-mode--buffer) -- cgit v1.2.3 From 867224348a5d979af7a965c9bbe476dea3c3638f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 1 Dec 2014 01:46:34 +0000 Subject: Refactor sx-question-mode--window into a function. It made little sense the way it was, and it was complicated. Now that it's a function, it's always up to date. --- sx-question-mode.el | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index 6423ad8..bee3e29 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -38,15 +38,20 @@ This is not used when navigating the question list with `\\[sx-question-list-vie :type 'function :group 'sx-question-mode) -(defvar sx-question-mode--window nil - "Window where the content of questions is displayed.") - (defvar sx-question-mode--buffer nil "Buffer being used to display questions.") (defvar sx-question-mode--data nil "The data of the question being displayed.") +(defun sx-question-mode--get-window () + "Return a window displaying a question, or nil." + (car-safe + (cl-member-if + (lambda (x) (with-selected-window x + (derived-mode-p 'sx-question-mode))) + (window-list nil 'never nil)))) + (defun sx-question-mode--display (data &optional window) "Display question given by DATA on WINDOW. If WINDOW is nil, use selected one. -- cgit v1.2.3 From 2a87b0f4830d408d59cf4ddb21ddb8371e4787c7 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 1 Dec 2014 10:45:15 +0000 Subject: Comments are now hidden when you fold the question --- sx-question-mode.el | 14 ++++++++------ sx-question-print.el | 54 ++++++++++++++++++++++++++-------------------------- 2 files changed, 35 insertions(+), 33 deletions(-) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index 6f5dec3..c44519c 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -141,9 +141,9 @@ If DIRECTION is negative, move backwards instead." "Hide or show section under point. Optional argument _ is for `push-button'." (interactive) - (let ((ov (car (or (sx-question-mode--section-overlays-at (point)) - (sx-question-mode--section-overlays-at - (line-end-position)))))) + (let ((ov (or (sx-question-mode--section-overlays-at + (line-end-position)) + (sx-question-mode--section-overlays-at (point))))) (goto-char (overlay-start ov)) (forward-line 0) (overlay-put @@ -151,9 +151,11 @@ Optional argument _ is for `push-button'." (null (overlay-get ov 'invisible))))) (defun sx-question-mode--section-overlays-at (pos) - "Return a list of `sx-question-mode--section-content' overlays at POS." - (cl-remove-if (lambda (x) (null (overlay-get x 'sx-question-mode--section-content))) - (overlays-at pos))) + "Return the highest priority section overlay at POS. +A section overlay has a `sx-question-mode--section-content' +property." + (cdr-safe (get-char-property-and-overlay + pos 'sx-question-mode--section-content nil))) ;;; Major-mode diff --git a/sx-question-print.el b/sx-question-print.el index d6d554d..307742a 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -237,35 +237,35 @@ DATA can represent a question or an answer." .body_markdown) "\n" (propertize sx-question-mode-separator - 'face 'sx-question-mode-header)))) - ;; Comments have their own `sx--data-here' property (so they can - ;; be upvoted too). - (when .comments - (insert "\n") - (insert-text-button - sx-question-mode-comments-title - 'face 'sx-question-mode-title-comments - 'sx-question-mode--section 3 - 'sx-button-copy .share_link - :type 'sx-question-mode-title) - (sx--wrap-in-overlay - '(sx-question-mode--section-content t) + 'face 'sx-question-mode-header))) + ;; Comments have their own `sx--data-here' property (so they can + ;; be upvoted too). + (when .comments (insert "\n") + (insert-text-button + sx-question-mode-comments-title + 'face 'sx-question-mode-title-comments + 'sx-question-mode--section 3 + 'sx-button-copy .share_link + :type 'sx-question-mode-title) (sx--wrap-in-overlay - '(face sx-question-mode-content-face) - (mapc #'sx-question-mode--print-comment .comments)) - ;; If there are comments, we want part of this margin to go - ;; inside them, so the button get's placed beside the - ;; "Comments" header when you hide them. - (insert " "))) - ;; If there are no comments, we have to add this margin here. - (unless .comments - (insert " ")) - (insert " ") - ;; This is where the "add a comment" button is printed. - (insert-text-button "Add a Comment" - :type 'sx-button-comment) - (insert "\n")))) + '(sx-question-mode--section-content t) + (insert "\n") + (sx--wrap-in-overlay + '(face sx-question-mode-content-face) + (mapc #'sx-question-mode--print-comment .comments)) + ;; If there are comments, we want part of this margin to go + ;; inside them, so the button get's placed beside the + ;; "Comments" header when you hide them. + (insert " "))) + ;; If there are no comments, we have to add this margin here. + (unless .comments + (insert " ")) + (insert " ") + ;; This is where the "add a comment" button is printed. + (insert-text-button "Add a Comment" + :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." -- cgit v1.2.3