forked from mirrors/org-mode
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:
parent
aa52550e4b
commit
1124b2fc2a
106
lisp/org-feed.el
106
lisp/org-feed.el
|
@ -1,6 +1,6 @@
|
|||
;;; 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>
|
||||
;; Keywords: outlines, hypermedia, calendar, wp
|
||||
|
@ -513,66 +513,70 @@ ENTRY is a property list. This function adds a `:formatted-for-org' property
|
|||
and returns the full property list.
|
||||
If that property is already present, nothing changes."
|
||||
(require 'org-capture)
|
||||
(if formatter
|
||||
(funcall formatter entry)
|
||||
(let (dlines time escape name tmp
|
||||
v-h v-t v-T v-u v-U v-a)
|
||||
(setq dlines (org-split-string (or (plist-get entry :description) "???")
|
||||
"\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)))
|
||||
(current-time))
|
||||
v-t (format-time-string (org-time-stamp-format nil nil) time)
|
||||
v-T (format-time-string (org-time-stamp-format t nil) time)
|
||||
v-u (format-time-string (org-time-stamp-format nil t) time)
|
||||
v-U (format-time-string (org-time-stamp-format t t) time)
|
||||
v-a (if (setq tmp (or (and (plist-get entry :guid-permalink)
|
||||
(plist-get entry :guid))
|
||||
(plist-get entry :link)))
|
||||
(concat "[[" tmp "]]\n")
|
||||
""))
|
||||
(if formatter (funcall formatter entry)
|
||||
(let* ((dlines
|
||||
(org-split-string (or (plist-get entry :description) "???")
|
||||
"\n"))
|
||||
(time (or (if (plist-get entry :pubDate)
|
||||
(org-read-date t t (plist-get entry :pubDate)))
|
||||
(current-time)))
|
||||
(v-h (or (plist-get entry :title) (car dlines) "???"))
|
||||
(v-t (format-time-string (org-time-stamp-format nil nil) time))
|
||||
(v-T (format-time-string (org-time-stamp-format t nil) time))
|
||||
(v-u (format-time-string (org-time-stamp-format nil t) time))
|
||||
(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 :link))))
|
||||
(if tmp (format "[[%s]]\n" tmp ) ""))))
|
||||
(with-temp-buffer
|
||||
(insert template)
|
||||
(insert template)
|
||||
(goto-char (point-min))
|
||||
|
||||
;; 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)
|
||||
(unless (org-capture-escaped-%)
|
||||
(setq name (match-string 1)
|
||||
escape (org-capture-inside-embedded-elisp-p))
|
||||
(cond
|
||||
((member name '("h" "t" "T" "u" "U" "a"))
|
||||
(setq tmp (symbol-value (intern (concat "v-" name)))))
|
||||
((setq tmp (plist-get entry (intern (concat ":" name))))
|
||||
(save-excursion
|
||||
(save-match-data
|
||||
(beginning-of-line 1)
|
||||
(when (looking-at
|
||||
(concat "^\\([ \t]*\\)%" name "[ \t]*$"))
|
||||
(setq tmp (org-feed-make-indented-block
|
||||
tmp (org-get-indentation))))))))
|
||||
(when tmp
|
||||
;; escape string delimiters `"' when inside %() embedded lisp
|
||||
(when escape
|
||||
(setq tmp (replace-regexp-in-string "\"" "\\\\\"" tmp)))
|
||||
(replace-match tmp t t))))
|
||||
;; Mark %() embedded elisp for later evaluation.
|
||||
(org-capture-expand-embedded-elisp 'mark)
|
||||
|
||||
;; %() embedded elisp
|
||||
(org-capture-expand-embedded-elisp)
|
||||
;; Simple %-escapes
|
||||
(while (re-search-forward "%\\([a-zA-Z]+\\)" nil t)
|
||||
(unless (org-capture-escaped-%)
|
||||
(let ((replacement
|
||||
(pcase (match-string-no-properties 1)
|
||||
("h" v-h)
|
||||
("t" v-t)
|
||||
("T" v-T)
|
||||
("u" v-u)
|
||||
("U" v-U)
|
||||
("a" v-a)
|
||||
(name
|
||||
(let ((v (plist-get entry (intern (concat ":" name)))))
|
||||
(save-excursion
|
||||
(save-match-data
|
||||
(beginning-of-line)
|
||||
(if (looking-at
|
||||
(concat "^\\([ \t]*\\)%" name "[ \t]*$"))
|
||||
(org-feed-make-indented-block
|
||||
v (org-get-indentation))
|
||||
v))))))))
|
||||
(when replacement
|
||||
(replace-match
|
||||
;; Escape string delimiters within embedded lisp.
|
||||
(if (org-capture-inside-embedded-elisp-p)
|
||||
(replace-regexp-in-string "\"" "\\\\\"" replacement nil t)
|
||||
replacement))))))
|
||||
|
||||
(decode-coding-string
|
||||
(buffer-string) (detect-coding-region (point-min) (point-max) t))))))
|
||||
;; %() embedded elisp
|
||||
(org-capture-expand-embedded-elisp)
|
||||
|
||||
(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."
|
||||
(if (not (string-match "\n" s))
|
||||
s
|
||||
(mapconcat 'identity
|
||||
(org-split-string s "\n")
|
||||
(concat "\n" (make-string n ?\ )))))
|
||||
(org-split-string s "\n")
|
||||
(concat "\n" (make-string n ?\ )))))
|
||||
|
||||
(defun org-feed-skip-http-headers (buffer)
|
||||
"Remove HTTP headers from BUFFER, and return it.
|
||||
|
|
Loading…
Reference in New Issue