From 9d39b0d1bcaa3186e21171f656b807fde2611b53 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 03:36:29 +0000 Subject: Improve button-copy --- sx.el | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sx.el') diff --git a/sx.el b/sx.el index 0fe98c7..83278d3 100644 --- a/sx.el +++ b/sx.el @@ -63,6 +63,7 @@ question.upvoted question.downvoted question.question_id + question.share_link user.display_name comment.owner comment.body_markdown @@ -78,6 +79,7 @@ answer.answer_id answer.last_editor answer.link + answer.share_link answer.owner answer.body_markdown answer.upvoted -- cgit v1.2.3 From 69b90717fb304958be8aabe6c3d02199293b27b4 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 20:02:14 +0000 Subject: New sx--shorten-url function in sx.el --- sx.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'sx.el') diff --git a/sx.el b/sx.el index 83278d3..10c0baa 100644 --- a/sx.el +++ b/sx.el @@ -173,6 +173,21 @@ would yield cons-cell)))) data)))) +(defun sx--shorten-url (url) + "Shorten URL hiding anything other than the domain. +Paths after the domain are replaced with \"...\". +Anything before the (sub)domain is removed." + (replace-regexp-in-string + ;; Remove anything after domain. + (rx (group-n 1 (and (1+ (any word ".")) "/")) + (1+ anything) string-end) + (eval-when-compile + (concat "\\1" (if (char-displayable-p ?…) "…" "..."))) + ;; Remove anything before subdomain. + (replace-regexp-in-string + (rx string-start (or (and (0+ word) (optional ":") "//"))) + "" url))) + ;;; Printing request data (defvar sx--overlays nil -- cgit v1.2.3 From 58c3a9c3a85920dfcaccea63b347f98b945e409f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 22:05:00 +0000 Subject: Add sx--unindent-text function Used to extract the code contained in code-blocks --- sx.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'sx.el') diff --git a/sx.el b/sx.el index 10c0baa..fc58b02 100644 --- a/sx.el +++ b/sx.el @@ -188,6 +188,27 @@ Anything before the (sub)domain is removed." (rx string-start (or (and (0+ word) (optional ":") "//"))) "" url))) +(defun sx--unindent-text (text) + "Remove indentation from TEXT." + (with-temp-buffer + (insert text) + (goto-char (point-min)) + (let (result) + (while (null (eobp)) + (skip-chars-forward "[:blank:]") + (unless (looking-at "$") + (push (current-column) result)) + (forward-line 1)) + (when result + (let ((rx (format "^ \\{0,%s\\}" + (apply #'min result)))) + (goto-char (point-min)) + (while (and (null (eobp)) + (search-forward-regexp rx nil 'noerror)) + (replace-match "") + (forward-line 1))))) + (buffer-string))) + ;;; Printing request data (defvar sx--overlays nil -- cgit v1.2.3 From 39f2ae05597edd902610764b9b402111d33a8fe7 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 1 Dec 2014 10:30:08 +0000 Subject: question-mod now uses overlays to store the sx--data-here property This lets us stack one inside each other (comments inside questions) without overwriting them. --- sx-interaction.el | 6 +++--- sx-question-print.el | 4 ++-- sx.el | 24 +++++++++++++----------- 3 files changed, 18 insertions(+), 16 deletions(-) (limited to 'sx.el') diff --git a/sx-interaction.el b/sx-interaction.el index 92b062b..b6113a2 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -31,11 +31,11 @@ ;;; Using data in buffer (defun sx--data-here () "Get the text property `sx--data-here'." - (or (get-text-property (point) 'sx--data-here) + (or (get-pos-property (point) 'sx--data-here) (and (derived-mode-p 'sx-question-list-mode) (tabulated-list-get-id)) - (or (derived-mode-p 'sx-question-mode) - sx-question-mode--data))) + (and (derived-mode-p 'sx-question-mode) + sx-question-mode--data))) (defun sx--maybe-update-display () "Refresh the question list if we're inside it." diff --git a/sx-question-print.el b/sx-question-print.el index f49346b..45124c4 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -185,7 +185,7 @@ QUESTION must be a data structure returned by `json-read'." DATA can represent a question or an answer." ;; This makes `data' accessible through `sx--data-here'. (sx-assoc-let data - (sx--wrap-in-text-property + (sx--wrap-in-overlay (list 'sx--data-here data) (insert sx-question-mode-header-title) (insert-text-button @@ -270,7 +270,7 @@ DATA can represent a question or an answer." "Print the comment described by alist COMMENT-DATA. The comment is indented, filled, and then printed according to `sx-question-mode-comments-format'." - (sx--wrap-in-text-property + (sx--wrap-in-overlay (list 'sx--data-here comment-data) (sx-assoc-let comment-data (insert diff --git a/sx.el b/sx.el index fc58b02..f1d3634 100644 --- a/sx.el +++ b/sx.el @@ -215,6 +215,11 @@ Anything before the (sub)domain is removed." "Overlays created by sx on this buffer.") (make-variable-buffer-local 'sx--overlays) +(defvar sx--overlay-printing-depth 0 + "Track how many overlays we're printing on top of each other. +Used for assigning higher priority to inner overlays.") +(make-variable-buffer-local 'sx--overlay-printing-depth) + (defmacro sx--wrap-in-overlay (properties &rest body) "Start a scope with overlay PROPERTIES and execute BODY. Overlay is pushed on the buffer-local variable `sx--overlays' and @@ -224,24 +229,21 @@ Return the result of BODY." (declare (indent 1) (debug t)) `(let ((p (point-marker)) - (result (progn ,@body))) + (result (progn ,@body)) + ;; The first overlay is the shallowest. Any overlays created + ;; while the first one is still being created go deeper and + ;; deeper. + (sx--overlay-printing-depth (1+ sx--overlay-printing-depth))) (let ((ov (make-overlay p (point))) (props ,properties)) (while props (overlay-put ov (pop props) (pop props))) + ;; Let's multiply by 10 just in case we ever want to put + ;; something in the middle. + (overlay-put ov 'priority (* 10 sx--overlay-printing-depth)) (push ov sx--overlays)) result)) -(defmacro sx--wrap-in-text-property (properties &rest body) - "Start a scope with PROPERTIES and execute BODY. -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--user-@name (user) "Get the `display_name' of USER prepended with @. In order to correctly @mention the user, all whitespace is -- cgit v1.2.3