From 026f8f42a124da1dcc0a7254e49e2cf787b82fe1 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 25 Nov 2014 22:39:52 -0500 Subject: Remove whitespace for effective at-mentions If the display name contained whitespace, the function would keep the whitespace in the at-mention. According to observed behavior on the website, this is not correct. This commit removes all whitespace from the returned display name in the appropriate function. --- sx.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sx.el b/sx.el index d4c3ac2..e47e6e3 100644 --- a/sx.el +++ b/sx.el @@ -199,10 +199,13 @@ Return the result of BODY." result)) (defun sx--user-@name (user) - "Get the `display_name' of USER prepended with @." + "Get the `display_name' of USER prepended with @. +In order to correctly @mention the user, all whitespace is +removed from the display name before it is returned." (sx-assoc-let user (when (stringp .display_name) - (concat "@" .display_name)))) + (concat "@" (replace-regexp-in-string + "[[:space:]]" "" .display_name))))) ;;; Assoc-let -- cgit v1.2.3 From eb6d7c4567313b5b4a729bd56f53c56ed2cad27c Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 25 Nov 2014 22:42:27 -0500 Subject: Streamline replying to comments Append a single space after the at-mention in comment replies. --- sx-interaction.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-interaction.el b/sx-interaction.el index 404fb56..de27ca5 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -123,7 +123,7 @@ TEXT is a string. Interactively, it is read from the minibufer." (setq text (read-string "Comment text: " (when .comment_id - (sx--user-@name .owner)))) + (concat (sx--user-@name .owner) " ")))) (while (< (string-width text) 15) (setq text (read-string "Comment text (at least 15 characters): " text)))) ;; If non-interactive, `text' could be anything. -- cgit v1.2.3 From 85835a2031d046e529f39b108b960c993d9bcaab Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 25 Nov 2014 23:01:33 -0500 Subject: Add ability to copy link instead of visiting it --- sx-interaction.el | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/sx-interaction.el b/sx-interaction.el index 404fb56..1e6164f 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -51,16 +51,25 @@ Only fields contained in TO are copied." (setcar to (car from)) (setcdr to (cdr from))) -(defun sx-visit (data) +(defun sx-visit (data &optional copy-as-kill) "Visit DATA in a web browser. DATA can be a question, answer, or comment. Interactively, it is derived from point position. + +If copy-as-kill is non-nil, do not call `browse-url'. +Instead, copy the link as a new kill with `kill-new'. +Interactively, this is specified with a prefix argument. + If DATA is a question, also mark it as read." - (interactive (list (sx--data-here))) + (interactive (list (sx--data-here) current-prefix-arg)) (sx-assoc-let data - (when (stringp .link) - (browse-url .link)) - (when .title + (let ((link + (when (stringp .link) + (funcall (if copy-as-kill #'kill-new #'browse-url) + .link)))) + (when (and (called-interactively-p 'any) copy-as-kill) + (message "Copied: %S" link))) + (when (and .title (not copy-as-kill)) (sx-question--mark-read data) (sx--maybe-update-display)))) -- cgit v1.2.3 From 1c43146e78bc292541133b2798892d78dec64765 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 26 Nov 2014 11:59:23 +0000 Subject: Add months to sx-time-seconds-to-string Fixes #102 --- sx-time.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sx-time.el b/sx-time.el index 9c4dfaa..c0ca867 100644 --- a/sx-time.el +++ b/sx-time.el @@ -29,11 +29,15 @@ ;; (LIMIT NAME VALUE) ;; We use an entry if the number of seconds in question is less than ;; LIMIT, but more than the previous entry's LIMIT. + ;; For instance, if time is less than 100 sec, we write it in seconds; + ;; if it is between 100 and 6000 sec, we use minutes. + ;; VALUE is the actual number of seconds which NAME represents. '((100 "s" 1) (6000 "m" 60.0) (108000 "h" 3600.0) - (34560000 "d" 86400.0) - (nil "y" 31557600.0)) + (3456000 "d" 86400.0) + (31622400 "M" 2628000.0) + (nil "Y" 31557600.0)) "Auxiliary variable used by `sx-time-since'.") (defun sx-time-since (time) -- cgit v1.2.3 From 7471aa7c0775a633c9a4c1504cb5edb8eec3e16e Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 26 Nov 2014 12:01:14 +0000 Subject: Change months identifier --- sx-time.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sx-time.el b/sx-time.el index c0ca867..057a397 100644 --- a/sx-time.el +++ b/sx-time.el @@ -36,8 +36,8 @@ (6000 "m" 60.0) (108000 "h" 3600.0) (3456000 "d" 86400.0) - (31622400 "M" 2628000.0) - (nil "Y" 31557600.0)) + (31622400 "mo" 2628000.0) + (nil "y" 31557600.0)) "Auxiliary variable used by `sx-time-since'.") (defun sx-time-since (time) -- cgit v1.2.3 From 244aca25de91f6b6e5e9d59775ab05f0669df80c Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 26 Nov 2014 12:22:34 +0000 Subject: Preserve visual position when refreshing Both for question list and question mode. --- sx-question-list.el | 20 +++++++++++--------- sx-question-mode.el | 9 ++++++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/sx-question-list.el b/sx-question-list.el index 2965ede..bb49b54 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -371,19 +371,21 @@ a new list before redisplaying." (setq sx-question-list--unread-count 0) (unless no-update (setq sx-question-list--pages-so-far 1)) - (let ((question-list - (or (and no-update sx-question-list--dataset) - (and (functionp sx-question-list--refresh-function) - (funcall sx-question-list--refresh-function)) - (and (functionp sx-question-list--next-page-function) - (funcall sx-question-list--next-page-function 1)) - sx-question-list--dataset))) + (cl-letf ((question-list + (or (and no-update sx-question-list--dataset) + (and (functionp sx-question-list--refresh-function) + (funcall sx-question-list--refresh-function)) + (and (functionp sx-question-list--next-page-function) + (funcall sx-question-list--next-page-function 1)) + sx-question-list--dataset)) + ;; Preserve window positioning. + ((window-start))) (setq sx-question-list--dataset question-list) ;; Print the result. (setq tabulated-list-entries (mapcar sx-question-list--print-function - (cl-remove-if #'sx-question--hidden-p question-list)))) - (when redisplay (tabulated-list-print 'remember))) + (cl-remove-if #'sx-question--hidden-p question-list))) + (when redisplay (tabulated-list-print 'remember)))) (defcustom sx-question-list-ago-string " ago" "String appended to descriptions of the time since something happened. diff --git a/sx-question-mode.el b/sx-question-mode.el index 70b8866..c90e3e1 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -595,15 +595,18 @@ With non-nil prefix argument NO-UPDATE, just redisplay, don't query the api." (interactive "P") (sx-question-mode--ensure-mode) - (let ((point (point))) + (let ((point (point)) + (line (count-screen-lines + (window-start) (point)))) (sx-question-mode--erase-and-print-question (if no-update sx-question-mode--data (sx-assoc-let sx-question-mode--data (sx-question-get-question .site .question_id)))) (goto-char point) - (when (get-buffer-window (current-buffer)) - (recenter)))) + (when (equal (selected-window) + (get-buffer-window (current-buffer))) + (recenter line)))) (defun sx-question-mode--ensure-mode () "Ensures we are in question mode, erroring otherwise." -- cgit v1.2.3 From 16952fa49769398bf47373e7585812ac06392ee8 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 26 Nov 2014 12:24:14 +0000 Subject: Give feedback on finished refresh. Now that position is preserved, refreshing is so discreet that we need some feedback. :) --- sx-question-list.el | 3 ++- sx-question-mode.el | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sx-question-list.el b/sx-question-list.el index bb49b54..98e7736 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -385,7 +385,8 @@ a new list before redisplaying." (setq tabulated-list-entries (mapcar sx-question-list--print-function (cl-remove-if #'sx-question--hidden-p question-list))) - (when redisplay (tabulated-list-print 'remember)))) + (when redisplay (tabulated-list-print 'remember)) + (sx-message "Done."))) (defcustom sx-question-list-ago-string " ago" "String appended to descriptions of the time since something happened. diff --git a/sx-question-mode.el b/sx-question-mode.el index c90e3e1..b2f4604 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -606,7 +606,8 @@ query the api." (goto-char point) (when (equal (selected-window) (get-buffer-window (current-buffer))) - (recenter line)))) + (recenter line))) + (sx-message "Done.")) (defun sx-question-mode--ensure-mode () "Ensures we are in question mode, erroring otherwise." -- cgit v1.2.3 From a104916864ab053fff81dcdcba71e6b8af219913 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 26 Nov 2014 12:28:01 +0000 Subject: Use let instead of letf Older letfs are bugged. --- sx-question-list.el | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sx-question-list.el b/sx-question-list.el index 98e7736..fbed4ea 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -371,22 +371,25 @@ a new list before redisplaying." (setq sx-question-list--unread-count 0) (unless no-update (setq sx-question-list--pages-so-far 1)) - (cl-letf ((question-list - (or (and no-update sx-question-list--dataset) - (and (functionp sx-question-list--refresh-function) - (funcall sx-question-list--refresh-function)) - (and (functionp sx-question-list--next-page-function) - (funcall sx-question-list--next-page-function 1)) - sx-question-list--dataset)) - ;; Preserve window positioning. - ((window-start))) + (let* ((question-list + (or (and no-update sx-question-list--dataset) + (and (functionp sx-question-list--refresh-function) + (funcall sx-question-list--refresh-function)) + (and (functionp sx-question-list--next-page-function) + (funcall sx-question-list--next-page-function 1)) + sx-question-list--dataset)) + ;; Preserve window positioning. + (window (get-buffer-window (current-buffer))) + (old-start (when window (window-start window)))) (setq sx-question-list--dataset question-list) ;; Print the result. (setq tabulated-list-entries (mapcar sx-question-list--print-function (cl-remove-if #'sx-question--hidden-p question-list))) (when redisplay (tabulated-list-print 'remember)) - (sx-message "Done."))) + (when window + (set-window-start window old-start))) + (sx-message "Done.")) (defcustom sx-question-list-ago-string " ago" "String appended to descriptions of the time since something happened. -- cgit v1.2.3 From 536a325f55b5c757e3acf5a96b00cb4367999c05 Mon Sep 17 00:00:00 2001 From: Jonathan Leech-Pepin Date: Wed, 26 Nov 2014 09:09:48 -0500 Subject: Fixes #92. Change default filter from `'none` to `'(())`. --- sx-method.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-method.el b/sx-method.el index 04d973d..4bd98a5 100644 --- a/sx-method.el +++ b/sx-method.el @@ -35,7 +35,7 @@ (cl-defun sx-method-call (method &key id submethod keywords - (filter 'none) + (filter '(())) auth (url-method "GET") site) -- cgit v1.2.3 From 6848008b60938100d04cda96c093a24cb3370f9a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 27 Nov 2014 16:04:40 +0000 Subject: Delete stack-exchange.el --- stack-exchange.el | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 stack-exchange.el diff --git a/stack-exchange.el b/stack-exchange.el deleted file mode 100644 index bca777b..0000000 --- a/stack-exchange.el +++ /dev/null @@ -1,30 +0,0 @@ -;;; stack-exchange.el --- A StackExchange Mode -*- lexical-binding: t; -*- - -;; Copyright (C) 2014 Sean Allred - -;; Author: Sean Allred -;; Keywords: help, hypermedia, mail, news, tools - -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;;; Commentary: - -;; - -;;; Code: - -(mapc #'load (file-expand-wildcards "sx*.el")) - -(provide 'stack-exchange) -;;; stack-exchange.el ends here -- cgit v1.2.3