Update Writer's Block code to pre-fill Subject header.
authorSteve Youngs <steve@sxemacs.org>
Fri, 24 Jun 2011 06:28:19 +0000 (16:28 +1000)
committerSteve Youngs <steve@sxemacs.org>
Fri, 24 Jun 2011 06:28:19 +0000 (16:28 +1000)
* lj.el (lj-parse-qotd-archive): Fix regexp.

* lj.el (lj-qotd-subject): New.  Pre-fills the Subject header with
the title of the Writer's Block question.

* lj.el (lj-narrow-to-qotd): Use it.

* lj.el (lj-version): Bump.

Signed-off-by: Steve Youngs <steve@sxemacs.org>
lj.el

diff --git a/lj.el b/lj.el
index 9b2712c..ae6459f 100644 (file)
--- a/lj.el
+++ b/lj.el
 ;;      choose different qotd's after one has been selected.  Also, be
 ;;      able to view older qotd's.
 ;;
-;;    o Find a way to pre-fill the subject header properly for writer's
-;;      block.
-;;
 ;;    o Rewrite the twitter code to use OAuth.
 ;;
 
 ;;
 
 ;;; Version:
-(defconst lj-version 1.24
+(defconst lj-version 1.25
   "Version number of SXEmacs/LJ.")
 
 ;;; Code:
@@ -2641,8 +2638,10 @@ With two prefix args, also set a \"date out of order\" flag."
   (let ((buf (get-buffer-create lj-qotd-buffer))
        (bregexp "<!-- Content -->")
        (eregexp "<p class='skiplinks'>")
-       (qregexp "^<p class='qotd-archive-item-question'>\\(.*\\)</p><p")
-       (dregexp "^<p class='qotd-archive-item-date'>\\(.*[0-9]+\\)</p>")
+       (qregexp "<p class='qotd-archive-item-question'>\\(.*\\)</p><p")
+       (dregexp
+        (concat "<div class=\"b-qotd-question\">"
+                "<p class='qotd-archive-item-date'>\\(.*[0-9]+\\)</p>"))
        (idregexp "^.*qotd=\\([0-9]+\\).*\n.*$")
        (url "http://www.livejournal.com/misc/qotdarchive.bml")
        b e)
@@ -2675,6 +2674,22 @@ With two prefix args, also set a \"date out of order\" flag."
                                         (match-string 1))
                                 (make-string 72 ?=)) t))))))
 
+(defun lj-qotd-subject (qotd)
+  "Update the Subject header with title of QOTD."
+  (let ((url (format "http://www.livejournal.com/update.bml?qotd=%d"
+                    qotd))
+       (subject))
+    (with-temp-buffer
+      (mm-url-insert url)
+      (goto-char (point-min))
+      (when (re-search-forward "Writer&#39;s Block: \\(.*\\)\" name="
+                              nil t)
+       (setq subject (match-string 1))))
+    (lj-goto-subject)
+    (goto-char (point-at-eol))
+    (insert subject)
+    (goto-char (point-max))))
+
 (defun lj-narrow-to-qotd (qotd)
   "Narrow Writer's Block buffer to a single QOTD."
   (let ((delim (make-string 72 ?=))
@@ -2690,7 +2705,8 @@ With two prefix args, also set a \"date out of order\" flag."
       (switch-to-buffer "*LJ-Post*"))
     (unless (zerop lj-qotd)
       (insert (format "<lj-template name=\"qotd\" id=\"%d\" />\n\n"
-                     lj-qotd)))))
+                     lj-qotd))
+      (lj-qotd-subject lj-qotd))))
 
 (defun lj-cleanup-qotd ()
   "Reset `lj-qotd' to zero and kill the qotd buffer."