aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2015-03-08 16:45:23 -0300
committerArtur Malabarba <bruce.connor.am@gmail.com>2015-03-08 16:45:23 -0300
commit8bbca9bff462fef6d1daafd35583b301f896ce15 (patch)
tree1cd1528bb76ca896185c1ebc0950ad7e2cc2c92a
parent019ab80c7935da8236ef902cd04e0216825e79f8 (diff)
parent62e8ced2af638f3646ae53b0472b4ec3284a9cc7 (diff)
Merge pull request #273 from vermiculus/issue-271--asking-vs-auth
Issue 271 asking vs auth
-rw-r--r--sx-compose.el13
-rw-r--r--sx-interaction.el17
2 files changed, 22 insertions, 8 deletions
diff --git a/sx-compose.el b/sx-compose.el
index ae13fb6..e3f9c00 100644
--- a/sx-compose.el
+++ b/sx-compose.el
@@ -294,15 +294,14 @@ Keywords meant to be used in `sx-method-call'.
`body' is read as the `buffer-string'. If IS-QUESTION is non-nil,
other keywords are read from the header "
+ (goto-char (point-min))
`(,@(when is-question
(let ((inhibit-point-motion-hooks t)
- (inhibit-read-only t)
(header-end
(next-single-property-change
(point-min) 'sx-compose-separator))
keywords)
;; Read the Title.
- (goto-char (point-min))
(unless (search-forward-regexp
"^Title: *\\(.*\\) *$" header-end 'noerror)
(error "No Title header found"))
@@ -314,13 +313,11 @@ other keywords are read from the header "
(error "No Tags header found"))
(push (cons 'tags (sx--split-string (match-string 1) "[[:space:],;]"))
keywords)
- ;; And erase the header so it doesn't get sent.
- (delete-region
- (point-min)
- (next-single-property-change
- header-end 'sx-compose-separator))
+ ;; And move past the header so it doesn't get sent.
+ (goto-char (next-single-property-change
+ header-end 'sx-compose-separator))
keywords))
- (body . ,(buffer-string))))
+ (body . ,(buffer-substring-no-properties (point) (point-max)))))
(defun sx-compose--get-buffer-create (site data)
"Get or create a buffer for use with `sx-compose-mode'.
diff --git a/sx-interaction.el b/sx-interaction.el
index 368da09..43b1efc 100644
--- a/sx-interaction.el
+++ b/sx-interaction.el
@@ -44,6 +44,7 @@
(require 'sx-question-mode)
(require 'sx-question-list)
(require 'sx-compose)
+(require 'sx-cache)
;;; Using data in buffer
@@ -105,6 +106,18 @@ Only fields contained in TO are copied."
(setcar to (car from))
(setcdr to (cdr from)))
+(defun sx-ensure-authentication ()
+ "Signal user-error if the user refuses to authenticate.
+Note that `sx-method-call' already does authentication checking.
+This function is meant to be used by commands that don't
+immediately perform method calls, such as `sx-ask'. This way,
+the unauthenticated user will be prompted before going through
+the trouble of composing an entire question."
+ (unless (sx-cache-get 'auth)
+ (if (y-or-n-p "This command requires authentication, would you like to authenticate? ")
+ (sx-authenticate)
+ (sx-user-error "This command requires authentication, please run `M-x sx-authenticate' and try again."))))
+
;;; Visiting
(defun sx-visit-externally (data &optional copy-as-kill)
@@ -299,6 +312,7 @@ If DATA is a comment, the comment is posted as a reply to it.
TEXT is a string. Interactively, it is read from the minibufer."
(interactive (list (sx--error-if-unread (sx--data-here)) 'query))
+ (sx-ensure-authentication)
;; When clicking the "Add a Comment" button, first arg is a marker.
(when (markerp data)
(setq data (sx--data-here))
@@ -396,6 +410,7 @@ OBJECT can be a question or an answer."
DATA is an answer or question alist. Interactively, it is guessed
from context at point."
(interactive (list (sx--data-here)))
+ (sx-ensure-authentication)
;; If we ever make an "Edit" button, first arg is a marker.
(when (markerp data) (setq data (sx--data-here)))
(sx-assoc-let data
@@ -444,6 +459,7 @@ If nil, use `sx--interactive-site-prompt' anyway."
"Start composing a question for SITE.
SITE is a string, indicating where the question will be posted."
(interactive (list (sx--interactive-site-prompt)))
+ (sx-ensure-authentication)
(let ((buffer (current-buffer)))
(pop-to-buffer
(sx-compose-create
@@ -461,6 +477,7 @@ context at point. "
;; probaby hit the button by accident.
(interactive
(list (sx--error-if-unread (sx--data-here 'question))))
+ (sx-ensure-authentication)
;; When clicking the "Write an Answer" button, first arg is a marker.
(when (markerp data) (setq data (sx--data-here)))
(let ((buffer (current-buffer)))