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