From 8f4caddf383196c23e8131c4baa0b42d5e06e7dd Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 26 Nov 2014 12:51:51 +0000 Subject: Don't fill link labels or headers Fixes #97 --- sx-question-mode.el | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/sx-question-mode.el b/sx-question-mode.el index 70b8866..36d0090 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -385,12 +385,27 @@ where `value' is given `face' as its face. (goto-char (point-min)) (while (null (eobp)) ;; Don't fill pre blocks. - (unless (sx-question-mode--move-over-pre) + (unless (sx-question-mode--dont-fill-here) (skip-chars-forward "\r\n[:blank:]") (fill-paragraph) (forward-paragraph))) (buffer-string))) +(defun sx-question-mode--dont-fill-here () + "If text shouldn't be filled here, return t and skip over it." + (or (sx-question-mode--move-over-pre) + ;; Skip headers and references + (let ((pos (point))) + (skip-chars-forward "\r\n[:blank:]") + (goto-char (line-beginning-position)) + (if (or (looking-at-p sx-question-mode--reference-regexp) + (looking-at-p "^#")) + ;; Returns non-nil + (forward-paragraph) + ;; Go back and return nil + (goto-char pos) + nil)))) + (defvar sx-question-mode--link-regexp ;; Done at compile time. (rx "[" (group-n 1 (1+ (not (any "]")))) "]" @@ -445,6 +460,13 @@ URL is used as 'help-echo and 'url properties." (or (get-text-property (or pos (point)) 'url) (user-error "No url under point: %s" (or pos (point)))))) +(defvar sx-question-mode--reference-regexp + (rx line-start (0+ blank) "[%s]:" (0+ blank) + (group-n 1 (1+ (not blank)))) + "Regexp used to find the url of labeled links. +E.g.: + [1]: https://...") + (defun sx-question-mode-find-reference (id &optional fallback-id) "Find url identified by reference ID in current buffer. If ID is nil, use FALLBACK-ID instead." @@ -452,8 +474,7 @@ If ID is nil, use FALLBACK-ID instead." (save-match-data (goto-char (point-min)) (when (search-forward-regexp - (format (rx line-start (0+ blank) "[%s]:" (0+ blank) - (group-n 1 (1+ (not blank)))) + (format sx-question-mode--reference-regexp (or id fallback-id)) nil t) (match-string-no-properties 1))))) -- cgit v1.2.3 From 49b85115b488bd88d706d1630764f25c4e4312a2 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 26 Nov 2014 16:15:55 +0000 Subject: Finish partial fix. --- sx-question-mode.el | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sx-question-mode.el b/sx-question-mode.el index 36d0090..19930e7 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -391,6 +391,13 @@ where `value' is given `face' as its face. (forward-paragraph))) (buffer-string))) +(defvar sx-question-mode--reference-regexp + (rx line-start (0+ blank) "[%s]:" (0+ blank) + (group-n 1 (1+ (not blank)))) + "Regexp used to find the url of labeled links. +E.g.: + [1]: https://...") + (defun sx-question-mode--dont-fill-here () "If text shouldn't be filled here, return t and skip over it." (or (sx-question-mode--move-over-pre) @@ -398,7 +405,7 @@ where `value' is given `face' as its face. (let ((pos (point))) (skip-chars-forward "\r\n[:blank:]") (goto-char (line-beginning-position)) - (if (or (looking-at-p sx-question-mode--reference-regexp) + (if (or (looking-at-p (format sx-question-mode--reference-regexp ".+")) (looking-at-p "^#")) ;; Returns non-nil (forward-paragraph) @@ -460,13 +467,6 @@ URL is used as 'help-echo and 'url properties." (or (get-text-property (or pos (point)) 'url) (user-error "No url under point: %s" (or pos (point)))))) -(defvar sx-question-mode--reference-regexp - (rx line-start (0+ blank) "[%s]:" (0+ blank) - (group-n 1 (1+ (not blank)))) - "Regexp used to find the url of labeled links. -E.g.: - [1]: https://...") - (defun sx-question-mode-find-reference (id &optional fallback-id) "Find url identified by reference ID in current buffer. If ID is nil, use FALLBACK-ID instead." -- cgit v1.2.3 From 185365628b3088f77713e569c3390898b7848c22 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 26 Nov 2014 22:10:07 +0000 Subject: Make site a url argument This addresses the apparent api bug which affected both the retrieval of favorites and the site-switching. Se #82 As far as I can see, this issue affects ALL api calls, so it seems reasonable that it should be fixed inside `sx-method-call`. The usage of sx-method-call stays the same, only the internal has changed. --- sx-favorites.el | 3 ++- sx-method.el | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/sx-favorites.el b/sx-favorites.el index aaf2734..d957167 100644 --- a/sx-favorites.el +++ b/sx-favorites.el @@ -52,7 +52,8 @@ Added as hook to initialization." (defun sx-favorites--retrieve-favorites (site) "Obtain list of starred QUESTION_IDs for SITE." (sx-method-call 'me - :submethod (format "favorites?site=%s" site) + :submethod 'favorites + :site site :filter sx-favorite-list-filter :auth t)) diff --git a/sx-method.el b/sx-method.el index 4bd98a5..238f46a 100644 --- a/sx-method.el +++ b/sx-method.el @@ -75,7 +75,9 @@ Return the entire response as a complex alist." (when id (format "/%s" id)) (when submethod - (format "/%s" submethod)))) + (format "/%s" submethod)) + (when (stringp site) + (format "?site=%s" site)))) (call 'sx-request-make)) (lwarn "sx-call-method" :debug "A: %S T: %S. M: %S,%s. F: %S" (equal 'warn auth) access-token method-auth full-method filter-auth) @@ -96,10 +98,8 @@ Return the entire response as a complex alist." (error "This request requires authentication.")))) ;; Concatenate all parameters now that filter is ensured. (setq parameters - (cons `(site . ,site) - (cons (cons 'filter - (sx-filter-get-var filter)) - keywords))) + (cons (cons 'filter (sx-filter-get-var filter)) + keywords)) (funcall call full-method parameters -- cgit v1.2.3 From 5c416202f4897e04d8f5eadc0457b86ca643e716 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 26 Nov 2014 22:42:01 +0000 Subject: Don't do this patch when POSTing --- sx-method.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sx-method.el b/sx-method.el index 238f46a..4810e8c 100644 --- a/sx-method.el +++ b/sx-method.el @@ -76,8 +76,12 @@ Return the entire response as a complex alist." (format "/%s" id)) (when submethod (format "/%s" submethod)) - (when (stringp site) - (format "?site=%s" site)))) + ;; On GET methods site is buggy, so we + ;; need to provide it as a url argument. + (when (and site (string= url-method "GET")) + (prog1 + (format "?site=%s" site) + (setq site nil))))) (call 'sx-request-make)) (lwarn "sx-call-method" :debug "A: %S T: %S. M: %S,%s. F: %S" (equal 'warn auth) access-token method-auth full-method filter-auth) @@ -100,6 +104,8 @@ Return the entire response as a complex alist." (setq parameters (cons (cons 'filter (sx-filter-get-var filter)) keywords)) + (when site + (setq parameters (cons (cons 'site site) parameters))) (funcall call full-method parameters -- cgit v1.2.3 From f9c12d9c09e1dff7c29b3bf94dbccd042f48f078 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 27 Nov 2014 01:47:11 +0000 Subject: Function quote sx-request-make --- sx-method.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-method.el b/sx-method.el index 4810e8c..1b20cbf 100644 --- a/sx-method.el +++ b/sx-method.el @@ -82,7 +82,7 @@ Return the entire response as a complex alist." (prog1 (format "?site=%s" site) (setq site nil))))) - (call 'sx-request-make)) + (call #'sx-request-make)) (lwarn "sx-call-method" :debug "A: %S T: %S. M: %S,%s. F: %S" (equal 'warn auth) access-token method-auth full-method filter-auth) (unless access-token -- cgit v1.2.3