aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stack-exchange.el30
-rw-r--r--sx-interaction.el21
-rw-r--r--sx-method.el2
-rw-r--r--sx-question-list.el24
-rw-r--r--sx-question-mode.el10
-rw-r--r--sx-time.el6
-rw-r--r--sx.el7
7 files changed, 48 insertions, 52 deletions
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 <code@seanallred.com>
-;; 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 <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;;
-
-;;; Code:
-
-(mapc #'load (file-expand-wildcards "sx*.el"))
-
-(provide 'stack-exchange)
-;;; stack-exchange.el ends here
diff --git a/sx-interaction.el b/sx-interaction.el
index 404fb56..e4234b0 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))))
@@ -123,7 +132,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.
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)
diff --git a/sx-question-list.el b/sx-question-list.el
index 2965ede..fbed4ea 100644
--- a/sx-question-list.el
+++ b/sx-question-list.el
@@ -371,19 +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))
- (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)))
+ (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)))
+ (cl-remove-if #'sx-question--hidden-p question-list)))
+ (when redisplay (tabulated-list-print 'remember))
+ (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.
diff --git a/sx-question-mode.el b/sx-question-mode.el
index bc7c62c..a58bc43 100644
--- a/sx-question-mode.el
+++ b/sx-question-mode.el
@@ -602,15 +602,19 @@ 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)))
+ (sx-message "Done."))
(defun sx-question-mode--ensure-mode ()
"Ensures we are in question mode, erroring otherwise."
diff --git a/sx-time.el b/sx-time.el
index 9c4dfaa..057a397 100644
--- a/sx-time.el
+++ b/sx-time.el
@@ -29,10 +29,14 @@
;; (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)
+ (3456000 "d" 86400.0)
+ (31622400 "mo" 2628000.0)
(nil "y" 31557600.0))
"Auxiliary variable used by `sx-time-since'.")
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