org-feed.el 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. ;;; org-feed.el --- Add RSS feed items to Org files
  2. ;;
  3. ;; Copyright (C) 2009 Free Software Foundation, Inc.
  4. ;;
  5. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  6. ;; Keywords: outlines, hypermedia, calendar, wp
  7. ;; Homepage: http://orgmode.org
  8. ;; Version: 6.25trans
  9. ;;
  10. ;; This file is part of GNU Emacs.
  11. ;;
  12. ;; GNU Emacs is free software: you can redistribute it and/or modify
  13. ;; it under the terms of the GNU General Public License as published by
  14. ;; the Free Software Foundation, either version 3 of the License, or
  15. ;; (at your option) any later version.
  16. ;; GNU Emacs is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;; GNU General Public License for more details.
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;;
  24. ;;; Commentary:
  25. ;;
  26. ;; This module allows to create and change entries in an Org-mode
  27. ;; file triggered by items in an RSS feed. The basic functionality is
  28. ;; geared toward simply adding new items found in a feed as outline nodes
  29. ;; to an Org file. Using hooks, arbitrary actions can be triggered for
  30. ;; new or changed items.
  31. ;;
  32. ;; Selecting feeds and target locations
  33. ;; ------------------------------------
  34. ;;
  35. ;; This module is configured through a single variable, `org-feed-alist'.
  36. ;; Here is an example, using a notes/tasks feed from reQall.com.
  37. ;;
  38. ;; (setq org-feed-alist
  39. ;; '(("ReQall"
  40. ;; "http://www.reqall.com/user/feeds/rss/a1b2c3....."
  41. ;; "~/org/feeds.org" "ReQall Entries")
  42. ;;
  43. ;; With this setup, the command `M-x org-feed-update-all' will
  44. ;; collect new entries in the feed at the given URL and create
  45. ;; entries as subheadings under the "ReQall Entries" heading in the
  46. ;; file "~/org-feeds.org". Each feed should normally have its own
  47. ;; heading - however see the `:drawer' parameter.
  48. ;;
  49. ;; Besides these standard elements that need to be specified for each
  50. ;; feed, keyword-value pairs can set additional options. For example,
  51. ;; to de-select transitional entries with a title containing
  52. ;;
  53. ;; "reQall is typing what you said",
  54. ;;
  55. ;; you could use the `:filter' argument:
  56. ;;
  57. ;; (setq org-feed-alist
  58. ;; '(("ReQall"
  59. ;; "http://www.reqall.com/user/feeds/rss/a1b2c3....."
  60. ;; "~/org/feeds.org" "ReQall Entries"
  61. ;; :filter my-reqall-filter)))
  62. ;;
  63. ;; (defun my-reqall-filter (e)
  64. ;; (if (string-match "reQall is typing what you said"
  65. ;; (plist-get e :title))
  66. ;; nil
  67. ;; e))
  68. ;;
  69. ;; See the docstring for `org-feed-alist' for more details.
  70. ;;
  71. ;;
  72. ;; Keeping track of previously added entries
  73. ;; -----------------------------------------
  74. ;;
  75. ;; Since Org allows you to delete, archive, or move outline nodes,
  76. ;; org-feed.el needs to keep track of which feed items have been handled
  77. ;; before, so that they will not be handled again. For this, org-feed.el
  78. ;; stores information in a special drawer, FEEDSTATUS, under the heading
  79. ;; that received the input of the feed. You should add FEEDSTATUS
  80. ;; to your list of drawers in the files that receive feed input:
  81. ;;
  82. ;; #+DRAWERS: PROPERTIES LOGBOOK FEEDSTATUS
  83. ;;
  84. ;; Acknowledgments
  85. ;; ----------------
  86. ;;
  87. ;; org-feed.el is based on ideas by Brad Bozarth who implemented a
  88. ;; similar mechanism using shell and awk scripts.
  89. ;;; Code:
  90. (require 'org)
  91. (require 'sha1)
  92. (declare-function url-retrieve-synchronously "url" (url))
  93. (defgroup org-feed nil
  94. "Options concerning RSS feeds as inputs for Org files."
  95. :tag "Org ID"
  96. :group 'org)
  97. ;;;###autoload
  98. (defcustom org-feed-alist nil
  99. "Alist specifying RSS feeds that should create inputs for Org.
  100. Each entry in this list specified an RSS feed tat should be queried
  101. to create inbox items in Org. Each entry is a list with the following items:
  102. name a custom name for this feed
  103. URL the Feed URL
  104. file the target Org file where entries should be listed
  105. headline the headline under which entries should be listed
  106. Additional arguments can be given using keyword-value pairs. Many of these
  107. specify functions that receive one or a list of \"entries\" as their single
  108. argument. An entry is a property list that describes a feed item. The
  109. property list has properties for each field in the item, for example `:title'
  110. for the `<title>' field and `:pubDate' for the publication date. In addition,
  111. it contains the following properties:
  112. `:item-full-text' the full text in the <item> tag
  113. `:guid-permalink' t when the guid property is a permalink
  114. Here are the keyword-value pair allows in `org-feed-alist'.
  115. :drawer drawer-name
  116. The name of the drawer for storing feed information. The default is
  117. \"FEEDSTATUS\". Using different drawers for different feeds allows
  118. several feeds to target the same inbox heading.
  119. :filter filter-function
  120. A function to select interesting entries in the feed. It gets a single
  121. entry as parameter. It should return the entry if it is relevant, or
  122. nil if it is not.
  123. :template template-string
  124. The default action on new items in the feed is to add them as children
  125. under the headline for the feed. The template describes how the entry
  126. should be formatted. If not given, it defaults to
  127. `org-feed-default-template'.
  128. :formatter formatter-function
  129. Instead of relying on a template, you may specify a function to format
  130. the outline node to be inserted as a child. This function gets passed
  131. a property list describing a single feed item, and it should return a
  132. string that is a properly formatted Org outline node of level 1.
  133. :new-handler function
  134. If adding new items as children to the outline is not what you want
  135. to do with new items, define a handler function that is called with
  136. a list of all new items in the feed, each one represented as a property
  137. list. The handler should do what needs to be done, and org-feed will
  138. mark all items given to this handler as \"handled\", i.e. they will not
  139. be passed to this handler again in future readings of the feed.
  140. When the handler is called, point will be at the feed headline.
  141. :changed-handler function
  142. This function gets passed a list of all entries that have been
  143. handled before, but are now still in the feed and have *changed*
  144. since last handled (as evidenced by a different sha1 hash).
  145. When the handler is called, point will be at the feed headline."
  146. :group 'org-feed
  147. :type '(repeat
  148. (list :value ("" "http://" "" "")
  149. (string :tag "Name")
  150. (string :tag "Feed URL")
  151. (file :tag "File for inbox")
  152. (string :tag "Headline for inbox")
  153. (repeat :inline t
  154. (choice
  155. (list :inline t :tag "Filter"
  156. (const :filter)
  157. (symbol :tag "Filter Function"))
  158. (list :inline t :tag "Template"
  159. (const :template)
  160. (string :tag "Template"))
  161. (list :inline t :tag "Formatter"
  162. (const :formatter)
  163. (symbol :tag "Formatter Function"))
  164. (list :inline t :tag "New items handler"
  165. (const :new-handler)
  166. (symbol :tag "Handler Function"))
  167. (list :inline t :tag "Changed items"
  168. (const :changed-handler)
  169. (symbol :tag "Handler Function"))
  170. )))))
  171. (defcustom org-feed-drawer "FEEDSTATUS"
  172. "The name of the drawer for feed status information.
  173. Each feed may also specify its own drawer name using the `:drawer'
  174. parameter in `org-feed-alist'.
  175. Note that in order to make these drawers behave like drawers, they must
  176. be added to the variable `org-drawers' or configured with a #+DRAWERS
  177. line."
  178. :group 'org-feed
  179. :type '(string :tag "Drawer Name"))
  180. (defcustom org-feed-default-template "\n* %h\n %U\n %description\n %a\n"
  181. "Template for the Org node created from RSS feed items.
  182. This is just the default, each feed can specify its own.
  183. Any fields from the feed item can be interpolated into the template with
  184. %name, for example %title, %description, %pubDate etc. In addition, the
  185. following special escapes are valid as well:
  186. %h the title, or the first line of the description
  187. %t the date as a stamp, either from <pubDate> (if present), or
  188. the current date.
  189. %T date and time
  190. %u,%U like %t,%T, but inactive time stamps
  191. %a A link, from <guid> if that is a permalink, else from <link>"
  192. :group 'org-feed
  193. :type '(string :tag "Template"))
  194. (defcustom org-feed-save-after-adding t
  195. "Non-nil means, save buffer after adding new feed items."
  196. :group 'org-feed
  197. :type 'boolean)
  198. (defcustom org-feed-retrieve-method 'url-retrieve-synchronously
  199. "The method to be used to retrieve a feed URL.
  200. This can be `curl' or `wget' to call these external programs, or it can be
  201. an Emacs Lisp function that will return a buffer containing the content
  202. of the file pointed to by the URL."
  203. :group 'org-feed
  204. :type '(choice
  205. (const :tag "Internally with url.el" url-retrieve-synchronously)
  206. (const :tag "Externally with curl" curl)
  207. (const :tag "Externally with wget" wget)
  208. (function :tag "Function")))
  209. (defcustom org-feed-before-adding-hook nil
  210. "Hook that is run before adding new feed items to a file.
  211. You might want to commit the file in its current state to version control,
  212. for example."
  213. :group 'org-feed
  214. :type 'hook)
  215. (defcustom org-feed-after-adding-hook nil
  216. "Hook that is run after new items have been added to a file.
  217. Depending on `org-feed-save-after-adding', the buffer will already
  218. have been saved."
  219. :group 'org-feed
  220. :type 'hook)
  221. (defvar org-feed-buffer "*Org feed*"
  222. "The buffer used to retrieve a feed.")
  223. ;;;###autoload
  224. (defun org-feed-update-all ()
  225. "Get inbox items from all feeds in `org-feed-alist'."
  226. (interactive)
  227. (let ((nfeeds (length org-feed-alist))
  228. (nnew (apply '+ (mapcar 'org-feed-update org-feed-alist))))
  229. (message "%s from %d %s"
  230. (cond ((= nnew 0) "No new entries")
  231. ((= nnew 1) "1 new entry")
  232. (t (format "%d new entries" nnew)))
  233. nfeeds
  234. (if (= nfeeds 1) "feed" "feeds"))))
  235. ;;;###autoload
  236. (defun org-feed-update (feed &optional retrieve-only)
  237. "Get inbox items from FEED.
  238. FEED can be a string with an association in `org-feed-alist', or
  239. it can be a list structured like an entry in `org-feed-alist'."
  240. (interactive (list (org-completing-read "Feed name: " org-feed-alist)))
  241. (if (stringp feed) (setq feed (assoc feed org-feed-alist)))
  242. (unless feed
  243. (error "No such feed in `org-feed-alist"))
  244. (catch 'exit
  245. (let ((name (car feed))
  246. (url (nth 1 feed))
  247. (file (nth 2 feed))
  248. (headline (nth 3 feed))
  249. (filter (nth 1 (memq :filter feed)))
  250. (formatter (nth 1 (memq :formatter feed)))
  251. (new-handler (nth 1 (memq :new-handler feed)))
  252. (changed-handler (nth 1 (memq :changed-handler feed)))
  253. (template (or (nth 1 (memq :template feed))
  254. org-feed-default-template))
  255. (drawer (or (nth 1 (memq :drawer feed))
  256. org-feed-drawer))
  257. feed-buffer inbox-pos new-formatted
  258. entries old-status status new changed guid-alist e guid olds)
  259. (setq feed-buffer (org-feed-get-feed url))
  260. (unless (and feed-buffer (bufferp feed-buffer))
  261. (error "Cannot get feed %s" name))
  262. (when retrieve-only
  263. (throw 'exit feed-buffer))
  264. (setq entries (org-feed-parse-feed feed-buffer))
  265. (ignore-errors (kill-buffer feed-buffer))
  266. (save-excursion
  267. (save-window-excursion
  268. (setq inbox-pos (org-feed-goto-inbox-internal file headline))
  269. (setq old-status (org-feed-read-previous-status inbox-pos drawer))
  270. ;; Add the "handled" status to the appropriate entries
  271. (setq entries (mapcar (lambda (e)
  272. (setq e (plist-put e :handled
  273. (nth 1 (assoc
  274. (plist-get e :guid)
  275. old-status)))))
  276. entries))
  277. ;; Find out which entries are new and which are changed
  278. (dolist (e entries)
  279. (if (not (plist-get e :handled))
  280. (push e new)
  281. (setq olds (nth 2 (assoc (plist-get e :guid) old-status)))
  282. (if (and olds
  283. (not (string= (org-sha1-string
  284. (plist-get e :item-full-text))
  285. olds)))
  286. (push e changed))))
  287. ;; Parse the relevant entries fully
  288. (setq new (mapcar 'org-feed-parse-entry new)
  289. changed (mapcar 'org-feed-parse-entry changed))
  290. ;; Run the filter
  291. (when filter
  292. (setq new (delq nil (mapcar filter new))
  293. changed (delq nil (mapcar filter new))))
  294. (when (not (or new changed))
  295. (message "No new items in feed %s" name)
  296. (throw 'exit 0))
  297. ;; Get alist based on guid, to look up entries
  298. (setq guid-alist
  299. (append
  300. (mapcar (lambda (e) (list (plist-get e :guid) e)) new)
  301. (mapcar (lambda (e) (list (plist-get e :guid) e)) changed)))
  302. ;; Construct the new status
  303. (setq status
  304. (mapcar
  305. (lambda (e)
  306. (setq guid (plist-get e :guid))
  307. (list guid
  308. ;; things count as handled if we handle them now,
  309. ;; or if they were handled previously
  310. (if (assoc guid guid-alist) t (plist-get e :handled))
  311. ;; A hash, to detect changes
  312. (org-sha1-string (plist-get e :item-full-text))))
  313. entries))
  314. ;; Handle new items in the feed
  315. (when new
  316. (if new-handler
  317. (progn
  318. (goto-char inbox-pos)
  319. (funcall new-handler new))
  320. ;; No custom handler, do the default adding
  321. ;; Format the new entries into an alist with GUIDs in the car
  322. (setq new-formatted
  323. (mapcar
  324. (lambda (e) (org-feed-format-entry e template formatter))
  325. new)))
  326. ;; Insert the new items
  327. (org-feed-add-items inbox-pos new-formatted))
  328. ;; Handle changed items in the feed
  329. (when (and changed-handler changed)
  330. (goto-char inbox-pos)
  331. (funcall changed-handler changed))
  332. ;; Write the new status
  333. ;; We do this only now, in case something goes wrong above, so
  334. ;; that would would end up with a status that does not reflect
  335. ;; which items truely have been handled
  336. (org-feed-write-status inbox-pos drawer status)
  337. ;; Normalize the visibility of the inbox tree
  338. (goto-char inbox-pos)
  339. (hide-subtree)
  340. (show-children)
  341. (org-cycle-hide-drawers 'children)
  342. ;; Hooks and messages
  343. (when org-feed-save-after-adding (save-buffer))
  344. (message "Added %d new item%s from feed %s to file %s, heading %s"
  345. (length new) (if (> (length new) 1) "s" "")
  346. name
  347. (file-name-nondirectory file) headline)
  348. (run-hooks 'org-feed-after-adding-hook)
  349. (length new))))))
  350. ;;;###autoload
  351. (defun org-feed-goto-inbox (feed)
  352. "Go to the inbox that captures the feed named FEED."
  353. (interactive
  354. (list (if (= (length org-feed-alist) 1)
  355. (car org-feed-alist)
  356. (org-completing-read "Feed name: " org-feed-alist))))
  357. (if (stringp feed) (setq feed (assoc feed org-feed-alist)))
  358. (unless feed
  359. (error "No such feed in `org-feed-alist"))
  360. (org-feed-goto-inbox-internal (nth 2 feed) (nth 3 feed)))
  361. ;;;###autoload
  362. (defun org-feed-show-raw-feed (feed)
  363. "Show the raw feed buffer of a feed."
  364. (interactive
  365. (list (if (= (length org-feed-alist) 1)
  366. (car org-feed-alist)
  367. (org-completing-read "Feed name: " org-feed-alist))))
  368. (if (stringp feed) (setq feed (assoc feed org-feed-alist)))
  369. (unless feed
  370. (error "No such feed in `org-feed-alist"))
  371. (switch-to-buffer
  372. (org-feed-update feed 'retrieve-only))
  373. (goto-char (point-min)))
  374. (defun org-feed-goto-inbox-internal (file heading)
  375. "Find or create HEADING in FILE.
  376. Switch to that buffer, and return the position of that headline."
  377. (find-file file)
  378. (widen)
  379. (goto-char (point-min))
  380. (if (re-search-forward
  381. (concat "^\\*+[ \t]+" heading "[ \t]*\\(:.*?:[ \t]*\\)?$")
  382. nil t)
  383. (goto-char (match-beginning 0))
  384. (goto-char (point-max))
  385. (insert "\n\n* " heading "\n\n")
  386. (org-back-to-heading t))
  387. (point))
  388. (defun org-feed-read-previous-status (pos drawer)
  389. "Get the alist of old GUIDs from the entry at POS.
  390. This will find DRAWER and extract the alist."
  391. (save-excursion
  392. (goto-char pos)
  393. (let ((end (save-excursion (org-end-of-subtree t t))))
  394. (if (re-search-forward
  395. (concat "^[ \t]*:" drawer ":[ \t]*\n\\([^\000]*?\\)\n[ \t]*:END:")
  396. end t)
  397. (read (match-string 1))
  398. nil))))
  399. (defun org-feed-write-status (pos drawer status)
  400. "Write the feed STATUS to DRAWER in entry at POS."
  401. (save-excursion
  402. (goto-char pos)
  403. (let ((end (save-excursion (org-end-of-subtree t t)))
  404. guid)
  405. (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*\n")
  406. end t)
  407. (progn
  408. (goto-char (match-end 0))
  409. (delete-region (point)
  410. (save-excursion
  411. (and (re-search-forward "^[ \t]*:END:" nil t)
  412. (match-beginning 0)))))
  413. (outline-next-heading)
  414. (insert " :" drawer ":\n :END:\n")
  415. (beginning-of-line 0))
  416. (insert (pp-to-string status)))))
  417. (defun org-feed-add-items (pos entries)
  418. "Add the formatted items to the headline as POS."
  419. (let (entry level)
  420. (save-excursion
  421. (goto-char pos)
  422. (unless (looking-at org-complex-heading-regexp)
  423. (error "Wrong position"))
  424. (setq level (org-get-valid-level (length (match-string 1)) 1))
  425. (org-end-of-subtree t t)
  426. (skip-chars-backward " \t\n")
  427. (beginning-of-line 2)
  428. (setq pos (point))
  429. (while (setq entry (pop entries))
  430. (org-paste-subtree level entry 'yank))
  431. (org-mark-ring-push pos))))
  432. (defun org-feed-format-entry (entry template formatter)
  433. "Format ENTRY so that it can be inserted into an Org file.
  434. ENTRY is a property list. This function adds a `:formatted-for-org' property
  435. and returns the full property list.
  436. If that property is already present, nothing changes."
  437. (if formatter
  438. (funcall formatter entry)
  439. (let (dlines fmt tmp indent time
  440. v-h v-t v-T v-u v-U v-a)
  441. (setq dlines (org-split-string (or (plist-get entry :description) "???")
  442. "\n")
  443. v-h (or (plist-get entry :title) (car dlines) "???")
  444. time (or (if (plist-get entry :pubDate)
  445. (org-read-date t t (plist-get entry :pubDate)))
  446. (current-time))
  447. v-t (format-time-string (org-time-stamp-format nil nil) time)
  448. v-T (format-time-string (org-time-stamp-format t nil) time)
  449. v-u (format-time-string (org-time-stamp-format nil t) time)
  450. v-U (format-time-string (org-time-stamp-format t t) time)
  451. v-a (if (setq tmp (or (and (plist-get entry :guid-permalink)
  452. (plist-get entry :guid))
  453. (plist-get entry :link)))
  454. (concat "[[" tmp "]]\n")
  455. ""))
  456. (with-temp-buffer
  457. (insert template)
  458. (goto-char (point-min))
  459. (while (re-search-forward "%\\([a-zA-Z]+\\)" nil t)
  460. (setq name (match-string 1))
  461. (cond
  462. ((member name '("h" "t" "T" "u" "U" "a"))
  463. (replace-match (symbol-value (intern (concat "v-" name))) t t))
  464. ((setq tmp (plist-get entry (intern (concat ":" name))))
  465. (save-excursion
  466. (save-match-data
  467. (beginning-of-line 1)
  468. (when (looking-at (concat "^\\([ \t]*\\)%" name "[ \t]*$"))
  469. (setq tmp (org-feed-make-indented-block
  470. tmp (org-get-indentation))))))
  471. (replace-match tmp t t))))
  472. (buffer-string)))))
  473. (defun org-feed-make-indented-block (s n)
  474. "Add indentaton of N spaces to a multiline string S."
  475. (if (not (string-match "\n" s))
  476. s
  477. (mapconcat 'identity
  478. (org-split-string s "\n")
  479. (concat "\n" (make-string n ?\ )))))
  480. (defun org-feed-get-feed (url)
  481. "Get the RSS feed file at URL and return the buffer."
  482. (cond
  483. ((eq org-feed-retrieve-method 'url-retrieve-synchronously)
  484. (url-retrieve-synchronously url))
  485. ((eq org-feed-retrieve-method 'curl)
  486. (ignore-errors (kill-buffer org-feed-buffer))
  487. (call-process "curl" nil org-feed-buffer nil url)
  488. org-feed-buffer)
  489. ((eq org-feed-retrieve-method 'wget)
  490. (ignore-errors (kill-buffer org-feed-buffer))
  491. (call-process "curl" nil org-feed-buffer nil "-q" "-O" "-" url)
  492. org-feed-buffer)
  493. ((functionp org-feed-retrieve-method)
  494. (funcall org-feed-retrieve-method url))))
  495. (defun org-feed-parse-feed (buffer)
  496. "Parse BUFFER for RS feed entries.
  497. Returns a list of entries, with each entry a property list,
  498. containing the properties `:guid' and `:item-full-text'."
  499. (let (entries beg end item guid entry)
  500. (with-current-buffer buffer
  501. (widen)
  502. (goto-char (point-min))
  503. (while (re-search-forward "<item>" nil t)
  504. (setq beg (point)
  505. end (and (re-search-forward "</item>" nil t)
  506. (match-beginning 0)))
  507. (setq item (buffer-substring beg end)
  508. guid (if (string-match "<guid\\>.*?>\\(.*?\\)</guid>" item)
  509. (org-match-string-no-properties 1 item)))
  510. (setq entry (list :guid guid :item-full-text item))
  511. (push entry entries)
  512. (widen)
  513. (goto-char end))
  514. (nreverse entries))))
  515. (defun org-feed-parse-entry (entry)
  516. "Parse the `:item-full-text' field for xml tags and create new properties."
  517. (with-temp-buffer
  518. (insert (plist-get entry :item-full-text))
  519. (goto-char (point-min))
  520. (while (re-search-forward "<\\([a-zA-Z]+\\>\\).*?>\\([^\000]*?\\)</\\1>"
  521. nil t)
  522. (setq entry (plist-put entry
  523. (intern (concat ":" (match-string 1)))
  524. (match-string 2))))
  525. (goto-char (point-min))
  526. (unless (re-search-forward "isPermaLink[ \t]*=[ \t]*\"false\"" nil t)
  527. (setq entry (plist-put entry :guid-permalink t))))
  528. entry)
  529. (provide 'org-feed)
  530. ;; arch-tag: 0929b557-9bc4-47f4-9633-30a12dbb5ae2
  531. ;;; org-feed.el ends here