Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tidied documentation which should now conform to emacs-wiki and GNU g…

…uidelines. Corrected parameter passing bug. Merged in Tim Disney's posterous-new-markdown-post function. Tidied formatting.
  • Loading branch information...
commit e481fa8e918f0d413d570321601d8687dd593b81 1 parent 30f6042
@snim2 authored
Showing with 88 additions and 78 deletions.
  1. +88 −78 posterous.el
View
166 posterous.el
@@ -1,12 +1,19 @@
;;; posterous.el --- Emacs integration for posterous.com
-(defvar posterous-version "0.1")
-
-;; Maintainer: Sarah Mount snim2@snim2.org
-;; Author: Sarah Mount snim2@snim2.org
-;; Version: 0.1
+(defvar posterous-version "0.2")
+
+;; Maintainer: Sarah Mount <snim2@snim2.org>
+;; Author: Sarah Mount <snim2@snim2.org>
+;; Jonas Bernoulli <jonasbernoulli@gmail.com>
+;; zanoni https://github.com/zanoni
+;; Tim Disney <tim.disney@gmail.com>
+;; Version: 0.2
;; Created: 14 May 2010
;; Keywords: posterous blog
+;; Last-Updated: Mon Feb 27 08:50:54 GMT 2012
+;; By: Sarah Mount
+;; Update: Tidied documentation, fixed posterous-new-markdown-post
+;; URL: https://github.com/snim2/posterous.el
;; This file is NOT part of GNU Emacs.
@@ -55,6 +62,11 @@
;; M-x posterous-buffer-private
;; -- post a buffer of text to posterous as a private post.
+;; M-x posterous-new-markdown-post
+;; -- Create a new post with a nice markdown template and put into
+;; markdown mode.
+
+
;; If you do not wish to post to your default posterous site, you can
;; customise the variable:
@@ -87,8 +99,7 @@
(defcustom posterous-default-siteid nil
- "Siteid for default posterous blog to post to. If this variable
- is null the user's default site will be used."
+ "Siteid for default posterous blog to post to. If this variable is null the user's default site will be used."
:type 'string
:group 'posterous)
@@ -122,98 +133,97 @@
(defconst posterous-result-buffer "*posterous*"
"Buffer name for copying responses from posterous.com.")
-(defun posterous-newpost ()
- "Create a new post with a nice markdown template and put into markdown mode"
- (interactive)
- ;(setq title (read-from-minibuffer "Post title: "))
- (switch-to-buffer (get-buffer-create "New Post"))
- (markdown-mode)
- (insert "<markdown>\n\n</markdown>")
- (previous-line))
+(defun posterous-new-markdown-post ()
+ "Create a new post with a nice markdown template and put into markdown mode."
+ (interactive)
+ (let (title)
+ (setq title (read-from-minibuffer "Post title: "))
+ (switch-to-buffer (get-buffer-create title))
+ (markdown-mode)
+ (insert "<markdown>\n\n</markdown>"))
+ )
(defun posterous-getsites ()
"Get a list of sites owned by this user."
(interactive)
(let ((url-request-method "GET")
- (url-request-extra-headers
- `(("Authorization" . ,(base64-encode-string
- (format "%s:%s" posterous-email posterous-password))))))
- (save-excursion
- (if (null posterous-email)
- (setq posterous-email (read-from-minibuffer "Email address: ")))
- (if (null posterous-password)
- (setq posterous-password (read-from-minibuffer "Posterous password: ")))
- (url-retrieve posterous-getsites-url 'posterous-getsites-callback))))
+ (url-request-extra-headers
+ `(("Authorization" . ,(base64-encode-string
+ (format "%s:%s" posterous-email posterous-password))))))
+ (save-excursion
+ (if (null posterous-email)
+ (setq posterous-email (read-from-minibuffer "Email address: ")))
+ (if (null posterous-password)
+ (setq posterous-password (read-from-minibuffer "Posterous password: ")))
+ (url-retrieve posterous-getsites-url 'posterous-getsites-callback))))
(defun posterous-post-base (post private media title tags autopost)
- "Generic post to posterous function. Called by posterous-post-generic."
- (let ((url-request-method "POST")
- (url-request-extra-headers
- `(("Content-Type" . "application/x-www-form-urlencoded")
- ("Authorization" . ,(base64-encode-string
- (format "%s:%s" posterous-email posterous-password)))))
- (url-request-data
- (concat "site_id=" (url-hexify-string posterous-default-siteid) ;; site_id
- "&title=" (url-hexify-string title) ;; title
- "&body=" (url-hexify-string post) ;; body
- "&autopost=" (url-hexify-string autopost) ;; autopost
- "&private=" (url-hexify-string private) ;; private
- "&tags=" (url-hexify-string tags) ;; tags
- "&media=" (url-hexify-string media) ;; media
- )))
- (url-retrieve posterous-post-url 'posterous-post-callback)))
+ "Generic POST to posterous function. Called by posterous-post-generic."
+ (let ((url-request-method "POST")
+ (url-request-extra-headers
+ `(("Content-Type" . "application/x-www-form-urlencoded")
+ ("Authorization" . ,(base64-encode-string
+ (format "%s:%s" posterous-email posterous-password)))))
+ (url-request-data
+ (concat "site_id=" (url-hexify-string posterous-default-siteid)
+ "&title=" (url-hexify-string title) ;; title
+ "&body=" (url-hexify-string post) ;; body
+ "&autopost=" (url-hexify-string autopost) ;; autopost
+ "&private=" (url-hexify-string private) ;; private
+ "&tags=" (url-hexify-string tags) ;; tags
+ "&media=" (url-hexify-string media) ;; media
+ )))
+ (url-retrieve posterous-post-url 'posterous-post-callback)))
(defun posterous-post-generic (start end private media)
"Generic post function called by all interactive functions."
(let (post title tags autopost)
- (setq post (buffer-substring start end))
- (setq title (read-from-minibuffer "Post title: "))
- (setq tags (read-from-minibuffer "Tags (comma-separated): "))
- (if (null posterous-email)
- (setq posterous-email (read-from-minibuffer "Email address: ")))
- (if (null posterous-password)
- (setq posterous-password (read-from-minibuffer "Posterous password: ")))
- (if posterous-suppress-autopost
- (setq autopost "1")
- (setq autopost "0"))
- (posterous-post-base post private media title tags autopost)))
+ (setq post (buffer-substring start end))
+ (setq title (read-from-minibuffer "Post title: "))
+ (setq tags (read-from-minibuffer "Tags (comma-separated): "))
+ (if (null posterous-email)
+ (setq posterous-email (read-from-minibuffer "Email address: ")))
+ (if (null posterous-password)
+ (setq posterous-password (read-from-minibuffer "Posterous password: ")))
+ (if posterous-suppress-autopost
+ (setq autopost "1")
+ (setq autopost "0"))
+ (posterous-post-base post private media title tags autopost)))
(defun posterous-region (start end)
"Post a region of text to posterous."
(interactive "r")
(save-excursion
- (posterous-post-generic start end "0" "")))
+ (posterous-post-generic start end "0" "")))
(defun posterous-region-private (start end)
"Post a region of text to posterous as a private post."
(interactive "r")
(save-excursion
- (posterous-post-generic start end "1" "")))
+ (posterous-post-generic start end "1" "")))
(defun posterous-buffer ()
"Post a whole buffer to posterous."
(interactive)
(save-excursion
- (posterous-region (point-min) (point-max))))
+ (posterous-region (point-min) (point-max))))
(defun posterous-buffer-private ()
"Post a whole buffer to posterous as a private post."
(interactive)
(save-excursion
- (posterous-region (point-min) (point-max) "1" "emacs,posterous" "")))
+ (posterous-region (point-min) (point-max))))
(defun posterous-getsites-callback (response)
- "Deal with an HTTP response from posterous.com.
- Remove the HTTP header, parse the XML returned from posterous.
- "
+ "Deal with an HTTP RESPONSE from posterous.com. Remove the HTTP header, parse the XML returned from posterous."
(rename-buffer posterous-result-buffer)
;;; Delete HTTP header
(goto-char (point-min))
@@ -239,28 +249,28 @@
(switch-to-buffer (current-buffer))
;;; Parse XML returned by posterous.com
(let* ((root (xml-parse-region (point-min) (point-max)))
- (rsp (car root))
- (attrs (xml-node-attributes rsp))
- (stat (cdr (assq 'stat attrs))))
- (cond ((null stat)
- (message "No status returned from posterous.com. Unknown error."))
- ;;; Posting was successful.
- ((string-equal stat "ok")
- (let* ((post (car (xml-get-children rsp 'post)))
- (id (car (xml-get-children post 'id)))
- (text-id (car (xml-node-children id)))
- (url (car (xml-get-children post 'url)))
- (text-url (car (xml-node-children url))))
- (message "New post at has id %s at: %s" text-id text-url)))
- ;;; Posting failed.
- ((string-equal stat "fail")
- (let* ((err (car (xml-get-children rsp 'err)))
- (err-attrs (xml-node-attributes err))
- (msg (cdr (assq 'msg err-attrs))))
- (message "Posting to posterous failed: %s." msg)))))
+ (rsp (car root))
+ (attrs (xml-node-attributes rsp))
+ (stat (cdr (assq 'stat attrs))))
+ (cond ((null stat)
+ (message "No status returned from posterous.com. Unknown error."))
+ ;;; Posting was successful.
+ ((string-equal stat "ok")
+ (let* ((post (car (xml-get-children rsp 'post)))
+ (id (car (xml-get-children post 'id)))
+ (text-id (car (xml-node-children id)))
+ (url (car (xml-get-children post 'url)))
+ (text-url (car (xml-node-children url))))
+ (message "New post at has id %s at: %s" text-id text-url)))
+ ;;; Posting failed.
+ ((string-equal stat "fail")
+ (let* ((err (car (xml-get-children rsp 'err)))
+ (err-attrs (xml-node-attributes err))
+ (msg (cdr (assq 'msg err-attrs))))
+ (message "Posting to posterous failed: %s." msg)))))
(kill-buffer (current-buffer)))
(provide 'posterous)
-;; posterous.el end.
+;;; posterous.el ends here
Please sign in to comment.
Something went wrong with that request. Please try again.