Function: org-feed-format-entry

org-feed-format-entry is a byte-compiled function defined in org-feed.el.gz.

Signature

(org-feed-format-entry ENTRY TEMPLATE FORMATTER)

Documentation

Format ENTRY so that it can be inserted into an Org file.

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.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-feed.el.gz
(defun org-feed-format-entry (entry template formatter)
  "Format ENTRY so that it can be inserted into an Org file.
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
            (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)
        (goto-char (point-min))

        ;; Mark %() embedded elisp for later evaluation.
        (org-capture-expand-embedded-elisp 'mark)

        ;; Simple %-escapes.  `org-capture-escaped-%' may modify
	;; buffer and cripple match-data.  Use markers instead.
        (while (re-search-forward "%\\([a-zA-Z]+\\)" nil t)
          (let ((key (match-string 1))
		(beg (copy-marker (match-beginning 0)))
		(end (copy-marker (match-end 0))))
	    (unless (org-capture-escaped-%)
	      (delete-region beg end)
	      (set-marker beg nil)
	      (set-marker end nil)
	      (let ((replacement
		     (pcase key
		       ("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 (current-indentation))
				v))))))))
		(when replacement
		  (insert
		   ;; Escape string delimiters within embedded lisp.
		   (if (org-capture-inside-embedded-elisp-p)
		       (replace-regexp-in-string "\"" "\\\\\"" replacement)
		     replacement)))))))

        ;; %() embedded elisp
        (org-capture-expand-embedded-elisp)

        (decode-coding-string
         (buffer-string) (detect-coding-region (point-min) (point-max) t))))))