org-feed: Fix `org-feed-format-entry'

* lisp/org-feed.el (org-feed-format-entry): Fix function according to
  recent changes to Org Capture library.  Small refactoring.

Reported-by: Michael Brand <michael.ch.brand@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/103941>
This commit is contained in:
Nicolas Goaziou 2016-01-07 17:23:33 +01:00
parent aa52550e4b
commit 1124b2fc2a
1 changed files with 55 additions and 51 deletions

View File

@ -1,6 +1,6 @@
;;; org-feed.el --- Add RSS feed items to Org files ;;; org-feed.el --- Add RSS feed items to Org files
;; ;;
;; Copyright (C) 2009-2015 Free Software Foundation, Inc. ;; Copyright (C) 2009-2016 Free Software Foundation, Inc.
;; ;;
;; Author: Carsten Dominik <carsten at orgmode dot org> ;; Author: Carsten Dominik <carsten at orgmode dot org>
;; Keywords: outlines, hypermedia, calendar, wp ;; Keywords: outlines, hypermedia, calendar, wp
@ -513,52 +513,56 @@ ENTRY is a property list. This function adds a `:formatted-for-org' property
and returns the full property list. and returns the full property list.
If that property is already present, nothing changes." If that property is already present, nothing changes."
(require 'org-capture) (require 'org-capture)
(if formatter (if formatter (funcall formatter entry)
(funcall formatter entry) (let* ((dlines
(let (dlines time escape name tmp (org-split-string (or (plist-get entry :description) "???")
v-h v-t v-T v-u v-U v-a) "\n"))
(setq dlines (org-split-string (or (plist-get entry :description) "???") (time (or (if (plist-get entry :pubDate)
"\n")
v-h (or (plist-get entry :title) (car dlines) "???")
time (or (if (plist-get entry :pubDate)
(org-read-date t t (plist-get entry :pubDate))) (org-read-date t t (plist-get entry :pubDate)))
(current-time)) (current-time)))
v-t (format-time-string (org-time-stamp-format nil nil) time) (v-h (or (plist-get entry :title) (car dlines) "???"))
v-T (format-time-string (org-time-stamp-format t nil) time) (v-t (format-time-string (org-time-stamp-format nil nil) time))
v-u (format-time-string (org-time-stamp-format nil t) time) (v-T (format-time-string (org-time-stamp-format t nil) time))
v-U (format-time-string (org-time-stamp-format t t) time) (v-u (format-time-string (org-time-stamp-format nil t) time))
v-a (if (setq tmp (or (and (plist-get entry :guid-permalink) (v-U (format-time-string (org-time-stamp-format t t) time))
(v-a (let ((tmp (or (and (plist-get entry :guid-permalink)
(plist-get entry :guid)) (plist-get entry :guid))
(plist-get entry :link))) (plist-get entry :link))))
(concat "[[" tmp "]]\n") (if tmp (format "[[%s]]\n" tmp ) ""))))
""))
(with-temp-buffer (with-temp-buffer
(insert template) (insert template)
(goto-char (point-min))
;; Mark %() embedded elisp for later evaluation.
(org-capture-expand-embedded-elisp 'mark)
;; Simple %-escapes ;; Simple %-escapes
;; before embedded elisp to support simple %-escapes as
;; arguments for embedded elisp
(goto-char (point-min))
(while (re-search-forward "%\\([a-zA-Z]+\\)" nil t) (while (re-search-forward "%\\([a-zA-Z]+\\)" nil t)
(unless (org-capture-escaped-%) (unless (org-capture-escaped-%)
(setq name (match-string 1) (let ((replacement
escape (org-capture-inside-embedded-elisp-p)) (pcase (match-string-no-properties 1)
(cond ("h" v-h)
((member name '("h" "t" "T" "u" "U" "a")) ("t" v-t)
(setq tmp (symbol-value (intern (concat "v-" name))))) ("T" v-T)
((setq tmp (plist-get entry (intern (concat ":" name)))) ("u" v-u)
("U" v-U)
("a" v-a)
(name
(let ((v (plist-get entry (intern (concat ":" name)))))
(save-excursion (save-excursion
(save-match-data (save-match-data
(beginning-of-line 1) (beginning-of-line)
(when (looking-at (if (looking-at
(concat "^\\([ \t]*\\)%" name "[ \t]*$")) (concat "^\\([ \t]*\\)%" name "[ \t]*$"))
(setq tmp (org-feed-make-indented-block (org-feed-make-indented-block
tmp (org-get-indentation)))))))) v (org-get-indentation))
(when tmp v))))))))
;; escape string delimiters `"' when inside %() embedded lisp (when replacement
(when escape (replace-match
(setq tmp (replace-regexp-in-string "\"" "\\\\\"" tmp))) ;; Escape string delimiters within embedded lisp.
(replace-match tmp t t)))) (if (org-capture-inside-embedded-elisp-p)
(replace-regexp-in-string "\"" "\\\\\"" replacement nil t)
replacement))))))
;; %() embedded elisp ;; %() embedded elisp
(org-capture-expand-embedded-elisp) (org-capture-expand-embedded-elisp)