X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/99a33b77e15b9a075024701d060d912b2fd87caf..e68fe57c52a815a4289380a8bdd3eaa1b7e6dc88:/lisp/net/newst-reader.el diff --git a/lisp/net/newst-reader.el b/lisp/net/newst-reader.el index 1fbba29ec1..9c29216cca 100644 --- a/lisp/net/newst-reader.el +++ b/lisp/net/newst-reader.el @@ -1,11 +1,10 @@ ;;; newst-reader.el --- Generic RSS reader functions. -;; Copyright (C) 2003-2011 Free Software Foundation, Inc. +;; Copyright (C) 2003-2016 Free Software Foundation, Inc. ;; Author: Ulf Jasper ;; Filename: newst-reader.el ;; URL: http://www.nongnu.org/newsticker -;; Time-stamp: "13. Mai 2011, 20:55:24 (ulf)" ;; Package: newsticker ;; ====================================================================== @@ -67,6 +66,13 @@ This must be one of the functions `newsticker-plainview' or :group 'newsticker-reader) ;; image related things +(defcustom newsticker-download-logos + t + "If non-nil newsticker downloads logo images of subscribed feeds." + :version "25.1" + :type 'boolean + :group 'newsticker-reader) + (defcustom newsticker-enable-logo-manipulations t "If non-nil newsticker manipulates logo images. @@ -101,32 +107,18 @@ window is used when filling. See also `newsticker-justification'." :group 'newsticker-reader) (defcustom newsticker-html-renderer - nil + (if (fboundp 'libxml-parse-html-region) + #'shr-render-region) "Function for rendering HTML contents. -If non-nil, newsticker.el will call this function whenever it finds -HTML-like tags in item descriptions. Possible functions are, for -example, `w3m-region', `w3-region', and (if you have htmlr.el installed) +If non-nil, newsticker.el will call this function whenever it +finds HTML-like tags in item descriptions. +Possible functions include `shr-render-region', `w3m-region', `w3-region', and `newsticker-htmlr-render'. - -In order to make sure that the HTML renderer is loaded when you -run newsticker, you should add one of the following statements to -your .emacs. If you use w3m, - - (autoload 'w3m-region \"w3m\" - \"Render region in current buffer and replace with result.\" t) - - (autoload 'w3m-toggle-inline-image \"w3m\" - \"Toggle the visibility of an image under point.\" t) - -or, if you use w3, - - (require 'w3-auto) - -or, if you use htmlr - - (require 'htmlr)" +Newsticker automatically loads the respective package w3m, w3, or +htmlr if this option is set." :type '(choice :tag "Function" (const :tag "None" nil) + (const :tag "SHR" shr-render-region) (const :tag "w3" w3-region) (const :tag "w3m" w3m-region) (const :tag "htmlr" newsticker-htmlr-render)) @@ -146,26 +138,23 @@ See `format-time-string' for a list of valid specifiers." :group 'newsticker-reader) (defface newsticker-feed-face - '((((class color) (background dark)) - (:family "sans" :bold t :height 1.2 :foreground "white")) - (((class color) (background light)) - (:family "sans" :bold t :height 1.2 :foreground "black"))) + '((default :weight bold :height 1.2) + (((class color) (background dark)) :foreground "white") + (((class color) (background light)) :foreground "black")) "Face for news feeds." :group 'newsticker-faces) (defface newsticker-extra-face - '((((class color) (background dark)) - (:italic t :foreground "gray50" :height 0.8)) - (((class color) (background light)) - (:italic t :foreground "gray50" :height 0.8))) + '((default :slant italic :height 0.8) + (((class color) (background dark)) :foreground "gray50") + (((class color) (background light)) :foreground "gray50")) "Face for newsticker dates." :group 'newsticker-faces) (defface newsticker-enclosure-face - '((((class color) (background dark)) - (:bold t :background "orange")) - (((class color) (background light)) - (:bold t :background "orange"))) + '((default :weight bold) + (((class color) (background dark)) :background "orange") + (((class color) (background light)) :background "orange")) "Face for enclosed elements." :group 'newsticker-faces) @@ -203,15 +192,18 @@ KEYMAP will be applied." 'nt-type 'desc)) (insert "\n"))))) -(defun newsticker--print-extra-elements (item keymap) +(defun newsticker--print-extra-elements (item keymap &optional htmlish) "Insert extra-elements of ITEM in a pretty form into the current buffer. -KEYMAP is applied." +KEYMAP is applied. If HTMLISH is non-nil then HTML-markup is used +for formatting." (let ((ignored-elements '(items link title description content - content:encoded dc:subject - dc:date entry item guid pubDate + content:encoded encoded + dc:subject subject + dc:date date entry item guid pubDate published updated enclosure)) (left-column-width 1)) + (if htmlish (insert "")))) -(defun newsticker--do-print-extra-element (extra-element width keymap) +(defun newsticker--do-print-extra-element (extra-element width keymap htmlish) "Actually print an EXTRA-ELEMENT using the given WIDTH. -KEYMAP is applied." +KEYMAP is applied. If HTMLISH is non-nil then HTML-markup is used +for formatting." (let ((name (symbol-name (car extra-element)))) - (insert (format "%s: " name)) - (insert (make-string (- width (length name)) ? ))) + (if htmlish + (insert (format "
  • %s: " name)) + (insert (format "%s: " name)) + (insert (make-string (- width (length name)) ? )))) (let (;;(attributes (cadr extra-element)) ;FIXME!!!! (contents (cddr extra-element))) (cond ((listp contents) @@ -255,30 +252,58 @@ KEYMAP is applied." contents)) (t (insert (format "%s" contents)))) - (insert "\n"))) + (if htmlish + (insert "
  • ") + (insert "\n")))) -(defun newsticker--image-read (feed-name-symbol disabled) +(defun newsticker--image-read (feed-name-symbol disabled &optional max-height) "Read the cached image for FEED-NAME-SYMBOL from disk. If DISABLED is non-nil the image will be converted to a disabled look -\(unless `newsticker-enable-logo-manipulations' is not t\). +\(unless `newsticker-enable-logo-manipulations' is not t). +Optional argument MAX-HEIGHT specifies the maximal image height. Return the image." (let ((image-name (concat (newsticker--images-dir) - (symbol-name feed-name-symbol))) - (img nil)) + (symbol-name feed-name-symbol)))) (when (file-exists-p image-name) (condition-case error-data - (setq img (create-image - image-name nil nil - :conversion (and newsticker-enable-logo-manipulations - disabled - 'disabled) - :mask (and newsticker-enable-logo-manipulations - 'heuristic) - :ascent 70)) + (create-image + image-name + (and (fboundp 'imagemagick-types) + (imagemagick-types) + 'imagemagick) + nil + :conversion (and newsticker-enable-logo-manipulations + disabled + 'disabled) + :mask (and newsticker-enable-logo-manipulations + 'heuristic) + :ascent 100 + :max-height max-height) (error (message "Error: cannot create image for %s: %s" - feed-name-symbol error-data)))) - img)) + feed-name-symbol error-data)))))) + +(defun newsticker--icon-read (feed-name-symbol) + "Read the cached icon for FEED-NAME-SYMBOL from disk. +Return the image." + (catch 'icon + (when (file-exists-p (newsticker--icons-dir)) + (dolist (file (directory-files (newsticker--icons-dir) t + (concat (symbol-name feed-name-symbol) "\\..*"))) + (condition-case error-data + (throw 'icon (create-image + file (and (fboundp 'imagemagick-types) + (imagemagick-types) + 'imagemagick) + nil + :ascent 'center + :max-width 16 + :max-height 16)) + (error + (message "Error: cannot create icon for %s: %s" + feed-name-symbol error-data))))) + ;; Fallback: default icon. + (find-image '((:type png :file "newsticker/rss-feed.png" :ascent center))))) ;; the functions we need for retrieval and display ;;;###autoload @@ -286,6 +311,14 @@ Return the image." "Start reading news. You may want to bind this to a key." (interactive) (newsticker-start t) ;; will start only if not running + ;; Load the html rendering packages + (if newsticker-html-renderer + (cond ((eq newsticker-html-renderer 'w3m-region) + (require 'w3m)) + ((eq newsticker-html-renderer 'w3-region) + (require 'w3-auto)) + ((eq newsticker-html-renderer 'newsticker-htmlr-render) + (require 'htmlr)))) (funcall newsticker-frontend)) ;; ======================================================================