From 7da9b2567c2635dfab5f9400fb76297f61b80be4 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 16:57:49 -0500 Subject: Test sx-time-since --- test/test-printing.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test-printing.el b/test/test-printing.el index 6225bf6..60382b2 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -27,6 +27,18 @@ after being run through `sx-question--tag-format'." ;;; Tests +(ert-deftest time-since () + (cl-letf (((symbol-function #'float-time) + (lambda () 1420148997.))) + (should + (string= + "67m" + (sx-time-since 1420145000.))) + (should + (string= + "12h" + (sx-time-since 1420105000.))))) + (ert-deftest question-list-tag () "Test `sx-question--tag-format'." (should -- cgit v1.2.3 From 54849b2564c3d9bb95bc3512b568e30aa21a3db4 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 23:29:55 -0500 Subject: Update Makefile Clean compiled files before every test. This ensures that the changes made during the current session are applied when re-testing. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 7b0b698..a72bea1 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ $(VERSIONS) :: evm use emacs-24.$@-bin emacs --version cask install + cask clean-elc emacs --batch -L . -l ert -l test/tests.el -f ert-run-tests-batch-and-exit install_cask: -- cgit v1.2.3 From 3b275a93789a568d23ece65086ffebb8de430f3a Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 23:40:20 -0500 Subject: Add test for user entry functions --- test/tests.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/tests.el b/test/tests.el index d709600..7bfc86c 100644 --- a/test/tests.el +++ b/test/tests.el @@ -59,3 +59,19 @@ (mapc #'sx-load-test '(api macros printing util)) + +(ert-deftest user-entry-functions () + "Ensures all entry functions are autoloaded." + (should + (cl-every + #'fboundp + '(sx-ask + sx-authenticate + sx-bug-report + sx-tab-frontpage + sx-tab-hot + sx-tab-month + sx-tab-newest + sx-tab-topvoted + sx-tab-week + sx-version)))) -- cgit v1.2.3 From 7a75cd61e822a4895b85bc17780b163bd6876ca7 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 4 Jan 2015 17:26:16 -0500 Subject: Add more autoloads to test --- test/tests.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/tests.el b/test/tests.el index 5eec57c..493d7dc 100644 --- a/test/tests.el +++ b/test/tests.el @@ -69,10 +69,14 @@ '(sx-ask sx-authenticate sx-bug-report + sx-switchto-map + sx-tab-featured sx-tab-frontpage sx-tab-hot sx-tab-month sx-tab-newest + sx-tab-starred sx-tab-topvoted + sx-tab-unanswered sx-tab-week sx-version)))) -- cgit v1.2.3 From 2d4b14482c92997b3c97731795e1eb6f054fecf6 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 15 Jan 2015 19:13:33 -0200 Subject: Hitting RET on link buttons calls sx-open-link --- sx-button.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sx-button.el b/sx-button.el index 5a2f052..e00b086 100644 --- a/sx-button.el +++ b/sx-button.el @@ -98,9 +98,9 @@ usually part of a code-block." (defun sx-button-follow-link (&optional pos) "Follow link at POS. If POS is nil, use `point'." (interactive) - (browse-url - (or (get-text-property (or pos (point)) 'sx-button-url) - (sx-user-error "No url under point: %s" (or pos (point)))))) + (let ((url (or (get-text-property (or pos (point)) 'sx-button-url) + (sx-user-error "No url under point: %s" (or pos (point)))))) + (sx-open-link url))) ;;; Help-echo definitions -- cgit v1.2.3 From 2ee72cc4361031f3ab34e312fca191125ce18bfc Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 15 Jan 2015 20:04:24 -0200 Subject: Move tag-format to sx-tag.el --- sx-question-list.el | 2 +- sx-question-print.el | 2 +- sx-question.el | 4 ---- sx-tag.el | 6 ++++++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sx-question-list.el b/sx-question-list.el index 884f994..306d39f 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -170,7 +170,7 @@ Also see `sx-question-list-refresh'." " " ;; @TODO: Make this width customizable. (Or maybe just make ;; the whole thing customizable) - (propertize (format "%-40s" (mapconcat #'sx-question--tag-format .tags " ")) + (propertize (format "%-40s" (mapconcat #'sx-tag--format .tags " ")) 'face 'sx-question-list-tags) " " (sx-user--format "%15d %4r" .owner) diff --git a/sx-question-print.el b/sx-question-print.el index 9a51efb..b258fde 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -223,7 +223,7 @@ DATA can represent a question or an answer." ;; Tags (sx-question-mode--insert-header sx-question-mode-header-tags - (mapconcat #'sx-question--tag-format .tags " ") + (mapconcat #'sx-tag--format .tags " ") 'sx-question-mode-tags)) ;; Body (insert "\n" diff --git a/sx-question.el b/sx-question.el index 1adbc24..0f73795 100644 --- a/sx-question.el +++ b/sx-question.el @@ -183,10 +183,6 @@ If no cache exists for it, initialize one with SITE." (and (integerp .accepted_answer_id) .accepted_answer_id))) -(defun sx-question--tag-format (tag) - "Formats TAG for display." - (concat "[" tag "]")) - (provide 'sx-question) ;;; sx-question.el ends here diff --git a/sx-tag.el b/sx-tag.el index b2ad375..d69f330 100644 --- a/sx-tag.el +++ b/sx-tag.el @@ -133,6 +133,12 @@ tags." (push input list)) (reverse list))) + +;;; Printing +(defun sx-tag--format (tag) + "Formats TAG for display." + (concat "[" tag "]")) + (provide 'sx-tag) ;;; sx-tag.el ends here -- cgit v1.2.3 From c08dc31400711fbebea2c7ca650bd72dc3f92392 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 15 Jan 2015 21:56:45 -0200 Subject: Implement sx-search-tag-at-point command --- sx-search.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sx-search.el b/sx-search.el index aefd12e..c22a554 100644 --- a/sx-search.el +++ b/sx-search.el @@ -32,6 +32,7 @@ (require 'sx) (require 'sx-question-list) +(require 'sx-question-mode) (require 'sx-tag) (defvar sx-search--query-history nil @@ -103,6 +104,19 @@ prefix argument, the user is asked for everything." (sx-question-list-refresh 'redisplay) (switch-to-buffer (current-buffer)))) + +;;; Tag +(defun sx-search-tag-at-point (&optional pos) + "Follow tag under position POS or point." + (interactive) + (let ((tag (save-excursion + (when pos (goto-char pos)) + (or (get-text-property (point) 'sx-tag) + (thing-at-point 'symbol))))) + (sx-search (or sx-question-list--site + (sx-assoc-let sx-question-mode--data .site_par)) + nil tag))) + (provide 'sx-search) ;;; sx-search.el ends here -- cgit v1.2.3 From 2fd860b5a17fe3f8b7bc3759a79bb7a2ae343bf2 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 15 Jan 2015 21:57:03 -0200 Subject: Define button-tag --- sx-button.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sx-button.el b/sx-button.el index 5a2f052..69e8a7e 100644 --- a/sx-button.el +++ b/sx-button.el @@ -158,6 +158,13 @@ usually part of a code-block." 'face 'sx-user-name :supertype 'sx-button) +(declare-function sx-search-tag-at-point "sx-tag") +(define-button-type 'sx-button-tag + 'action #'sx-search-tag-at-point + 'help-echo sx-button--tag-help-echo + 'face 'sx-tag + :supertype 'sx-button) + (define-button-type 'sx-button-comment 'help-echo (concat "mouse-1, RET" (propertize ": write a comment" -- cgit v1.2.3 From feb8082bac11154d4f6cc768add49bd9b7c0c107 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 15 Jan 2015 22:02:41 -0200 Subject: Turn tags into buttons --- sx-tag.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sx-tag.el b/sx-tag.el index d69f330..ba32544 100644 --- a/sx-tag.el +++ b/sx-tag.el @@ -137,7 +137,12 @@ tags." ;;; Printing (defun sx-tag--format (tag) "Formats TAG for display." - (concat "[" tag "]")) + (with-temp-buffer + (insert-text-button (concat "[" tag "]") + 'sx-button-copy tag + 'sx-tag tag + :type 'sx-button-tag) + (buffer-string))) (provide 'sx-tag) ;;; sx-tag.el ends here -- cgit v1.2.3 From 1dfa97db27a72f0121001b1d85c13d1cdee37f31 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 15 Jan 2015 22:07:09 -0200 Subject: sx-question-mode--insert-header accepts a nil face as third arg --- sx-question-print.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sx-question-print.el b/sx-question-print.el index b258fde..0ae0f04 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -299,7 +299,10 @@ where `value' is given `face' as its face. (while args (insert (propertize (pop args) 'face 'sx-question-mode-header) - (propertize (pop args) 'face (pop args))))) + (let ((header (pop args)) + (face (pop args))) + (if face (propertize header 'face face) + header))))) ;;;; Printing and Font-locking the content (body) -- cgit v1.2.3 From 74fce2c36f803abe232eebe9f542696b8d0fac23 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 15 Jan 2015 22:07:48 -0200 Subject: Always use sx-tag face for tags --- sx-question-list.el | 8 +------- sx-question-print.el | 7 +------ sx-tag.el | 6 ++++++ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/sx-question-list.el b/sx-question-list.el index 306d39f..256bdb4 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -81,11 +81,6 @@ "" :group 'sx-question-list-faces) -(defface sx-question-list-tags - '((t :inherit sx-question-mode-tags)) - "" - :group 'sx-question-list-faces) - (defface sx-question-list-date '((t :inherit font-lock-comment-face)) "" @@ -170,8 +165,7 @@ Also see `sx-question-list-refresh'." " " ;; @TODO: Make this width customizable. (Or maybe just make ;; the whole thing customizable) - (propertize (format "%-40s" (mapconcat #'sx-tag--format .tags " ")) - 'face 'sx-question-list-tags) + (format "%-40s" (mapconcat #'sx-tag--format .tags " ")) " " (sx-user--format "%15d %4r" .owner) (propertize " " 'display "\n"))))))) diff --git a/sx-question-print.el b/sx-question-print.el index 0ae0f04..6791222 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -79,11 +79,6 @@ Some faces of this mode might be defined in the `sx-user' group." :type 'string :group 'sx-question-mode) -(defface sx-question-mode-tags - '((t :underline nil :inherit font-lock-function-name-face)) - "Face used on the question tags in the question buffer." - :group 'sx-question-mode-faces) - (defface sx-question-mode-score '((t)) "Face used for the score in the question buffer." @@ -224,7 +219,7 @@ DATA can represent a question or an answer." (sx-question-mode--insert-header sx-question-mode-header-tags (mapconcat #'sx-tag--format .tags " ") - 'sx-question-mode-tags)) + nil)) ;; Body (insert "\n" (propertize sx-question-mode-separator diff --git a/sx-tag.el b/sx-tag.el index ba32544..d9e2877 100644 --- a/sx-tag.el +++ b/sx-tag.el @@ -24,6 +24,12 @@ (require 'sx) (require 'sx-method) +(defface sx-tag + '((t :underline nil :inherit font-lock-function-name-face)) + "Face used on the question tags in the question buffer." + :group 'sx-question-mode-faces + :group 'sx-question-list-faces) + ;;; Getting the list from a site (defconst sx-tag-filter -- cgit v1.2.3 From faddde5ff2c4f41c4844ee4ae88819dcfab5d8c8 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 15 Jan 2015 22:17:20 -0200 Subject: Define sx-button--tag-help-echo --- sx-button.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sx-button.el b/sx-button.el index 69e8a7e..1d4eb4f 100644 --- a/sx-button.el +++ b/sx-button.el @@ -117,6 +117,12 @@ usually part of a code-block." "link") "Help echoed in the minibuffer when point is on a user.") +(defconst sx-button--tag-help-echo + (format sx-button--help-echo + "Tag search" + "tag") + "Help echoed in the minibuffer when point is on a tag.") + (defconst sx-button--question-title-help-echo (format sx-button--help-echo "hide content" -- cgit v1.2.3 From 33746908e639e53320fe1412ae01b01854a98605 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 15 Jan 2015 22:31:08 -0200 Subject: Define sx-tag--insert --- sx-tag.el | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sx-tag.el b/sx-tag.el index d9e2877..009c8b1 100644 --- a/sx-tag.el +++ b/sx-tag.el @@ -142,14 +142,18 @@ tags." ;;; Printing (defun sx-tag--format (tag) - "Formats TAG for display." + "Format and return TAG for display." (with-temp-buffer - (insert-text-button (concat "[" tag "]") - 'sx-button-copy tag - 'sx-tag tag - :type 'sx-button-tag) + (sx-tag--insert tag) (buffer-string))) +(defun sx-tag--insert (tag) + "Insert TAG button." + (insert-text-button (concat "[" tag "]") + 'sx-button-copy tag + 'sx-tag tag + :type 'sx-button-tag)) + (provide 'sx-tag) ;;; sx-tag.el ends here -- cgit v1.2.3 From b4c850e313e51f27196de473e1bcfc546c0abb6a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 15 Jan 2015 22:31:53 -0200 Subject: Turn tags inside body into buttons. Fix #229 --- sx-question-print.el | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index 6791222..d7c2a20 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -315,7 +315,8 @@ E.g.: (defconst sx-question-mode--link-regexp ;; Done at compile time. - (rx (or (and "[" (group-n 1 (1+ (not (any "]")))) "]" + (rx (or (and "[tag:" (group-n 5 (+ (not (any " ]")))) "]") + (and "[" (group-n 1 (1+ (not (any "]")))) "]" (or (and "(" (group-n 2 (1+ (not (any ")")))) ")") (and "[" (group-n 3 (1+ (not (any "]")))) "]"))) (group-n 4 (and (and "http" (opt "s") "://") "" @@ -363,18 +364,24 @@ E.g.: (save-excursion (goto-char (point-min)) (while (search-forward-regexp sx-question-mode--link-regexp nil t) - (let* ((text (match-string-no-properties 1)) - (url (or (match-string-no-properties 2) - (match-string-no-properties 4) - (sx-question-mode-find-reference - (match-string-no-properties 3) - text))) - (full-text (match-string-no-properties 0))) - (when (stringp url) - (replace-match "") - (sx-question-mode--insert-link - (or (if sx-question-mode-pretty-links text full-text) url) - url)))))) + ;; Tags are tag-buttons. + (let ((tag (match-string-no-properties 5))) + (if (and tag (> (length tag) 0)) + (progn (replace-match "") + (sx-tag--insert tag)) + ;; Other links are link-buttons. + (let* ((text (match-string-no-properties 1)) + (url (or (match-string-no-properties 2) + (match-string-no-properties 4) + (sx-question-mode-find-reference + (match-string-no-properties 3) + text))) + (full-text (match-string-no-properties 0))) + (when (stringp url) + (replace-match "") + (sx-question-mode--insert-link + (or (if sx-question-mode-pretty-links text full-text) url) + url)))))))) (defun sx-question-mode--insert-link (text url) "Return a link propertized version of string TEXT. -- cgit v1.2.3 From 058cca312d48ad44dc8b633be74e5731446d158e Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 15 Jan 2015 22:46:32 -0200 Subject: require 'sx-button --- sx-tag.el | 1 + 1 file changed, 1 insertion(+) diff --git a/sx-tag.el b/sx-tag.el index 009c8b1..316226b 100644 --- a/sx-tag.el +++ b/sx-tag.el @@ -23,6 +23,7 @@ (require 'sx) (require 'sx-method) +(require 'sx-button) (defface sx-tag '((t :underline nil :inherit font-lock-function-name-face)) -- cgit v1.2.3 From bed5191a0137cb115656baf6ae3535b2a646d0b2 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Fri, 16 Jan 2015 12:56:02 -0200 Subject: Fix and improve tests --- test/test-printing.el | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/test-printing.el b/test/test-printing.el index 7384829..52fe5be 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -28,11 +28,18 @@ after being run through `sx-question--tag-format'." ;;; Tests (ert-deftest question-list-tag () - "Test `sx-question--tag-format'." + "Test `sx-tag--format'." (should - (string= - (sx-question--tag-format "tag") - "[tag]"))) + (string= (sx-tag--format "tag") "[tag]")) + (with-temp-buffer + (insert (sx-tag--format "tag")) + (should (get-char-property (point-min) 'button)) + (should + (eq (get-char-property (point-min) 'face) 'sx-tag)) + (should + (string= (get-char-property (point-min) 'sx-tag) "tag")) + (should + (string= (get-char-property (point-min) 'sx-button-copy) "tag")))) (ert-deftest question-list-display () (cl-letf (((symbol-function #'sx-request-make) -- cgit v1.2.3 From 802f778bb28506d9be92618913c8db0cb4eda539 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Fri, 16 Jan 2015 12:42:53 -0200 Subject: load test-state --- test/tests.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests.el b/test/tests.el index 493d7dc..be1552b 100644 --- a/test/tests.el +++ b/test/tests.el @@ -59,7 +59,7 @@ (apply #'message message args))) (mapc #'sx-load-test - '(api macros printing util search)) + '(api macros printing util search state)) (ert-deftest user-entry-functions () "Ensures all entry functions are autoloaded." -- cgit v1.2.3 From 148da420d9f464f3cc8046fed99a103af0fd7bed Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Fri, 16 Jan 2015 12:52:14 -0200 Subject: Test displaying a question --- test/test-printing.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test-printing.el b/test/test-printing.el index 677dca3..9512a5e 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -146,6 +146,14 @@ after being run through `sx-question--tag-format'." (should (equal object '((answers . [something "answer"])))))) + +;;; question-mode +(ert-deftest sx-display-question () + (should + (sx-display-question sx-test-data-questions)) + (should-error + (sx-display-question sx-test-data-questions nil 1))) + (ert-deftest sx-question-mode--fill-and-fontify () "Check complicated questions are filled correctly." (should @@ -202,3 +210,4 @@ if you used the Stack Exchange login method, you'd... [1]: http://i.stack.imgur.com/ktFTs.png [2]: http://i.stack.imgur.com/5l2AY.png [3]: http://i.stack.imgur.com/22myl.png"))) + -- cgit v1.2.3 From 6f83f1ef10f1316b489eba926aebecb51f37a6e7 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 26 Jan 2015 14:52:21 -0200 Subject: Fix test --- test/test-printing.el | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/test-printing.el b/test/test-printing.el index 52fe5be..a6815e2 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -13,7 +13,7 @@ (defmacro question-list-regex (title votes answers &rest tags) "Construct a matching regexp for TITLE, VOTES, and ANSWERS. Each element of TAGS is appended at the end of the expression -after being run through `sx-question--tag-format'." +after being run through `sx-tag--format'." `(rx line-start (+ whitespace) ,(number-to-string votes) (+ whitespace) ,(number-to-string answers) @@ -22,8 +22,7 @@ after being run through `sx-question--tag-format'." (+ (any whitespace digit)) (or "y" "d" "h" "m" "mo" "s") " ago" (+ whitespace) - (eval (mapconcat #'sx-question--tag-format - (list ,@tags) " ")))) + (eval (mapconcat #'sx-tag--format (list ,@tags) " ")))) ;;; Tests -- cgit v1.2.3 From 3116757fbbbd2a16a5809d316067338a9492e78f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 3 Feb 2015 13:39:30 -0200 Subject: Fix test --- test/test-printing.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test-printing.el b/test/test-printing.el index 9512a5e..1eea281 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -150,6 +150,8 @@ after being run through `sx-question--tag-format'." ;;; question-mode (ert-deftest sx-display-question () (should + (sx-display-question (elt sx-test-data-questions 0))) + (should-error (sx-display-question sx-test-data-questions)) (should-error (sx-display-question sx-test-data-questions nil 1))) -- cgit v1.2.3 From cf2e0f10498a4fe3f65d20454dee621062d194fd Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 3 Feb 2015 16:32:42 -0200 Subject: Really fix test --- test/test-printing.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test-printing.el b/test/test-printing.el index 1eea281..bcc3dd9 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -149,8 +149,9 @@ after being run through `sx-question--tag-format'." ;;; question-mode (ert-deftest sx-display-question () - (should - (sx-display-question (elt sx-test-data-questions 0))) + ;; Check it doesn't error. + (sx-display-question (elt sx-test-data-questions 0)) + ;; Check it does error. (should-error (sx-display-question sx-test-data-questions)) (should-error -- cgit v1.2.3 From 4ed76728809666cee41336dc5191dcf982806f38 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 3 Feb 2015 16:55:21 -0200 Subject: Don't freak out because question_id is nil. --- sx-question.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sx-question.el b/sx-question.el index 1df4900..1fde1aa 100644 --- a/sx-question.el +++ b/sx-question.el @@ -148,7 +148,8 @@ See `sx-question--user-read-list'." ;; Question wasn't present. (t (sx-sorted-insert-skip-first - q-cell site-cell (lambda (x y) (> (car x) (car y)))))))) + q-cell site-cell + (lambda (x y) (> (or (car x) -1) (or (car y) -1)))))))) ;; Save the results. ;; @TODO This causes a small lag on `j' and `k' as the list gets ;; large. Should we do this on a timer? -- cgit v1.2.3 From b7d1d7c47e6bbb907df90ee078ef18ba47412b75 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 12 Feb 2015 18:54:41 -0200 Subject: Try sx-open-link, THEN do sx-visit-externally --- sx-button.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sx-button.el b/sx-button.el index e00b086..992c654 100644 --- a/sx-button.el +++ b/sx-button.el @@ -100,7 +100,12 @@ usually part of a code-block." (interactive) (let ((url (or (get-text-property (or pos (point)) 'sx-button-url) (sx-user-error "No url under point: %s" (or pos (point)))))) - (sx-open-link url))) + ;; If we didn't recognize the link, this errors immediately. If + ;; we mistakenly recognize it, it will error when we try to fetch + ;; whatever we thought it was. + (condition-case nil (sx-open-link url) + ;; When it errors, don't blame the user, just visit externally. + (error (sx-visit-externally url))))) ;;; Help-echo definitions -- cgit v1.2.3 From 1f73185f411de81a5e26152377c499498d732d8c Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 12 Feb 2015 21:26:03 -0200 Subject: require 'sx-tag --- sx-question-list.el | 1 + 1 file changed, 1 insertion(+) diff --git a/sx-question-list.el b/sx-question-list.el index 07355d0..333fd83 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -27,6 +27,7 @@ (require 'sx) (require 'sx-time) +(require 'sx-tag) (require 'sx-site) (require 'sx-question) (require 'sx-question-mode) -- cgit v1.2.3 From cb29144eb54eb8541f469995a13909ec0bdb1c1d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 14 Feb 2015 15:46:39 -0200 Subject: Fix declare-function --- sx-button.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-button.el b/sx-button.el index 8a4bcc0..9f6d3b3 100644 --- a/sx-button.el +++ b/sx-button.el @@ -169,7 +169,7 @@ usually part of a code-block." 'face 'sx-user-name :supertype 'sx-button) -(declare-function sx-search-tag-at-point "sx-tag") +(declare-function sx-search-tag-at-point "sx-search") (define-button-type 'sx-button-tag 'action #'sx-search-tag-at-point 'help-echo sx-button--tag-help-echo -- cgit v1.2.3 From 9140a717b13b2e4919164b249f6d4b83b47ba53e Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 14 Feb 2015 15:48:53 -0200 Subject: Add an sx-tag-meta property to tags. --- sx-search.el | 12 +++++++++--- sx-tag.el | 13 ++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/sx-search.el b/sx-search.el index b33efff..b245cbe 100644 --- a/sx-search.el +++ b/sx-search.el @@ -126,9 +126,15 @@ prefix argument, the user is asked for everything." (let ((tag (save-excursion (when pos (goto-char pos)) (or (get-text-property (point) 'sx-tag) - (thing-at-point 'symbol))))) - (sx-search (or sx-question-list--site - (sx-assoc-let sx-question-mode--data .site_par)) + (thing-at-point 'symbol)))) + (meta (save-excursion + (when pos (goto-char pos)) + (get-text-property (point) 'sx-tag-meta))) + (site (replace-regexp-in-string + (rx string-start "meta.") "" + (or sx-question-list--site + (sx-assoc-let sx-question-mode--data .site_par))))) + (sx-search (concat (when meta "meta.") site) nil tag))) (provide 'sx-search) diff --git a/sx-tag.el b/sx-tag.el index 316226b..a59e0d7 100644 --- a/sx-tag.el +++ b/sx-tag.el @@ -142,17 +142,20 @@ tags." ;;; Printing -(defun sx-tag--format (tag) - "Format and return TAG for display." +(defun sx-tag--format (tag &optional meta) + "Format and return TAG for display. +If META is non-nil, the tag is for the meta site." (with-temp-buffer - (sx-tag--insert tag) + (sx-tag--insert tag meta) (buffer-string))) -(defun sx-tag--insert (tag) - "Insert TAG button." +(defun sx-tag--insert (tag &optional meta) + "Insert TAG button. +If META is non-nil, the tag is for the meta site." (insert-text-button (concat "[" tag "]") 'sx-button-copy tag 'sx-tag tag + 'sx-tag-meta meta :type 'sx-button-tag)) (provide 'sx-tag) -- cgit v1.2.3 From ded9c419cbbbe77446681460e4352168a8b33e80 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 14 Feb 2015 15:58:01 -0200 Subject: Define sx-tag--format-tags to format multiple tags. --- sx-tag.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sx-tag.el b/sx-tag.el index a59e0d7..3c00ae2 100644 --- a/sx-tag.el +++ b/sx-tag.el @@ -158,6 +158,19 @@ If META is non-nil, the tag is for the meta site." 'sx-tag-meta meta :type 'sx-button-tag)) +(defun sx-tag--format-tags (tags &optional site) + "Format and concatenate a sequence of TAGS. +Returns a string of all tags in TAGS, separated by a space. + +SITE is the site to which the tags refer, it is only used to +decide whether they are main or meta tags. SITE can also be t or +nil, which respectively indicate meta and main." + (let ((is-meta + (if (stringp site) (string-match (rx string-start "meta.") site) + site))) + (mapconcat (lambda (tag) (sx-tag--format tag is-meta)) + tags " "))) + (provide 'sx-tag) ;;; sx-tag.el ends here -- cgit v1.2.3 From b8124d4056632ae3eb1381b19db743625a715548 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 14 Feb 2015 15:58:17 -0200 Subject: Use sx-tag--format-tags --- sx-question-list.el | 2 +- sx-question-print.el | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sx-question-list.el b/sx-question-list.el index 333fd83..6bae225 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -166,7 +166,7 @@ Also see `sx-question-list-refresh'." " " ;; @TODO: Make this width customizable. (Or maybe just make ;; the whole thing customizable) - (format "%-40s" (mapconcat #'sx-tag--format .tags " ")) + (format "%-40s" (sx-tag--format-tags .tags sx-question-list--site)) " " (sx-user--format "%15d %4r" .owner) (propertize " " 'display "\n"))))))) diff --git a/sx-question-print.el b/sx-question-print.el index 190c924..e535091 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -223,7 +223,7 @@ DATA can represent a question or an answer." ;; Tags (sx-question-mode--insert-header sx-question-mode-header-tags - (mapconcat #'sx-tag--format .tags " ") + (sx-tag--format-tags .tags .site_par) nil)) ;; Body (insert "\n" -- cgit v1.2.3 From 3b0008b6fc32548905510cf86ab5651e529b84ee Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 14 Feb 2015 16:02:01 -0200 Subject: Understand [meta-tag:TAG] links --- sx-question-print.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index e535091..abf3236 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -320,7 +320,8 @@ E.g.: (defconst sx-question-mode--link-regexp ;; Done at compile time. - (rx (or (and "[tag:" (group-n 5 (+ (not (any " ]")))) "]") + (rx (or (and "[" (optional (group-n 6 "meta-")) "tag:" + (group-n 5 (+ (not (any " ]")))) "]") (and "[" (group-n 1 (1+ (not (any "]")))) "]" (or (and "(" (group-n 2 (1+ (not (any ")")))) ")") (and "[" (group-n 3 (1+ (not (any "]")))) "]"))) @@ -373,7 +374,8 @@ E.g.: (let ((tag (match-string-no-properties 5))) (if (and tag (> (length tag) 0)) (progn (replace-match "") - (sx-tag--insert tag)) + ;; `match-string' 6 is the "meta-" prefix. + (sx-tag--insert tag (match-string 6))) ;; Other links are link-buttons. (let* ((text (match-string-no-properties 1)) (url (or (match-string-no-properties 2) -- cgit v1.2.3