]> code.delx.au - gnu-emacs/blobdiff - lisp/org/org-feed.el
Copyright, license, and header fixes for Org.
[gnu-emacs] / lisp / org / org-feed.el
index 9d14daea9dfd2bfff361340853082796915cfbcc..f5186aaacf3f399a64cbd8b06028a7aae2e7e5e8 100644 (file)
@@ -1,11 +1,10 @@
 ;;; org-feed.el --- Add RSS feed items to Org files
 ;;
-;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2009-2012 Free Software Foundation, Inc.
 ;;
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 7.01
 ;;
 ;; This file is part of GNU Emacs.
 ;;
 (declare-function xml-get-children "xml" (node child-name))
 (declare-function xml-get-attribute "xml" (node attribute))
 (declare-function xml-get-attribute-or-nil "xml" (node attribute))
-(defvar xml-entity-alist)
+(declare-function xml-substitute-special "xml" (string))
 
 (defgroup org-feed  nil
   "Options concerning RSS feeds as inputs for Org files."
-  :tag "Org ID"
+  :tag "Org Feed"
   :group 'org)
 
 (defcustom org-feed-alist nil
@@ -269,17 +268,6 @@ have been saved."
 (defvar org-feed-buffer "*Org feed*"
   "The buffer used to retrieve a feed.")
 
-(defun org-feed-unescape (s)
-  "Unescape protected entities in S."
-  (require 'xml)
-  (let ((re (concat "&\\("
-                   (mapconcat 'car xml-entity-alist "\\|")
-                   "\\);")))
-    (while (string-match re s)
-      (setq s (replace-match
-              (cdr (assoc (match-string 1 s) xml-entity-alist)) nil nil s)))
-    s))
-
 ;;;###autoload
 (defun org-feed-update-all ()
   "Get inbox items from all feeds in `org-feed-alist'."
@@ -447,7 +435,7 @@ it can be a list structured like an entry in `org-feed-alist'."
   (if (stringp feed) (setq feed (assoc feed org-feed-alist)))
   (unless feed
     (error "No such feed in `org-feed-alist"))
-  (switch-to-buffer
+  (org-pop-to-buffer-same-window
    (org-feed-update feed 'retrieve-only))
   (goto-char (point-min)))
 
@@ -553,7 +541,8 @@ If that property is already present, nothing changes."
                  (setq tmp (org-feed-make-indented-block
                             tmp (org-get-indentation))))))
            (replace-match tmp t t))))
-       (buffer-string)))))
+       (decode-coding-string
+        (buffer-string) (detect-coding-region (point-min) (point-max) t))))))
 
 (defun org-feed-make-indented-block (s n)
   "Add indentation of N spaces to a multiline string S."
@@ -613,6 +602,7 @@ containing the properties `:guid' and `:item-full-text'."
 
 (defun org-feed-parse-rss-entry (entry)
   "Parse the `:item-full-text' field for xml tags and create new properties."
+  (require 'xml)
   (with-temp-buffer
     (insert (plist-get entry :item-full-text))
     (goto-char (point-min))
@@ -620,7 +610,7 @@ containing the properties `:guid' and `:item-full-text'."
                              nil t)
       (setq entry (plist-put entry
                             (intern (concat ":" (match-string 1)))
-                            (org-feed-unescape (match-string 2)))))
+                            (xml-substitute-special (match-string 2)))))
     (goto-char (point-min))
     (unless (re-search-forward "isPermaLink[ \t]*=[ \t]*\"false\"" nil t)
       (setq entry (plist-put entry :guid-permalink t))))
@@ -654,7 +644,7 @@ formatted as a string, not the original XML data."
                            'href)))
     ;; Add <title/> as :title.
     (setq entry (plist-put entry :title
-                          (org-feed-unescape
+                          (xml-substitute-special
                            (car (xml-node-children
                                  (car (xml-get-children xml 'title)))))))
     (let* ((content (car (xml-get-children xml 'content)))
@@ -664,12 +654,12 @@ formatted as a string, not the original XML data."
         ((string= type "text")
          ;; We like plain text.
          (setq entry (plist-put entry :description
-                                (org-feed-unescape
+                                (xml-substitute-special
                                  (car (xml-node-children content))))))
         ((string= type "html")
          ;; TODO: convert HTML to Org markup.
          (setq entry (plist-put entry :description
-                                (org-feed-unescape
+                                (xml-substitute-special
                                  (car (xml-node-children content))))))
         ((string= type "xhtml")
          ;; TODO: convert XHTML to Org markup.
@@ -683,5 +673,4 @@ formatted as a string, not the original XML data."
 
 (provide 'org-feed)
 
-;; arch-tag: 0929b557-9bc4-47f4-9633-30a12dbb5ae2
 ;;; org-feed.el ends here