1 ;;; newsticker.el --- A Newsticker for Emacs.
3 ;; Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; Author: Ulf Jasper <ulf.jasper@web.de>
8 ;; Filename: newsticker.el
9 ;; URL: http://www.nongnu.org/newsticker
10 ;; Created: 17. June 2003
11 ;; Keywords: News, RSS
12 ;; Time-stamp: "26. August 2005, 16:33:46 (ulf)"
14 (defconst newsticker-version "1.8" "Version number of newsticker.el.")
16 ;; ======================================================================
18 ;; This program is free software; you can redistribute it and/or modify
19 ;; it under the terms of the GNU General Public License as published by
20 ;; the Free Software Foundation; either version 2 of the License, or (at
21 ;; your option) any later version.
23 ;; This program is distributed in the hope that it will be useful, but
24 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 ;; General Public License for more details.
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with this program; if not, write to the Free Software Foundation,
30 ;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 ;; ======================================================================
38 ;; Newsticker provides a newsticker for Emacs. A newsticker is a thing that
39 ;; asynchronously retrieves headlines from a list of news sites, prepares
40 ;; these headlines for reading, and allows for loading the corresponding
41 ;; articles in a web browser.
43 ;; Headlines consist of a title and (possibly) a small description. They
44 ;; are contained in RSS (RDF Site Summary) files. Newsticker should work
45 ;; with all RSS files that follow the RDF Rich Site Summary 1.0
46 ;; specification. It should also work with version 2.0 as well as
47 ;; other/older/alternative RSS formats (like 0.9<something> or such). In
48 ;; other words: Newsticker is a "RSS reader" or "RSS aggregator".
50 ;; Newsticker provides several commands for reading headlines, navigating
51 ;; through them, marking them as read/unread, hiding old headlines
52 ;; etc. Headlines can be displayed as plain text or as rendered HTML.
54 ;; Headlines can be displayed in the echo area, either scrolling like
55 ;; messages in a stock-quote ticker, or just changing.
57 ;; Newsticker allows for automatic processing of headlines by providing
58 ;; hooks and (sample) functions for automatically downloading images and
59 ;; enclosed files (as delivered by podcasts, e.g.).
65 ;; Newsticker can be used with GNU Emacs version 21.1 or later as well as
66 ;; XEmacs. It requires an XML-parser (`xml.el') which is part of GNU
67 ;; Emacs. If you are using XEmacs you want to get the `net-utils' package
68 ;; which contains `xml.el' for XEmacs.
70 ;; Newsticker requires a program which can retrieve files via http and
71 ;; prints them to stdout. By default Newsticker will use wget for this
76 ;; Place Newsticker in a directory where Emacs can find it. Add the
77 ;; following line to your Emacs startup file (`~/.emacs').
78 ;; (add-to-list 'load-path "/path/to/newsticker/")
79 ;; (autoload 'newsticker-start "newsticker" "Emacs Newsticker" t)
80 ;; (autoload 'newsticker-show-news "newsticker" "Emacs Newsticker" t)
82 ;; Newsticker-mode supports imenu. It allows for navigating with the help
83 ;; of a menu. In order to use this feature you should also add the
85 ;; (add-hook 'newsticker-mode-hook 'imenu-add-menubar-index)
91 ;; The command newsticker-show-news will display all available headlines in
92 ;; a special buffer, called `*newsticker*'. It will also start the
93 ;; asynchronous download of headlines. The modeline in the `*newsticker*'
94 ;; buffer informs whenever new headlines have arrived. Clicking
95 ;; mouse-button 2 or pressing RET in this buffer on a headline will call
96 ;; browse-url to load the corresponding news story in your favourite web
99 ;; The scrolling, or flashing of headlines in the echo area, can be started
100 ;; with the command newsticker-start-ticker. It can be stopped with
101 ;; newsticker-stop-ticker.
103 ;; If you just want to start the periodic download of headlines use the
104 ;; command newsticker-start. Calling newsticker-stop will stop the periodic
105 ;; download, but will call newsticker-stop-ticker as well.
109 ;; All Newsticker options are customizable, i.e. they can be changed with
110 ;; Emacs customization methods: Call the command customize-group and enter
111 ;; `newsticker' for the customization group.
113 ;; All Newsticker options have reasonable default values, so that in most
114 ;; cases it is not necessary to customize settings before starting
115 ;; Newsticker for the first time.
117 ;; Newsticker options are organized in the following groups.
119 ;; * newsticker-feed contains options that define which news
120 ;; feeds are retrieved and how this is done.
121 ;; o newsticker-url-list defines the list of headlines which are
123 ;; o newsticker-retrieval-interval defines how often headlines are
125 ;; * newsticker-headline-processing contains options that define how the
126 ;; retrieved headlines are processed.
127 ;; o newsticker-keep-obsolete-items decides whether unread headlines that
128 ;; have been removed from the feed are kept in the Newsticker cache.
129 ;; * newsticker-layout contains options that define how the buffer for
130 ;; reading RSS headlines is formatted.
131 ;; o newsticker-item-format defines how the title of a headline is
133 ;; * newsticker-ticker contains options that define how headlines are shown
135 ;; o newsticker-display-interval and newsticker-scroll-smoothly define
136 ;; how headlines are shown in the echo area.
137 ;; * newsticker-hooks contains options for hooking other Emacs commands to
138 ;; newsticker functions.
139 ;; o newsticker-new-item-functions allows for automatic processing of
140 ;; headlines. See `newsticker-download-images', and
141 ;; `newsticker-download-enclosures' for sample functions.
142 ;; * newsticker-miscellaneous contains other Newsticker options.
144 ;; Please have a look at the customization buffers for the complete list of
149 ;; This newsticker is designed do its job silently in the background
150 ;; without disturbing you. However, it is probably impossible to prevent
151 ;; such a tool from slightly attenuating your Editor's responsiveness every
154 ;; Byte-compiling newsticker.el is recommended.
156 ;; ======================================================================
160 ;; * Added commands `newsticker-show-extra' and `newsticker-hide-extra'
161 ;; to show and hide extra RSS elements, bound to "sx" and "hx"
162 ;; resp. Changed default value of `newsticker-show-all-rss-elements'
164 ;; * mode-line: Introduced special mode-line-format for newsticker.
165 ;; * Get feed logos only once every 24 h.
166 ;; * Default faces changed.
170 ;; * Tool-bar support: most important commands can be called from
172 ;; * Auto-Narrowing introduced: *newsticker* buffer can be narrowed to
173 ;; a single item (bound to key `xi') or a single feed (bound to `xf').
174 ;; * Enclosure support: enclosed items are shown (see
175 ;; `newsticker-enclosure-face') and can be (automatically) downloaded
176 ;; (see below). For those of you who read "podcasts".
177 ;; * Added variable `newsticker-auto-mark-filter' for automatically
178 ;; marking items as immortal or old.
179 ;; * Added hook variable `newsticker-new-item-functions' for handling
180 ;; new items. Added sample functions `newsticker-download-images',
181 ;; and `newsticker-download-enclosures'.
182 ;; * Added hook variable `newsticker-select-item-hook' which is run
183 ;; after `newsticker-(next|previous)-(new-)?-item'.
184 ;; * Added hook variable `newsticker-select-feed-hook' which is run
185 ;; after `newsticker-(next|previous)-feed'.
186 ;; * Added hook variable `newsticker-buffer-change-hook' which is run
187 ;; after the contents or visibility of the newsticker buffer has
188 ;; changed, e.g. after `newsticker-buffer-update' or
189 ;; `newsticker-show-feed-desc'.
190 ;; * Added command `newsticker-handle-url' for interactively launching
191 ;; arbitrary programs for URLs, bound to `C-RET'.
192 ;; * URLs in extra elements are clickable.
193 ;; * Better support for w3, added command
194 ;; `newsticker-w3m-show-inline-images' for displaying all inline
196 ;; * Insert an artificial headline which notifies about failed retrievals.
197 ;; * Use pubDate element (RSS 2.0) instead of retrieval time when
199 ;; * Customizable options grouped.
200 ;; * Bugfixes: `newsticker--imenu-create-index'; strip whitespace
201 ;; from links; apply coding-system to extra-elements; time-comparison
202 ;; for obsolete items; and others which I have forgotten.
203 ;; * Workaround for another bug in xml-parse-region -- thanks to anonymous
204 ;; for sending patch.
205 ;; * Renamed invisible buffers ` *wget-newsticker-<feed>*' to
206 ;; ` *newsticker-wget-<feed>*'.
207 ;; * Tested with GNU Emacs versions 21.3 and 22.0 and XEmacs 21.something.
209 ;; 1.6 * Support for (some) optional RSS elements: guid, dc:date. See
210 ;; `newsticker-show-all-rss-elements' `newsticker-extra-face'.
211 ;; * Better support for w3m -- `newsticker-default-face' is obsolete
212 ;; now, removed `newsticker-w3m-toggle-inline-image'.
213 ;; * Added `newsticker-desc-comp-max' -- comparison of item descriptions
214 ;; can take quite some time.
215 ;; * Added `newsticker--buffer-make-item-completely-visible' to
216 ;; ensure that the current item is fully visible.
217 ;; * Allow for non-positive retrieval-interval, which make newsticker
218 ;; get news only once.
219 ;; * Use :set for customizable variables.
220 ;; * Added `newsticker-buffer-force-update', bound to key `U'.
221 ;; * Added concept of obsolete items, see
222 ;; `newsticker-keep-obsolete-items', `newsticker-obsolete-item-face',
223 ;; `newsticker-obsolete-item-max-age'.
224 ;; * Added `newsticker-add-url'.
226 ;; * Save pre-formatted titles => even better performance!!
227 ;; * `newsticker-*-new-item' wraps at beginning/end of buffer.
228 ;; * Always sort obsolete items to end of item list.
230 ;; - newsticker-hide-entry,
231 ;; - changes of feed-titles led to duplicate feed items,
232 ;; - faces for rendered HTML texts,
233 ;; - length of ticker-text (for "exotic"/multibyte texts),
234 ;; Thanks to Hiroshi Maruyama.
235 ;; - suppress items with empty title and description
236 ;; - newsticker-sort-method was ignored!
237 ;; - prevent call of fill-region on HTML-rendered descriptions.
239 ;; 1.5 * Rewrote the visibility stuff. newsticker does not inherit
240 ;; outline anymore. Now you have complete freedom for
241 ;; `newsticker-*-format'.
242 ;; * Save pre-formatted descriptions => incredible performance boost!!
243 ;; * Introduced `newsticker-(start|stop)-ticker'.
244 ;; * Introduced statistics for heading-format and
245 ;; `newsticker-statistics-face'.
246 ;; * Introduced `newsticker-enable-logo-manipulations'.
247 ;; * Compare link of items (as well as title and desc).
248 ;; * Added `newsticker-start-hook' and `newsticker-stop-hook', thanks
250 ;; * Bugfixes -- thanks to Ryan Yeske, Jari Aalto, Bruce Ingalls.
251 ;; * Tested with Emacs 21.3.50, 21.3.1, 21.2, 21.1; XEmacs 21.4.15
253 ;; 1.4 * Enabled HTML rendering, added `newsticker-html-renderer' to
254 ;; choose a HTML rendering engine, thanks to Greg Scott for testing
255 ;; * New Outline handling using text properties instead of "**"
257 ;; * Added possibility to mark single item as old (bound to key
258 ;; `o' (`newsticker-mark-item-at-point-as-read').
259 ;; * Added possibility to mark single item as immortal (bound to key
260 ;; `i' (`newsticker-mark-item-at-point-as-immortal').
261 ;; * Added possibility to display feed logos.
262 ;; * Added `newsticker-heading-format', `newsticker-item-format'.
263 ;; * Added `newsticker-date-format'.
264 ;; * Added `newsticker-justification'.
265 ;; * Added `newsticker-automatically-mark-visited-items-as-old'.
266 ;; * Added `newsticker-w3m-toggle-inline-image' which calls
267 ;; `w3m-toggle-inline-image' if `newsticker-html-renderer' is
268 ;; `w3m-region'. Exists for convenience only (bound to key
271 ;; 1.3 * Compare title AND desc to check whether item is old, except
273 ;; * Mark as not-up-to-date only after new items have arrived.
274 ;; * Added XEmacs compatibility code, tested with XEmacs 21.4.13.
275 ;; * Tested with Emacs 21.3.50 and Emacs 21.2.something.
276 ;; * Bugfix: Apply coding-systems to feed title and description,
277 ;; thanks to OHASHI Akira
278 ;; * Bugfix: xml-parser-workaround did not work for japanese texts,
279 ;; thanks to OHASHI Akira
280 ;; * Kill wget-buffers unless newsticker-debug is not nil.
281 ;; * Bugfix: xml-parser-workaround for "DOCTYPE rdf:RDF"
283 ;; 1.2 Peter S Galbraith <psg@debian.org>
284 ;; * Added `newsticker-url-list-defaults', splitting the URLs into
285 ;; a customizable selection list, and a user add-on list.
286 ;; * Minor checkdoc fixes.
288 ;; 1.1 * Introduced optional feed-specific wget-arguments.
289 ;; * Keep order of feeds as given in `newsticker-url-list' in
290 ;; *newsticker* buffer.
291 ;; * Ignore unsupported coding systems.
293 ;; 1.0 * Introduced feed-specific retrieval-timers.
294 ;; * Removed dependency on 'cl (cddddr).
295 ;; * Thanks to Kevin Rodgers and T.V. Raman for their help.
296 ;; * Use utf-8 for reading and writing cache data.
297 ;; * Reported to work with Emacs 21.3.50.
299 ;; 0.99 * Minor tweaks.
300 ;; * Tested with Emacs 21.3.2
302 ;; 0.98 * Check exit status of wget processes. Keep cache data if
303 ;; something went wrong. Throw error when old wget-processes
304 ;; are hanging around.
305 ;; * Introduced newsticker-specific faces.
306 ;; * Added `newsticker-show-descriptions-of-new-items'.
307 ;; * Added `newsticker-hide-old-items-in-newsticker-buffer'.
308 ;; * Added `newsticker-(hide|show)-old-items'.
310 ;; 0.97 * Minor tweaks.
312 ;; 0.96 * Added caching.
313 ;; * newsticker-mode inherits outline-mode.
314 ;; * newsticker-mode supports imenu.
315 ;; * Easy buffer-navigation with newsticker-mode's keymap.
316 ;; * Some bugs fixed.
317 ;; * Thanks to Moritz Epple for documentation tips.
319 ;; 0.95 * Added newsticker-mode -- Thanks to T.V. Raman.
320 ;; * Catch xml-parser errors -- Thanks to T.V. Raman.
321 ;; * Remove stupid newlines in titles (headlines) -- Thanks to
324 ;; 0.94 * Added clickerability and description for channel headings.
325 ;; * Made it work for (at least some) rss 0.9<something> feeds.
327 ;; 0.93 * Added some more sites.
328 ;; * Do not flood the *Messages* buffer.
329 ;; * First attempt at handling coding systems.
331 ;; 0.92 * Added `newsticker-wget-name'.
332 ;; * Try to display message only if minibuffer and echo area are
333 ;; not in use already.
334 ;; * Dirty workaround for newer versions of xml.el: Remove
335 ;; whitespace in rdf.
336 ;; * Tested with Emacs 21.3.2 and CVS-snapshot of 2003-06-21.
338 ;; 0.91 * First bugfix: *newsticker* is read-only.
340 ;; 0.9 * First release.
341 ;; * Tested with Emacs 21.3.2 and wget 1.8.2.
343 ;; ======================================================================
346 ;; * Image handling for XEmacs (create-image does not exist)
348 ;; ======================================================================
355 (defvar tool-bar-map)
357 (defvar w3m-minor-mode-map)
359 ;; ======================================================================
361 ;; ======================================================================
362 (defgroup newsticker nil
364 :group 'applications)
366 (defconst newsticker--raw-url-list-defaults
368 "http://export.cnet.com/export/feeds/news/rss/1,11176,,00.xml")
369 ("Debian Security Advisories"
370 "http://www.debian.org/security/dsa.en.rdf")
371 ("Debian Security Advisories - Long format"
372 "http://www.debian.org/security/dsa-long.en.rdf")
374 "http://www.emacswiki.org/cgi-bin/wiki.pl?action=rss"
378 "http://freshmeat.net/backend/fm.rdf")
380 "http://www.kuro5hin.org/backend.rdf")
381 ("LWN (Linux Weekly News)"
382 "http://lwn.net/headlines/rss")
384 "http://newsforge.com/index.rss")
385 ("NY Times: Technology"
386 "http://partners.userland.com/nytRss/technology.xml")
388 "http://partners.userland.com/nytRss/nytHomepage.xml")
390 "http://www.quotationspage.com/data/qotd.rss"
394 "http://www.theregister.co.uk/tonys/slashdot.rdf")
396 "http://slashdot.org/index.rss"
398 3600) ;/. will ban you if under 3600 seconds!
400 "http://www.wired.com/news_drop/netcenter/netcenter.rdf")
401 ("Heise News (german)"
402 "http://www.heise.de/newsticker/heise.rdf")
403 ("Tagesschau (german)"
404 "http://www.tagesschau.de/newsticker.rdf"
407 ("Telepolis (german)"
408 "http://www.heise.de/tp/news.rdf"))
409 "Default URL list in raw form.
410 This list is fed into defcustom via `newsticker--splicer'.")
412 (defun newsticker--splicer (item)
413 "Convert ITEM for splicing into `newsticker-url-list-defaults'."
414 (let ((result (list 'list :tag (nth 0 item) (list 'const (nth 0 item))))
415 (element (cdr item)))
417 (setq result (append result (list (list 'const (car element)))))
418 (setq element (cdr element)))
421 ;; ======================================================================
423 ;; ======================================================================
424 (defun newsticker--set-customvar (symbol value)
425 "Set newsticker-variable SYMBOL value to VALUE.
427 Calls all necessary actions which are necessary in order to make
428 the new value effective. Changing `newsticker-url-list', for example,
429 will re-start the retrieval-timers."
430 (unless (condition-case nil
431 (eq (symbol-value symbol) value)
434 (cond ((eq symbol 'newsticker-sort-method)
435 (when (fboundp 'newsticker--cache-sort)
436 (message "Applying new sort method...")
437 (newsticker--cache-sort)
438 (newsticker--buffer-set-uptodate nil)
439 (message "Applying new sort method...done")))
440 ((memq symbol '(newsticker-url-list-defaults
442 newsticker-retrieval-interval))
443 (when (and (fboundp 'newsticker-running-p)
444 (newsticker-running-p))
445 (message "Restarting newsticker")
448 ((eq symbol 'newsticker-display-interval)
449 (when (and (fboundp 'newsticker-running-p)
450 (newsticker-running-p))
451 (message "Restarting ticker")
452 (newsticker-stop-ticker)
453 (newsticker-start-ticker)
455 ((memq symbol '(newsticker-hide-old-items-in-echo-area
456 newsticker-hide-obsolete-items-in-echo-area
457 newsticker-hide-immortal-items-in-echo-area))
458 (when (and (fboundp 'newsticker-running-p)
459 (newsticker-running-p))
460 (message "Restarting newsticker")
461 (newsticker-stop-ticker)
462 (newsticker--ticker-text-setup)
463 (newsticker-start-ticker)
465 ((memq symbol '(newsticker-hide-old-items-in-newsticker-buffer
466 newsticker-show-descriptions-of-new-items))
467 (when (fboundp 'newsticker--buffer-set-uptodate)
468 (newsticker--buffer-set-uptodate nil)))
469 ((memq symbol '(newsticker-heading-format
470 newsticker-item-format
471 newsticker-desc-format
472 newsticker-date-format
473 newsticker-statistics-format
474 newsticker-justification
475 newsticker-use-full-width
476 newsticker-html-renderer
478 newsticker-new-item-face
479 newsticker-old-item-face
480 newsticker-immortal-item-face
481 newsticker-obsolete-item-face
483 newsticker-statistics-face
484 ;;newsticker-default-face
486 (when (fboundp 'newsticker--forget-preformatted)
487 (newsticker--forget-preformatted)))
489 (error "Ooops %s" symbol)))))
491 ;; customization group feed
492 (defgroup newsticker-feed nil
493 "Settings for the RSS feeds."
496 (defcustom newsticker-url-list-defaults
498 "http://www.emacswiki.org/cgi-bin/wiki.pl?action=rss"
501 "A customizable list of news feeds to select from.
502 These were mostly extracted from the Radio Community Server at
503 http://subhonker6.userland.com/rcsPublic/rssHotlist.
505 You may add other entries in `newsticker-url-list'."
506 :type `(set ,@(mapcar `newsticker--splicer
507 newsticker--raw-url-list-defaults))
508 :set 'newsticker--set-customvar
509 :group 'newsticker-feed)
511 (defcustom newsticker-url-list nil
512 "The news feeds which you like to watch.
514 This alist will be used in addition to selection made customizing
515 `newsticker-url-list-defaults'.
517 This is an alist. Each element consists of two items: a LABEL and a URL,
518 optionally followed by a START-TIME, INTERVAL specifier and WGET-ARGUMENTS.
520 The LABEL gives the name of the news feed. It can be an arbitrary string.
522 The URL gives the location of the news feed. It must point to a valid
523 RSS file. The RSS file is retrieved by calling wget, or whatever you
524 specify as `newsticker-wget-name'.
526 The START-TIME can be either a string, or nil. If it is a string it
527 specifies a fixed time at which this feed shall be retrieved for the
528 first time. (Examples: \"11:00pm\", \"23:00\"). If it is nil (or
529 unspecified), this feed will be retrieved immediately after calling
532 The INTERVAL specifies the time between retrievals for this feed. If it
533 is nil (or unspecified) the default interval value as set in
534 `newsticker-retrieval-interval' is used.
536 \(newsticker.el calls `run-at-time'. The newsticker-parameters START-TIME
537 and INTERVAL correspond to the `run-at-time'-parameters TIME and REPEAT.)
539 WGET-ARGUMENTS specifies arguments for wget (see `newsticker-wget-name')
540 which apply for this feed only, overriding the value of
541 `newsticker-wget-arguments'."
542 :type '(repeat (list :tag "News feed"
543 (string :tag "Label")
546 (const :tag "Default" nil)
547 (string :tag "Fixed Time"))
548 (choice :tag "Interval"
549 (const :tag "Default" nil)
550 (const :tag "Hourly" 3600)
551 (const :tag "Daily" 86400)
552 (integer :tag "Interval"))
553 (choice :tag "Wget Arguments"
554 (const :tag "Default arguments" nil)
555 (repeat :tag "Special arguments" string))))
556 :set 'newsticker--set-customvar
557 :group 'newsticker-feed)
559 (defcustom newsticker-wget-name
561 "Name of the program which is called to retrieve news from the web.
562 The canonical choice is wget but you may take any other program which is
563 able to return the contents of a news feed file on stdout."
565 :group 'newsticker-feed)
567 (defcustom newsticker-wget-arguments
569 "Arguments which are passed to wget.
570 There is probably no reason to change the default settings, unless you
571 are living behind a firewall."
572 :type '(repeat (string :tag "Argument"))
573 :group 'newsticker-feed)
575 (defcustom newsticker-retrieval-interval
577 "Time interval for retrieving new news items (seconds).
578 If this value is not positive (i.e. less than or equal to 0)
579 items are retrieved only once!
580 Please note that some feeds, e.g. Slashdot, will ban you if you
581 make it less than 1800 seconds (30 minutes)!"
582 :type '(choice :tag "Interval"
583 (const :tag "No automatic retrieval" 0)
584 (const :tag "Hourly" 3600)
585 (const :tag "Daily" 86400)
586 (integer :tag "Interval"))
587 :set 'newsticker--set-customvar
588 :group 'newsticker-feed)
590 (defcustom newsticker-desc-comp-max
592 "Relevant length of headline descriptions.
593 This value gives the maximum number of characters which will be
594 taken into account when newsticker compares two headline
597 :group 'newsticker-feed)
599 ;; customization group behaviour
600 (defgroup newsticker-headline-processing nil
601 "Settings for the automatic processing of RSS headlines."
604 (defcustom newsticker-automatically-mark-items-as-old
606 "Decides whether to automatically mark items as old.
607 If t a new item is considered as new only after its first retrieval. As
608 soon as it is retrieved a second time, it becomes old. If not t all
609 items stay new until you mark them as old. This is done in the
610 *newsticker* buffer."
612 :group 'newsticker-headline-processing)
614 (defcustom newsticker-automatically-mark-visited-items-as-old
616 "Decides whether to automatically mark visited items as old.
617 If t an item is marked as old as soon as the associated link is
618 visited, i.e. after pressing RET or mouse2 on the item's
622 :group 'newsticker-headline-processing)
624 (defcustom newsticker-keep-obsolete-items
626 "Decides whether to keep unread items which have been removed from feed.
627 If t a new item, which has been removed from the feed, is kept in
628 the cache until it is marked as read."
630 :group 'newsticker-headline-processing)
632 (defcustom newsticker-obsolete-item-max-age
634 "Maximal age of obsolete items, in seconds.
635 Obsolete items which are older than this value will be silently
636 deleted at the next retrieval."
638 :group 'newsticker-headline-processing)
640 (defcustom newsticker-auto-mark-filter
642 "A filter for automatically marking headlines.
644 This is an alist of the form (FEED-NAME OLD-LIST IMMORTAL-LIST). I.e. each
645 element consists of a FEED-NAME and two lists. Each list consists a set of
646 regular expressions. The first list contains patterns of headlines which
647 will be marked as old. The second list contains patterns of headlines which
648 will be marked as immortal.
650 This filter is checked after a new headline has been retrieved. If
651 FEED-NAME matches the name of the corresponding news feed, both sublists
652 are checked: If the title of the headline matches any of the regular
653 expressions in OLD-LIST, this headline is marked as old, if it matches any
654 of the expressions in IMMORTAL-LIST it is marked as immortal.
656 If, for example, `newsticker-auto-mark-filter' looks like
657 \((slashdot (\"^Forget me!$\") (\"^Read me$\" \"important\")))
658 then all articles from slashdot are marked as old if they have the title
659 \"Forget me!\". All articles which have the title \"Read me\" and all
660 articles which contain the string \"important\" in their title are marked
662 :type '(repeat (list :tag "Feed filter rule"
663 (string :tag "Feed name")
664 ;;(choice ,@(mapcar (lambda (i)
665 ;; (list :tag (car i) (car i)))
666 ;; newsticker-url-list))
667 (repeat :tag "Mark as old" string)
668 (repeat :tag "Mark as immortal" string)))
669 :group 'newsticker-headline-processing)
671 ;; customization group layout
672 (defgroup newsticker-layout nil
673 "Settings for layout of the RSS reader."
676 (defcustom newsticker-sort-method
677 'sort-by-original-order
678 "Sort method for news items.
679 The following sort methods are available:
680 * `sort-by-original-order' keeps the order in which the items
681 appear in the RSS file (please note that for immortal items,
682 which have been removed from the news feed, there is no original
684 * `sort-by-time' looks at the time at which an item has been seen
685 the first time. The most recent item is put at top,
686 * `sort-by-title' will put the items in an alphabetical order."
688 (const :tag "Keep original order" sort-by-original-order)
689 (const :tag "Sort by time" sort-by-time)
690 (const :tag "Sort by title" sort-by-title))
691 :set 'newsticker--set-customvar
692 :group 'newsticker-layout)
694 (defcustom newsticker-hide-old-items-in-newsticker-buffer
696 "Decides whether to automatically hide old items in the *newsticker* buffer.
697 If set to t old items will be completely folded and only new items
698 will show up in the *newsticker* buffer. Otherwise old as well as new
699 items will be visible."
701 :set 'newsticker--set-customvar
702 :group 'newsticker-layout)
704 (defcustom newsticker-show-descriptions-of-new-items
706 "Whether to automatically show descriptions of new items in *newsticker*.
707 If set to t old items will be folded and new items will be
708 unfolded. Otherwise old as well as new items will be folded."
710 :set 'newsticker--set-customvar
711 :group 'newsticker-layout)
713 (defcustom newsticker-heading-format
716 "Format string for feed headings.
717 The following printf-like specifiers can be used:
718 %d The date the feed was retrieved. See `newsticker-date-format'.
719 %l The logo (image) of the feed. Most RSS feeds provide a small
720 image as logo. Newsticker can display them, if Emacs can --
721 see `image-types' for a list of supported image types.
722 %L The logo (image) of the feed. If the logo is not available
723 the title of the feed is used.
724 %s The statistical data of the feed. See `newsticker-statistics-format'.
725 %t The title of the feed, i.e. its name."
727 :set 'newsticker--set-customvar
728 :group 'newsticker-layout)
730 (defcustom newsticker-item-format
732 "Format string for news item headlines.
733 The following printf-like specifiers can be used:
734 %d The date the item was (first) retrieved. See `newsticker-date-format'.
735 %l The logo (image) of the feed. Most RSS feeds provide a small
736 image as logo. Newsticker can display them, if Emacs can --
737 see `image-types' for a list of supported image types.
738 %L The logo (image) of the feed. If the logo is not available
739 the title of the feed is used.
740 %t The title of the item."
742 :set 'newsticker--set-customvar
743 :group 'newsticker-layout)
745 (defcustom newsticker-desc-format
747 "Format string for news descriptions (contents).
748 The following printf-like specifiers can be used:
749 %c The contents (description) of the item.
750 %d The date the item was (first) retrieved. See `newsticker-date-format'."
752 :set 'newsticker--set-customvar
753 :group 'newsticker-layout)
755 (defcustom newsticker-date-format
757 "Format for the date part in item and feed lines.
758 See `format-time-string' for a list of valid specifiers."
760 :set 'newsticker--set-customvar
761 :group 'newsticker-layout)
763 (defcustom newsticker-statistics-format
764 "[%n + %i + %o + %O = %a]"
765 "Format for the statistics part in feed lines.
766 The following printf-like specifiers can be used:
767 %a The number of all items in the feed.
768 %i The number of immortal items in the feed.
769 %n The number of new items in the feed.
770 %o The number of old items in the feed.
771 %O The number of obsolete items in the feed."
773 :set 'newsticker--set-customvar
774 :group 'newsticker-layout)
776 (defcustom newsticker-show-all-rss-elements
778 "Show all RSS elements."
780 ;;:set 'newsticker--set-customvar
781 :group 'newsticker-layout)
783 ;; image related things
784 (defcustom newsticker-enable-logo-manipulations
786 "If non-nil newsticker manipulates logo images.
787 This enables the following image properties: heuristic mask for all
788 logos, and laplace-conversion for images without new items."
790 :group 'newsticker-layout)
794 (defcustom newsticker-justification
796 "How to fill item descriptions.
797 If non-nil newsticker calls `fill-region' to wrap long lines in
798 item descriptions. However, if an item description contains HTML
799 text and `newsticker-html-renderer' is non-nil, filling is not
801 :type '(choice :tag "Justification"
802 (const :tag "No filling" nil)
803 (const :tag "Left" left)
804 (const :tag "Right" right)
805 (const :tag "Center" center)
806 (const :tag "Full" full))
807 :set 'newsticker--set-customvar
808 :group 'newsticker-layout)
810 (defcustom newsticker-use-full-width
812 "Decides whether to use the full window width when filling.
813 If non-nil newsticker sets `fill-column' so that the whole
814 window is used when filling. See also `newsticker-justification'."
816 :set 'newsticker--set-customvar
817 :group 'newsticker-layout)
819 (defcustom newsticker-html-renderer
821 "Function for rendering HTML contents.
822 If non-nil, newsticker.el will call this function whenever it finds
823 HTML-like tags in item descriptions. Possible functions are, for
824 example, `w3m-region', `w3-region', and (if you have htmlr.el installed)
825 `newsticker-htmlr-render'.
827 In order to make sure that the HTML renderer is loaded when you
828 run newsticker, you should add one of the following statements to
829 your .emacs. If you use w3m,
831 (autoload 'w3m-region \"w3m\"
832 \"Render region in current buffer and replace with result.\" t)
841 :type '(choice :tag "Function"
842 (const :tag "None" nil)
843 (const :tag "w3" w3-region)
844 (const :tag "w3m" w3m-region)
845 (const :tag "htmlr" newsticker-htmlr-render))
846 :set 'newsticker--set-customvar
847 :group 'newsticker-layout)
851 (defgroup newsticker-faces nil
852 "Settings for the faces of the RSS reader."
853 :group 'newsticker-layout)
855 (defface newsticker-feed-face
856 '((((class color) (background dark))
857 (:family "helvetica" :bold t :height 1.2 :foreground "misty rose"))
858 (((class color) (background light))
859 (:family "helvetica" :bold t :height 1.2 :foreground "black")))
860 "Face for news feeds."
861 :group 'newsticker-faces)
863 (defface newsticker-new-item-face
864 '((((class color) (background dark))
865 (:family "helvetica" :bold t))
866 (((class color) (background light))
867 (:family "helvetica" :bold t)))
868 "Face for old news items."
869 :group 'newsticker-faces)
871 (defface newsticker-old-item-face
872 '((((class color) (background dark))
873 (:family "helvetica" :bold t :foreground "orange3"))
874 (((class color) (background light))
875 (:family "helvetica" :bold t :foreground "red4")))
876 "Face for old news items."
877 :group 'newsticker-faces)
879 (defface newsticker-immortal-item-face
880 '((((class color) (background dark))
881 (:family "helvetica" :bold t :italic t :foreground "orange"))
882 (((class color) (background light))
883 (:family "helvetica" :bold t :italic t :foreground "blue")))
884 "Face for immortal news items."
885 :group 'newsticker-faces)
887 (defface newsticker-obsolete-item-face
888 '((((class color) (background dark))
889 (:family "helvetica" :bold t :strike-through t))
890 (((class color) (background light))
891 (:family "helvetica" :bold t :strike-through t)))
892 "Face for old news items."
893 :group 'newsticker-faces)
895 (defface newsticker-date-face
896 '((((class color) (background dark))
897 (:family "helvetica" :italic t :height 0.8))
898 (((class color) (background light))
899 (:family "helvetica" :italic t :height 0.8)))
900 "Face for newsticker dates."
901 :group 'newsticker-faces)
903 (defface newsticker-statistics-face
904 '((((class color) (background dark))
905 (:family "helvetica" :italic t :height 0.8))
906 (((class color) (background light))
907 (:family "helvetica" :italic t :height 0.8)))
908 "Face for newsticker dates."
909 :group 'newsticker-faces)
911 (defface newsticker-enclosure-face
912 '((((class color) (background dark))
913 (:bold t :background "orange"))
914 (((class color) (background light))
915 (:bold t :background "orange")))
916 "Face for enclosed elements."
917 :group 'newsticker-faces)
919 (defface newsticker-extra-face
920 '((((class color) (background dark))
921 (:italic t :foreground "gray50" :height 0.8))
922 (((class color) (background light))
923 (:italic t :foreground "gray50" :height 0.8)))
924 "Face for newsticker dates."
925 :group 'newsticker-faces)
927 ;; (defface newsticker-default-face
928 ;; '((((class color) (background dark))
929 ;; (:inherit default))
930 ;; (((class color) (background light))
931 ;; (:inherit default)))
932 ;; "Face for the description of news items."
933 ;; ;;:set 'newsticker--set-customvar
934 ;; :group 'newsticker-faces)
937 ;; customization group ticker
938 (defgroup newsticker-ticker nil
939 "Settings for the RSS ticker."
942 (defcustom newsticker-display-interval
944 "Time interval for displaying news items in the echo area (seconds).
945 If equal or less than 0 no messages are shown in the echo area. For
946 smooth display (see `newsticker-scroll-smoothly') a value of 0.3 seems
947 reasonable. For non-smooth display a value of 10 is a good starting
950 :set 'newsticker--set-customvar
951 :group 'newsticker-ticker)
953 (defcustom newsticker-scroll-smoothly
955 "Decides whether to flash or scroll news items.
956 If t the news headlines are scrolled (more-or-less) smoothly in the echo
957 area. If nil one headline after another is displayed in the echo area.
958 The variable `newsticker-display-interval' determines how fast this
959 display moves/changes and whether headlines are shown in the echo area
960 at all. If you change `newsticker-scroll-smoothly' you should also change
961 `newsticker-display-interval'."
963 :group 'newsticker-ticker)
965 (defcustom newsticker-hide-immortal-items-in-echo-area
967 "Decides whether to show immortal/non-expiring news items in the ticker.
968 If t the echo area will not show immortal items. See also
969 `newsticker-hide-old-items-in-echo-area."
971 :set 'newsticker--set-customvar
972 :group 'newsticker-ticker)
974 (defcustom newsticker-hide-old-items-in-echo-area
976 "Decides whether to show only the newest news items in the ticker.
977 If t the echo area will show only new items, i.e. only items which have
978 been added between the last two retrievals."
980 :set 'newsticker--set-customvar
981 :group 'newsticker-ticker)
983 (defcustom newsticker-hide-obsolete-items-in-echo-area
985 "Decides whether to show obsolete items items in the ticker.
986 If t the echo area will not show obsolete items. See also
987 `newsticker-hide-old-items-in-echo-area."
989 :set 'newsticker--set-customvar
990 :group 'newsticker-ticker)
992 (defgroup newsticker-hooks nil
993 "Settings for newsticker hooks."
996 (defcustom newsticker-start-hook
998 "Hook run when starting newsticker.
999 This hook is run at the very end of `newsticker-start'."
1000 :options '(newsticker-start-ticker)
1002 :group 'newsticker-hooks)
1004 (defcustom newsticker-stop-hook
1006 "Hook run when stopping newsticker.
1007 This hook is run at the very end of `newsticker-stop'."
1010 :group 'newsticker-hooks)
1012 (defcustom newsticker-new-item-functions
1014 "List of functions run after a new headline has been retrieved.
1015 Each function is called with the following three arguments:
1016 FEED the name of the corresponding news feed,
1017 TITLE the title of the headline,
1018 DESC the decoded description of the headline.
1020 See `newsticker-download-images', and
1021 `newsticker-download-enclosures' for sample functions.
1023 Please note that these functions are called only once for a
1024 headline after it has been retrieved for the first time."
1026 :options '(newsticker-download-images
1027 newsticker-download-enclosures)
1028 :group 'newsticker-hooks)
1030 (defcustom newsticker-select-item-hook
1031 'newsticker--buffer-make-item-completely-visible
1032 "List of functions run after a headline has been selected.
1033 Each function is called after one of `newsticker-next-item',
1034 `newsticker-next-new-item', `newsticker-previous-item',
1035 `newsticker-previous-new-item' has been called.
1037 The default value 'newsticker--buffer-make-item-completely-visible
1038 assures that the current item is always completely visible."
1040 :options '(newsticker--buffer-make-item-completely-visible)
1041 :group 'newsticker-hooks)
1043 (defcustom newsticker-select-feed-hook
1044 'newsticker--buffer-make-item-completely-visible
1045 "List of functions run after a feed has been selected.
1046 Each function is called after one of `newsticker-next-feed', and
1047 `newsticker-previous-feed' has been called.
1049 The default value 'newsticker--buffer-make-item-completely-visible
1050 assures that the current feed is completely visible."
1052 :options '(newsticker--buffer-make-item-completely-visible)
1053 :group 'newsticker-hooks)
1055 (defcustom newsticker-buffer-change-hook
1056 'newsticker-w3m-show-inline-images
1057 "List of functions run after the newsticker buffer has been updated.
1058 Each function is called after `newsticker-buffer-update' has been called.
1060 The default value '`newsticker-w3m-show-inline-images' loads inline
1063 :group 'newsticker-hooks)
1065 (defcustom newsticker-narrow-hook
1066 'newsticker-w3m-show-inline-images
1067 "List of functions run after narrowing in newsticker buffer has changed.
1068 Each function is called after
1069 `newsticker-toggle-auto-narrow-to-feed' or
1070 `newsticker-toggle-auto-narrow-to-item' has been called.
1072 The default value '`newsticker-w3m-show-inline-images' loads inline
1075 :group 'newsticker-hooks)
1077 (defgroup newsticker-miscellaneous nil
1078 "Miscellaneous newsticker settings."
1081 (defcustom newsticker-cache-filename
1082 "~/.newsticker-cache"
1083 "Name of the newsticker cache file."
1085 :group 'newsticker-miscellaneous)
1087 (defcustom newsticker-imagecache-dirname
1088 "~/.newsticker-images"
1089 "Name of the directory where newsticker stores cached images."
1091 :group 'newsticker-miscellaneous)
1094 (defcustom newsticker-debug
1096 "Enables some features needed for debugging newsticker.el.
1098 If set to t newsticker.el will print lots of debugging messages, and the
1099 buffers *newsticker-wget-<feed>* will not be closed."
1101 ;;:set 'newsticker--set-customvar
1102 :group 'newsticker-miscellaneous)
1104 ;; ======================================================================
1105 ;;; Compatibility section, XEmacs, Emacs
1106 ;; ======================================================================
1107 (unless (fboundp 'time-add)
1108 (require 'time-date);;FIXME
1109 (defun time-add (t1 t2)
1110 (seconds-to-time (+ (time-to-seconds t1) (time-to-seconds t2)))))
1112 (unless (fboundp 'match-string-no-properties)
1113 (defalias 'match-string-no-properties 'match-string))
1115 (unless (fboundp 'replace-regexp-in-string)
1116 (defun replace-regexp-in-string (re rp st)
1117 (save-match-data ;; apparently XEmacs needs save-match-data
1118 (replace-in-string st re rp))))
1120 ;; copied from subr.el
1121 (unless (fboundp 'add-to-invisibility-spec)
1122 (defun add-to-invisibility-spec (arg)
1123 "Add elements to `buffer-invisibility-spec'.
1124 See documentation for `buffer-invisibility-spec' for the kind of elements
1126 (if (eq buffer-invisibility-spec t)
1127 (setq buffer-invisibility-spec (list t)))
1128 (setq buffer-invisibility-spec
1129 (cons arg buffer-invisibility-spec))))
1131 ;; copied from subr.el
1132 (unless (fboundp 'remove-from-invisibility-spec)
1133 (defun remove-from-invisibility-spec (arg)
1134 "Remove elements from `buffer-invisibility-spec'."
1135 (if (consp buffer-invisibility-spec)
1136 (setq buffer-invisibility-spec (delete arg buffer-invisibility-spec)))))
1138 ;; ======================================================================
1139 ;;; Internal variables
1140 ;; ======================================================================
1141 (defvar newsticker--display-timer nil
1142 "Timer for newsticker display.")
1143 (defvar newsticker--retrieval-timer-list nil
1144 "List of timers for news retrieval.
1145 This is an alist, each element consisting of (feed-name . timer)")
1146 (defvar newsticker--item-list nil
1147 "List of newsticker items.")
1148 (defvar newsticker--item-position 0
1149 "Actual position in list of newsticker items.")
1150 (defvar newsticker--prev-message "There was no previous message yet!"
1151 "Last message that the newsticker displayed.")
1152 (defvar newsticker--scrollable-text ""
1153 "The text which is scrolled smoothly in the echo area.")
1154 (defvar newsticker--buffer-uptodate-p nil
1155 "Tells whether the newsticker buffer is up to date.")
1156 (defvar newsticker--latest-update-time (current-time)
1157 "The time at which the latest news arrived.")
1159 (defvar newsticker--cache nil "Cached newsticker data.
1160 This is a list of the form
1163 (title description link time age index preformatted-contents
1167 (title description link time age index preformatted-contents
1172 where LABEL is a symbol. TITLE, DESCRIPTION, and LINK are
1173 strings. TIME is a time value as returned by `current-time'.
1174 AGE is a symbol: 'new, 'old, 'immortal, and 'obsolete denote
1175 ordinary news items, whereas 'feed denotes an item which is not a
1176 headline but describes the feed itself. INDEX denotes the
1177 original position of the item -- used for restoring the original
1178 order. PREFORMATTED-CONTENTS and PREFORMATTED-TITLE hold the
1179 formatted contents of the item's description and title. This
1180 speeds things up if HTML rendering is used, which is rather
1183 (defvar newsticker--auto-narrow-to-feed nil
1184 "Automatically narrow to current news feed.
1185 If non-nil only the items of the current news feed are visible.")
1187 (defvar newsticker--auto-narrow-to-item nil
1188 "Automatically narrow to current news item.
1189 If non-nil only the current headline is visible.")
1191 (defconst newsticker--error-headline
1192 "[COULD NOT DOWNLOAD HEADLINES!]"
1193 "Title of error headline which will be inserted if news retrieval fails.")
1195 ;; ======================================================================
1197 ;; ======================================================================
1198 (defconst newsticker--next-item-image
1199 (if (fboundp 'create-image)
1200 (create-image "/* XPM */
1201 static char * next_xpm[] = {
1271 "Image for the next item button."))
1273 (defconst newsticker--previous-item-image
1274 (if (fboundp 'create-image)
1275 (create-image "/* XPM */
1276 static char * previous_xpm[] = {
1343 "Image for the previous item button."))
1345 (defconst newsticker--previous-feed-image
1346 (if (fboundp 'create-image)
1347 (create-image "/* XPM */
1348 static char * prev_feed_xpm[] = {
1412 \" .:. .!!<>,'%. \",
1413 \" .&. .~[}>{*=-. \",
1414 \" .$. .|1,2/%@. \",
1428 "Image for the previous feed button."))
1430 (defconst newsticker--next-feed-image
1431 (if (fboundp 'create-image)
1432 (create-image "/* XPM */
1433 static char * next_feed_xpm[] = {
1502 \" .%:<[}||. .). \",
1503 \" .&*=12'3~. .-. \",
1504 \" .$45=6<7. .@. \",
1518 "Image for the next feed button."))
1520 (defconst newsticker--mark-read-image
1521 (if (fboundp 'create-image)
1522 (create-image "/* XPM */
1523 static char * mark_read_xpm[] = {
1595 "Image for the next feed button."))
1597 (defconst newsticker--mark-immortal-image
1598 (if (fboundp 'create-image)
1599 (create-image "/* XPM */
1600 static char * mark_immortal_xpm[] = {
1699 \" $ @ % & * * = - + + \",
1700 \" @ ; > , ' ) ' ! * - ~ @ \",
1701 \" @ { > ! ] ^ / / ( ' * ; _ : \",
1702 \" < _ ; [ ) / } | } / ] , 1 2 3 4 \",
1703 \" 5 6 7 , ] 8 9 9 9 } ^ ! = ~ 0 a \",
1704 \" b c 6 - , ] 8 9 9 9 } ^ ! % ~ 0 d 5 \",
1705 \" : e _ ; * ) / 8 } } / ] , 1 2 3 f 5 \",
1706 \" : g h { = i j ^ / ^ ] ! * ; k e l m \",
1707 \" : f n o ; > , ' ) ' ! * - 2 0 p q r \",
1708 \" : s g 0 6 ; % > * * = - ~ h t l u r \",
1709 \" v u w x y k ~ z A z B o C D E F G b \",
1710 \" 5 H I J e 0 h K h C c x L M N . \",
1711 \" 4 O P q Q d g x g J L R H S T < \",
1712 \" @ T U P F q V q M H N W X + \",
1713 \" @ Y T O W G G W O X Y @ \",
1714 \" 4 Z ` Y Y Y .` 4 4 \",
1721 "Image for the next feed button."))
1724 (defconst newsticker--narrow-image
1725 (if (fboundp 'create-image)
1726 (create-image "/* XPM */
1727 static char * narrow_xpm[] = {
1780 \" .................. \",
1781 \" .+@#$%&*=*-;>,')!. \",
1782 \" .................. \",
1785 \" .................. \",
1786 \" .~{]^/(___:<[}|12. \",
1787 \" .................. \",
1790 \" .................. \",
1791 \" .!3@45>666789'0ab. \",
1792 \" .................. \",
1795 \" .................. \",
1796 \" .cccdefghhgficccc. \",
1797 \" .................. \",
1803 "Image for the next feed button."))
1805 (defconst newsticker--get-all-image
1806 (if (fboundp 'create-image)
1807 (create-image "/* XPM */
1808 static char * get_all_xpm[] = {
1884 \" ................... \",
1885 \" .+@#$%&*=*&-;>,')!. \",
1886 \" ................... \",
1888 \" ................... \",
1889 \" .~{]^/(___:<[}|123. \",
1890 \" ................... \",
1892 \" ................... \",
1893 \" .45678909abcdefg. \",
1894 \" .h5icj7jklmeno. \",
1895 \" .pq5drrmshft. \",
1906 "Image for the next feed button."))
1909 (defconst newsticker--update-image
1910 (if (fboundp 'create-image)
1911 (create-image "/* XPM */
1912 static char * update_xpm[] = {
1977 "Image for the update button."))
1979 (defconst newsticker--browse-image
1980 (if (fboundp 'create-image)
1981 (create-image "/* XPM */
1982 static char * visit_xpm[] = {
2031 \" .++.%%%#&.++. \",
2032 \" .++.$%%%#*=.++. \",
2033 \" .++.-@;##$*>,.++. \",
2034 \" .++.')!&@@*=~{].++. \",
2035 \" .++.^{~>---)/(_:<.++. \",
2036 \" .++.^[,~/~'(_}|.++. \",
2037 \" .++.]_1[12^:|.++. \",
2038 \" .++.:}33:45.++. \",
2039 \" .++.<5567.++. \",
2049 "Image for the browse button."))
2052 (defvar newsticker-tool-bar-map
2053 (if (featurep 'xemacs)
2055 (let ((tool-bar-map (make-sparse-keymap)))
2056 (define-key tool-bar-map [newsticker-sep-1]
2057 (list 'menu-item "--double-line"))
2058 (define-key tool-bar-map [newsticker-browse-url]
2059 (list 'menu-item "newsticker-browse-url" 'newsticker-browse-url
2061 :help "Browse URL for item at point"
2062 :image newsticker--browse-image))
2063 (define-key tool-bar-map [newsticker-buffer-force-update]
2064 (list 'menu-item "newsticker-buffer-force-update"
2065 'newsticker-buffer-force-update
2067 :help "Update newsticker buffer"
2068 :image newsticker--update-image
2069 :enable '(not newsticker--buffer-uptodate-p)))
2070 (define-key tool-bar-map [newsticker-get-all-news]
2071 (list 'menu-item "newsticker-get-all-news" 'newsticker-get-all-news
2073 :help "Get news for all feeds"
2074 :image newsticker--get-all-image))
2075 (define-key tool-bar-map [newsticker-mark-item-at-point-as-read]
2076 (list 'menu-item "newsticker-mark-item-at-point-as-read"
2077 'newsticker-mark-item-at-point-as-read
2079 :image newsticker--mark-read-image
2080 :help "Mark current item as read"
2081 :enable '(newsticker-item-not-old-p)))
2082 (define-key tool-bar-map [newsticker-mark-item-at-point-as-immortal]
2083 (list 'menu-item "newsticker-mark-item-at-point-as-immortal"
2084 'newsticker-mark-item-at-point-as-immortal
2086 :image newsticker--mark-immortal-image
2087 :help "Mark current item as immortal"
2088 :enable '(newsticker-item-not-immortal-p)))
2089 (define-key tool-bar-map [newsticker-toggle-auto-narrow-to-feed]
2090 (list 'menu-item "newsticker-toggle-auto-narrow-to-feed"
2091 'newsticker-toggle-auto-narrow-to-feed
2093 :help "Toggle visibility of other feeds"
2094 :image newsticker--narrow-image))
2095 (define-key tool-bar-map [newsticker-next-feed]
2096 (list 'menu-item "newsticker-next-feed" 'newsticker-next-feed
2098 :help "Go to next feed"
2099 :image newsticker--next-feed-image
2100 :enable '(newsticker-next-feed-available-p)))
2101 (define-key tool-bar-map [newsticker-next-item]
2102 (list 'menu-item "newsticker-next-item" 'newsticker-next-item
2104 :help "Go to next item"
2105 :image newsticker--next-item-image
2106 :enable '(newsticker-next-item-available-p)))
2107 (define-key tool-bar-map [newsticker-previous-item]
2108 (list 'menu-item "newsticker-previous-item" 'newsticker-previous-item
2110 :help "Go to previous item"
2111 :image newsticker--previous-item-image
2112 :enable '(newsticker-previous-item-available-p)))
2113 (define-key tool-bar-map [newsticker-previous-feed]
2114 (list 'menu-item "newsticker-previous-feed" 'newsticker-previous-feed
2116 :help "Go to previous feed"
2117 :image newsticker--previous-feed-image
2118 :enable '(newsticker-previous-feed-available-p)))
2119 ;; standard icons / actions
2120 (tool-bar-add-item "close"
2121 'newsticker-close-buffer
2122 'newsticker-close-buffer
2123 :help "Close newsticker buffer")
2124 (tool-bar-add-item "preferences"
2125 'newsticker-customize
2126 'newsticker-customize
2127 :help "Customize newsticker")
2130 ;; ======================================================================
2132 ;; ======================================================================
2134 (define-derived-mode newsticker-mode fundamental-mode
2136 "Viewing RSS news feeds in Emacs."
2137 (set (make-local-variable 'tool-bar-map) newsticker-tool-bar-map)
2138 (set (make-local-variable 'imenu-sort-function) nil)
2139 (set (make-local-variable 'scroll-conservatively) 999)
2140 (setq imenu-create-index-function 'newsticker--imenu-create-index)
2141 (setq imenu-default-goto-function 'newsticker--imenu-goto)
2142 (setq buffer-read-only t)
2143 (auto-fill-mode -1) ;; turn auto-fill off!
2144 (font-lock-mode -1) ;; turn off font-lock!!
2145 (set (make-local-variable 'font-lock-defaults) nil)
2146 (set (make-local-variable 'line-move-ignore-invisible) t)
2147 (setq mode-line-format
2149 'mode-line-mule-info
2151 'mode-line-frame-identification
2153 '(newsticker--buffer-uptodate-p
2157 '(:eval (newsticker--buffer-get-feed-title-at-point))
2159 '(:eval (newsticker--buffer-get-item-title-at-point))
2161 (unless newsticker-show-all-rss-elements
2162 (add-to-invisibility-spec 'extra))
2163 (newsticker--buffer-set-uptodate nil))
2165 ;; refine its mode-map
2166 (define-key newsticker-mode-map "sO" 'newsticker-show-old-items)
2167 (define-key newsticker-mode-map "hO" 'newsticker-hide-old-items)
2168 (define-key newsticker-mode-map "sa" 'newsticker-show-all-desc)
2169 (define-key newsticker-mode-map "ha" 'newsticker-hide-all-desc)
2170 (define-key newsticker-mode-map "sf" 'newsticker-show-feed-desc)
2171 (define-key newsticker-mode-map "hf" 'newsticker-hide-feed-desc)
2172 (define-key newsticker-mode-map "so" 'newsticker-show-old-item-desc)
2173 (define-key newsticker-mode-map "ho" 'newsticker-hide-old-item-desc)
2174 (define-key newsticker-mode-map "sn" 'newsticker-show-new-item-desc)
2175 (define-key newsticker-mode-map "hn" 'newsticker-hide-new-item-desc)
2176 (define-key newsticker-mode-map "se" 'newsticker-show-entry)
2177 (define-key newsticker-mode-map "he" 'newsticker-hide-entry)
2178 (define-key newsticker-mode-map "sx" 'newsticker-show-extra)
2179 (define-key newsticker-mode-map "hx" 'newsticker-hide-extra)
2181 (define-key newsticker-mode-map " " 'scroll-up)
2182 (define-key newsticker-mode-map "q" 'newsticker-close-buffer)
2183 (define-key newsticker-mode-map "p" 'newsticker-previous-item)
2184 (define-key newsticker-mode-map "P" 'newsticker-previous-new-item)
2185 (define-key newsticker-mode-map "F" 'newsticker-previous-feed)
2186 (define-key newsticker-mode-map "\t" 'newsticker-next-item)
2187 (define-key newsticker-mode-map "n" 'newsticker-next-item)
2188 (define-key newsticker-mode-map "N" 'newsticker-next-new-item)
2189 (define-key newsticker-mode-map "f" 'newsticker-next-feed)
2190 (define-key newsticker-mode-map "M" 'newsticker-mark-all-items-as-read)
2191 (define-key newsticker-mode-map "m"
2192 'newsticker-mark-all-items-at-point-as-read)
2193 (define-key newsticker-mode-map "o" 'newsticker-mark-item-at-point-as-read)
2194 (define-key newsticker-mode-map "G" 'newsticker-get-all-news)
2195 (define-key newsticker-mode-map "g" 'newsticker-get-news-at-point)
2196 (define-key newsticker-mode-map "u" 'newsticker-buffer-update)
2197 (define-key newsticker-mode-map "U" 'newsticker-buffer-force-update)
2198 (define-key newsticker-mode-map "a" 'newsticker-add-url)
2200 (define-key newsticker-mode-map "i"
2201 'newsticker-mark-item-at-point-as-immortal)
2203 (define-key newsticker-mode-map "xf" 'newsticker-toggle-auto-narrow-to-feed)
2204 (define-key newsticker-mode-map "xi" 'newsticker-toggle-auto-narrow-to-item)
2206 ;; maps for the clickable portions
2207 (defvar newsticker--url-keymap (make-sparse-keymap)
2208 "Key map for click-able headings in the newsticker buffer.")
2209 (define-key newsticker--url-keymap [mouse-2]
2210 'newsticker-mouse-browse-url)
2211 (define-key newsticker--url-keymap "\n"
2212 'newsticker-browse-url)
2213 (define-key newsticker--url-keymap "\C-m"
2214 'newsticker-browse-url)
2215 (define-key newsticker--url-keymap [(control return)]
2216 'newsticker-handle-url)
2219 (defvar newsticker-menu (make-sparse-keymap "Newsticker"))
2221 (define-key newsticker-menu [newsticker-browse-url]
2222 '("Browse URL for item at point" . newsticker-browse-url))
2223 (define-key newsticker-menu [newsticker-separator-1]
2225 (define-key newsticker-menu [newsticker-buffer-update]
2226 '("Update buffer" . newsticker-buffer-update))
2227 (define-key newsticker-menu [newsticker-separator-2]
2229 (define-key newsticker-menu [newsticker-get-all-news]
2230 '("Get news from all feeds" . newsticker-get-all-news))
2231 (define-key newsticker-menu [newsticker-get-news-at-point]
2232 '("Get news from feed at point" . newsticker-get-news-at-point))
2233 (define-key newsticker-menu [newsticker-separator-3]
2235 (define-key newsticker-menu [newsticker-mark-all-items-as-read]
2236 '("Mark all items as read" . newsticker-mark-all-items-as-read))
2237 (define-key newsticker-menu [newsticker-mark-all-items-at-point-as-read]
2238 '("Mark all items in feed at point as read" .
2239 newsticker-mark-all-items-at-point-as-read))
2240 (define-key newsticker-menu [newsticker-mark-item-at-point-as-read]
2241 '("Mark item at point as read" .
2242 newsticker-mark-item-at-point-as-read))
2243 (define-key newsticker-menu [newsticker-mark-item-at-point-as-immortal]
2244 '("Toggle immortality for item at point" .
2245 newsticker-mark-item-at-point-as-immortal))
2246 (define-key newsticker-menu [newsticker-separator-4]
2248 (define-key newsticker-menu [newsticker-hide-old-items]
2249 '("Hide old items" . newsticker-hide-old-items))
2250 (define-key newsticker-menu [newsticker-show-old-items]
2251 '("Show old items" . newsticker-show-old-items))
2252 (define-key newsticker-menu [newsticker-next-item]
2253 '("Go to next item" . newsticker-next-item))
2254 (define-key newsticker-menu [newsticker-previous-item]
2255 '("Go to previous item" . newsticker-previous-item))
2257 ;; bind menu to mouse
2258 (define-key newsticker-mode-map [down-mouse-3] newsticker-menu)
2259 ;; Put menu in menu-bar
2260 (define-key newsticker-mode-map [menu-bar Newsticker]
2261 (cons "Newsticker" newsticker-menu))
2264 ;; ======================================================================
2266 ;; ======================================================================
2267 (defsubst newsticker--title (item)
2268 "Return title of ITEM."
2270 (defsubst newsticker--desc (item)
2271 "Return description of ITEM."
2273 (defsubst newsticker--link (item)
2274 "Return link of ITEM."
2276 (defsubst newsticker--time (item)
2277 "Return time of ITEM."
2279 (defsubst newsticker--age (item)
2280 "Return age of ITEM."
2282 (defsubst newsticker--pos (item)
2283 "Return position/index of ITEM."
2285 (defsubst newsticker--preformatted-contents (item)
2286 "Return pre-formatted text of ITEM."
2288 (defsubst newsticker--preformatted-title (item)
2289 "Return pre-formatted title of ITEM."
2291 (defsubst newsticker--extra (item)
2292 "Return extra attributes of ITEM."
2294 (defsubst newsticker--guid (item)
2295 "Return guid of ITEM."
2296 (let ((guid (assoc 'guid (newsticker--extra item))))
2299 (car (xml-node-children guid)))))
2300 (defsubst newsticker--enclosure (item)
2301 "Return enclosure element of ITEM in the form \(...FIXME...\)or nil."
2302 (let ((enclosure (assoc 'enclosure (newsticker--extra item))))
2304 (xml-node-attributes enclosure))))
2306 ;; ======================================================================
2308 ;; ======================================================================
2310 (defun newsticker-start (&optional do-not-complain-if-running)
2311 "Start the newsticker.
2312 Start the timers for display and retrieval. If the newsticker, i.e. the
2313 timers, are running already a warning message is printed unless
2314 DO-NOT-COMPLAIN-IF-RUNNING is not nil.
2315 Run `newsticker-start-hook' if newsticker was not running already."
2317 (let ((running (newsticker-running-p)))
2318 ;; read old cache if it exists and newsticker is not running
2320 (let* ((coding-system-for-read 'utf-8)
2321 (buf (find-file-noselect newsticker-cache-filename)))
2324 (goto-char (point-min))
2326 (setq newsticker--cache (read buf))
2328 (message "Error while reading newsticker cache file!")
2329 (setq newsticker--cache nil))))))
2330 ;; start retrieval timers -- for sake of simplicity we will start
2331 ;; one timer for each feed
2332 (mapc (lambda (item)
2333 (let* ((feed-name (car item))
2334 (start-time (nth 2 item))
2335 (interval (or (nth 3 item)
2336 newsticker-retrieval-interval))
2337 (timer (assoc (car item)
2338 newsticker--retrieval-timer-list)))
2340 (or do-not-complain-if-running
2341 (message "Timer for %s is running already!"
2343 (newsticker--debug-msg "Starting timer for %s: %s, %d"
2344 feed-name start-time interval)
2345 ;; do not repeat retrieval if interval not positive
2347 (setq interval nil))
2348 ;; Suddenly XEmacs doesn't like start-time 0
2349 (if (or (not start-time)
2350 (and (numberp start-time) (= start-time 0)))
2351 (setq start-time 1))
2352 (message "start-time %s" start-time)
2353 (setq timer (run-at-time start-time interval
2354 'newsticker-get-news feed-name))
2356 (add-to-list 'newsticker--retrieval-timer-list
2357 (cons feed-name timer))))))
2358 (append newsticker-url-list-defaults newsticker-url-list))
2360 (run-hooks 'newsticker-start-hook)
2361 (message "Newsticker started!"))))
2363 (defun newsticker-start-ticker ()
2364 "Start newsticker's ticker (but not the news retrieval.
2365 Start display timer for the actual ticker if wanted and not
2368 (if (and (> newsticker-display-interval 0)
2369 (not newsticker--display-timer))
2370 (setq newsticker--display-timer
2371 (run-at-time newsticker-display-interval
2372 newsticker-display-interval
2373 'newsticker--display-tick))))
2375 (defun newsticker-stop ()
2376 "Stop the newsticker and the newsticker-ticker.
2377 Cancel the timers for display and retrieval. Run `newsticker-stop-hook'
2378 if newsticker has been running."
2380 (newsticker--cache-update t)
2381 (newsticker-stop-ticker)
2382 (when (newsticker-running-p)
2383 (mapc (lambda (name-and-timer)
2384 (cancel-timer (cdr name-and-timer)))
2385 newsticker--retrieval-timer-list)
2386 (setq newsticker--retrieval-timer-list nil)
2387 (run-hooks 'newsticker-stop-hook)
2388 (message "Newsticker stopped!")))
2390 (defun newsticker-stop-ticker ()
2391 "Stop newsticker's ticker (but not the news retrieval)."
2393 (when newsticker--display-timer
2394 (cancel-timer newsticker--display-timer)
2395 (setq newsticker--display-timer nil)))
2397 ;; the functions we need for retrieval and display
2398 (defun newsticker-show-news ()
2399 "Switch to newsticker buffer. You may want to bind this to a key."
2401 (newsticker-start t) ;; will start only if not running
2402 (newsticker-buffer-update)
2403 (switch-to-buffer "*newsticker*"))
2405 (defun newsticker-buffer-force-update ()
2406 "Update the newsticker buffer, even if not necessary."
2408 (newsticker-buffer-update t))
2410 (defun newsticker-buffer-update (&optional force)
2411 "Update the *newsticker* buffer.
2412 Unless FORCE is t this is donly only if necessary, i.e. when the
2413 *newsticker* buffer is not up-to-date."
2415 ;; bring cache data into proper order....
2416 (newsticker--cache-sort)
2419 (let ((buf (get-buffer "*newsticker*")))
2421 (switch-to-buffer buf)
2422 (switch-to-buffer (get-buffer-create "*newsticker*"))
2423 (newsticker--buffer-set-uptodate nil)))
2425 (not newsticker--buffer-uptodate-p))
2426 (message "Preparing newsticker buffer...")
2427 (setq buffer-undo-list t)
2428 (let ((inhibit-read-only t))
2429 (set-buffer-modified-p nil)
2432 ;; Emacs 21.3.50 does not care if we turn off auto-fill in the
2433 ;; definition of newsticker-mode, so we do it here (again)
2436 (set-buffer-file-coding-system 'utf-8)
2438 (if newsticker-use-full-width
2439 (set (make-local-variable 'fill-column) (1- (window-width))))
2440 (newsticker--buffer-insert-all-items)
2442 ;; FIXME: needed for methods buffer in ecb
2443 ;; (set-visited-file-name "*newsticker*")
2445 (set-buffer-modified-p nil)
2446 (newsticker-hide-all-desc)
2447 (if newsticker-hide-old-items-in-newsticker-buffer
2448 (newsticker-hide-old-items))
2449 (if newsticker-show-descriptions-of-new-items
2450 (newsticker-show-new-item-desc))
2453 (newsticker--buffer-set-uptodate t)
2454 (run-hooks 'newsticker-buffer-change-hook)))
2456 (defun newsticker-get-all-news ()
2457 "Launch retrieval of news from all configured newsticker sites.
2458 This does NOT start the retrieval timers."
2460 ;; launch retrieval of news
2461 (mapc (lambda (item)
2462 (newsticker-get-news (car item)))
2463 (append newsticker-url-list-defaults newsticker-url-list)))
2465 (defun newsticker-get-news-at-point ()
2466 "Launch retrieval of news for the feed point is in.
2467 This does NOT start the retrieval timers."
2469 ;; launch retrieval of news
2470 (let ((feed (get-text-property (point) 'feed)))
2472 (newsticker--debug-msg "Getting news for %s" (symbol-name feed))
2473 (newsticker-get-news (symbol-name feed)))))
2475 (defun newsticker-add-url (url name)
2476 "Add given URL under given NAME to `newsticker-url-list'.
2477 If URL is nil it is searched at point."
2480 (read-string "URL: "
2486 (if (> (point) (+ (point-min) 100))
2491 "http://[-a-zA-Z0-9&/_.]*"
2492 (if (< (point) (- (point-max) 200))
2496 (buffer-substring-no-properties (match-beginning 0)
2498 (read-string "Name: ")))
2499 (add-to-list 'newsticker-url-list (list name url nil nil nil) t)
2500 (customize-variable 'newsticker-url-list))
2502 (defun newsticker-w3m-show-inline-images ()
2503 "Show inline images in visible text ranges.
2504 In-line images in invisible text ranges are hidden. This function
2505 calls `w3m-toggle-inline-image'. It works only if
2506 `newsticker-html-renderer' is set to `w3m-region'"
2508 (if (eq newsticker-html-renderer 'w3m-region)
2509 (let ((inhibit-read-only t))
2513 (goto-char (point-min))
2514 (let ((pos (point)))
2516 (setq pos (next-single-property-change pos 'w3m-image))
2519 (when (get-text-property pos 'w3m-image)
2520 (let ((invis (newsticker--lists-intersect-p
2521 (get-text-property (1- (point)) 'invisible)
2522 buffer-invisibility-spec)))
2525 pos (next-single-property-change pos 'w3m-image))
2526 (w3m-toggle-inline-image t))))))))))))
2528 ;; ======================================================================
2530 ;; ======================================================================
2531 (defun newsticker-close-buffer ()
2532 "Close the newsticker buffer."
2534 (newsticker--cache-update t)
2537 (defun newsticker-next-new-item (&optional do-not-wrap-at-eob)
2538 "Go to next new news item.
2539 If no new item is found behind point, search is continued at
2540 beginning of buffer unless optional argument DO-NOT-WRAP-AT-EOB
2546 (unless (newsticker--buffer-goto '(item) 'new)
2547 ;; found nothing -- wrap
2548 (unless do-not-wrap-at-eob
2549 (goto-char (point-min))
2550 (newsticker-next-new-item t))
2551 (setq go-ahead nil))
2552 (unless (newsticker--lists-intersect-p
2553 (get-text-property (point) 'invisible)
2554 buffer-invisibility-spec)
2555 ;; this item is invisible -- continue search
2556 (setq go-ahead nil))))
2557 (run-hooks 'newsticker-select-item-hook)
2560 (defun newsticker-previous-new-item (&optional do-not-wrap-at-bob)
2561 "Go to previous new news item.
2562 If no new item is found before point, search is continued at
2563 beginning of buffer unless optional argument DO-NOT-WRAP-AT-BOB
2569 (unless (newsticker--buffer-goto '(item) 'new t)
2570 (unless do-not-wrap-at-bob
2571 (goto-char (point-max))
2572 (newsticker--buffer-goto '(item) 'new t)))
2573 (unless (newsticker--lists-intersect-p
2574 (get-text-property (point) 'invisible)
2575 buffer-invisibility-spec)
2576 (setq go-ahead nil))))
2577 (run-hooks 'newsticker-select-item-hook)
2580 (defun newsticker-next-item (&optional do-not-wrap-at-eob)
2581 "Go to next news item.
2582 Return new buffer position.
2583 If no item is found below point, search is continued at beginning
2584 of buffer unless optional argument DO-NOT-WRAP-AT-EOB is
2589 (search-list '(item)))
2590 (if newsticker--auto-narrow-to-item
2591 (setq search-list '(item feed)))
2593 (unless (newsticker--buffer-goto search-list)
2594 ;; found nothing -- wrap
2595 (unless do-not-wrap-at-eob
2596 (goto-char (point-min)))
2597 (setq go-ahead nil))
2598 (unless (newsticker--lists-intersect-p
2599 (get-text-property (point) 'invisible)
2600 buffer-invisibility-spec)
2601 (setq go-ahead nil))))
2602 (run-hooks 'newsticker-select-item-hook)
2605 (defun newsticker-previous-item (&optional do-not-wrap-at-bob)
2606 "Go to previous news item.
2607 Return new buffer position.
2608 If no item is found before point, search is continued at
2609 beginning of buffer unless optional argument DO-NOT-WRAP-AT-BOB
2614 (search-list '(item)))
2615 (if newsticker--auto-narrow-to-item
2616 (setq search-list '(item feed)))
2618 (unless do-not-wrap-at-bob
2619 (goto-char (point-max))))
2621 (if (newsticker--buffer-goto search-list nil t)
2622 (unless (newsticker--lists-intersect-p
2623 (get-text-property (point) 'invisible)
2624 buffer-invisibility-spec)
2625 (setq go-ahead nil))
2626 (goto-char (point-min))
2627 (setq go-ahead nil))))
2628 (run-hooks 'newsticker-select-item-hook)
2631 (defun newsticker-next-feed ()
2632 "Go to next news feed.
2633 Return new buffer position."
2636 (newsticker--buffer-goto '(feed))
2637 (run-hooks 'newsticker-select-feed-hook)
2640 (defun newsticker-previous-feed ()
2641 "Go to previous news feed.
2642 Return new buffer position."
2645 (newsticker--buffer-goto '(feed) nil t)
2646 (run-hooks 'newsticker-select-feed-hook)
2649 (defun newsticker-mark-all-items-at-point-as-read ()
2650 "Mark all items as read and clear ticker contents."
2652 (when (or newsticker--buffer-uptodate-p
2654 "Buffer is not up to date -- really mark items as read? "))
2655 (let ((feed (get-text-property (point) 'feed))
2658 (message "Marking all items as read for %s" (symbol-name feed))
2659 (newsticker--cache-replace-age newsticker--cache feed 'new 'old)
2660 (newsticker--cache-replace-age newsticker--cache feed 'obsolete 'old)
2661 (newsticker--cache-update)
2662 (newsticker--buffer-set-uptodate nil)
2663 (newsticker--ticker-text-setup)
2664 (newsticker-buffer-update)
2665 ;; go back to where we came frome
2668 (newsticker--buffer-goto '(feed) nil t)))))
2670 (defun newsticker-mark-item-at-point-as-read (&optional respect-immortality)
2671 "Mark item at point as read.
2672 If optional argument RESPECT-IMMORTALITY is not nil immortal items do
2675 (when (or newsticker--buffer-uptodate-p
2677 "Buffer is not up to date -- really mark this item as read? "))
2678 (let ((feed (get-text-property (point) 'feed))
2682 (newsticker--buffer-beginning-of-item)
2683 (let ((inhibit-read-only t)
2684 (age (get-text-property (point) 'nt-age))
2685 (title (get-text-property (point) 'nt-title))
2686 (guid (get-text-property (point) 'nt-guid))
2687 (nt-desc (get-text-property (point) 'nt-desc))
2688 (pos (save-excursion (newsticker--buffer-end-of-item))))
2689 (when (or (eq age 'new)
2691 (and (eq age 'immortal)
2692 (not respect-immortality)))
2694 (setq item (newsticker--cache-contains newsticker--cache
2699 (setcar (nthcdr 4 item) 'old)
2700 (newsticker--do-forget-preformatted item))
2702 (if (or (and (eq age 'new)
2703 newsticker-hide-immortal-items-in-echo-area)
2704 (and (memq age '(old immortal))
2706 (eq newsticker-hide-old-items-in-newsticker-buffer
2707 newsticker-hide-immortal-items-in-echo-area))))
2708 (newsticker--ticker-text-remove feed title))
2713 (put-text-property (point) pos 'nt-age 'old)
2714 (newsticker--buffer-set-faces (point) pos)))
2715 (set-buffer-modified-p nil))))
2717 (newsticker-next-item t)))))
2719 (defun newsticker-mark-item-at-point-as-immortal ()
2720 "Mark item at point as read."
2722 (when (or newsticker--buffer-uptodate-p
2724 "Buffer is not up to date -- really mark this item as read? "))
2725 (let ((feed (get-text-property (point) 'feed))
2729 (newsticker--buffer-beginning-of-item)
2730 (let ((inhibit-read-only t)
2731 (oldage (get-text-property (point) 'nt-age))
2732 (title (get-text-property (point) 'nt-title))
2733 (guid (get-text-property (point) 'nt-guid))
2734 (pos (save-excursion (newsticker--buffer-end-of-item))))
2735 (let ((newage 'immortal))
2736 (if (eq oldage 'immortal)
2738 (setq item (newsticker--cache-contains newsticker--cache
2739 feed title nil nil nil
2743 (setcar (nthcdr 4 item) newage)
2744 (newsticker--do-forget-preformatted item))
2745 (if (or (and (eq newage 'immortal)
2746 newsticker-hide-immortal-items-in-echo-area)
2747 (and (eq newage 'obsolete)
2748 newsticker-hide-obsolete-items-in-echo-area)
2749 (and (eq oldage 'immortal)
2751 (eq newsticker-hide-old-items-in-newsticker-buffer
2752 newsticker-hide-immortal-items-in-echo-area))))
2753 (newsticker--ticker-text-remove feed title)
2754 (newsticker--ticker-text-setup))
2758 (put-text-property (point) pos 'nt-age newage)
2759 (if (eq newage 'immortal)
2760 (put-text-property (point) pos 'nt-age 'immortal)
2761 (put-text-property (point) pos 'nt-age 'old))
2762 (newsticker--buffer-set-faces (point) pos))))))
2764 (newsticker-next-item t))))))
2766 (defun newsticker-mark-all-items-as-read ()
2767 "Mark all items as read and clear ticker contents."
2769 (when (or newsticker--buffer-uptodate-p
2771 "Buffer is not up to date -- really mark items as read? "))
2772 (newsticker--cache-replace-age newsticker--cache 'any 'new 'old)
2773 (newsticker--buffer-set-uptodate nil)
2774 (newsticker--ticker-text-setup)
2775 (newsticker--cache-update)
2776 (newsticker-buffer-update)))
2778 (defun newsticker-hide-extra ()
2779 "Hide the extra elements of items."
2781 (newsticker--buffer-hideshow 'extra nil)
2782 (newsticker--buffer-redraw))
2784 (defun newsticker-show-extra ()
2785 "Show the extra elements of items."
2787 (newsticker--buffer-hideshow 'extra t)
2788 (newsticker--buffer-redraw))
2790 (defun newsticker-hide-old-item-desc ()
2791 "Hide the description of old items."
2793 (newsticker--buffer-hideshow 'desc-old nil)
2794 (newsticker--buffer-redraw))
2796 (defun newsticker-show-old-item-desc ()
2797 "Show the description of old items."
2799 (newsticker--buffer-hideshow 'item-old t)
2800 (newsticker--buffer-hideshow 'desc-old t)
2801 (newsticker--buffer-redraw))
2803 (defun newsticker-hide-new-item-desc ()
2804 "Hide the description of new items."
2806 (newsticker--buffer-hideshow 'desc-new nil)
2807 (newsticker--buffer-hideshow 'desc-immortal nil)
2808 (newsticker--buffer-hideshow 'desc-obsolete nil)
2809 (newsticker--buffer-redraw))
2811 (defun newsticker-show-new-item-desc ()
2812 "Show the description of new items."
2814 (newsticker--buffer-hideshow 'desc-new t)
2815 (newsticker--buffer-hideshow 'desc-immortal t)
2816 (newsticker--buffer-hideshow 'desc-obsolete t)
2817 (newsticker--buffer-redraw))
2819 (defun newsticker-hide-feed-desc ()
2820 "Hide the description of feeds."
2822 (newsticker--buffer-hideshow 'desc-feed nil)
2823 (newsticker--buffer-redraw))
2825 (defun newsticker-show-feed-desc ()
2826 "Show the description of old items."
2828 (newsticker--buffer-hideshow 'desc-feed t)
2829 (newsticker--buffer-redraw))
2831 (defun newsticker-hide-all-desc ()
2832 "Hide the descriptions of feeds and all items."
2834 (newsticker--buffer-hideshow 'desc-feed nil)
2835 (newsticker--buffer-hideshow 'desc-immortal nil)
2836 (newsticker--buffer-hideshow 'desc-obsolete nil)
2837 (newsticker--buffer-hideshow 'desc-new nil)
2838 (newsticker--buffer-hideshow 'desc-old nil)
2839 (newsticker--buffer-redraw))
2841 (defun newsticker-show-all-desc ()
2842 "Show the descriptions of feeds and all items."
2844 (newsticker--buffer-hideshow 'desc-feed t)
2845 (newsticker--buffer-hideshow 'desc-immortal t)
2846 (newsticker--buffer-hideshow 'desc-obsolete t)
2847 (newsticker--buffer-hideshow 'desc-new t)
2848 (newsticker--buffer-hideshow 'desc-old t)
2849 (newsticker--buffer-redraw))
2851 (defun newsticker-hide-old-items ()
2854 (newsticker--buffer-hideshow 'desc-old nil)
2855 (newsticker--buffer-hideshow 'item-old nil)
2856 (newsticker--buffer-redraw))
2858 (defun newsticker-show-old-items ()
2861 (newsticker--buffer-hideshow 'desc-old t)
2862 (newsticker--buffer-hideshow 'item-old t)
2863 (newsticker--buffer-redraw))
2865 (defun newsticker-hide-entry ()
2866 "Hide description of entry at point."
2870 (inhibit-read-only t)
2871 inv-prop org-inv-prop
2873 (newsticker--buffer-beginning-of-item)
2874 (newsticker--buffer-goto '(desc))
2875 (setq pos1 (max (point-min) (1- (point))))
2876 (newsticker--buffer-goto '(extra feed item))
2877 (setq pos2 (max (point-min) (1- (point))))
2878 (setq inv-prop (get-text-property pos1 'invisible))
2879 (setq org-inv-prop (get-text-property pos1 'org-invisible))
2880 (cond ((eq inv-prop t)
2883 ((eq org-inv-prop nil)
2884 (add-text-properties pos1 pos2 (list 'invisible t
2885 'org-invisible inv-prop)))
2888 (add-text-properties pos1 pos2 (list 'invisible org-inv-prop))
2889 (remove-text-properties pos1 pos2 '(org-invisible))))))
2890 (newsticker--buffer-redraw))
2892 (defun newsticker-show-entry ()
2893 "Show description of entry at point."
2897 (inhibit-read-only t)
2898 inv-prop org-inv-prop
2900 (newsticker--buffer-beginning-of-item)
2901 (newsticker--buffer-goto '(desc))
2902 (setq pos1 (max (point-min) (1- (point))))
2903 (newsticker--buffer-goto '(extra feed item))
2904 (setq pos2 (max (point-min) (1- (point))))
2905 (setq inv-prop (get-text-property pos1 'invisible))
2906 (setq org-inv-prop (get-text-property pos1 'org-invisible))
2907 (cond ((eq org-inv-prop nil)
2908 (add-text-properties pos1 pos2 (list 'invisible nil
2909 'org-invisible inv-prop)))
2912 (add-text-properties pos1 pos2 (list 'invisible org-inv-prop))
2913 (remove-text-properties pos1 pos2 '(org-invisible))))))
2914 (newsticker--buffer-redraw))
2916 (defun newsticker-toggle-auto-narrow-to-feed ()
2917 "Toggle narrowing to current news feed.
2918 If auto-narrowing is active, only news item of the current feed
2921 (newsticker-set-auto-narrow-to-feed (not newsticker--auto-narrow-to-feed)))
2923 (defun newsticker-set-auto-narrow-to-feed (value)
2924 "Turn narrowing to current news feed on or off.
2925 If VALUE is nil, auto-narrowing is turned off, otherwise it is turned on."
2927 (setq newsticker--auto-narrow-to-item nil)
2928 (setq newsticker--auto-narrow-to-feed value)
2930 (run-hooks 'newsticker-narrow-hook))
2932 (defun newsticker-toggle-auto-narrow-to-item ()
2933 "Toggle narrowing to current news item.
2934 If auto-narrowing is active, only one item of the current feed
2937 (newsticker-set-auto-narrow-to-item (not newsticker--auto-narrow-to-item)))
2939 (defun newsticker-set-auto-narrow-to-item (value)
2940 "Turn narrowing to current news item on or off.
2941 If VALUE is nil, auto-narrowing is turned off, otherwise it is turned on."
2943 (setq newsticker--auto-narrow-to-feed nil)
2944 (setq newsticker--auto-narrow-to-item value)
2946 (run-hooks 'newsticker-narrow-hook))
2948 (defun newsticker-customize ()
2949 "Open the newsticker customization group."
2951 (customize-group "newsticker"))
2953 (defun newsticker-next-feed-available-p ()
2954 "Return t if position is before last feed, nil otherwise."
2957 (newsticker--buffer-goto '(feed))
2958 (not (= p (point))))))
2960 (defun newsticker-previous-feed-available-p ()
2961 "Return t if position is behind first feed, nil otherwise."
2964 (newsticker--buffer-goto '(feed) nil t)
2965 (not (= p (point))))))
2967 (defun newsticker-next-item-available-p ()
2968 "Return t if position is before last feed, nil otherwise."
2971 (while (< (point) (point-max))
2972 (unless (newsticker--buffer-goto '(item))
2973 (throw 'result nil))
2974 (unless (newsticker--lists-intersect-p
2975 (get-text-property (point) 'invisible)
2976 buffer-invisibility-spec)
2977 (throw 'result t))))))
2979 (defun newsticker-previous-item-available-p ()
2980 "Return t if position is behind first item, nil otherwise."
2983 (while (> (point) (point-min))
2984 (unless (newsticker--buffer-goto '(item) nil t)
2985 (throw 'result nil))
2986 (unless (newsticker--lists-intersect-p
2987 (get-text-property (point) 'invisible)
2988 buffer-invisibility-spec)
2989 (throw 'result t))))))
2991 (defun newsticker-item-not-old-p ()
2992 "Return t if there is an item at point which is not old, nil otherwise."
2993 (when (get-text-property (point) 'feed)
2995 (newsticker--buffer-beginning-of-item)
2996 (let ((age (get-text-property (point) 'nt-age)))
2997 (and (memq age '(new immortal obsolete)) t)))))
2999 (defun newsticker-item-not-immortal-p ()
3000 "Return t if there is an item at point which is not immortal, nil otherwise."
3001 (when (get-text-property (point) 'feed)
3003 (newsticker--buffer-beginning-of-item)
3004 (let ((age (get-text-property (point) 'nt-age)))
3005 (and (memq age '(new old obsolete)) t)))))
3007 ;; ======================================================================
3009 ;; ======================================================================
3010 (defun newsticker-running-p ()
3011 "Check whether newsticker is running.
3012 Return t if newsticker is running, nil otherwise. Newsticker is
3013 considered to be running if the newsticker timer list is not empty."
3014 (> (length newsticker--retrieval-timer-list) 0))
3016 (defun newsticker-ticker-running-p ()
3017 "Check whether newsticker's actual ticker is running.
3018 Return t if ticker is running, nil otherwise. Newsticker is
3019 considered to be running if the newsticker timer list is not
3021 (timerp newsticker--display-timer))
3023 ;; ======================================================================
3025 ;; ======================================================================
3026 (defun newsticker-get-news (feed-name)
3027 "Get news from the site FEED-NAME and load feed logo.
3028 FEED-NAME must be a string which occurs as the label (i.e. the first element)
3029 in an element of `newsticker-url-list' or `newsticker-url-list-defaults'."
3030 (newsticker--debug-msg "%s: Getting news for %s"
3031 (format-time-string "%A, %H:%M" (current-time))
3033 (let* ((buffername (concat " *newsticker-wget-" feed-name "*"))
3034 (item (or (assoc feed-name newsticker-url-list)
3035 (assoc feed-name newsticker-url-list-defaults)
3037 "Cannot get news for %s: Check newsticker-url-list"
3040 (wget-arguments (or (car (cdr (cdr (cdr (cdr item)))))
3041 newsticker-wget-arguments)))
3043 (set-buffer (get-buffer-create buffername))
3045 ;; throw an error if there is an old wget-process around
3046 (if (get-process feed-name)
3047 (error "Another wget-process is running for %s" feed-name))
3049 (let* ((args (append wget-arguments (list url)))
3050 (proc (apply 'start-process feed-name buffername
3051 newsticker-wget-name args)))
3052 (set-process-coding-system proc 'no-conversion 'no-conversion)
3053 (set-process-sentinel proc 'newsticker--sentinel)))))
3056 (defun newsticker-mouse-browse-url (event)
3057 "Call `browse-url' for the link of the item at which the EVENT occurred."
3060 (switch-to-buffer (window-buffer (posn-window (event-end event))))
3061 (let ((url (get-text-property (posn-point (event-end event))
3066 (goto-char (posn-point (event-end event)))
3067 (if newsticker-automatically-mark-visited-items-as-old
3068 (newsticker-mark-item-at-point-as-read t)))))))
3070 (defun newsticker-browse-url ()
3071 "Call `browse-url' for the link of the item at point."
3073 (let ((url (get-text-property (point) 'nt-link)))
3076 (if newsticker-automatically-mark-visited-items-as-old
3077 (newsticker-mark-item-at-point-as-read t)))))
3079 (defvar newsticker-open-url-history
3080 '("wget" "xmms" "realplay")
3083 (defun newsticker-handle-url ()
3084 "Ask for a program to open the link of the item at point."
3086 (let ((url (get-text-property (point) 'nt-link)))
3088 (let ((prog (read-string "Open url with: " nil
3089 'newsticker-open-url-history)))
3091 (message "%s %s" prog url)
3092 (start-process prog prog prog url)
3093 (if newsticker-automatically-mark-visited-items-as-old
3094 (newsticker-mark-item-at-point-as-read t)))))))
3096 (defun newsticker--sentinel (process event)
3097 "Sentinel for extracting news titles from an RDF buffer.
3098 Argument PROCESS is the process which has just changed its state.
3099 Argument EVENT tells what has happened to the process."
3100 (let* ((p-status (process-status process))
3101 (exit-status (process-exit-status process))
3102 (time (current-time))
3103 (name (process-name process))
3104 (name-symbol (intern name))
3105 (something-was-added nil))
3106 ;; catch known errors (zombie processes, rubbish-xml etc.
3107 ;; if an error occurs the news feed is not updated!
3109 (unless (and (eq p-status 'exit)
3111 (setq newsticker--cache
3112 (newsticker--cache-add
3115 newsticker--error-headline
3117 (concat "%s: Newsticker could not retrieve news from %s.\n"
3118 "Return status: `%s'\n"
3120 (format-time-string "%A, %H:%M" (current-time))
3121 name event (process-command process))
3126 (message "%s: Error while retrieving news from %s"
3127 (format-time-string "%A, %H:%M" (current-time))
3128 (process-name process))
3130 (let* ((coding-system nil)
3132 (save-current-buffer
3133 (set-buffer (process-buffer process))
3134 ;; a very very dirty workaround to overcome the
3135 ;; problems with the newest (20030621) xml.el:
3136 ;; remove all unnecessary whitespace
3137 (goto-char (point-min))
3138 (while (re-search-forward ">[ \t\r\n]+<" nil t)
3139 (replace-match "><" nil t))
3140 ;; and another brutal workaround (20031105)! For some
3141 ;; reason the xml parser does not like the colon in the
3142 ;; doctype name "rdf:RDF"
3143 (goto-char (point-min))
3144 (if (re-search-forward "<!DOCTYPE[ \t\n]+rdf:RDF" nil t)
3145 (replace-match "<!DOCTYPE rdfColonRDF" nil t))
3146 ;; finally.... ~##^°!!!!!
3147 (goto-char (point-min))
3148 (while (search-forward "\r\n" nil t)
3149 (replace-match "\n" nil t))
3150 ;; still more brutal workarounds (20040309)! The xml
3151 ;; parser does not like doctype rss
3152 (goto-char (point-min))
3153 (if (re-search-forward "<!DOCTYPE[ \t\n]+rss[ \t\n]*>" nil t)
3154 (replace-match "" nil t))
3155 ;; And another one (20050618)! (Fixed in GNU Emacs 22.0.50.18)
3156 ;; Remove comments to avoid this xml-parsing bug:
3157 ;; "XML files can have only one toplevel tag"
3158 (goto-char (point-min))
3159 (while (search-forward "<!--" nil t)
3160 (let ((start (match-beginning 0)))
3161 (unless (search-forward "-->" nil t)
3162 (error "Can't find end of comment"))
3163 (delete-region start (point))))
3164 ;; And another one (20050702)! If description is HTML
3165 ;; encoded and starts with a `<', wrap the whole
3166 ;; description in a CDATA expression. This happened for
3167 ;; http://www.thefreedictionary.com/_/WoD/rss.aspx?type=quote
3168 (goto-char (point-min))
3169 (while (re-search-forward
3170 "<description>\\(<img.*?\\)</description>" nil t)
3172 "<description><![CDATA[ \\1 ]]></description>"))
3174 (set-buffer-modified-p nil)
3175 (goto-char (point-min))
3176 (if (re-search-forward "encoding=\"\\([^\"]+\\)\""
3178 (setq coding-system (intern
3179 (downcase(match-string 1)))))
3180 (condition-case errordata
3181 ;; The xml parser might fail
3182 ;; or the xml might be bugged
3183 (xml-parse-region (point-min) (point-max))
3184 (error (message "Could not parse %s: %s"
3185 (buffer-name) (cadr errordata))
3186 (throw 'oops nil)))))
3187 (topnode (car node-list))
3188 (channelnode (car (xml-get-children topnode 'channel)))
3191 ;; mark all items as obsolete
3192 (newsticker--cache-replace-age newsticker--cache
3195 (newsticker--cache-replace-age newsticker--cache
3198 (newsticker--cache-replace-age newsticker--cache
3200 'feed 'obsolete-old)
3202 (if (eq (xml-node-name topnode) 'rss)
3203 ;; this is RSS 0.91 or something similar
3204 ;; all items are inside the channel node
3205 (setq topnode channelnode))
3207 (car (xml-node-children
3208 (car (xml-get-children
3209 (car (xml-get-children
3213 (let ((title (or (car (xml-node-children (car (xml-get-children
3214 channelnode 'title))))
3216 (link (or (car (xml-node-children (car (xml-get-children
3217 channelnode 'link))))
3219 (desc (or (car (xml-node-children (car (xml-get-children
3221 'content:encoded))))
3222 (car (xml-node-children (car (xml-get-children
3225 "[No description available]"))
3227 ;; check coding system
3230 (check-coding-system coding-system)
3231 (coding-system-error
3232 (message "newsticker.el: %s %s %s %s"
3233 "ignoring coding system "
3238 ;; apply coding system
3240 (setq title (newsticker--decode-coding-string title coding-system))
3242 (setq desc (newsticker--decode-coding-string desc
3244 (setq link (newsticker--decode-coding-string link coding-system)))
3245 ;; decode numeric entities
3246 (setq title (newsticker--decode-numeric-entities title))
3247 (setq desc (newsticker--decode-numeric-entities desc))
3248 (setq link (newsticker--decode-numeric-entities link))
3249 ;; remove whitespace from title, desc, and link
3250 (setq title (newsticker--remove-whitespace title))
3251 (setq desc (newsticker--remove-whitespace desc))
3252 (setq link (newsticker--remove-whitespace link))
3254 ;; handle the feed itself
3255 (unless (newsticker--cache-contains newsticker--cache
3258 (setq something-was-added t))
3259 (setq newsticker--cache
3260 (newsticker--cache-add
3261 newsticker--cache name-symbol
3262 title desc link time 'feed position
3263 (xml-node-children channelnode)
3265 ;; gather all items for this feed
3266 (mapc (lambda (node)
3267 (when (eq (xml-node-name node) 'item)
3268 (setq position (1+ position))
3269 (setq title (or (car (xml-node-children
3270 (car (xml-get-children
3273 (setq link (or (car (xml-node-children
3274 (car (xml-get-children
3278 (car (xml-node-children
3279 (car (xml-get-children
3280 node 'content:encoded))))
3281 (car (xml-node-children
3282 (car (xml-get-children
3283 node 'description))))))
3284 ;; use pubDate value if present
3285 (setq time (or (newsticker--decode-rfc822-date
3286 (car (xml-node-children
3287 (car (xml-get-children
3290 ;; use dc:date value if present
3291 (setq time (or (newsticker--decode-iso8601-date
3292 (car (xml-node-children
3293 (car (xml-get-children
3296 ;; It happened that the title or description
3297 ;; contained evil HTML code that confused the
3298 ;; xml parser. Therefore:
3299 (unless (stringp title)
3300 (setq title (prin1-to-string title)))
3301 (unless (or (stringp desc) (not desc))
3302 (setq desc (prin1-to-string desc)))
3303 ;; ignore items with empty title AND empty desc
3304 (when (or (> (length title) 0)
3305 (> (length desc) 0))
3306 ;; apply coding system
3308 (setq title (newsticker--decode-coding-string
3309 title coding-system))
3311 (setq desc (newsticker--decode-coding-string desc
3313 (setq link (newsticker--decode-coding-string
3314 link coding-system)))
3315 ;; decode numeric entities
3316 (setq title (newsticker--decode-numeric-entities title))
3318 (setq desc (newsticker--decode-numeric-entities desc)))
3319 (setq link (newsticker--decode-numeric-entities link))
3320 ;; remove whitespace from title, desc, and link
3321 (setq title (newsticker--remove-whitespace title))
3322 (setq desc (newsticker--remove-whitespace desc))
3323 (setq link (newsticker--remove-whitespace link))
3324 ;; add data to cache
3325 ;; do we have this item already?
3326 (let* ((tguid (assoc 'guid (xml-node-children node)))
3327 (guid (if (stringp tguid)
3329 (car (xml-node-children tguid)))))
3330 ;;(message "guid=%s" guid)
3332 (newsticker--cache-contains newsticker--cache
3334 desc link nil guid)))
3335 ;; add this item, or mark it as old, or do nothing
3340 (let ((prev-age (newsticker--age old-item)))
3342 newsticker-automatically-mark-items-as-old
3343 (if (eq prev-age 'obsolete-old)
3346 (if (eq prev-age 'immortal)
3347 (setq age2 'immortal)))
3348 ;; item was not there
3350 (setq something-was-added t))
3351 (setq newsticker--cache
3352 (newsticker--cache-add
3353 newsticker--cache name-symbol title desc link
3354 time age1 position (xml-node-children node)
3357 (let ((item (newsticker--cache-contains
3361 (if newsticker-auto-mark-filter
3362 (newsticker--run-auto-mark-filter name item))
3364 'newsticker-new-item-functions name item)))))))
3365 (xml-get-children topnode 'item)))
3366 ;; Remove those old items from cache which have been removed from
3368 (newsticker--cache-replace-age newsticker--cache
3369 name-symbol 'obsolete-old 'deleteme)
3370 (newsticker--cache-remove newsticker--cache name-symbol
3372 ;; Remove those new items from cache which have been removed from
3373 ;; the feed. Or keep them as `obsolete'
3374 (if (not newsticker-keep-obsolete-items)
3375 (newsticker--cache-remove newsticker--cache
3376 name-symbol 'obsolete-new)
3377 (setq newsticker--cache
3378 (newsticker--cache-mark-expired
3379 newsticker--cache name-symbol 'obsolete 'obsolete-expired
3380 newsticker-obsolete-item-max-age))
3381 (newsticker--cache-remove newsticker--cache
3382 name-symbol 'obsolete-expired)
3383 (newsticker--cache-replace-age newsticker--cache
3384 name-symbol 'obsolete-new
3386 ;; bring cache data into proper order....
3387 ;; (newsticker--cache-sort)
3388 ;; setup scrollable text
3389 (newsticker--ticker-text-setup)
3390 (setq newsticker--latest-update-time (current-time))
3391 (when something-was-added
3392 ;; FIXME: should we care about removed items as well?
3393 (newsticker--cache-update)
3394 (newsticker--buffer-set-uptodate nil))
3395 ;; kill the process buffer if wanted
3396 (unless newsticker-debug
3397 (kill-buffer (process-buffer process)))
3398 ;; launch retrieval of image
3400 (string-match "%l" newsticker-heading-format))
3401 (newsticker--image-get name imageurl))))))
3403 (defun newsticker--display-tick ()
3404 "Called from the display timer.
3405 This function calls a display function, according to the variable
3406 `newsticker-scroll-smoothly'."
3407 (if newsticker-scroll-smoothly
3408 (newsticker--display-scroll)
3409 (newsticker--display-jump)))
3411 (defsubst newsticker--echo-area-clean-p ()
3412 "Check whether somebody is using the echo area / minibuffer.
3413 Return t if echo area and minibuffer are unused."
3414 (not (or (active-minibuffer-window)
3415 (and (current-message)
3416 (not (string= (current-message)
3417 newsticker--prev-message))))))
3419 (defun newsticker--display-jump ()
3420 "Called from the display timer.
3421 This function displays the next ticker item in the echo area, unless
3422 there is another message displayed or the minibuffer is active."
3423 (let ((message-log-max nil));; prevents message text from being logged
3424 (when (newsticker--echo-area-clean-p)
3425 (setq newsticker--item-position (1+ newsticker--item-position))
3426 (when (>= newsticker--item-position (length newsticker--item-list))
3427 (setq newsticker--item-position 0))
3428 (setq newsticker--prev-message
3429 (nth newsticker--item-position newsticker--item-list))
3430 (message "%s" newsticker--prev-message))))
3432 (defun newsticker--display-scroll ()
3433 "Called from the display timer.
3434 This function scrolls the ticker items in the echo area, unless
3435 there is another message displayed or the minibuffer is active."
3436 (when (newsticker--echo-area-clean-p)
3437 (let* ((width (- (frame-width) 1))
3438 (message-log-max nil);; prevents message text from being logged
3439 (i newsticker--item-position)
3441 (s-text newsticker--scrollable-text)
3442 (l (length s-text)))
3443 ;; don't show anything if there is nothing to show
3444 (unless (< (length s-text) 1)
3445 ;; repeat the ticker string if it is shorter than frame width
3446 (while (< (length s-text) width)
3447 (setq s-text (concat s-text s-text)))
3448 ;; get the width of the printed string
3449 (setq l (length s-text))
3450 (cond ((< i (- l width))
3451 (setq subtext (substring s-text i (+ i width))))
3453 (setq subtext (concat
3454 (substring s-text i l)
3455 (substring s-text 0 (- width (- l i)))))))
3456 ;; Take care of multibyte strings, for which (string-width) is
3457 ;; larger than (length).
3458 ;; Actually, such strings may be smaller than (frame-width)
3459 ;; because return values of (string-width) are too large:
3460 ;; (string-width "<japanese character>") => 2
3461 (let ((t-width (1- (length subtext))))
3462 (while (> (string-width subtext) width)
3463 (setq subtext (substring subtext 0 t-width))
3464 (setq t-width (1- t-width))))
3465 ;; show the ticker text and save current position
3466 (message "%s" subtext)
3467 (setq newsticker--prev-message subtext)
3468 (setq newsticker--item-position (1+ i))
3469 (when (>= newsticker--item-position l)
3470 (setq newsticker--item-position 0))))))
3472 ;; ======================================================================
3474 ;; ======================================================================
3475 (defun newsticker--decode-coding-string (string coding-system)
3476 "Wrapper around `decode-coding-string'.
3477 This functions passes the arguments STRING and CODING-SYSTEM to
3478 `decode-coding-string'. If the decoding is successful the
3479 decoded string is returned, otherwise the unmodified input string
3482 (decode-coding-string string coding-system)
3484 (message "Cannot decode encoded string `%s'" string)
3487 (defun newsticker--decode-numeric-entities (string)
3488 "Decode SGML numeric entities by their respective utf characters.
3489 This function replaces numeric entities in the input STRING and
3490 returns the modified string. For example \"*\" gets replaced
3493 (while (string-match "&#\\([0-9]+\\);" string start)
3495 (setq string (replace-match
3496 (string (read (substring string (match-beginning 1)
3500 (setq start (1+ (match-beginning 0))))
3503 (defun newsticker--remove-whitespace (string)
3504 "Remove leading and trailing whitespace from STRING."
3505 ;; we must have ...+ but not ...* in the regexps otherwise xemacs loops
3508 (replace-regexp-in-string
3510 (replace-regexp-in-string "^[ \t\r\n]+" "" string))))
3512 (defun newsticker--do-forget-preformatted (item)
3513 "Forget all cached pre-formatted data.
3514 Remove the pre-formatted from `newsticker--cache'."
3516 (setcar (nthcdr 7 item) nil))
3518 (setcar (nthcdr 6 item) nil)))
3520 (defun newsticker--forget-preformatted ()
3521 "Forget all cached pre-formatted data.
3522 Remove the pre-formatted from `newsticker--cache'."
3523 (mapc (lambda (feed)
3524 (mapc 'newsticker--do-forget-preformatted
3527 (newsticker--buffer-set-uptodate nil))
3529 (defun newsticker--debug-msg (string &rest args)
3530 "Print newsticker debug messages.
3531 This function calls `message' with arguments STRING and ARGS, if
3532 `newsticker-debug' is non-nil."
3533 (and newsticker-debug
3534 ;;(not (active-minibuffer-window))
3535 ;;(not (current-message))
3536 (apply 'message string args)))
3538 (defun newsticker--decode-iso8601-date (iso8601-string)
3539 "Return ISO8601-STRING in format like `decode-time'.
3540 Converts from ISO-8601 to Emacs representation. If ISO8601-STRING
3542 2004-09-17T05:09:49+00:00
3543 2004-09-17T05:09+00:00
3552 "\\([0-9]\\{4\\}\\)"
3553 "\\(-\\([0-9]\\{2\\}\\)"
3554 "\\(-\\([0-9]\\{2\\}\\)"
3556 "\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)"
3557 "\\(:\\([0-9]\\{2\\}\\)\\)?"
3558 "\\(\\([-+Z]\\)\\(\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)?"
3561 (let ((year (read (match-string 1 iso8601-string)))
3562 (month (read (match-string 3 iso8601-string)))
3563 (day (read (match-string 5 iso8601-string)))
3564 (hour (read (or (match-string 7 iso8601-string)
3566 (minute (read (or (match-string 8 iso8601-string)
3568 ;;(second (read (or (match-string 10 iso8601-string)
3570 (sign (match-string 12 iso8601-string))
3571 (offset-hour (read (or (match-string 14 iso8601-string)
3573 (offset-minute (read (or (match-string 15 iso8601-string)
3576 (cond ((string= sign "+")
3577 (setq hour (- hour offset-hour))
3578 (setq minute (- minute offset-minute)))
3580 (setq hour (+ hour offset-hour))
3581 (setq minute (+ minute offset-minute))))
3582 ;; if UTC subtract current-time-zone offset
3583 ;;(setq second (+ (car (current-time-zone)) second)))
3586 (encode-time second minute hour day month year t)
3588 (message "Cannot decode \"%s\"" iso8601-string)
3592 (defun newsticker--decode-rfc822-date (rfc822-string)
3593 "Return RFC822-STRING in format like `decode-time'.
3594 Converts from RFC822 to Emacs representation.
3596 Sat, 07 Sep 2002 00:00:01 GMT
3597 07 Sep 2002 00:00:01 GMT"
3603 "\\(\\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\)\\s-*,?\\)\\s-+"
3605 "\\([0-9]\\{1,2\\}\\)\\s-+"
3607 "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|"
3608 "Sep\\|Oct\\|Nov\\|Dec\\)\\s-+"
3610 "\\([0-9]\\{2,4\\}\\)\\s-+"
3612 "\\([0-9]\\{2\\}\\)"
3614 ":\\([0-9]\\{2\\}\\)"
3616 "\\(:\\([0-9]\\{2\\}\\)\\)?"
3620 (let ((day (read (match-string 3 rfc822-string)))
3621 (month-name (match-string 4 rfc822-string))
3623 (year (read (match-string 5 rfc822-string)))
3624 (hour (read (match-string 6 rfc822-string)))
3625 (minute (read (match-string 7 rfc822-string)))
3626 (second (read (or (match-string 9 rfc822-string)
3628 ;;(zone (match-string 10 rfc822-string))
3630 (condition-case error-data
3633 (if (string= month-name m)
3636 '("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug"
3637 "Sep" "Oct" "Nov" "Dec"))
3638 (encode-time second minute hour day month year t))
3640 (message "Cannot decode \"%s\": %s %s" rfc822-string
3641 (car error-data) (cdr error-data))
3645 (defun newsticker--lists-intersect-p (list1 list2)
3646 "Return t if LIST1 and LIST2 share elements."
3649 (if (memq elt list2)
3654 ;; ======================================================================
3656 ;; ======================================================================
3657 (defun newsticker--image-get (feed-name url)
3658 "Get image of the news site FEED-NAME from URL.
3659 If the image has been downloaded in the last 24h do nothing."
3660 (let ((image-name (concat newsticker-imagecache-dirname "/"
3662 (if (and (file-exists-p image-name)
3663 (time-less-p (current-time)
3664 (time-add (nth 5 (file-attributes image-name))
3665 (seconds-to-time 86400))))
3666 (newsticker--debug-msg "%s: Getting image for %s skipped"
3667 (format-time-string "%A, %H:%M" (current-time))
3670 (newsticker--debug-msg "%s: Getting image for %s"
3671 (format-time-string "%A, %H:%M" (current-time))
3673 (let* ((buffername (concat " *newsticker-wget-image-" feed-name "*"))
3674 (item (or (assoc feed-name newsticker-url-list)
3675 (assoc feed-name newsticker-url-list-defaults)
3677 "Cannot get news for %s: Check newsticker-url-list"
3679 (wget-arguments (or (car (cdr (cdr (cdr (cdr item)))))
3680 newsticker-wget-arguments)))
3682 (set-buffer (get-buffer-create buffername))
3684 ;; throw an error if there is an old wget-process around
3685 (if (get-process feed-name)
3686 (error "Another wget-process is running for image %s"
3689 (let* ((args (append wget-arguments (list url)))
3690 (proc (apply 'start-process feed-name buffername
3691 newsticker-wget-name args)))
3692 (set-process-coding-system proc 'no-conversion 'no-conversion)
3693 (set-process-sentinel proc 'newsticker--image-sentinel)))))))
3695 (defun newsticker--image-sentinel (process event)
3696 "Sentinel for image-retrieving PROCESS caused by EVENT."
3697 (let* ((p-status (process-status process))
3698 (exit-status (process-exit-status process))
3699 (feed-name (process-name process)))
3700 ;; catch known errors (zombie processes, rubbish-xml etc.
3701 ;; if an error occurs the news feed is not updated!
3703 (unless (and (eq p-status 'exit)
3705 (message "%s: Error while retrieving image from %s"
3706 (format-time-string "%A, %H:%M" (current-time))
3711 (set-buffer (process-buffer process))
3712 (setq image-name (concat newsticker-imagecache-dirname "/"
3714 (set-buffer-file-coding-system 'no-conversion)
3715 ;; make sure the cache dir exists
3716 (unless (file-directory-p newsticker-imagecache-dirname)
3717 (make-directory newsticker-imagecache-dirname))
3718 ;; write and close buffer
3719 (let ((require-final-newline nil)
3720 (backup-inhibited t)
3721 (coding-system-for-write 'no-conversion))
3722 (write-region nil nil image-name nil 'quiet))
3723 (set-buffer-modified-p nil)
3724 (kill-buffer (current-buffer)))))))
3726 (defun newsticker--image-read (feed-name-symbol disabled)
3727 "Read the cached image for FEED-NAME-SYMBOL from disk.
3728 If DISABLED is non-nil the image will be converted to a disabled look
3729 \(unless `newsticker-enable-logo-manipulations' is not t\).
3731 (let ((image-name (concat newsticker-imagecache-dirname "/"
3732 (symbol-name feed-name-symbol)))
3734 (when (file-exists-p image-name)
3735 (condition-case error-data
3736 (setq img (create-image
3738 :conversion (and newsticker-enable-logo-manipulations
3741 :mask (and newsticker-enable-logo-manipulations
3745 (message "Error: cannot create image: %s"
3746 (cadr error-data)))))
3749 ;; ======================================================================
3751 ;; ======================================================================
3752 (defun newsticker--imenu-create-index ()
3753 "Scan newsticker buffer and return an index for imenu."
3755 (goto-char (point-min))
3756 (let ((index-alist nil)
3760 (let ((type (get-text-property (point) 'nt-type))
3761 (title (get-text-property (point) 'nt-title)))
3762 (cond ((eq type 'feed)
3763 ;; we're on a feed heading
3766 (nconc index-alist (list feed-list))
3767 (setq index-alist (list feed-list))))
3768 (setq feed-list (list title)))
3771 (list (cons title (point)))))))
3772 (setq go-ahead (newsticker--buffer-goto '(item feed))))
3774 (nconc index-alist (list feed-list))
3775 (setq index-alist (list feed-list)))
3778 (defun newsticker--imenu-goto (name pos &rest args)
3779 "Go item NAME at position POS and show item.
3782 (newsticker-show-entry))
3784 ;; ======================================================================
3786 ;; ======================================================================
3787 (defun newsticker--buffer-set-uptodate (value)
3788 "Set the uptodate-status of the newsticker buffer to VALUE.
3789 The mode-line is changed accordingly."
3790 (setq newsticker--buffer-uptodate-p value)
3791 (let ((b (get-buffer "*newsticker*")))
3796 (setq mode-name "Newsticker -- up to date -- ")
3797 (setq mode-name "Newsticker -- NEED UPDATE -- ")))
3800 (defun newsticker--buffer-redraw ()
3801 "Sometimes (CVS) Emacs forgets to update the window..."
3802 (if (fboundp 'force-window-update)
3803 (force-window-update (current-buffer))
3804 (redraw-frame (selected-frame)))
3805 (run-hooks 'newsticker-buffer-change-hook)
3808 (defun newsticker--buffer-insert-all-items ()
3809 "Insert all cached newsticker items into the current buffer.
3810 Keeps order of feeds as given in `newsticker-url-list' and
3811 `newsticker-url-list-defaults'."
3812 (goto-char (point-min))
3813 (mapc (lambda (url-item)
3814 (let* ((feed-name (car url-item))
3815 (feed-name-symbol (intern feed-name))
3816 (feed (assoc feed-name-symbol newsticker--cache))
3820 ;; insert the feed description
3821 (mapc (lambda (item)
3822 (when (eq (newsticker--age item) 'feed)
3823 (newsticker--buffer-insert-item item
3827 (mapc (lambda (item)
3828 (if (memq (newsticker--age item) '(new immortal old
3830 (newsticker--buffer-insert-item item
3833 (put-text-property pos (point) 'feed (car feed))
3835 ;; insert empty line between feeds
3838 (put-text-property p (point) 'hard t)))))
3839 (append newsticker-url-list newsticker-url-list-defaults))
3841 (newsticker--buffer-set-faces (point-min) (point-max))
3842 (newsticker--buffer-set-invisibility (point-min) (point-max))
3843 (goto-char (point-min)))
3845 (defun newsticker--buffer-insert-item (item &optional feed-name-symbol)
3846 "Insert a news item in the current buffer.
3847 Insert the string PREFIX and a formatted representation of the
3848 ITEM. The optional parameter FEED-NAME-SYMBOL determines how the
3849 item is formatted and whether the item-retrieval time is added as
3852 (if (eq (newsticker--age item) 'feed)
3853 (newsticker--buffer-do-insert-text item 'feed feed-name-symbol)
3854 (newsticker--buffer-do-insert-text item 'item feed-name-symbol))
3855 ;; insert the description
3856 (newsticker--buffer-do-insert-text item 'desc feed-name-symbol))
3858 (defun newsticker--buffer-do-insert-text (item type feed-name-symbol)
3859 "Actually insert contents of news item, format it, render it and all that.
3860 ITEM is a news item, TYPE tells which part of the item shall be inserted,
3861 FEED-NAME-SYMBOL tells to which feed this item belongs."
3862 (let* ((pos (point))
3863 (format newsticker-desc-format)
3864 (pos-date-start nil)
3866 (pos-stat-start nil)
3868 (pos-text-start nil)
3870 (pos-extra-start nil)
3872 (pos-enclosure-start nil)
3873 (pos-enclosure-end nil)
3874 (age (newsticker--age item))
3875 (preformatted-contents (newsticker--preformatted-contents item))
3876 (preformatted-title (newsticker--preformatted-title item)))
3877 (cond ((and preformatted-contents
3878 (not (eq (aref preformatted-contents 0) ?\n));; we must
3882 (insert preformatted-contents))
3883 ((and preformatted-title
3884 (not (eq (aref preformatted-title 0) ?\n));; we must NOT have a
3887 (insert preformatted-title))
3889 ;; item was not formatted before.
3892 (setq format newsticker-item-format)
3894 (setq format newsticker-heading-format)))
3896 (while (> (length format) 0)
3897 (let ((prefix (if (> (length format) 1)
3898 (substring format 0 2)
3900 (cond ((string= "%c" prefix)
3902 (when (newsticker--desc item)
3903 (setq pos-text-start (point-marker))
3904 (insert (newsticker--desc item))
3905 (setq pos-text-end (point-marker)))
3906 (setq format (substring format 2)))
3907 ((string= "%d" prefix)
3909 (setq pos-date-start (point-marker))
3910 (if (newsticker--time item)
3911 (insert (format-time-string newsticker-date-format
3912 (newsticker--time item))))
3913 (setq pos-date-end (point-marker))
3914 (setq format (substring format 2)))
3915 ((string= "%l" prefix)
3917 (let ((disabled (cond ((eq (newsticker--age item) 'feed)
3918 (= (newsticker--stat-num-items
3919 feed-name-symbol 'new) 0))
3921 (not (eq (newsticker--age item)
3923 (let ((img (newsticker--image-read feed-name-symbol
3926 (newsticker--insert-image img (car item)))))
3927 (setq format (substring format 2)))
3928 ((string= "%L" prefix)
3930 (let ((disabled (cond ((eq (newsticker--age item) 'feed)
3931 (= (newsticker--stat-num-items
3932 feed-name-symbol 'new) 0))
3934 (not (eq (newsticker--age item)
3936 (let ((img (newsticker--image-read feed-name-symbol
3939 (newsticker--insert-image img (car item))
3941 (setq pos-text-start (point-marker))
3942 (if (eq (newsticker--age item) 'feed)
3943 (insert (newsticker--title item))
3944 ;; FIXME: This is not the "real" title!
3945 (insert (format "%s"
3946 (car (newsticker--cache-get-feed
3947 feed-name-symbol)))))
3948 (setq pos-text-end (point-marker))))))
3949 (setq format (substring format 2)))
3950 ((string= "%s" prefix)
3952 (setq pos-stat-start (point-marker))
3953 (if (eq (newsticker--age item) 'feed)
3954 (insert (newsticker--buffer-statistics
3956 (setq pos-stat-end (point-marker))
3957 (setq format (substring format 2)))
3958 ((string= "%t" prefix)
3961 (setq pos-text-start (point-marker))
3963 (setq pos-text-end (point-marker)))
3964 (setq format (substring format 2)))
3965 ((string-match "%." prefix)
3966 ;; unknown specifier!
3968 (setq format (substring format 2)))
3969 ((string-match "^\\([^%]*\\)\\(.*\\)" format) ;; FIXME!
3972 (insert (substring format
3973 (match-beginning 1) (match-end 1)))
3974 ;; in case that the format string contained newlines
3975 (put-text-property p (point) 'hard t))
3976 (setq format (substring format (match-beginning 2)))))))
3978 ;; decode HTML if possible...
3979 (let ((is-rendered-HTML nil))
3980 (when (and newsticker-html-renderer pos-text-start pos-text-end)
3981 (condition-case error-data
3983 ;; check whether it is necessary to call html renderer
3984 ;; (regexp inspired by htmlr.el)
3985 (goto-char pos-text-start)
3986 (when (re-search-forward
3987 "</?[A-Za-z1-6]*\\|&#?[A-Za-z0-9]+;" pos-text-end t)
3988 ;; (message "%s" (newsticker--title item))
3989 (let ((w3m-fill-column (if newsticker-use-full-width
3991 (w3-maximum-line-length
3992 (if newsticker-use-full-width nil fill-column)))
3994 (funcall newsticker-html-renderer pos-text-start
3996 (cond ((eq newsticker-html-renderer 'w3m-region)
3997 (add-text-properties pos (point-max)
3999 w3m-minor-mode-map)))
4000 ((eq newsticker-html-renderer 'w3-region)
4001 (add-text-properties pos (point-max)
4002 (list 'keymap w3-mode-map))))
4003 (setq is-rendered-HTML t)))
4005 (message "Error: HTML rendering failed: %s, %s"
4006 (car error-data) (cdr error-data)))))
4007 (when (and newsticker-justification
4009 (not is-rendered-HTML))
4011 (let ((use-hard-newlines t))
4012 (fill-region pos (point-max) newsticker-justification))
4015 ;; remove leading and trailing newlines
4017 (unless (= 0 (skip-chars-forward " \t\r\n"))
4018 (delete-region pos (point)))
4019 (goto-char (point-max))
4020 (let ((end (point)))
4021 (unless (= 0 (skip-chars-backward " \t\r\n" (1+ pos)))
4022 (delete-region (point) end)))
4023 (goto-char (point-max))
4026 (unless nil ;;(eq pos (point))
4028 (put-text-property (1- (point)) (point) 'hard t))
4030 ;; insert enclosure element
4031 (when (eq type 'desc)
4032 (setq pos-enclosure-start (point))
4033 (newsticker--buffer-insert-enclosure item)
4034 (setq pos-enclosure-end (point)))
4036 ;; show extra elements
4037 (when (eq type 'desc)
4038 (goto-char (point-max))
4039 (setq pos-extra-start (point))
4040 (mapc (lambda (extra-element)
4041 (unless (memq (car extra-element)
4042 '(items link title description
4044 dc:subject dc:date item guid
4047 (newsticker--buffer-print-extra-element
4049 (newsticker--extra item))
4050 (setq pos-extra-end (point)))
4053 (when (memq type '(feed item))
4054 (add-text-properties pos (1- (point))
4055 (list 'mouse-face 'highlight
4056 'nt-link (newsticker--link item)
4058 (format "mouse-2: visit item (%s)"
4059 (newsticker--link item))
4060 'keymap newsticker--url-keymap))
4061 (add-text-properties pos (point)
4062 (list 'nt-title (newsticker--title item)
4063 'nt-desc (newsticker--desc item))))
4065 (add-text-properties pos (point)
4069 'nt-guid (newsticker--guid item)))
4070 (when (and pos-date-start pos-date-end)
4071 (put-text-property pos-date-start pos-date-end 'nt-face 'date))
4072 (when (and pos-stat-start pos-stat-end)
4073 (put-text-property pos-stat-start pos-stat-end 'nt-face 'stat))
4074 (when (and pos-extra-start pos-extra-end)
4075 (put-text-property pos-extra-start pos-extra-end
4077 (put-text-property pos-extra-start pos-extra-end
4079 (when (and pos-enclosure-start pos-enclosure-end
4080 (> pos-enclosure-end pos-enclosure-start))
4081 (put-text-property pos-enclosure-start (1- pos-enclosure-end)
4082 'nt-face 'enclosure))
4085 ;;(unless (memq type '(feed item))
4086 ;;(set-left-margin pos (1- (point)) 1))
4088 ;; save rendered stuff
4089 (cond ((eq type 'desc)
4090 ;; preformatted contents
4091 (newsticker--cache-set-preformatted-contents
4092 item (buffer-substring pos (point))))
4094 ;; preformatted title
4095 (newsticker--cache-set-preformatted-title
4096 item (buffer-substring pos (point)))))))))
4098 (defun newsticker--buffer-print-extra-element (extra-element)
4099 "Insert EXTRA-ELEMENT in a pretty form into the current buffer."
4100 (insert (format "%s:\t" (car extra-element)))
4101 (let (;;(attributes (cadr extra-element)) ;FIXME!!!!
4102 (contents (cddr extra-element)))
4103 (cond ((listp contents)
4105 (if (and (stringp i)
4106 (string-match "^http://.*" i))
4107 (let ((pos (point)))
4108 (insert i " ") ; avoid self-reference from the
4110 (add-text-properties
4112 (list 'mouse-face 'highlight
4115 (format "mouse-2: visit (%s)" i)
4116 'keymap newsticker--url-keymap)))
4117 (insert (format "%s" i))))
4120 (insert (format "%s" contents))))
4123 (defun newsticker--buffer-insert-enclosure (item)
4124 "Insert enclosure element of an RSS ITEM into the current buffer."
4125 (let ((enclosure (newsticker--enclosure item))
4128 (let ((url (cdr (assoc 'url enclosure)))
4129 (length (cdr (assoc 'length enclosure)))
4130 (type (cdr (assoc 'type enclosure))))
4131 (insert (format "Enclosed file (%s, %1.2f kBytes)" type
4132 (/ (string-to-number length) 1024)))
4133 (add-text-properties beg (point)
4134 (list 'mouse-face 'highlight
4137 "mouse-2: visit (%s)" url)
4138 'keymap newsticker--url-keymap
4143 (defun newsticker--buffer-statistics (feed-name-symbol)
4144 "Return a statistic string for the feed given by FEED-NAME-SYMBOL.
4145 See `newsticker-statistics-format'."
4146 (let ((case-fold-search nil))
4147 (replace-regexp-in-string
4149 (format "%d" (newsticker--stat-num-items feed-name-symbol))
4150 (replace-regexp-in-string
4152 (format "%d" (newsticker--stat-num-items feed-name-symbol 'immortal))
4153 (replace-regexp-in-string
4155 (format "%d" (newsticker--stat-num-items feed-name-symbol 'new))
4156 (replace-regexp-in-string
4158 (format "%d" (newsticker--stat-num-items feed-name-symbol 'old))
4159 (replace-regexp-in-string
4161 (format "%d" (newsticker--stat-num-items feed-name-symbol 'obsolete))
4162 newsticker-statistics-format)))))))
4164 (defun newsticker--buffer-set-faces (start end)
4165 "Add face properties according to mark property.
4166 Scans the buffer between START and END."
4168 ;;(put-text-property start end 'face 'newsticker-default-face)
4172 (nt-face (get-text-property start 'nt-face))
4173 (nt-age (get-text-property start 'nt-age)))
4175 (setq pos2 (next-single-property-change (point) 'nt-face))
4176 (newsticker--set-face-properties pos1 pos2 nt-face nt-age)
4177 (setq nt-face (get-text-property pos2 'nt-face))
4179 (while (and (setq pos2 (next-single-property-change pos1 'nt-face))
4182 (newsticker--set-face-properties pos1 pos2 nt-face nt-age)
4183 (setq nt-face (get-text-property pos2 'nt-face))
4184 (setq nt-age (get-text-property pos2 'nt-age))
4185 (setq pos1 pos2)))))
4187 (defun newsticker--buffer-set-invisibility (start end)
4188 "Add invisibility properties according to nt-type property.
4189 Scans the buffer between START and END. Sets the 'invisible
4190 property to '(<nt-type>-<nt-age> <nt-type> <nt-age>)."
4192 ;; reset invisibility settings
4193 (put-text-property start end 'invisible nil)
4198 (nt-type (get-text-property start 'nt-type))
4199 (nt-age (get-text-property start 'nt-age)))
4201 (setq pos2 (next-single-property-change (point) 'nt-type))
4202 (put-text-property (max (point-min) pos1) (1- pos2)
4207 (if (eq nt-type 'extra) 'desc nt-type))
4209 (symbol-name nt-age)))
4212 (setq nt-type (get-text-property pos2 'nt-type))
4214 (while (and (setq pos2 (next-single-property-change pos1 'nt-type))
4217 ;; must shift one char to the left in order to handle inivisible
4218 ;; newlines, motion in invisible text areas and all that correctly
4219 (put-text-property (1- pos1) (1- pos2)
4224 (if (eq nt-type 'extra) 'desc nt-type))
4226 (symbol-name nt-age)))
4229 (setq nt-type (get-text-property pos2 'nt-type))
4230 (setq nt-age (get-text-property pos2 'nt-age))
4231 (setq pos1 pos2)))))
4233 (defun newsticker--set-face-properties (pos1 pos2 nt-face age)
4234 "Set the face for the text between the positions POS1 and POS2.
4235 The face is chosen according the values of NT-FACE and AGE."
4236 (let ((face (cond ((eq nt-face 'feed)
4237 'newsticker-feed-face)
4239 (cond ((eq age 'new)
4240 'newsticker-new-item-face)
4242 'newsticker-old-item-face)
4244 'newsticker-immortal-item-face)
4246 'newsticker-obsolete-item-face)))
4248 'newsticker-date-face)
4250 'newsticker-statistics-face)
4251 ((eq nt-face 'extra)
4252 'newsticker-extra-face)
4253 ((eq nt-face 'enclosure)
4254 'newsticker-enclosure-face))))
4256 (put-text-property pos1 (max pos1 pos2) 'face face))))
4258 (defun newsticker--insert-image (img string)
4259 "Insert IMG with STRING at point.
4260 This is a work-around for a strange behavior of Emacs versions before
4261 21.3.50. Images inserted with `insert-image' vanished after doing
4263 ;; This should work:
4264 ;;(insert-image img string)
4265 ;; but it does not. Therefore we do this, which should be equivalent!
4266 (let ((pos (point)))
4269 (add-text-properties pos (point) (list 'display img))))
4271 ;; ======================================================================
4273 ;; ======================================================================
4274 (defun newsticker-htmlr-render (pos1 pos2) ;
4275 "Replacement for `htmlr-render'.
4276 Renders the HTML code in the region POS1 to POS2 using htmlr."
4277 (let ((str (buffer-substring-no-properties pos1 pos2)))
4278 (delete-region pos1 pos2)
4282 (goto-char (point-min))
4283 ;; begin original htmlr-render
4285 ;; something omitted here...
4286 (while (< (point) (point-max))
4288 ;; end original htmlr-render
4289 (newsticker--remove-whitespace (buffer-string))))))
4291 ;; ======================================================================
4292 ;;; Functions working on the *newsticker* buffer
4293 ;; ======================================================================
4294 (defun newsticker--buffer-make-item-completely-visible ()
4295 "Scroll buffer until current item is completely visible."
4296 (switch-to-buffer (get-buffer-create "*newsticker*"))
4297 (when newsticker--auto-narrow-to-feed
4298 (let* ((min (or (save-excursion (newsticker--buffer-beginning-of-feed))
4300 (max (or (save-excursion (newsticker--buffer-end-of-feed))
4302 (narrow-to-region min max)))
4303 (when newsticker--auto-narrow-to-item
4304 (let* ((min (or (save-excursion (newsticker--buffer-beginning-of-item))
4306 (max (or (save-excursion (newsticker--buffer-end-of-item))
4308 (narrow-to-region min max)))
4310 ;; do not count lines and stuff because that does not work when images
4311 ;; are displayed. Do it the simple way:
4313 (newsticker--buffer-end-of-item)
4314 (unless (pos-visible-in-window-p)
4316 (unless (pos-visible-in-window-p)
4319 (defun newsticker--buffer-get-feed-title-at-point ()
4320 "Return feed symbol of headline at point."
4321 (format "%s" (or (get-text-property (point) 'feed) " ")))
4323 (defun newsticker--buffer-get-item-title-at-point ()
4324 "Return feed symbol of headline at point."
4325 (format "%s" (or (get-text-property (point) 'nt-title) " ")))
4327 (defun newsticker--buffer-goto (types &optional age backwards)
4328 "Search next occurrence of TYPES in current buffer.
4329 TYPES is a list of symbols. If TYPES is found point is moved, if
4330 not point is left unchanged. If optional parameter AGE is not
4331 nil, the type AND the age must match. If BACKWARDS is t, search
4333 (let ((pos (save-excursion
4337 (let ((tpos (point)))
4340 (if (eq tpos (point-min))
4342 (or (previous-single-property-change
4345 (next-single-property-change
4347 (and (memq (get-text-property tpos 'nt-type) types)
4349 (eq (get-text-property tpos 'nt-age) age))
4350 (throw 'found tpos)))))))))
4355 (defun newsticker--buffer-hideshow (mark-age onoff )
4356 "Hide or show items of type MARK-AGE.
4357 If ONOFF is nil the item is hidden, otherwise it is shown."
4359 (remove-from-invisibility-spec mark-age )
4360 (add-to-invisibility-spec mark-age)))
4362 (defun newsticker--buffer-beginning-of-item ()
4363 "Move point to the beginning of the item at point.
4364 Return new position."
4367 (let ((type (get-text-property (point) 'nt-type))
4368 (typebefore (get-text-property (1- (point)) 'nt-type)))
4369 (if (and (memq type '(item feed))
4370 (not (eq type typebefore)))
4372 (newsticker--buffer-goto '(item feed) nil t)
4375 (defun newsticker--buffer-beginning-of-feed ()
4376 "Move point to the beginning of the feed at point.
4377 Return new position."
4380 (let ((type (get-text-property (point) 'nt-type))
4381 (typebefore (get-text-property (1- (point)) 'nt-type)))
4382 (if (and (memq type '(feed))
4383 (not (eq type typebefore)))
4385 (newsticker--buffer-goto '(feed) nil t)
4388 (defun newsticker--buffer-end-of-item ()
4389 "Move point to the end of the item at point.
4390 Take care: end of item is at the end of its last line!"
4391 (when (newsticker--buffer-goto '(item feed nil))
4394 (defun newsticker--buffer-end-of-feed ()
4395 "Move point to the end of the last item of the feed at point.
4396 Take care: end of item is at the end of its last line!"
4397 (when (newsticker--buffer-goto '(feed nil))
4401 ;; ======================================================================
4402 ;;; manipulation of ticker text
4403 ;; ======================================================================
4404 (defun newsticker--ticker-text-setup ()
4405 "Build the ticker text which is scrolled or flashed in the echo area."
4406 ;; reset scrollable text
4407 (setq newsticker--scrollable-text "")
4408 (setq newsticker--item-list nil)
4409 (setq newsticker--item-position 0)
4410 ;; build scrollable text from cache data
4411 (let ((have-something nil))
4414 (let ((feed-name (symbol-name (car feed))))
4415 (let ((num-new (newsticker--stat-num-items (car feed) 'new))
4416 (num-old (newsticker--stat-num-items (car feed) 'old))
4417 (num-imm (newsticker--stat-num-items (car feed) 'immortal))
4418 (num-obs (newsticker--stat-num-items (car feed) 'obsolete)))
4419 (when (or (> num-new 0)
4421 (not newsticker-hide-old-items-in-echo-area))
4423 (not newsticker-hide-immortal-items-in-echo-area))
4425 (not newsticker-hide-obsolete-items-in-echo-area)))
4426 (setq have-something t)
4429 (let ((title (replace-regexp-in-string
4431 (newsticker--title item)))
4432 (age (newsticker--age item)))
4433 (unless (string= title newsticker--error-headline)
4437 (not newsticker-hide-old-items-in-echo-area))
4438 (and (eq age 'obsolete)
4440 newsticker-hide-obsolete-items-in-echo-area))
4441 (and (eq age 'immortal)
4443 newsticker-hide-immortal-items-in-echo-area)))
4444 (setq title (newsticker--remove-whitespace title))
4445 ;; add to flash list
4446 (add-to-list 'newsticker--item-list
4447 (concat feed-name ": " title) t)
4448 ;; and to the scrollable text
4449 (setq newsticker--scrollable-text
4450 (concat newsticker--scrollable-text
4451 " " feed-name ": " title " +++"))))))
4454 (when have-something
4455 (setq newsticker--scrollable-text
4457 (format-time-string "%A, %H:%M"
4458 newsticker--latest-update-time)
4459 " ++++++" newsticker--scrollable-text)))))
4461 (defun newsticker--ticker-text-remove (feed title)
4462 "Remove the item of FEED with TITLE from the ticker text."
4463 ;; reset scrollable text
4464 (setq newsticker--item-position 0)
4465 (let ((feed-name (symbol-name feed))
4466 (t-title (replace-regexp-in-string "[\r\n]+" " " title)))
4467 ;; remove from flash list
4468 (setq newsticker--item-list (remove (concat feed-name ": " t-title)
4469 newsticker--item-list))
4470 ;; and from the scrollable text
4471 (setq newsticker--scrollable-text
4472 (replace-regexp-in-string
4473 (regexp-quote (concat " " feed-name ": " t-title " +++"))
4475 newsticker--scrollable-text))
4476 (if (string-match (concat "^\\+\\+\\+ [A-Z][a-z]+, "
4477 "[012]?[0-9]:[0-9][0-9] \\+\\+\\+\\+\\+\\+$")
4478 newsticker--scrollable-text)
4479 (setq newsticker--scrollable-text ""))))
4481 ;; ======================================================================
4482 ;;; manipulation of cached data
4483 ;; ======================================================================
4484 (defun newsticker--cache-set-preformatted-contents (item contents)
4485 "Set preformatted contents of ITEM to CONTENTS."
4487 (setcar (nthcdr 6 item) contents)
4488 (setcdr (nthcdr 5 item) (list contents))))
4490 (defun newsticker--cache-set-preformatted-title (item title)
4491 "Set preformatted title of ITEM to TITLE."
4493 (setcar (nthcdr 7 item) title)
4494 (setcdr (nthcdr 6 item) title)))
4496 (defun newsticker--cache-replace-age (data feed old-age new-age)
4497 "Mark all items in DATA in FEED which carry age OLD-AGE with NEW-AGE.
4498 If FEED is 'any it applies to all feeds. If OLD-AGE is 'any,
4499 all marks are replaced by NEW-AGE. Removes all pre-formatted contents."
4500 (mapc (lambda (a-feed)
4501 (when (or (eq feed 'any)
4502 (eq (car a-feed) feed))
4503 (let ((items (cdr a-feed)))
4504 (mapc (lambda (item)
4505 (when (or (eq old-age 'any)
4506 (eq (newsticker--age item) old-age))
4507 (setcar (nthcdr 4 item) new-age)
4508 (newsticker--do-forget-preformatted item)))
4513 (defun newsticker--cache-mark-expired (data feed old-age new-age time)
4514 "Mark all expired entries.
4515 This function sets the age entries in DATA in the feed FEED. If
4516 an item's age is OLD-AGE it is set to NEW-AGE if the item is
4520 (when (or (eq feed 'any)
4521 (eq (car a-feed) feed))
4522 (let ((items (cdr a-feed)))
4525 (when (eq (newsticker--age item) old-age)
4526 (let ((exp-time (time-add (newsticker--time item)
4527 (seconds-to-time time))))
4528 (when (time-less-p exp-time (current-time))
4529 (newsticker--debug-msg
4530 "Item `%s' from %s has expired on %s"
4531 (newsticker--title item)
4532 (format-time-string "%Y-%02m-%d, %H:%M"
4533 (newsticker--time item))
4534 (format-time-string "%Y-%02m-%d, %H:%M" exp-time))
4535 (setcar (nthcdr 4 item) new-age)))))
4540 (defun newsticker--cache-contains (data feed title desc link age
4542 "Check DATA whether FEED contains an item with the given properties.
4543 This function returns the contained item or nil if it is not
4545 The properties which are checked are TITLE, DESC, LINK, AGE, and
4546 GUID. In general all properties must match in order to return a
4547 certain item, except for the following cases.
4549 If AGE equals 'feed the TITLE, DESCription and LINK do not
4550 matter. If DESC is nil it is ignored as well. If
4551 `newsticker-desc-comp-max' is non-nil, only the first
4552 `newsticker-desc-comp-max' characters of DESC are taken into
4555 If GUID is non-nil it is sufficient to match this value, and the
4556 other properties are ignored."
4559 (when (and desc newsticker-desc-comp-max
4560 (> (length desc) newsticker-desc-comp-max))
4561 (setq desc (substring desc 0 newsticker-desc-comp-max)))
4564 (when (eq (car this-feed) feed)
4565 (mapc (lambda (anitem)
4567 ;; global unique id can match
4569 (string= guid (newsticker--guid anitem)))
4570 ;; or title, desc, etc.
4572 ;;(or (not (eq age 'feed))
4573 ;; (eq (newsticker--age anitem) 'feed))
4574 (string= (newsticker--title anitem)
4577 (string= (newsticker--link anitem)
4580 (if (and desc newsticker-desc-comp-max
4581 (> (length (newsticker--desc anitem))
4582 newsticker-desc-comp-max))
4584 (newsticker--desc anitem)
4585 0 newsticker-desc-comp-max)
4587 (string= (newsticker--desc anitem)
4589 (throw 'found anitem)))
4595 (defun newsticker--cache-add (data feed-name-symbol title desc link time age
4596 position extra-elements
4597 &optional updated-age updated-time
4598 preformatted-contents
4600 "Add another item to cache data.
4601 Add to DATA in the FEED-NAME-SYMBOL an item with TITLE, DESC,
4602 LINK, TIME, AGE, POSITION, and EXTRA-ELEMENTS. If this item is
4603 contained already, its mark is set to UPDATED-AGE, its time is
4604 set to UPDATED-TIME, and its pre-formatted contents is set to
4605 PREFORMATTED-CONTENTS and PREFORMATTED-TITLE. Returns the age
4606 which the item got."
4607 (let ((item (newsticker--cache-contains data feed-name-symbol title
4610 ;; does exist already -- change age, update time and position
4613 (setcar (nthcdr 5 item) position)
4614 (setcdr (nthcdr 4 item) (list position)))
4615 (setcar (nthcdr 4 item) updated-age)
4617 (setcar (nthcdr 3 item) updated-time))
4618 ;; replace cached pre-formatted contents
4619 (newsticker--cache-set-preformatted-contents
4620 item preformatted-contents)
4621 (newsticker--cache-set-preformatted-title
4622 item preformatted-title))
4623 ;; did not exist or age equals 'feed-name-symbol
4625 (mapc (lambda (this-feed)
4626 (when (eq (car this-feed) feed-name-symbol)
4627 (setcdr this-feed (nconc (cdr this-feed)
4628 (list (list title desc link
4630 preformatted-contents
4633 (throw 'found this-feed)))
4635 ;; the feed is not contained
4636 (add-to-list 'data (list feed-name-symbol
4637 (list title desc link time age position
4638 preformatted-contents
4644 (defun newsticker--cache-remove (data feed-symbol age)
4645 "Remove all entries from DATA in the feed FEED-SYMBOL with AGE.
4646 FEED-SYMBOL may be 'any. Entries from old feeds, which are no longer in
4647 `newsticker-url-list' or `newsticker-url-list-defaults', are removed as
4653 (if (or (assoc (symbol-name (car feed)) newsticker-url-list)
4654 (assoc (symbol-name (car feed)) newsticker-url-list-defaults))
4655 ;; feed is still valid=active
4656 ;; (message "Keeping feed %s" (car feed))
4657 (if (or (eq feed-symbol 'any)
4658 (eq feed-symbol (car feed)))
4659 (let* ((item-pos (cdr feed))
4660 (item (car item-pos))
4663 ;;(message "%s" (car item))
4664 (if (eq age (newsticker--age item))
4667 ;;(message "Removing item %s" (car item))
4669 (setcdr prev-pos (cdr item-pos))
4670 (setcdr feed (cdr item-pos))))
4671 ;;(message "Keeping item %s" (car item))
4672 (setq prev-pos item-pos))
4673 (setq item-pos (cdr item-pos))
4674 (setq item (car item-pos)))))
4675 ;; feed is not active anymore
4676 ;; (message "Removing feed %s" (car feed))
4678 (setcdr last-pos (cdr pos))
4679 (setq data (cdr pos))))
4681 (setq pos (cdr pos))
4682 (setq feed (car pos)))))
4684 ;; ======================================================================
4686 ;; ======================================================================
4687 (defun newsticker--cache-item-compare-by-time (item1 item2)
4688 "Compare two news items ITEM1 and ITEM2 by comparing their time values."
4690 (let ((age1 (newsticker--age item1))
4691 (age2 (newsticker--age item2)))
4692 (if (not (eq age1 age2))
4693 (cond ((eq age1 'obsolete)
4694 (throw 'result nil))
4695 ((eq age2 'obsolete)
4696 (throw 'result t)))))
4697 (let* ((time1 (newsticker--time item1))
4698 (time2 (newsticker--time item2)))
4699 (cond ((< (nth 0 time1) (nth 0 time2))
4701 ((> (nth 0 time1) (nth 0 time2))
4703 ((< (nth 1 time1) (nth 1 time2))
4705 ((> (nth 1 time1) (nth 1 time2))
4707 ((< (or (nth 2 time1) 0) (or (nth 2 time2) 0))
4709 ((> (or (nth 2 time1) 0) (or (nth 2 time2) 0))
4714 (defun newsticker--cache-item-compare-by-title (item1 item2)
4715 "Compare ITEM1 and ITEM2 by comparing their titles."
4717 (let ((age1 (newsticker--age item1))
4718 (age2 (newsticker--age item2)))
4719 (if (not (eq age1 age2))
4720 (cond ((eq age1 'obsolete)
4721 (throw 'result nil))
4722 ((eq age2 'obsolete)
4723 (throw 'result t)))))
4724 (string< (newsticker--title item1) (newsticker--title item2))))
4726 (defun newsticker--cache-item-compare-by-position (item1 item2)
4727 "Compare ITEM1 and ITEM2 by comparing their original positions."
4729 (let ((age1 (newsticker--age item1))
4730 (age2 (newsticker--age item2)))
4731 (if (not (eq age1 age2))
4732 (cond ((eq age1 'obsolete)
4733 (throw 'result nil))
4734 ((eq age2 'obsolete)
4735 (throw 'result t)))))
4736 (< (or (newsticker--pos item1) 0) (or (newsticker--pos item2) 0))))
4738 (defun newsticker--cache-sort ()
4739 "Sort the newsticker cache data."
4740 (let ((sort-fun (cond ((eq newsticker-sort-method 'sort-by-time)
4741 'newsticker--cache-item-compare-by-time)
4742 ((eq newsticker-sort-method 'sort-by-title)
4743 'newsticker--cache-item-compare-by-title)
4744 ((eq newsticker-sort-method 'sort-by-original-order)
4745 'newsticker--cache-item-compare-by-position))))
4746 (mapc (lambda (feed-list)
4747 (setcdr feed-list (sort (cdr feed-list)
4749 newsticker--cache)))
4751 (defun newsticker--cache-update (&optional save)
4752 "Update newsticker cache file.
4753 If optional argument SAVE is not nil the cache file is saved to disk."
4755 (let ((coding-system-for-write 'utf-8)
4756 (buf (find-file-noselect newsticker-cache-filename)))
4759 (setq buffer-undo-list t)
4761 (insert ";; -*- coding: utf-8 -*-\n")
4762 (insert (prin1-to-string newsticker--cache))
4766 (defun newsticker--cache-get-feed (feed)
4767 "Return the cached data for the feed FEED.
4769 (assoc feed newsticker--cache))
4771 ;; ======================================================================
4773 ;; ======================================================================
4774 (defun newsticker--stat-num-items (feed &optional age)
4775 "Return number of items in the given FEED which have the given AGE.
4776 If AGE is nil, the total number items is returned."
4777 (let ((items (cdr (newsticker--cache-get-feed feed)))
4781 (if (eq (newsticker--age (car items)) age)
4782 (setq num (1+ num)))
4783 (if (memq (newsticker--age (car items)) '(new old immortal obsolete))
4784 (setq num (1+ num))))
4785 (setq items (cdr items)))
4788 ;; ======================================================================
4790 ;; ======================================================================
4791 (defun newsticker-opml-export ()
4792 "OPML subscription export.
4793 Export subscriptions to a buffer in OPML Format."
4795 (with-current-buffer (get-buffer-create "*OPML Export*")
4796 (set-buffer-file-coding-system 'utf-8)
4798 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
4799 "<!-- OPML generated by Emacs newsticker.el -->\n"
4800 "<opml version=\"1.0\">\n"
4802 " <title>mySubscriptions</title>\n"
4803 " <dateCreated>" (format-time-string "%a, %d %b %Y %T %z")
4805 " <ownerEmail>" user-mail-address "</ownerEmail>\n"
4806 " <ownerName>" (user-full-name) "</ownerName>\n"
4810 (insert " <outline text=\"")
4811 (insert (newsticker--title sub))
4812 (insert "\" xmlUrl=\"")
4815 (append newsticker-url-list newsticker-url-list-defaults))
4816 (insert " </body>\n</opml>\n"))
4817 (pop-to-buffer "*OPML Export*")
4818 (when (fboundp 'sgml-mode)
4821 (defun newsticker-opml-import (filename)
4822 "Import OPML data from FILENAME."
4823 (interactive "fOPML file: ")
4824 (set-buffer (find-file-noselect filename))
4825 (goto-char (point-min))
4826 (let* ((node-list (xml-parse-region (point-min) (point-max)))
4827 (body (car (xml-get-children (car node-list) 'body)))
4828 (outlines (xml-get-children body 'outline)))
4829 (mapc (lambda (outline)
4830 (let ((name (xml-get-attribute outline 'text))
4831 (url (xml-get-attribute outline 'xmlUrl)))
4832 (add-to-list 'newsticker-url-list
4833 (list name url nil nil nil) t)))
4835 (customize-variable 'newsticker-url-list))
4837 ;; ======================================================================
4839 ;; ======================================================================
4840 (defun newsticker--run-auto-mark-filter (feed item)
4841 "Automatically mark an item as old or immortal.
4842 This function checks the variable `newsticker-auto-mark-filter'
4843 for an entry that matches FEED and ITEM."
4844 (let ((case-fold-search t))
4845 (mapc (lambda (filter)
4846 (let ((filter-feed (car filter))
4847 (old-list (nth 1 filter))
4848 (imm-list (nth 2 filter)))
4849 (when (string-match filter-feed feed)
4850 (newsticker--do-run-auto-mark-filter item 'old old-list)
4851 (newsticker--do-run-auto-mark-filter item 'immortal imm-list))))
4852 newsticker-auto-mark-filter)))
4854 (defun newsticker--do-run-auto-mark-filter (item age list)
4855 "Actually compare ITEM AGE LIST against `newsticker-auto-mark-filter'."
4856 (mapc (lambda (pattern)
4857 (when (string-match pattern (newsticker--title item))
4858 (setcar (nthcdr 4 item) age)))
4862 ;; ======================================================================
4864 ;; ======================================================================
4865 (defun newsticker-new-item-functions-sample (feed item)
4866 "Demonstrate the use of the `newsticker-new-item-functions' hook.
4867 This function just prints out the values of the FEED and title of the ITEM."
4868 (message (concat "newsticker-new-item-functions-sample: feed=`%s', "
4870 feed (newsticker--title item)))
4872 (defun newsticker-download-images (feed item)
4873 "Download the first image.
4874 If FEED equals \"imagefeed\" download the first image URL found
4875 in the description=contents of ITEM to the directory
4876 \"~/tmp/newsticker/FEED/TITLE\" where TITLE is the title of the item."
4877 (when (string= feed "imagefeed")
4878 (let ((title (newsticker--title item))
4879 (desc (newsticker--desc item)))
4880 (when (string-match "<img src=\"\\(http://[^ \"]+\\)\"" desc)
4881 (let ((url (substring desc (match-beginning 1) (match-end 1)))
4882 (temp-dir (concat "~/tmp/newsticker/" feed "/" title))
4883 (org-dir default-directory))
4884 (unless (file-directory-p temp-dir)
4885 (make-directory temp-dir t))
4887 (message "Getting image %s" url)
4888 (apply 'start-process "wget-image"
4889 " *newsticker-wget-download-images*"
4890 newsticker-wget-name
4894 (defun newsticker-download-enclosures (feed item)
4895 "In all FEEDs download the enclosed object of the news ITEM.
4896 The object is saved to the directory \"~/tmp/newsticker/FEED/TITLE\", which
4897 is created if it does not exist. TITLE is the title of the news
4898 item. Argument FEED is ignored.
4899 This function is suited for adding it to `newsticker-new-item-functions'."
4900 (let ((title (newsticker--title item))
4901 (enclosure (newsticker--enclosure item)))
4903 (let ((url (cdr (assoc 'url enclosure)))
4904 (temp-dir (concat "~/tmp/newsticker/" feed "/" title))
4905 (org-dir default-directory))
4906 (unless (file-directory-p temp-dir)
4907 (make-directory temp-dir t))
4909 (message "Getting enclosure %s" url)
4910 (apply 'start-process "wget-enclosure"
4911 " *newsticker-wget-download-enclosures*"
4912 newsticker-wget-name
4917 (provide 'newsticker)
4919 ;; arch-tag: ab761dfa-67bc-4207-bc64-4307271dc381
4920 ;;; newsticker.el ends here