From 6c111d0eb2e6a15c02a925458d64b870c96ac74c Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 2 Dec 2014 00:04:01 -0500 Subject: Prune unused parameter --- sx-request.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-request.el b/sx-request.el index a98af5a..7ed8792 100644 --- a/sx-request.el +++ b/sx-request.el @@ -170,7 +170,7 @@ Currently returns nil." ;;; Support Functions (defun sx-request--build-keyword-arguments (alist &optional - kv-sep need-auth) + kv-sep) "Format ALIST as a key-value list joined with KV-SEP. If authentication is needed, include it also or error if it is not available. -- cgit v1.2.3 From d72f3128b1c4615c2d9c38550c0f244d4096d9df Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 2 Dec 2014 00:04:16 -0500 Subject: Add missing dot-operator --- sx-interaction.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-interaction.el b/sx-interaction.el index d0c4c47..7f851e7 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -169,7 +169,7 @@ TEXT is a string. Interactively, it is read from the minibufer." :url-method "POST" :filter sx-browse-filter :site .site - :keywords `((body ,text))))) + :keywords `((body . ,text))))) ;; The api returns the new DATA. (when (> (length result) 0) (sx--add-comment-to-object -- cgit v1.2.3 From fd0eb04a72eae2d85a2a023e44cf641e450fa2f1 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 2 Dec 2014 00:04:44 -0500 Subject: Augment `sx--thing-as-string' to hexify as needed Also fix issue where function options would not be transferred from the original use into its recursive steps. --- sx.el | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/sx.el b/sx.el index f1d3634..411c9e2 100644 --- a/sx.el +++ b/sx.el @@ -115,19 +115,32 @@ See `format'." (let ((echo (get-text-property (point) 'help-echo))) (when echo (message "%s" echo)))) -(defun sx--thing-as-string (thing &optional sequence-sep) +(defun sx--thing-as-string (thing &optional sequence-sep url-hexify) "Return a string representation of THING. If THING is already a string, just return it. Optional argument SEQUENCE-SEP is the separator applied between -elements of a sequence." - (cond - ((stringp thing) thing) - ((symbolp thing) (symbol-name thing)) - ((numberp thing) (number-to-string thing)) - ((sequencep thing) - (mapconcat #'sx--thing-as-string - thing (if sequence-sep sequence-sep ";"))))) +elements of a sequence. If SEQUENCE-SEP is a list, use the first +element for the top level joining, the second for the next level, +etc. \";\" is used as a default. + +If optional argument URL-HEXIFY is non-nil, this function behaves +as `url-hexify-string'; this option is only effective on strings +and sequences of strings." + (let ((process (if url-hexify #'url-hexify-string #'identity)) + (first-f (if (listp sequence-sep) #'car #'identity)) + (rest-f (if (listp sequence-sep) #'cdr #'identity))) + (cond + ((stringp thing) (funcall process thing)) + ((symbolp thing) (funcall process (symbol-name thing))) + ((numberp thing) (number-to-string thing)) + ((sequencep thing) + (mapconcat (lambda (thing) + (sx--thing-as-string + thing (funcall rest-f sequence-sep) url-hexify)) + thing (if sequence-sep + (funcall first-f sequence-sep) + ";")))))) (defun sx--filter-data (data desired-tree) "Filter DATA and return the DESIRED-TREE. -- cgit v1.2.3 From 07ead3d320ebe2d14c89f47a715571f9b124187d Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 2 Dec 2014 00:06:36 -0500 Subject: Hexify value in key-value pairs Fixes #130 --- sx-request.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-request.el b/sx-request.el index 7ed8792..c8c6eb6 100644 --- a/sx-request.el +++ b/sx-request.el @@ -194,7 +194,7 @@ false, use the symbol `false'. Each element is processed with (concat (sx--thing-as-string (car pair)) "=" - (sx--thing-as-string (cdr pair) kv-sep))) + (sx--thing-as-string (cdr pair) kv-sep t))) (delq nil (mapcar (lambda (pair) (when (cdr pair) pair)) -- cgit v1.2.3 From 114ca09da984738df2510bc72753a3443d16857c Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 2 Dec 2014 00:07:16 -0500 Subject: Add tests for `sx--thing-as-string' --- test/tests.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/tests.el b/test/tests.el index 75238fe..43531b4 100644 --- a/test/tests.el +++ b/test/tests.el @@ -133,3 +133,35 @@ (macroexpand '(sx-assoc-let data (cons .test-one .test-two)))))) + +(ert-deftest thing-as-string () + "Tests `sx--thing-as-string'" + (should + (string= (sx--thing-as-string + '(hello world (this is a test)) + '(";" "+")) + "hello;world;this+is+a+test")) + (should + (string= (sx--thing-as-string + '(this is a test) '(";" "+")) + "this;is;a;test")) + (should + (string= (sx--thing-as-string + '(this is a test) "+") + "this+is+a+test")) + (should + (string= (sx--thing-as-string + '(this is a test)) + "this;is;a;test")) + (should + (string= (sx--thing-as-string + 'test) + "test")) + (should + (string= (sx--thing-as-string + 'test&) + "test&")) + (should + (string= (sx--thing-as-string + 'test& nil t) + "test%26"))) -- cgit v1.2.3 From a9dc66a6fc3a9d6e8cbf2a15601aea3510052679 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Fri, 5 Dec 2014 18:01:14 +0000 Subject: Cleanup whitespace --- sx-compose.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sx-compose.el b/sx-compose.el index d7d3ff3..4560c15 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -43,7 +43,7 @@ ;;; Faces and Variables -(defvar sx-compose-before-send-hook nil +(defvar sx-compose-before-send-hook nil "Hook run before POSTing to the API. Functions are called without arguments and should return non-nil. @@ -54,7 +54,7 @@ notifying the user. Current buffer is the compose-mode buffer whose content is about to be POSTed.") -(defvar sx-compose-after-send-functions nil +(defvar sx-compose-after-send-functions nil "Hook run after POSTing to the API. Functions on this hook should take two arguments, the `sx-compose-mode' buffer (which not be live) and the data @@ -129,9 +129,9 @@ contents to the API, then calls `sx-compose-after-send-functions'." ;;; Functions to help preparing buffers (defun sx-compose-create (site parent &optional before-functions after-functions) "Create an `sx-compose-mode' buffer. -SITE is the site where it will be posted. +SITE is the site where it will be posted. -If composing questions, PARENT is nil. +If composing questions, PARENT is nil. If composing answers, it is the `question_id'. If editing answers or questions, it should be the alist data related to that object. @@ -194,7 +194,7 @@ other keywords are read from the header " `(,@(when is-question (let ((inhibit-point-motion-hooks t) (inhibit-read-only t) - (header-end + (header-end (next-single-property-change (point-min) 'sx-compose-separator)) keywords) -- cgit v1.2.3 From 307895c5533636c9e1380dd55b38309f8dba702f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Fri, 5 Dec 2014 18:01:35 +0000 Subject: Fix bug when editing questions --- sx-compose.el | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/sx-compose.el b/sx-compose.el index 4560c15..d8f3b23 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -70,12 +70,15 @@ Is invoked between `sx-compose-before-send-hook' and (defvar sx-compose--question-headers (concat #("Title: " 0 7 (intangible t read-only t rear-nonsticky t)) + "%s" #("\n" 0 1 (read-only t)) #("Tags : " 0 7 (read-only t intangible t rear-nonsticky t)) + "%s" #("\n" 0 1 (read-only t rear-nonsticky t)) - #("________________________________________\n\n" - 0 42 (read-only t rear-nonsticky t intangible t - sx-compose-separator t))) + #("________________________________________\n" + 0 41 (read-only t rear-nonsticky t intangible t + sx-compose-separator t)) + "\n") "Headers inserted when composing a new question. Used by `sx-compose-create'.") @@ -172,19 +175,32 @@ respectively added locally to `sx-compose-before-send-hook' and (add-hook 'sx-compose-after-send-functions it nil t)) ;; If the buffer is empty, the draft didn't exist. So prepare the ;; question. - (when (and is-question (string= (buffer-string) "")) - (let ((inhibit-point-motion-hooks)) - (insert sx-compose--question-headers) - (goto-char (point-min)) - (goto-char (line-end-position)))) - (when (consp parent) - (when (or (string= (buffer-string) "") - (y-or-n-p "Draft buffer exists. Reset it? ")) + (when (or (string= (buffer-string) "") + (y-or-n-p "Draft buffer exists. Reset it? ")) + (let ((inhibit-point-motion-hooks t) + (inhibit-read-only t)) (erase-buffer) - (insert (cdr (assoc 'body_markdown parent))))) + (when (consp parent) + (insert (cdr (assoc 'body_markdown parent)))) + (when is-question + (sx-compose--print-question-headers + (when (consp parent) parent)) + (unless (consp parent) + (goto-char (point-min)) + (goto-char (line-end-position)))))) ;; Return the buffer (current-buffer)))) +(defun sx-compose--print-question-headers (question) + "Print question headers for the compose buffer. +If QUESTION is non-nil, fill the headers with the data from +QUESTION." + (sx-assoc-let question + (goto-char (point-min)) + (insert + (format sx-compose--question-headers + (or .title "") (mapconcat #'identity .tags " "))))) + (defun sx-compose--generate-keywords (is-question) "Reading current buffer, generate a keywords alist. Keywords meant to be used in `sx-method-call'. -- cgit v1.2.3 From d06afce72182573c7ec1834c866fc39213c151cc Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 6 Dec 2014 18:04:56 +0000 Subject: Improve some header comments. --- sx-filter.el | 2 +- sx-method.el | 2 +- sx-question-mode.el | 2 +- sx-question-print.el | 2 +- sx-question.el | 2 +- sx-request.el | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sx-filter.el b/sx-filter.el index 38084b9..8c00c12 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -1,4 +1,4 @@ -;;; sx-filter.el --- filters -*- lexical-binding: t; -*- +;;; sx-filter.el --- Handles retrieval of filters. -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Sean Allred diff --git a/sx-method.el b/sx-method.el index 83455b8..5646772 100644 --- a/sx-method.el +++ b/sx-method.el @@ -1,4 +1,4 @@ -;;; sx-method.el --- method calls +;;; sx-method.el --- Main interface for API method calls. -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Sean Allred diff --git a/sx-question-mode.el b/sx-question-mode.el index bccb658..ccd9433 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -1,4 +1,4 @@ -;;; sx-question-mode.el --- Creating the buffer that displays questions +;;; sx-question-mode.el --- Major-mode for displaying a question. -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba diff --git a/sx-question-print.el b/sx-question-print.el index eb79a7a..2a0a035 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -1,4 +1,4 @@ -;;; sx-question-print.el --- Populating the question-mode buffer with content. +;;; sx-question-print.el --- Populating the question-mode buffer with content. -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Artur Malabarba diff --git a/sx-question.el b/sx-question.el index c4b2445..fea8978 100644 --- a/sx-question.el +++ b/sx-question.el @@ -1,4 +1,4 @@ -;;; sx-question.el --- question logic +;;; sx-question.el --- Base question logic. -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Sean Allred diff --git a/sx-request.el b/sx-request.el index 0994fbd..a17a982 100644 --- a/sx-request.el +++ b/sx-request.el @@ -1,4 +1,4 @@ -;;; sx-request.el --- requests and url manipulation -*- lexical-binding: t; -*- +;;; sx-request.el --- Requests and url manipulation. -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Sean Allred -- cgit v1.2.3 From 499e2551cba2481463eb84f4deee6897c02609af Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 6 Dec 2014 18:05:23 +0000 Subject: Bring sx.org up to date --- sx.org | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sx.org b/sx.org index f866aa5..58acbbb 100644 --- a/sx.org +++ b/sx.org @@ -67,7 +67,8 @@ a cache file. ** Browsing Questions To browse a list of questions retrieved from the site, use ~sx-tab-frontpage~. This queries for a site, pulls the first page of -questions for that site, and displays them in a list. +questions for that site, and displays them in a list. Alternatively, +use any of the other ~sx-tab-~ commands. - Refresh the page with =g= or by scrolling past the top. - Use =n=, =p=, =N=, =P= to navigate without viewing the question. @@ -86,6 +87,12 @@ Scrolling past the bottom of the list fetches more questions. # used only by contributors. - ~sx-init-hook~ :: Run when ~sx-initialize~ is called. +- ~sx-compose-before-send-hook~ :: Run before POSTing to the API from + a buffer in ~sx-compose-mode~. If any of the functions in this + hook, return nil, the transaction is cancelled. +- ~sx-compose-after-send-functions~ :: Run after POSTing to the API + from a buffer in ~sx-compose-mode~, if the transaction was + successful. * Contributing This document is maintained in Org format. Updates to the source code -- cgit v1.2.3 From c6cb8dc93ce2913d24772f642007e02f21a00b80 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 6 Dec 2014 18:05:43 +0000 Subject: Expand the Contributing section. --- sx.org | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/sx.org b/sx.org index 58acbbb..78bc5da 100644 --- a/sx.org +++ b/sx.org @@ -95,6 +95,19 @@ Scrolling past the bottom of the list fetches more questions. successful. * Contributing +Contributions, be them to the code or to this document, are very much +welcome. Both of these can be found at [[github.com/vermiculus/sx.el][the GitHub repository]]. The +easiest way to contribute is to clone it, make your changes, and +submit a pull request. If you prefer, you can also email a patch of +your changes to one of the authors or maintainers listed in the header +comments. But please, when you do, heed the following conventions. + +1. Contributions to the code which change or add user-facing + functionality should be accompanied by updates to this document. +2. Both in code and in this document, sentences should end in double + space. + +** Contributing to this Document This document is maintained in Org format. Updates to the source code should be accompanied by updates to this document when user-facing functionality is changed. @@ -102,7 +115,7 @@ functionality is changed. Note that some distinctions are made which may not be apparent when viewing the document with Info. -** Markup Conventions +*** Markup Conventions Markup is used consistently as follows: - packages :: =package.el= @@ -115,7 +128,7 @@ To make the Info export readable, lists and source code blocks are separated from body text with a blank line (as to start a new paragraph). -** Document Attributes +*** Document Attributes Attributes should be given in uppercase: #+BEGIN_SRC org @@ -124,11 +137,52 @@ Attributes should be given in uppercase: ,#+END_SRC #+END_SRC -** Source Code Blocks +*** Source Code Blocks The language for Emacs Lisp source code blocks should be given as =elisp= and its content should be indented by two spaces. See ~org-edit-src-content-indentation~. +** Contributing to the Code +Contributing to the code should be fairly straightforward. Each file +has a descriptive header explaining its purpose. Still, to help you +find your way around, we describe below the current project +structure. This list is very loosely ordered form low to high-level. + +- ~sx.el~ - Utility functions used throughout the package. Essentially + every file indirectly requires this one. If you're adding a function + that's used by different parts of the package, add it to this file. +- ~sx-time.el~ - Similar to ~sx.el~, but only contains a few + time-related functions. +- ~sx-filter.el~ - Handles retrieval of filters. +- ~sx-cache.el~ - Saves and restores persistent data between sessions. +- ~sx-button.el~ - Defines all button types used throughout the + package. Currently used only by ~sx-question-print.el~. + +- ~sx-request.el~ - Requests and url manipulation. Backend used by + ~sx-method.el~. It shouldn't be necessary to use the functions in + this file outside ~sx-method.el~. +- ~sx-method.el~ - Main interface for API method calls. + +- ~sx-favorites.el~ - Starred questions. +- ~sx-networks.el~ - User network information. +- ~sx-site.el~ - Browsing sites. +- ~sx-auth.el~ - Handles user authentication. + +- ~sx-question.el~ - Base question logic. Holds several functions for + retrieving questions and for processing retrieved questions. Doesn't + do any sort of user interface, that is left for + ~sx-question-list.el~ and ~sx-question-mode.el~. +- ~sx-question-list.el~ - Major-mode for navigating questions list. +- ~sx-question-mode.el~ - User interface for displaying a + question. Creates the buffer and defines the major-mode. +- ~sx-question-print.el~ - Populating the question buffer with + content. Used by ~sx-question-mode.el~ to actually print the content + of a question. + +- ~sx-compose.el~ - Major-mode for composing questions and answers. +- ~sx-interaction.el~ - Voting, commenting, and otherwise interacting with questions. +- ~sx-tab.el~ - Functions for viewing different tabs. + * COMMENT Local Variables # LocalWords: StackExchange SX inbox sx API url json inline Org # LocalWords: Markup keybinding keybindings customizability webpage -- cgit v1.2.3 From 512cfda1f0ba120f6fcfe62496936bba1ca42ebc Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 7 Dec 2014 01:30:40 +0000 Subject: Create sx-load file whose sole purpose is to load everything. --- README.org | 3 +-- sx-load.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 sx-load.el diff --git a/README.org b/README.org index 460ba34..db47904 100644 --- a/README.org +++ b/README.org @@ -36,8 +36,7 @@ As always, =C-h m= is the definitive resource for the functions of this mode. To install the development version, follow the usual steps: - Clone this repository - Add this directory to your ~load-path~ -- Issue ~(require 'sx)~ -- Issue ~(require 'sx-tab)~ +- Issue ~(require 'sx-load)~ This should give you access to the ~sx-tab-~ functions (the main entry points at this time). diff --git a/sx-load.el b/sx-load.el new file mode 100644 index 0000000..e29d439 --- /dev/null +++ b/sx-load.el @@ -0,0 +1,51 @@ +;;; sx-load.el --- Load all files of the sx package. + +;; Copyright (C) 2014 Artur Malabarba + +;; Author: Artur Malabarba + +;; 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 #'require + '(sx + sx-time + sx-auth + sx-button + sx-cache + sx-compose + sx-encoding + sx-favorites + sx-filter + sx-interaction + sx-method + sx-networks + sx.org + sx-question + sx-question-list + sx-question-mode + sx-question-print + sx-request + sx-site + sx-tab + )) + +(provide 'sx-load) +;;; sx-load.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: -- cgit v1.2.3 From 98a004b8f5a0f160c62563dc034372535f99a58e Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 8 Dec 2014 12:40:04 +0000 Subject: Update sx.org --- sx.org | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sx.org b/sx.org index 78bc5da..e9c1211 100644 --- a/sx.org +++ b/sx.org @@ -55,6 +55,14 @@ Emacs conventions. Of course, the core convention of Emacs is arbitrary customizability -- [[#hooks][hack away]]! * Basic Usage + +** Activation + +If you install ~SX~ with ~package-install~, you should have every +needed command properly autoloaded. If you install it manually, +require the ~sx-load~ file to make sure everything is correctly +loaded. + ** Authenticating Use ~sx-auth-authenticate~. Calling this function will open up a webpage on StackExchange that will prompt you to authorize this @@ -183,6 +191,8 @@ structure. This list is very loosely ordered form low to high-level. - ~sx-interaction.el~ - Voting, commenting, and otherwise interacting with questions. - ~sx-tab.el~ - Functions for viewing different tabs. +- ~sx-load.el~ - Load all files of the sx package. Designed as an easy way in for users who install the package manually (since they don't have autoloads). + * COMMENT Local Variables # LocalWords: StackExchange SX inbox sx API url json inline Org # LocalWords: Markup keybinding keybindings customizability webpage -- cgit v1.2.3 From af26d7303a98cf9b16baf29b86493e73559a5c20 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 9 Dec 2014 11:26:22 -0500 Subject: Don't require sx.org Branch: hotfix-sx.org --- sx-load.el | 1 - 1 file changed, 1 deletion(-) diff --git a/sx-load.el b/sx-load.el index e29d439..659f54b 100644 --- a/sx-load.el +++ b/sx-load.el @@ -33,7 +33,6 @@ sx-interaction sx-method sx-networks - sx.org sx-question sx-question-list sx-question-mode -- cgit v1.2.3