From c05c57537aff8e258c8448ecc5492bc3e047a757 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 1 Dec 2014 15:58:59 +0000 Subject: Initial compose-mode implementation. --- sx-compose.el | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 sx-compose.el (limited to 'sx-compose.el') diff --git a/sx-compose.el b/sx-compose.el new file mode 100644 index 0000000..edce659 --- /dev/null +++ b/sx-compose.el @@ -0,0 +1,163 @@ +;;; sx-compose.el --- Major-mode for coposing questions and answers. -*- lexical-binding: t; -*- + +;; 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: +(require 'markdown-mode) + +(require 'sx) + +(defgroup sx-compose-mode nil + "Customization group for sx-compose-mode." + :prefix "sx-compose-mode-" + :tag "SX compose Mode" + :group 'sx) + + +;;; Faces and Variables +(defvar sx-compose-before-send-hook nil + "Hook run before POSTing to the API. +Functions are called without arguments and should return non-nil. + +Returning nil indicates something went wrong and the sending will +be aborted. In this case, the function is responsible for +notifying the user. + +Current buffer is the compose-mode buffer whose content is about +to be POSTed.") + +(defvar sx-compose-after-send-functions nil + "Hook run after POSTing to the API. +Functions on this hook should take one argument, the data +returned by `sx-compose--send-function' (usually the object +created by the API). They are only called if the transaction +succeeds.") + +(defvar sx-compose--send-function nil + "Function used by `sx-compose-send' to send the data. +Is invoked between `sx-compose-before-send-hook' and +`sx-compose-after-send-functions'.") + + +;;; Major-mode +(define-derived-mode sx-compose-mode markdown-mode "Compose" + "Major mode for coposing questions and answers. +Most of the functionality comes from `markdown-mode'. This mode +just implements some extra features related to posting to the +API. + +This mode won't function if `sx-compose--send-function' isn't +set. To make sure you set it correctly, you can create the buffer +with the `sx-compose--create' function. + +\\ +\\{sx-compose-mode}") + +(define-key sx-compose-mode-map "\C-c\C-c" #'sx-compose-send) + + +;;; Functions to help preparing buffers +(defun sx-compose--create (site parent &optional before-hooks after-functions) + "Create a `sx-compose-mode' buffer. +SITE is the site where it will be posted. + +If composing questions (not yet supported), 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. + +Each element of BEFORE-HOOKS and AFTER-FUNCTIONS are respectively +added locally to `sx-compose-before-send-hook' and +`sx-compose-after-send-functions'." + (or (integerp parent) (listp parent) + (error "Invalid PARENT")) + (with-current-buffer (sx-compose--get-buffer-create site parent) + (sx-compose-mode) + (setq sx-compose--send-function + (if (consp parent) + (sx-assoc-let parent + (lambda () (sx-method-call (if .title 'questions 'answers) + :site site + :keywords (sx-compose--generate-keywords .title) + :id (or .answer_id .question_id) + :submethod 'edit))) + (lambda () (sx-method-call 'questions + :site site + :keywords (sx-compose--generate-keywords (null parent)) + :id parent + :submethod (if parent 'answers/add 'add))))) + ;; Reverse so they're left in the same order. + (dolist (it (reverse before-hooks)) + (add-hook 'sx-compose-before-send-hook it nil t)) + (dolist (it (reverse after-functions)) + (add-hook 'sx-compose-after-send-functions it nil t)) + ;; Return the buffer + (current-buffer))) + +(defun sx-compose--generate-keywords (is-question) + "Reading current buffer, generate a keywords alist. +Keywords meant to be used in `sx-method-call'. + +`body_markdown' is read as the `buffer-string'. If IS-QUESTION is +non-nil, other keywords are read from the header " + (if (null is-question) + `((body_markdown . ,(buffer-string))) + ;; Question code will go here. + )) + +(defun sx-compose--get-buffer-create (site data) + "Get or create a buffer for use with `sx-compose-mode'. +SITE is the site for which composing is aimed (just used to +uniquely identify the buffers). + +If DATA is nil, get a fresh compose buffer. +If DATA is an integer, try to find an existing buffer +corresponding to that integer, otherwise create one. +If DATA is an alist (question or answer data), like above but use +the id property." + (cond + ((null data) + (generate-new-buffer + (format "*sx draft question %s*" site))) + ((integerp data) + (get-buffer-create + (format "*sx draft answer %s %s" + site data))) + (t + (get-buffer-create + (format "*sx draft edit %s %s" + site (sx-assoc-let data (or .answer_id .question_id))))))) + + +;;; Functions +(defun sx-compose-send () + "Finish composing current buffer and send it. +Calls `sx-compose-before-send-hook', POSTs the the current buffer +contents to the API, then calls `sx-compose-after-send-functions'." + (interactive) + (unless (run-hook-with-args-until-failure + sx-compose-before-send-hook) + (let ((result (funcall sx-compose--send-function))) + (run-hook-with-args sx-compose-after-send-functions + result)))) + +(provide 'sx-compose) +;;; sx-compose.el ends here -- cgit v1.2.3 From 5bba68bbbd76ae4db723354ba9112034cc0a724d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 1 Dec 2014 16:36:07 +0000 Subject: Some after-send-hooks to improve experience --- sx-compose.el | 63 ++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 20 deletions(-) (limited to 'sx-compose.el') diff --git a/sx-compose.el b/sx-compose.el index edce659..1eb4aa6 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -46,7 +46,8 @@ to be POSTed.") (defvar sx-compose-after-send-functions nil "Hook run after POSTing to the API. -Functions on this hook should take one argument, the data +Functions on this hook should take two arguments, the +`sx-compose-mode' buffer (which not be live) and the data returned by `sx-compose--send-function' (usually the object created by the API). They are only called if the transaction succeeds.") @@ -69,9 +70,38 @@ set. To make sure you set it correctly, you can create the buffer with the `sx-compose--create' function. \\ -\\{sx-compose-mode}") +\\{sx-compose-mode}" + (add-hook 'sx-compose-after-send-functions + #'sx-compose-quit nil t) + (add-hook 'sx-compose-after-send-functions + #'sx-compose--copy-as-kill nil t)) (define-key sx-compose-mode-map "\C-c\C-c" #'sx-compose-send) +(define-key sx-compose-mode-map "\C-c\C-k" #'sx-compose-quit) + +(defun sx-compose-send () + "Finish composing current buffer and send it. +Calls `sx-compose-before-send-hook', POSTs the the current buffer +contents to the API, then calls `sx-compose-after-send-functions'." + (interactive) + (when (run-hook-with-args-until-failure + sx-compose-before-send-hook) + (let ((result (funcall sx-compose--send-function))) + (with-demoted-errors + (run-hook-with-args sx-compose-after-send-functions + (current-buffer) result))))) + +(defun sx-compose-quit (buffer _) + "Kill BUFFER." + (interactive (list (current-buffer) nil)) + (when (buffer-live-p buffer) + (kill-buffer buffer))) + +(defun sx-compose--copy-as-kill (buffer _) + "Copy BUFFER contents to the kill-ring." + (when (buffer-live-p buffer) + (with-current-buffer buffer + (kill-new (buffer-string))))) ;;; Functions to help preparing buffers @@ -95,11 +125,17 @@ added locally to `sx-compose-before-send-hook' and (if (consp parent) (sx-assoc-let parent (lambda () (sx-method-call (if .title 'questions 'answers) + :auth 'warn + :url-method "POST" + :filter sx-browse-filter :site site :keywords (sx-compose--generate-keywords .title) :id (or .answer_id .question_id) :submethod 'edit))) (lambda () (sx-method-call 'questions + :auth 'warn + :url-method "POST" + :filter sx-browse-filter :site site :keywords (sx-compose--generate-keywords (null parent)) :id parent @@ -116,10 +152,10 @@ added locally to `sx-compose-before-send-hook' and "Reading current buffer, generate a keywords alist. Keywords meant to be used in `sx-method-call'. -`body_markdown' is read as the `buffer-string'. If IS-QUESTION is -non-nil, other keywords are read from the header " +`body' is read as the `buffer-string'. If IS-QUESTION is non-nil, +other keywords are read from the header " (if (null is-question) - `((body_markdown . ,(buffer-string))) + `((body . ,(buffer-string))) ;; Question code will go here. )) @@ -139,25 +175,12 @@ the id property." (format "*sx draft question %s*" site))) ((integerp data) (get-buffer-create - (format "*sx draft answer %s %s" + (format "*sx draft answer %s %s*" site data))) (t (get-buffer-create - (format "*sx draft edit %s %s" + (format "*sx draft edit %s %s*" site (sx-assoc-let data (or .answer_id .question_id))))))) - -;;; Functions -(defun sx-compose-send () - "Finish composing current buffer and send it. -Calls `sx-compose-before-send-hook', POSTs the the current buffer -contents to the API, then calls `sx-compose-after-send-functions'." - (interactive) - (unless (run-hook-with-args-until-failure - sx-compose-before-send-hook) - (let ((result (funcall sx-compose--send-function))) - (run-hook-with-args sx-compose-after-send-functions - result)))) - (provide 'sx-compose) ;;; sx-compose.el ends here -- cgit v1.2.3 From a803e5855553e7ce039d540a3550317e6805730d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 1 Dec 2014 23:09:39 +0000 Subject: Rename before-functions --- sx-compose.el | 80 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 31 deletions(-) (limited to 'sx-compose.el') diff --git a/sx-compose.el b/sx-compose.el index 1eb4aa6..45b2288 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -105,7 +105,17 @@ contents to the API, then calls `sx-compose-after-send-functions'." ;;; Functions to help preparing buffers -(defun sx-compose--create (site parent &optional before-hooks after-functions) +(defvar sx-compose--question-headers + (insert (concat + (propertize "Title: " 'rear-nonsticky t + 'read-only t + 'field 'sx-compose-header-title) + (propertize "\nTags: " 'rear-nonsticky t + 'field 'sx-compose-header-tags + 'read-only t ))) + "") + +(defun sx-compose--create (site parent &optional before-functions after-functions) "Create a `sx-compose-mode' buffer. SITE is the site where it will be posted. @@ -114,39 +124,47 @@ If composing answers, it is the `question_id'. If editing answers or questions, it should be the alist data related to that object. -Each element of BEFORE-HOOKS and AFTER-FUNCTIONS are respectively -added locally to `sx-compose-before-send-hook' and +Each element of BEFORE-FUNCTIONS and AFTER-FUNCTIONS are +respectively added locally to `sx-compose-before-send-hook' and `sx-compose-after-send-functions'." (or (integerp parent) (listp parent) (error "Invalid PARENT")) - (with-current-buffer (sx-compose--get-buffer-create site parent) - (sx-compose-mode) - (setq sx-compose--send-function - (if (consp parent) - (sx-assoc-let parent - (lambda () (sx-method-call (if .title 'questions 'answers) - :auth 'warn - :url-method "POST" - :filter sx-browse-filter - :site site - :keywords (sx-compose--generate-keywords .title) - :id (or .answer_id .question_id) - :submethod 'edit))) - (lambda () (sx-method-call 'questions - :auth 'warn - :url-method "POST" - :filter sx-browse-filter - :site site - :keywords (sx-compose--generate-keywords (null parent)) - :id parent - :submethod (if parent 'answers/add 'add))))) - ;; Reverse so they're left in the same order. - (dolist (it (reverse before-hooks)) - (add-hook 'sx-compose-before-send-hook it nil t)) - (dolist (it (reverse after-functions)) - (add-hook 'sx-compose-after-send-functions it nil t)) - ;; Return the buffer - (current-buffer))) + (let ((is-question + (and (listp parent) + (null (cdr (assoc 'answer_id parent)))))) + (with-current-buffer (sx-compose--get-buffer-create site parent) + (sx-compose-mode) + (setq sx-compose--send-function + (if (consp parent) + (sx-assoc-let parent + (lambda () (sx-method-call (if .title 'questions 'answers) + :auth 'warn + :url-method "POST" + :filter sx-browse-filter + :site site + :keywords (sx-compose--generate-keywords is-question) + :id (or .answer_id .question_id) + :submethod 'edit))) + (lambda () (sx-method-call 'questions + :auth 'warn + :url-method "POST" + :filter sx-browse-filter + :site site + :keywords (sx-compose--generate-keywords is-question) + :id parent + :submethod (if parent 'answers/add 'add))))) + ;; Reverse so they're left in the same order. + (dolist (it (reverse before-functions)) + (add-hook 'sx-compose-before-send-hook it nil t)) + (dolist (it (reverse after-functions)) + (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) "")) + (insert sx-compose--question-headers)) + ;; Return the buffer + (current-buffer)))) (defun sx-compose--generate-keywords (is-question) "Reading current buffer, generate a keywords alist. -- cgit v1.2.3 From aeb4303d3f0b0917f30fc9d9d66f1a4ca3d541b9 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 2 Dec 2014 00:13:41 +0000 Subject: Implement asking --- sx-compose.el | 63 ++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 20 deletions(-) (limited to 'sx-compose.el') diff --git a/sx-compose.el b/sx-compose.el index 45b2288..e09240f 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -57,6 +57,16 @@ succeeds.") Is invoked between `sx-compose-before-send-hook' and `sx-compose-after-send-functions'.") +(defvar sx-compose--question-headers + (concat + #("Title: " 0 7 (intangible t read-only t rear-nonsticky t)) + #("\n" 0 1 (read-only t)) + #("Tags: " 0 7 (read-only t intangible t rear-nonsticky t)) + #("\n----------------------------------------\n" + 0 42 (read-only t))) + "Headers inserted when composing a new question. +Used by `sx-compose--create'.") + ;;; Major-mode (define-derived-mode sx-compose-mode markdown-mode "Compose" @@ -85,10 +95,10 @@ Calls `sx-compose-before-send-hook', POSTs the the current buffer contents to the API, then calls `sx-compose-after-send-functions'." (interactive) (when (run-hook-with-args-until-failure - sx-compose-before-send-hook) + 'sx-compose-before-send-hook) (let ((result (funcall sx-compose--send-function))) (with-demoted-errors - (run-hook-with-args sx-compose-after-send-functions + (run-hook-with-args 'sx-compose-after-send-functions (current-buffer) result))))) (defun sx-compose-quit (buffer _) @@ -105,21 +115,11 @@ contents to the API, then calls `sx-compose-after-send-functions'." ;;; Functions to help preparing buffers -(defvar sx-compose--question-headers - (insert (concat - (propertize "Title: " 'rear-nonsticky t - 'read-only t - 'field 'sx-compose-header-title) - (propertize "\nTags: " 'rear-nonsticky t - 'field 'sx-compose-header-tags - 'read-only t ))) - "") - (defun sx-compose--create (site parent &optional before-functions after-functions) "Create a `sx-compose-mode' buffer. SITE is the site where it will be posted. -If composing questions (not yet supported), 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. @@ -160,9 +160,11 @@ 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) "")) - (insert sx-compose--question-headers)) + (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)))) ;; Return the buffer (current-buffer)))) @@ -172,10 +174,31 @@ 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 " - (if (null is-question) - `((body . ,(buffer-string))) - ;; Question code will go here. - )) + `(,@(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)) + (when (search-forward-regexp "^Title: *\\(.*\\) *$" header-end 'noerror) + (error "No Title header found")) + (push (cons 'title (match-string 1)) keywords) + ;; And the tags + (goto-char (point-min)) + (unless (search-forward-regexp "^Tags: *\\([^[:space:]].*\\) *$" header-end 'noerror) + (error "No Tags header found")) + (push (cons 'tags (replace-regexp-in-string + "[[:space:],]" ";" (match-string 1))) + keywords) + ;; And erase the header so it doesn't get sent. + (delete-region + (point-min) + (next-single-property-change + header-end 'sx-compose-separator)))) + (body . ,(buffer-string)))) (defun sx-compose--get-buffer-create (site data) "Get or create a buffer for use with `sx-compose-mode'. -- cgit v1.2.3 From 59c49ce60fcfa1fac4827beb11a04c0ef8585b9a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 2 Dec 2014 01:20:09 +0000 Subject: Editing implemented Fix #11 --- sx-compose.el | 5 +++++ sx-interaction.el | 31 +++++++++++++++++++++++++++---- sx-question-mode.el | 1 + 3 files changed, 33 insertions(+), 4 deletions(-) (limited to 'sx-compose.el') diff --git a/sx-compose.el b/sx-compose.el index e09240f..dcb1bb0 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -165,6 +165,11 @@ respectively added locally to `sx-compose-before-send-hook' and (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? ")) + (erase-buffer) + (insert (cdr (assoc 'body_markdown parent))))) ;; Return the buffer (current-buffer)))) diff --git a/sx-interaction.el b/sx-interaction.el index 8673400..df871dd 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -199,6 +199,28 @@ OBJECT can be a question or an answer." (setcdr object (cons (car object) (cdr object))) (setcar object `(comments . [,comment]))))) + +;;; Editing +(defun sx-edit (data) + "Start editing an answer or question given by DATA. +DATA is an answer or question alist. Interactively, it is guessed +from context at point." + ;; Answering doesn't really make sense from anywhere other than + ;; inside a question. So we don't need `sx--data-here' here. + (interactive (list (sx--data-here))) + ;; If we ever make an "Edit" button, first arg is a marker. + (when (markerp data) (setq data (sx--data-here))) + (sx-assoc-let data + (when .comment_id (user-error "Editing comments is not supported yet")) + (let ((buffer (current-buffer))) + (pop-to-buffer + (sx-compose--create + .site data nil + ;; After send functions + (list (lambda (_ res) + (sx--copy-data (elt res 0) data) + (sx--maybe-update-display buffer)))))))) + ;;; Answering (defun sx-answer (data) @@ -215,10 +237,11 @@ context at point. " (pop-to-buffer (sx-compose--create .site .question_id nil - ;; After change functions - (lambda (_ res) - (sx--add-answer-to-question-object res sx-question-mode--data) - (sx--maybe-update-display buffer))))))) + ;; After send functions + (list (lambda (_ res) + (sx--add-answer-to-question-object + (elt res 0) sx-question-mode--data) + (sx--maybe-update-display buffer)))))))) (defun sx--add-answer-to-question-object (answer question) "Add alist ANSWER to alist QUESTION in the right place." diff --git a/sx-question-mode.el b/sx-question-mode.el index 24b2cfb..cc4c082 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -189,6 +189,7 @@ Letters do not insert themselves; instead, they are commands. ("q" quit-window) (" " scroll-up-command) ("a" sx-answer) + ("e" sx-edit) (,(kbd "S-SPC") scroll-down-command) ([backspace] scroll-down-command) ([tab] forward-button) -- cgit v1.2.3 From 89a45e4724089a8bfdecaa6f58ae5394c10d85e3 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 2 Dec 2014 01:48:55 +0000 Subject: Fix up asking logic --- sx-compose.el | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'sx-compose.el') diff --git a/sx-compose.el b/sx-compose.el index dcb1bb0..0ae1f93 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -61,9 +61,11 @@ Is invoked between `sx-compose-before-send-hook' and (concat #("Title: " 0 7 (intangible t read-only t rear-nonsticky t)) #("\n" 0 1 (read-only t)) - #("Tags: " 0 7 (read-only t intangible t rear-nonsticky t)) - #("\n----------------------------------------\n" - 0 42 (read-only t))) + #("Tags : " 0 7 (read-only t intangible t rear-nonsticky t)) + #("\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))) "Headers inserted when composing a new question. Used by `sx-compose--create'.") @@ -188,21 +190,24 @@ other keywords are read from the header " keywords) ;; Read the Title. (goto-char (point-min)) - (when (search-forward-regexp "^Title: *\\(.*\\) *$" header-end 'noerror) + (unless (search-forward-regexp + "^Title: *\\(.*\\) *$" header-end 'noerror) (error "No Title header found")) (push (cons 'title (match-string 1)) keywords) ;; And the tags (goto-char (point-min)) - (unless (search-forward-regexp "^Tags: *\\([^[:space:]].*\\) *$" header-end 'noerror) + (unless (search-forward-regexp "^Tags : *\\([^[:space:]].*\\) *$" + header-end 'noerror) (error "No Tags header found")) - (push (cons 'tags (replace-regexp-in-string - "[[:space:],]" ";" (match-string 1))) + (push (cons 'tags (split-string (match-string 1) "[[:space:],;]" + 'omit-nulls "[[: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)))) + header-end 'sx-compose-separator)) + keywords)) (body . ,(buffer-string)))) (defun sx-compose--get-buffer-create (site data) -- cgit v1.2.3 From f800936f58d13d8de97eab4b57d3965256482e38 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 2 Dec 2014 02:18:25 +0000 Subject: Refactor sx-compose-create --- sx-compose.el | 8 ++++---- sx-interaction.el | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'sx-compose.el') diff --git a/sx-compose.el b/sx-compose.el index 0ae1f93..273e02d 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -67,7 +67,7 @@ Is invoked between `sx-compose-before-send-hook' and 0 42 (read-only t rear-nonsticky t intangible t sx-compose-separator t))) "Headers inserted when composing a new question. -Used by `sx-compose--create'.") +Used by `sx-compose-create'.") ;;; Major-mode @@ -79,7 +79,7 @@ API. This mode won't function if `sx-compose--send-function' isn't set. To make sure you set it correctly, you can create the buffer -with the `sx-compose--create' function. +with the `sx-compose-create' function. \\ \\{sx-compose-mode}" @@ -117,8 +117,8 @@ 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 a `sx-compose-mode' buffer. +(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. If composing questions, PARENT is nil. diff --git a/sx-interaction.el b/sx-interaction.el index ce00889..85d681c 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -216,7 +216,7 @@ from context at point." (when .comment_id (user-error "Editing comments is not supported yet")) (let ((buffer (current-buffer))) (pop-to-buffer - (sx-compose--create + (sx-compose-create .site data nil ;; After send functions (list (lambda (_ res) @@ -233,7 +233,7 @@ SITE is a string, indicating where the question will be posted." (interactive (list (sx-tab--interactive-site-prompt))) (let ((buffer (current-buffer))) (pop-to-buffer - (sx-compose--create + (sx-compose-create site nil nil ;; After send functions (list (lambda (_ res) (sx--maybe-update-display buffer))))))) @@ -252,7 +252,7 @@ context at point. " (let ((buffer (current-buffer))) (sx-assoc-let data (pop-to-buffer - (sx-compose--create + (sx-compose-create .site .question_id nil ;; After send functions (list (lambda (_ res) -- cgit v1.2.3 From e5ebab3f99537b2dab0a7264f7e280564fdd6e6b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 2 Dec 2014 02:18:43 +0000 Subject: Header Commentary to sx-compose --- sx-compose.el | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sx-compose.el') diff --git a/sx-compose.el b/sx-compose.el index 273e02d..f5aef79 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -19,6 +19,16 @@ ;;; Commentary: +;; This file defines `sx-compose-mode' and its auxiliary functions and +;; variables. In order to use `sx-compose-mode', it is adamant that +;; the variable `sx-compose--send-function' be set. Otherwise it's +;; just a regular markdown buffer. +;; +;; In order to help avoid mistakes, there is the function +;; `sx-compose-create'. This is the preferred way of activating the +;; mode. It creates a buffer, activates the major mode, and sets the +;; `send-function' variable according to the arguments it is given. + ;;; Code: (require 'markdown-mode) -- cgit v1.2.3 From 46de3f0ddba5a7611f025b816d637136593b20b1 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 3 Dec 2014 14:13:29 +0000 Subject: Not adamant --- sx-compose.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sx-compose.el') diff --git a/sx-compose.el b/sx-compose.el index f5aef79..d7d3ff3 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -20,9 +20,9 @@ ;;; Commentary: ;; This file defines `sx-compose-mode' and its auxiliary functions and -;; variables. In order to use `sx-compose-mode', it is adamant that -;; the variable `sx-compose--send-function' be set. Otherwise it's -;; just a regular markdown buffer. +;; variables. In order to use `sx-compose-mode', it is vital that the +;; variable `sx-compose--send-function' be set. Otherwise it's just a +;; regular markdown buffer. ;; ;; In order to help avoid mistakes, there is the function ;; `sx-compose-create'. This is the preferred way of activating the -- cgit v1.2.3