From a2d526c4b12ffa1cece78be7e6bfedf0b2b60576 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 24 Jan 2015 01:01:37 -0200 Subject: Less demanding final regexp for questions. --- sx.el | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'sx.el') diff --git a/sx.el b/sx.el index e0609a7..26151b3 100644 --- a/sx.el +++ b/sx.el @@ -148,12 +148,7 @@ with a `link' property)." ;; From URL (string-match (rx "/questions/" ;; Question ID - (group-n 1 (+ digit)) "/" - ;; Optional question title - (optional (+ (not (any "/"))) "/") - ;; Garbage at the end - (optional (and (any "?#") (* any))) - string-end) + (group-n 1 (+ digit)) "/") link)) (push '(type . question) result))) (push (cons 'id (string-to-number (match-string-no-properties 1 link))) -- cgit v1.2.3 From ba4489691847ed1cff2f33f1bfa9aeda85af2a6b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 3 Feb 2015 13:17:59 -0200 Subject: New function sx--squash-whitespace --- sx.el | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sx.el') diff --git a/sx.el b/sx.el index 26151b3..14af94d 100644 --- a/sx.el +++ b/sx.el @@ -331,6 +331,10 @@ GET-FUNC and performs the actual comparison." (funcall ,get-func a) (funcall ,get-func b)))) +(defun sx--squash-whitespace (string) + "Return STRING with consecutive whitespace squashed together." + (replace-regexp-in-string "[ \r\n]+" " " string)) + ;;; Printing request data (defvar sx--overlays nil -- cgit v1.2.3 From 208c91548a100d6a214b2161351d0a04d60adb8d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 7 Feb 2015 23:54:58 -0200 Subject: Version bump --- sx.el | 4 ++-- sx.org | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'sx.el') diff --git a/sx.el b/sx.el index 14af94d..33b36b6 100644 --- a/sx.el +++ b/sx.el @@ -4,7 +4,7 @@ ;; Author: Sean Allred ;; URL: https://github.com/vermiculus/sx.el/ -;; Version: 0.1 +;; Version: 0.2 ;; Keywords: help, hypermedia, tools ;; Package-Requires: ((emacs "24.1") (cl-lib "0.5") (json "1.3") (markdown-mode "2.0") (let-alist "1.0.3")) @@ -28,7 +28,7 @@ ;;; Code: (require 'tabulated-list) -(defconst sx-version "0.1" "Version of the `sx' package.") +(defconst sx-version "0.2" "Version of the `sx' package.") (defgroup sx nil "Customization group for the `sx' package." diff --git a/sx.org b/sx.org index e206cc2..014b0de 100644 --- a/sx.org +++ b/sx.org @@ -1,4 +1,4 @@ -#+MACRO: version 0.1 +#+MACRO: version 0.2 #+MACRO: versiondate 16 November 2014 #+MACRO: updated last updated {{{versiondate}}} -- cgit v1.2.3 From ade5fe434b5fd031db8cd4e601f26f2933354ab2 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 12 Feb 2015 14:18:55 -0200 Subject: Compiler warnings --- sx-button.el | 10 +++++----- sx.el | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'sx.el') diff --git a/sx-button.el b/sx-button.el index 5a2f052..46855e7 100644 --- a/sx-button.el +++ b/sx-button.el @@ -77,23 +77,23 @@ This is usually a link's URL, or the content of a code block." (point) 'sx-button-copy-type) content))))) -(defun sx-button-edit-this (text-or-marker &optional major-mode) - "Open a temp buffer populated with the string TEXT-OR-MARKER using MAJOR-MODE. +(defun sx-button-edit-this (text-or-marker &optional majormode) + "Open a temp buffer populated with the string TEXT-OR-MARKER using MAJORMODE. When given a marker (or interactively), use the 'sx-button-copy and the 'sx-mode text-properties under the marker. These are usually part of a code-block." (interactive (list (point-marker))) ;; Buttons receive markers. (when (markerp text-or-marker) - (setq major-mode (get-text-property text-or-marker 'sx-mode)) + (setq majormode (get-text-property text-or-marker 'sx-mode)) (unless (setq text-or-marker (get-text-property text-or-marker 'sx-button-copy)) (sx-message "Nothing of interest here."))) (with-current-buffer (pop-to-buffer (generate-new-buffer "*sx temp buffer*")) (insert text-or-marker) - (when major-mode - (funcall major-mode)))) + (when majormode + (funcall majormode)))) (defun sx-button-follow-link (&optional pos) "Follow link at POS. If POS is nil, use `point'." diff --git a/sx.el b/sx.el index 33b36b6..73d874f 100644 --- a/sx.el +++ b/sx.el @@ -204,7 +204,7 @@ is intentionally skipped." (while (and ;; We're not at the end. (cdr-safe tail) ;; We're not at the right place. - (,(or predicate #'<) x (cadr tail))) + (funcall (or ,predicate #'<) x (cadr tail))) (setq tail (cdr tail))) (setcdr tail (cons x (cdr tail))))) -- cgit v1.2.3 From 85109b7dd2ffb896151ccef2c014c7d9ea33e682 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 12 Feb 2015 14:59:46 -0200 Subject: Define possible values for answer sorting --- sx-question-print.el | 19 +++++++++++++++---- sx.el | 6 ++++++ 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'sx.el') diff --git a/sx-question-print.el b/sx-question-print.el index 778b580..4f50560 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -153,13 +153,24 @@ replaced with the comment." :type 'boolean :group 'sx-question-mode) +(defconst sx-question-mode--sort-methods + (let ((methods + '(("Higher-scoring" . sx-answer-higher-score-p) + ("Newer" . sx-answer-newer-p) + ("More active" . sx-answer-more-active-p)))) + (append (mapcar (lambda (x) (cons (concat (car x) " first") (cdr x))) + methods) + (mapcar (lambda (x) (cons (concat (car x) " last") + (sx--invert-predicate (cdr x)))) + methods)))) + (defcustom sx-question-mode-answer-sort-function #'sx-answer-higher-score-p "Function used to sort answers in the question buffer." - :type '(choice - (const :tag "Higher-scoring first" sx-answer-higher-score-p) - (const :tag "Newer first" sx-answer-newer-p) - (const :tag "More active first" sx-answer-more-active-p)) + :type + (cons 'choice + (mapcar (lambda (x) `(const :tag ,(car x) ,(cdr x))) + sx-question-mode--sort-methods)) :group 'sx-question-mode) diff --git a/sx.el b/sx.el index 33b36b6..381f78e 100644 --- a/sx.el +++ b/sx.el @@ -335,6 +335,12 @@ GET-FUNC and performs the actual comparison." "Return STRING with consecutive whitespace squashed together." (replace-regexp-in-string "[ \r\n]+" " " string)) +(defun sx--invert-predicate (predicate) + "Return PREDICATE function with arguments inverted. +For instance (sx--invert-predicate #'<) is the same as #'>. +Note this is not the same as negating PREDICATE." + (lambda (&rest args) (apply predicate (reverse args)))) + ;;; Printing request data (defvar sx--overlays nil -- cgit v1.2.3 From d73ba0621e1e73df155a09126ecef8df8c2d232a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 21 Feb 2015 10:48:28 -0200 Subject: Standardize prettification of site names. --- sx-question-list.el | 4 +--- sx-question-mode.el | 9 +++++++-- sx.el | 6 ++++++ 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'sx.el') diff --git a/sx-question-list.el b/sx-question-list.el index def490b..32bc140 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -397,9 +397,7 @@ Non-interactively, DATA is a question alist." (defconst sx-question-list--mode-line-format '(" " (:propertize - (:eval (mapconcat #'capitalize - (split-string sx-question-list--site "\\.") - " ")) + (:eval (sx--pretty-site-parameter sx-question-list--site)) face mode-line-buffer-id) " " mode-name ": " (:propertize sx-question-list--current-tab diff --git a/sx-question-mode.el b/sx-question-mode.el index 2d06e5b..d4b7f8d 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -191,7 +191,8 @@ property." ;; `sx-assoc-let' to improve performance (since the mode-line is ;; updated a lot). (:propertize - (:eval (let-alist sx-question-mode--data .site_par)) + (:eval (sx--pretty-site-parameter + (let-alist sx-question-mode--data .site_par))) face mode-line-buffer-id) " " mode-name " [" @@ -216,10 +217,14 @@ property." "Major mode to display and navigate a question and its answers. Letters do not insert themselves; instead, they are commands. +Don't activate this mode directly. Instead, to print a question +on the current buffer use +`sx-question-mode--erase-and-print-question'. + \\ \\{sx-question-mode}" (setq header-line-format sx-question-mode--header-line) - (setq header-line-format sx-question-mode--mode-line) + (setq mode-line-format sx-question-mode--mode-line) ;; Determine how to close this window. (unless (window-parameter nil 'quit-restore) (set-window-parameter diff --git a/sx.el b/sx.el index 73d874f..fc0af92 100644 --- a/sx.el +++ b/sx.el @@ -187,6 +187,12 @@ If ALIST doesn't have a `site' property, one is created using the ,(macroexpand `(let-alist ,alist ,@body)))) +(defun sx--pretty-site-parameter (site) + "Returned a pretty and capitalized version of string SITE." + (mapconcat #'capitalize + (split-string site "\\.") + " ")) + ;;; Utility Functions (defun sx-completing-read (&rest args) -- cgit v1.2.3 From 24090d48422233b31f9eef041814e99c47c2534d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 26 Feb 2015 11:28:48 -0300 Subject: Manually string-trim for older emacsen. Fix #267 --- sx-compose.el | 6 ++---- sx.el | 5 +++++ 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'sx.el') diff --git a/sx-compose.el b/sx-compose.el index eb5e2eb..ae13fb6 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -193,8 +193,7 @@ tags. Return a list of already inserted tags." 'noerror) (error "No Tags header found")) (save-match-data - (split-string (match-string 1) (rx (any space ",;")) - 'omit-nulls (rx space)))) + (sx--split-string (match-string 1) (rx (any space ",;"))))) (defun sx-compose--check-tags () "Check if tags in current compose buffer are valid." @@ -313,8 +312,7 @@ other keywords are read from the header " (unless (search-forward-regexp "^Tags : *\\([^[:space:]].*\\) *$" header-end 'noerror) (error "No Tags header found")) - (push (cons 'tags (split-string (match-string 1) - "[[:space:],;]" 'omit-nulls)) + (push (cons 'tags (sx--split-string (match-string 1) "[[:space:],;]")) keywords) ;; And erase the header so it doesn't get sent. (delete-region diff --git a/sx.el b/sx.el index 33b36b6..ee7f0a6 100644 --- a/sx.el +++ b/sx.el @@ -189,6 +189,11 @@ If ALIST doesn't have a `site' property, one is created using the ;;; Utility Functions +(defun sx--split-string (string &optional separators) + "Split STRING into substrings bounded by matches for SEPARATORS." + (mapcar (lambda (s) (replace-regexp-in-string "\\` +\\| +\\'" "" s)) + (split-string string separators 'omit-nulls))) + (defun sx-completing-read (&rest args) "Like `completing-read', but possibly use ido. All ARGS are passed to `completing-read' or `ido-completing-read'." -- cgit v1.2.3