Commit | Line | Data |
---|---|---|
5629e04f RS |
1 | ;;; newsticker.el --- A Newsticker for Emacs. |
2 | ||
3 | ;; Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. | |
4 | ||
5 | ;; This file is part of GNU Emacs. | |
6 | ||
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)" | |
5629e04f RS |
13 | |
14 | (defconst newsticker-version "1.8" "Version number of newsticker.el.") | |
15 | ||
16 | ;; ====================================================================== | |
17 | ||
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. | |
22 | ||
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. | |
27 | ||
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 | |
30 | ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
31 | ;; USA | |
32 | ||
33 | ;; ====================================================================== | |
34 | ;;; Commentary: | |
35 | ||
36 | ;; Overview | |
37 | ;; -------- | |
38 | ||
39 | ;; Newsticker provides a newsticker for Emacs. A newsticker is a thing that | |
40 | ;; asynchronously retrieves headlines from a list of news sites, prepares | |
41 | ;; these headlines for reading, and allows for loading the corresponding | |
42 | ;; articles in a web browser. | |
43 | ||
44 | ;; Headlines consist of a title and (possibly) a small description. They | |
45 | ;; are contained in RSS (RDF Site Summary) files. Newsticker should work | |
46 | ;; with all RSS files that follow the RDF Rich Site Summary 1.0 | |
47 | ;; specification. It should also work with version 2.0 as well as | |
48 | ;; other/older/alternative RSS formats (like 0.9<something> or such). In | |
49 | ;; other words: Newsticker is a "RSS reader" or "RSS aggregator". | |
50 | ||
51 | ;; Newsticker provides several commands for reading headlines, navigating | |
52 | ;; through them, marking them as read/unread, hiding old headlines | |
53 | ;; etc. Headlines can be displayed as plain text or as rendered HTML. | |
54 | ||
55 | ;; Headlines can be displayed in the echo area, either scrolling like | |
56 | ;; messages in a stock-quote ticker, or just changing. | |
57 | ||
58 | ;; Newsticker allows for automatic processing of headlines by providing | |
59 | ;; hooks and (sample) functions for automatically downloading images and | |
60 | ;; enclosed files (as delivered by podcasts, e.g.). | |
61 | ||
62 | ||
63 | ||
64 | ;; Requirements | |
65 | ;; ------------ | |
66 | ;; Newsticker can be used with GNU Emacs version 21.1 or later as well as | |
67 | ;; XEmacs. It requires an XML-parser (`xml.el') which is part of GNU | |
68 | ;; Emacs. If you are using XEmacs you want to get the `net-utils' package | |
69 | ;; which contains `xml.el' for XEmacs. | |
70 | ||
71 | ;; Newsticker requires a program which can retrieve files via http and | |
72 | ;; prints them to stdout. By default Newsticker will use wget for this | |
73 | ;; task. | |
74 | ||
75 | ;; Installation | |
76 | ;; ------------ | |
77 | ;; Place Newsticker in a directory where Emacs can find it. Add the | |
78 | ;; following line to your Emacs startup file (`~/.emacs'). | |
79 | ;; (add-to-list 'load-path "/path/to/newsticker/") | |
80 | ;; (autoload 'newsticker-start "newsticker" "Emacs Newsticker" t) | |
81 | ;; (autoload 'newsticker-show-news "newsticker" "Emacs Newsticker" t) | |
82 | ||
83 | ;; Newsticker-mode supports imenu. It allows for navigating with the help | |
84 | ;; of a menu. In order to use this feature you should also add the | |
85 | ;; following. | |
86 | ;; (add-hook 'newsticker-mode-hook 'imenu-add-menubar-index) | |
87 | ||
e77274b7 | 88 | ;; That's it. |
5629e04f RS |
89 | |
90 | ;; Usage | |
91 | ;; ----- | |
92 | ;; The command newsticker-show-news will display all available headlines in | |
93 | ;; a special buffer, called `*newsticker*'. It will also start the | |
94 | ;; asynchronous download of headlines. The modeline in the `*newsticker*' | |
95 | ;; buffer informs whenever new headlines have arrived. Clicking | |
96 | ;; mouse-button 2 or pressing RET in this buffer on a headline will call | |
97 | ;; browse-url to load the corresponding news story in your favourite web | |
98 | ;; browser. | |
99 | ||
100 | ;; The scrolling, or flashing of headlines in the echo area, can be started | |
101 | ;; with the command newsticker-start-ticker. It can be stopped with | |
102 | ;; newsticker-stop-ticker. | |
103 | ||
104 | ;; If you just want to start the periodic download of headlines use the | |
105 | ;; command newsticker-start. Calling newsticker-stop will stop the periodic | |
106 | ;; download, but will call newsticker-stop-ticker as well. | |
107 | ||
108 | ;; Configuration | |
109 | ;; ------------- | |
110 | ;; All Newsticker options are customizable, i.e. they can be changed with | |
111 | ;; Emacs customization methods: Call the command customize-group and enter | |
112 | ;; `newsticker' for the customization group. | |
113 | ||
114 | ;; All Newsticker options have reasonable default values, so that in most | |
115 | ;; cases it is not necessary to customize settings before starting | |
116 | ;; Newsticker for the first time. | |
117 | ||
118 | ;; Newsticker options are organized in the following groups. | |
119 | ||
120 | ;; * newsticker-feed contains options that define which news | |
121 | ;; feeds are retrieved and how this is done. | |
122 | ;; o newsticker-url-list defines the list of headlines which are | |
123 | ;; retrieved. | |
124 | ;; o newsticker-retrieval-interval defines how often headlines are | |
125 | ;; retrieved. | |
126 | ;; * newsticker-headline-processing contains options that define how the | |
127 | ;; retrieved headlines are processed. | |
128 | ;; o newsticker-keep-obsolete-items decides whether unread headlines that | |
129 | ;; have been removed from the feed are kept in the Newsticker cache. | |
130 | ;; * newsticker-layout contains options that define how the buffer for | |
131 | ;; reading RSS headlines is formatted. | |
132 | ;; o newsticker-item-format defines how the title of a headline is | |
133 | ;; formatted. | |
134 | ;; * newsticker-ticker contains options that define how headlines are shown | |
135 | ;; in the echo area. | |
136 | ;; o newsticker-display-interval and newsticker-scroll-smoothly define | |
137 | ;; how headlines are shown in the echo area. | |
138 | ;; * newsticker-hooks contains options for hooking other Emacs commands to | |
139 | ;; newsticker functions. | |
140 | ;; o newsticker-new-item-functions allows for automatic processing of | |
141 | ;; headlines. See `newsticker-download-images', and | |
142 | ;; `newsticker-download-enclosures' for sample functions. | |
143 | ;; * newsticker-miscellaneous contains other Newsticker options. | |
144 | ||
145 | ;; Please have a look at the customization buffers for the complete list of | |
146 | ;; options. | |
147 | ||
148 | ;; Remarks | |
149 | ;; ------- | |
150 | ;; This newsticker is designed do its job silently in the background | |
151 | ;; without disturbing you. However, it is probably impossible to prevent | |
152 | ;; such a tool from slightly attenuating your Editor's responsiveness every | |
153 | ;; once in a while. | |
154 | ||
155 | ;; Byte-compiling newsticker.el is recommended. | |
156 | ||
157 | ;; ====================================================================== | |
158 | ;;; History: | |
159 | ||
160 | ;; 1.8 (2005-08-26) | |
161 | ;; * Added commands `newsticker-show-extra' and `newsticker-hide-extra' | |
162 | ;; to show and hide extra RSS elements, bound to "sx" and "hx" | |
163 | ;; resp. Changed default value of `newsticker-show-all-rss-elements' | |
164 | ;; to nil. | |
165 | ;; * mode-line: Introduced special mode-line-format for newsticker. | |
166 | ;; * Get feed logos only once every 24 h. | |
167 | ;; * Default faces changed. | |
168 | ;; * Minor fixes. | |
169 | ||
170 | ;; 1.7 (2005-06-25) | |
171 | ;; * Tool-bar support: most important commands can be called from | |
172 | ;; tool-bar buttons. | |
173 | ;; * Auto-Narrowing introduced: *newsticker* buffer can be narrowed to | |
174 | ;; a single item (bound to key `xi') or a single feed (bound to `xf'). | |
175 | ;; * Enclosure support: enclosed items are shown (see | |
176 | ;; `newsticker-enclosure-face') and can be (automatically) downloaded | |
177 | ;; (see below). For those of you who read "podcasts". | |
178 | ;; * Added variable `newsticker-auto-mark-filter' for automatically | |
179 | ;; marking items as immortal or old. | |
180 | ;; * Added hook variable `newsticker-new-item-functions' for handling | |
181 | ;; new items. Added sample functions `newsticker-download-images', | |
182 | ;; and `newsticker-download-enclosures'. | |
183 | ;; * Added hook variable `newsticker-select-item-hook' which is run | |
184 | ;; after `newsticker-(next|previous)-(new-)?-item'. | |
185 | ;; * Added hook variable `newsticker-select-feed-hook' which is run | |
186 | ;; after `newsticker-(next|previous)-feed'. | |
187 | ;; * Added hook variable `newsticker-buffer-change-hook' which is run | |
188 | ;; after the contents or visibility of the newsticker buffer has | |
189 | ;; changed, e.g. after `newsticker-buffer-update' or | |
190 | ;; `newsticker-show-feed-desc'. | |
191 | ;; * Added command `newsticker-handle-url' for interactively launching | |
192 | ;; arbitrary programs for URLs, bound to `C-RET'. | |
193 | ;; * URLs in extra elements are clickable. | |
194 | ;; * Better support for w3, added command | |
195 | ;; `newsticker-w3m-show-inline-images' for displaying all inline | |
196 | ;; images. | |
197 | ;; * Insert an artificial headline which notifies about failed retrievals. | |
198 | ;; * Use pubDate element (RSS 2.0) instead of retrieval time when | |
199 | ;; available. | |
200 | ;; * Customizable options grouped. | |
201 | ;; * Bugfixes: `newsticker--imenu-create-index'; strip whitespace | |
202 | ;; from links; apply coding-system to extra-elements; time-comparison | |
203 | ;; for obsolete items; and others which I have forgotten. | |
204 | ;; * Workaround for another bug in xml-parse-region -- thanks to anonymous | |
205 | ;; for sending patch. | |
206 | ;; * Renamed invisible buffers ` *wget-newsticker-<feed>*' to | |
207 | ;; ` *newsticker-wget-<feed>*'. | |
208 | ;; * Tested with GNU Emacs versions 21.3 and 22.0 and XEmacs 21.something. | |
209 | ||
210 | ;; 1.6 * Support for (some) optional RSS elements: guid, dc:date. See | |
211 | ;; `newsticker-show-all-rss-elements' `newsticker-extra-face'. | |
212 | ;; * Better support for w3m -- `newsticker-default-face' is obsolete | |
213 | ;; now, removed `newsticker-w3m-toggle-inline-image'. | |
214 | ;; * Added `newsticker-desc-comp-max' -- comparison of item descriptions | |
215 | ;; can take quite some time. | |
216 | ;; * Added `newsticker--buffer-make-item-completely-visible' to | |
217 | ;; ensure that the current item is fully visible. | |
218 | ;; * Allow for non-positive retrieval-interval, which make newsticker | |
219 | ;; get news only once. | |
220 | ;; * Use :set for customizable variables. | |
221 | ;; * Added `newsticker-buffer-force-update', bound to key `U'. | |
222 | ;; * Added concept of obsolete items, see | |
223 | ;; `newsticker-keep-obsolete-items', `newsticker-obsolete-item-face', | |
224 | ;; `newsticker-obsolete-item-max-age'. | |
225 | ;; * Added `newsticker-add-url'. | |
226 | ;; * OPML export. | |
227 | ;; * Save pre-formatted titles => even better performance!! | |
228 | ;; * `newsticker-*-new-item' wraps at beginning/end of buffer. | |
229 | ;; * Always sort obsolete items to end of item list. | |
230 | ;; * Bugfixes: | |
231 | ;; - newsticker-hide-entry, | |
232 | ;; - changes of feed-titles led to duplicate feed items, | |
233 | ;; - faces for rendered HTML texts, | |
234 | ;; - length of ticker-text (for "exotic"/multibyte texts), | |
235 | ;; Thanks to Hiroshi Maruyama. | |
236 | ;; - suppress items with empty title and description | |
237 | ;; - newsticker-sort-method was ignored! | |
238 | ;; - prevent call of fill-region on HTML-rendered descriptions. | |
239 | ||
240 | ;; 1.5 * Rewrote the visibility stuff. newsticker does not inherit | |
241 | ;; outline anymore. Now you have complete freedom for | |
242 | ;; `newsticker-*-format'. | |
243 | ;; * Save pre-formatted descriptions => incredible performance boost!! | |
244 | ;; * Introduced `newsticker-(start|stop)-ticker'. | |
245 | ;; * Introduced statistics for heading-format and | |
246 | ;; `newsticker-statistics-face'. | |
247 | ;; * Introduced `newsticker-enable-logo-manipulations'. | |
248 | ;; * Compare link of items (as well as title and desc). | |
249 | ;; * Added `newsticker-start-hook' and `newsticker-stop-hook', thanks | |
250 | ;; to mace. | |
251 | ;; * Bugfixes -- thanks to Ryan Yeske, Jari Aalto, Bruce Ingalls. | |
252 | ;; * Tested with Emacs 21.3.50, 21.3.1, 21.2, 21.1; XEmacs 21.4.15 | |
253 | ||
254 | ;; 1.4 * Enabled HTML rendering, added `newsticker-html-renderer' to | |
255 | ;; choose a HTML rendering engine, thanks to Greg Scott for testing | |
256 | ;; * New Outline handling using text properties instead of "**" | |
257 | ;; prefixes. | |
258 | ;; * Added possibility to mark single item as old (bound to key | |
259 | ;; `o' (`newsticker-mark-item-at-point-as-read'). | |
260 | ;; * Added possibility to mark single item as immortal (bound to key | |
261 | ;; `i' (`newsticker-mark-item-at-point-as-immortal'). | |
262 | ;; * Added possibility to display feed logos. | |
263 | ;; * Added `newsticker-heading-format', `newsticker-item-format'. | |
264 | ;; * Added `newsticker-date-format'. | |
265 | ;; * Added `newsticker-justification'. | |
266 | ;; * Added `newsticker-automatically-mark-visited-items-as-old'. | |
267 | ;; * Added `newsticker-w3m-toggle-inline-image' which calls | |
268 | ;; `w3m-toggle-inline-image' if `newsticker-html-renderer' is | |
269 | ;; `w3m-region'. Exists for convenience only (bound to key | |
270 | ;; `RET'). | |
271 | ||
272 | ;; 1.3 * Compare title AND desc to check whether item is old, except | |
273 | ;; for feed desc | |
274 | ;; * Mark as not-up-to-date only after new items have arrived. | |
275 | ;; * Added XEmacs compatibility code, tested with XEmacs 21.4.13. | |
276 | ;; * Tested with Emacs 21.3.50 and Emacs 21.2.something. | |
277 | ;; * Bugfix: Apply coding-systems to feed title and description, | |
278 | ;; thanks to OHASHI Akira | |
279 | ;; * Bugfix: xml-parser-workaround did not work for japanese texts, | |
280 | ;; thanks to OHASHI Akira | |
281 | ;; * Kill wget-buffers unless newsticker-debug is not nil. | |
282 | ;; * Bugfix: xml-parser-workaround for "DOCTYPE rdf:RDF" | |
283 | ||
284 | ;; 1.2 Peter S Galbraith <psg@debian.org> | |
285 | ;; * Added `newsticker-url-list-defaults', splitting the URLs into | |
286 | ;; a customizable selection list, and a user add-on list. | |
287 | ;; * Minor checkdoc fixes. | |
288 | ||
289 | ;; 1.1 * Introduced optional feed-specific wget-arguments. | |
290 | ;; * Keep order of feeds as given in `newsticker-url-list' in | |
291 | ;; *newsticker* buffer. | |
292 | ;; * Ignore unsupported coding systems. | |
293 | ||
294 | ;; 1.0 * Introduced feed-specific retrieval-timers. | |
295 | ;; * Removed dependency on 'cl (cddddr). | |
296 | ;; * Thanks to Kevin Rodgers and T.V. Raman for their help. | |
297 | ;; * Use utf-8 for reading and writing cache data. | |
298 | ;; * Reported to work with Emacs 21.3.50. | |
299 | ||
300 | ;; 0.99 * Minor tweaks. | |
301 | ;; * Tested with Emacs 21.3.2 | |
302 | ||
303 | ;; 0.98 * Check exit status of wget processes. Keep cache data if | |
304 | ;; something went wrong. Throw error when old wget-processes | |
305 | ;; are hanging around. | |
306 | ;; * Introduced newsticker-specific faces. | |
307 | ;; * Added `newsticker-show-descriptions-of-new-items'. | |
308 | ;; * Added `newsticker-hide-old-items-in-newsticker-buffer'. | |
309 | ;; * Added `newsticker-(hide|show)-old-items'. | |
310 | ||
311 | ;; 0.97 * Minor tweaks. | |
312 | ||
313 | ;; 0.96 * Added caching. | |
314 | ;; * newsticker-mode inherits outline-mode. | |
315 | ;; * newsticker-mode supports imenu. | |
316 | ;; * Easy buffer-navigation with newsticker-mode's keymap. | |
317 | ;; * Some bugs fixed. | |
318 | ;; * Thanks to Moritz Epple for documentation tips. | |
319 | ||
320 | ;; 0.95 * Added newsticker-mode -- Thanks to T.V. Raman. | |
321 | ;; * Catch xml-parser errors -- Thanks to T.V. Raman. | |
322 | ;; * Remove stupid newlines in titles (headlines) -- Thanks to | |
323 | ;; Jeff Rancier. | |
324 | ||
325 | ;; 0.94 * Added clickerability and description for channel headings. | |
326 | ;; * Made it work for (at least some) rss 0.9<something> feeds. | |
327 | ||
328 | ;; 0.93 * Added some more sites. | |
329 | ;; * Do not flood the *Messages* buffer. | |
330 | ;; * First attempt at handling coding systems. | |
331 | ||
332 | ;; 0.92 * Added `newsticker-wget-name'. | |
333 | ;; * Try to display message only if minibuffer and echo area are | |
334 | ;; not in use already. | |
335 | ;; * Dirty workaround for newer versions of xml.el: Remove | |
336 | ;; whitespace in rdf. | |
337 | ;; * Tested with Emacs 21.3.2 and CVS-snapshot of 2003-06-21. | |
338 | ||
339 | ;; 0.91 * First bugfix: *newsticker* is read-only. | |
340 | ||
341 | ;; 0.9 * First release. | |
342 | ;; * Tested with Emacs 21.3.2 and wget 1.8.2. | |
343 | ||
344 | ;; ====================================================================== | |
345 | ;;; To Do: | |
346 | ||
347 | ;; * Image handling for XEmacs (create-image does not exist) | |
348 | ||
349 | ;; ====================================================================== | |
350 | ;;; Code: | |
351 | ||
352 | (require 'derived) | |
353 | (require 'xml) | |
354 | ||
e77274b7 JB |
355 | ;; Silence warnings |
356 | (defvar tool-bar-map) | |
357 | (defvar w3-mode-map) | |
358 | (defvar w3m-minor-mode-map) | |
359 | ||
5629e04f RS |
360 | ;; ====================================================================== |
361 | ;;; Customizables | |
362 | ;; ====================================================================== | |
363 | (defgroup newsticker nil | |
364 | "RSS aggregator." | |
365 | :group 'applications) | |
366 | ||
367 | (defconst newsticker--raw-url-list-defaults | |
368 | '(("CNET News.com" | |
369 | "http://export.cnet.com/export/feeds/news/rss/1,11176,,00.xml") | |
370 | ("Debian Security Advisories" | |
371 | "http://www.debian.org/security/dsa.en.rdf") | |
372 | ("Debian Security Advisories - Long format" | |
373 | "http://www.debian.org/security/dsa-long.en.rdf") | |
374 | ("Emacs Wiki" | |
375 | "http://www.emacswiki.org/cgi-bin/wiki.pl?action=rss" | |
376 | nil | |
377 | 3600) | |
378 | ("Freshmeat.net" | |
379 | "http://freshmeat.net/backend/fm.rdf") | |
380 | ("Kuro5hin.org" | |
381 | "http://www.kuro5hin.org/backend.rdf") | |
382 | ("LWN (Linux Weekly News)" | |
383 | "http://lwn.net/headlines/rss") | |
384 | ("NewsForge" | |
385 | "http://newsforge.com/index.rss") | |
386 | ("NY Times: Technology" | |
387 | "http://partners.userland.com/nytRss/technology.xml") | |
388 | ("NY Times" | |
389 | "http://partners.userland.com/nytRss/nytHomepage.xml") | |
390 | ("Quote of the day" | |
391 | "http://www.quotationspage.com/data/qotd.rss" | |
392 | "07:00" | |
393 | 86400) | |
394 | ("The Register" | |
395 | "http://www.theregister.co.uk/tonys/slashdot.rdf") | |
396 | ("slashdot" | |
397 | "http://slashdot.org/index.rss" | |
398 | nil | |
399 | 3600) ;/. will ban you if under 3600 seconds! | |
400 | ("Wired News" | |
401 | "http://www.wired.com/news_drop/netcenter/netcenter.rdf") | |
402 | ("Heise News (german)" | |
403 | "http://www.heise.de/newsticker/heise.rdf") | |
404 | ("Tagesschau (german)" | |
405 | "http://www.tagesschau.de/newsticker.rdf" | |
406 | nil | |
407 | 1800) | |
408 | ("Telepolis (german)" | |
409 | "http://www.heise.de/tp/news.rdf")) | |
410 | "Default URL list in raw form. | |
411 | This list is fed into defcustom via `newsticker--splicer'.") | |
412 | ||
413 | (defun newsticker--splicer (item) | |
414 | "Convert ITEM for splicing into `newsticker-url-list-defaults'." | |
415 | (let ((result (list 'list :tag (nth 0 item) (list 'const (nth 0 item)))) | |
416 | (element (cdr item))) | |
417 | (while element | |
418 | (setq result (append result (list (list 'const (car element))))) | |
419 | (setq element (cdr element))) | |
420 | result)) | |
421 | ||
422 | ;; ====================================================================== | |
423 | ;;; Customization | |
424 | ;; ====================================================================== | |
425 | (defun newsticker--set-customvar (symbol value) | |
426 | "Set newsticker-variable SYMBOL value to VALUE. | |
427 | ||
428 | Calls all necessary actions which are necessary in order to make | |
429 | the new value effective. Changing `newsticker-url-list', for example, | |
430 | will re-start the retrieval-timers." | |
431 | (unless (condition-case nil | |
432 | (eq (symbol-value symbol) value) | |
433 | (error nil)) | |
434 | (set symbol value) | |
435 | (cond ((eq symbol 'newsticker-sort-method) | |
436 | (when (fboundp 'newsticker--cache-sort) | |
437 | (message "Applying new sort method...") | |
438 | (newsticker--cache-sort) | |
439 | (newsticker--buffer-set-uptodate nil) | |
440 | (message "Applying new sort method...done"))) | |
441 | ((memq symbol '(newsticker-url-list-defaults | |
442 | newsticker-url-list | |
443 | newsticker-retrieval-interval)) | |
444 | (when (and (fboundp 'newsticker-running-p) | |
445 | (newsticker-running-p)) | |
446 | (message "Restarting newsticker") | |
447 | (newsticker-stop) | |
448 | (newsticker-start))) | |
449 | ((eq symbol 'newsticker-display-interval) | |
450 | (when (and (fboundp 'newsticker-running-p) | |
451 | (newsticker-running-p)) | |
452 | (message "Restarting ticker") | |
453 | (newsticker-stop-ticker) | |
454 | (newsticker-start-ticker) | |
455 | (message ""))) | |
456 | ((memq symbol '(newsticker-hide-old-items-in-echo-area | |
457 | newsticker-hide-obsolete-items-in-echo-area | |
458 | newsticker-hide-immortal-items-in-echo-area)) | |
459 | (when (and (fboundp 'newsticker-running-p) | |
460 | (newsticker-running-p)) | |
461 | (message "Restarting newsticker") | |
462 | (newsticker-stop-ticker) | |
463 | (newsticker--ticker-text-setup) | |
464 | (newsticker-start-ticker) | |
465 | (message ""))) | |
466 | ((memq symbol '(newsticker-hide-old-items-in-newsticker-buffer | |
467 | newsticker-show-descriptions-of-new-items)) | |
468 | (when (fboundp 'newsticker--buffer-set-uptodate) | |
469 | (newsticker--buffer-set-uptodate nil))) | |
470 | ((memq symbol '(newsticker-heading-format | |
471 | newsticker-item-format | |
472 | newsticker-desc-format | |
473 | newsticker-date-format | |
474 | newsticker-statistics-format | |
475 | newsticker-justification | |
476 | newsticker-use-full-width | |
477 | newsticker-html-renderer | |
478 | newsticker-feed-face | |
479 | newsticker-new-item-face | |
480 | newsticker-old-item-face | |
481 | newsticker-immortal-item-face | |
482 | newsticker-obsolete-item-face | |
483 | newsticker-date-face | |
484 | newsticker-statistics-face | |
485 | ;;newsticker-default-face | |
486 | )) | |
487 | (when (fboundp 'newsticker--forget-preformatted) | |
488 | (newsticker--forget-preformatted))) | |
489 | (t | |
490 | (error "Ooops %s" symbol))))) | |
491 | ||
492 | ;; customization group feed | |
493 | (defgroup newsticker-feed nil | |
494 | "Settings for the RSS feeds." | |
495 | :group 'newsticker) | |
496 | ||
497 | (defcustom newsticker-url-list-defaults | |
498 | '(("Emacs Wiki" | |
499 | "http://www.emacswiki.org/cgi-bin/wiki.pl?action=rss" | |
500 | nil | |
501 | 3600)) | |
502 | "A customizable list of news feeds to select from. | |
503 | These were mostly extracted from the Radio Community Server at | |
504 | http://subhonker6.userland.com/rcsPublic/rssHotlist. | |
505 | ||
506 | You may add other entries in `newsticker-url-list'." | |
507 | :type `(set ,@(mapcar `newsticker--splicer | |
508 | newsticker--raw-url-list-defaults)) | |
509 | :set 'newsticker--set-customvar | |
510 | :group 'newsticker-feed) | |
511 | ||
512 | (defcustom newsticker-url-list nil | |
513 | "The news feeds which you like to watch. | |
514 | ||
515 | This alist will be used in addition to selection made customizing | |
516 | `newsticker-url-list-defaults'. | |
517 | ||
518 | This is an alist. Each element consists of two items: a LABEL and a URL, | |
519 | optionally followed by a START-TIME, INTERVAL specifier and WGET-ARGUMENTS. | |
520 | ||
521 | The LABEL gives the name of the news feed. It can be an arbitrary string. | |
522 | ||
523 | The URL gives the location of the news feed. It must point to a valid | |
524 | RSS file. The RSS file is retrieved by calling wget, or whatever you | |
525 | specify as `newsticker-wget-name'. | |
526 | ||
527 | The START-TIME can be either a string, or nil. If it is a string it | |
528 | specifies a fixed time at which this feed shall be retrieved for the | |
529 | first time. (Examples: \"11:00pm\", \"23:00\"). If it is nil (or | |
530 | unspecified), this feed will be retrieved immediately after calling | |
531 | `newsticker-start'. | |
532 | ||
533 | The INTERVAL specifies the time between retrievals for this feed. If it | |
534 | is nil (or unspecified) the default interval value as set in | |
535 | `newsticker-retrieval-interval' is used. | |
536 | ||
537 | \(newsticker.el calls `run-at-time'. The newsticker-parameters START-TIME | |
538 | and INTERVAL correspond to the `run-at-time'-parameters TIME and REPEAT.) | |
539 | ||
540 | WGET-ARGUMENTS specifies arguments for wget (see `newsticker-wget-name') | |
541 | which apply for this feed only, overriding the value of | |
542 | `newsticker-wget-arguments'." | |
543 | :type '(repeat (list :tag "News feed" | |
544 | (string :tag "Label") | |
545 | (string :tag "URI") | |
546 | (choice :tag "Start" | |
547 | (const :tag "Default" nil) | |
548 | (string :tag "Fixed Time")) | |
549 | (choice :tag "Interval" | |
550 | (const :tag "Default" nil) | |
551 | (const :tag "Hourly" 3600) | |
552 | (const :tag "Daily" 86400) | |
553 | (integer :tag "Interval")) | |
554 | (choice :tag "Wget Arguments" | |
555 | (const :tag "Default arguments" nil) | |
556 | (repeat :tag "Special arguments" string)))) | |
557 | :set 'newsticker--set-customvar | |
558 | :group 'newsticker-feed) | |
559 | ||
560 | (defcustom newsticker-wget-name | |
561 | "wget" | |
562 | "Name of the program which is called to retrieve news from the web. | |
563 | The canonical choice is wget but you may take any other program which is | |
564 | able to return the contents of a news feed file on stdout." | |
565 | :type 'string | |
566 | :group 'newsticker-feed) | |
567 | ||
568 | (defcustom newsticker-wget-arguments | |
569 | '("-q" "-O" "-") | |
570 | "Arguments which are passed to wget. | |
571 | There is probably no reason to change the default settings, unless you | |
572 | are living behind a firewall." | |
573 | :type '(repeat (string :tag "Argument")) | |
574 | :group 'newsticker-feed) | |
575 | ||
576 | (defcustom newsticker-retrieval-interval | |
577 | 3600 | |
578 | "Time interval for retrieving new news items (seconds). | |
579 | If this value is not positive (i.e. less than or equal to 0) | |
580 | items are retrieved only once! | |
581 | Please note that some feeds, e.g. Slashdot, will ban you if you | |
582 | make it less than 1800 seconds (30 minutes)!" | |
583 | :type '(choice :tag "Interval" | |
584 | (const :tag "No automatic retrieval" 0) | |
585 | (const :tag "Hourly" 3600) | |
586 | (const :tag "Daily" 86400) | |
587 | (integer :tag "Interval")) | |
588 | :set 'newsticker--set-customvar | |
589 | :group 'newsticker-feed) | |
590 | ||
591 | (defcustom newsticker-desc-comp-max | |
592 | 100 | |
593 | "Relevant length of headline descriptions. | |
594 | This value gives the maximum number of characters which will be | |
595 | taken into account when newsticker compares two headline | |
596 | descriptions." | |
597 | :type 'integer | |
598 | :group 'newsticker-feed) | |
599 | ||
600 | ;; customization group behaviour | |
601 | (defgroup newsticker-headline-processing nil | |
602 | "Settings for the automatic processing of RSS headlines." | |
603 | :group 'newsticker) | |
604 | ||
605 | (defcustom newsticker-automatically-mark-items-as-old | |
606 | t | |
607 | "Decides whether to automatically mark items as old. | |
608 | If t a new item is considered as new only after its first retrieval. As | |
609 | soon as it is retrieved a second time, it becomes old. If not t all | |
610 | items stay new until you mark them as old. This is done in the | |
611 | *newsticker* buffer." | |
612 | :type 'boolean | |
613 | :group 'newsticker-headline-processing) | |
614 | ||
615 | (defcustom newsticker-automatically-mark-visited-items-as-old | |
616 | t | |
617 | "Decides whether to automatically mark visited items as old. | |
618 | If t an item is marked as old as soon as the associated link is | |
619 | visited, i.e. after pressing RET or mouse2 on the item's | |
620 | headline." | |
621 | ||
622 | :type 'boolean | |
623 | :group 'newsticker-headline-processing) | |
624 | ||
625 | (defcustom newsticker-keep-obsolete-items | |
626 | t | |
627 | "Decides whether to keep unread items which have been removed from feed. | |
628 | If t a new item, which has been removed from the feed, is kept in | |
629 | the cache until it is marked as read." | |
630 | :type 'boolean | |
631 | :group 'newsticker-headline-processing) | |
632 | ||
633 | (defcustom newsticker-obsolete-item-max-age | |
634 | (* 60 60 24) | |
635 | "Maximal age of obsolete items, in seconds. | |
636 | Obsolete items which are older than this value will be silently | |
637 | deleted at the next retrieval." | |
638 | :type 'integer | |
639 | :group 'newsticker-headline-processing) | |
640 | ||
641 | (defcustom newsticker-auto-mark-filter | |
642 | nil | |
643 | "A filter for automatically marking headlines. | |
644 | ||
645 | This is an alist of the form (FEED-NAME OLD-LIST IMMORTAL-LIST). I.e. each | |
646 | element consists of a FEED-NAME and two lists. Each list consists a set of | |
647 | regular expressions. The first list contains patterns of headlines which | |
648 | will be marked as old. The second list contains patterns of headlines which | |
649 | will be marked as immortal. | |
650 | ||
651 | This filter is checked after a new headline has been retrieved. If | |
652 | FEED-NAME matches the name of the corresponding news feed, both sublists | |
653 | are checked: If the title of the headline matches any of the regular | |
654 | expressions in OLD-LIST, this headline is marked as old, if it matches any | |
655 | of the expressions in IMMORTAL-LIST it is marked as immortal. | |
656 | ||
657 | If, for example, `newsticker-auto-mark-filter' looks like | |
658 | \((slashdot (\"^Forget me!$\") (\"^Read me$\" \"important\"))) | |
659 | then all articles from slashdot are marked as old if they have the title | |
660 | \"Forget me!\". All articles which have the title \"Read me\" and all | |
661 | articles which contain the string \"important\" in their title are marked | |
662 | as immortal." | |
663 | :type '(repeat (list :tag "Feed filter rule" | |
664 | (string :tag "Feed name") | |
665 | ;;(choice ,@(mapcar (lambda (i) | |
666 | ;; (list :tag (car i) (car i))) | |
667 | ;; newsticker-url-list)) | |
668 | (repeat :tag "Mark as old" string) | |
669 | (repeat :tag "Mark as immortal" string))) | |
670 | :group 'newsticker-headline-processing) | |
671 | ||
672 | ;; customization group layout | |
673 | (defgroup newsticker-layout nil | |
674 | "Settings for layout of the RSS reader." | |
675 | :group 'newsticker) | |
676 | ||
677 | (defcustom newsticker-sort-method | |
678 | 'sort-by-original-order | |
679 | "Sort method for news items. | |
680 | The following sort methods are available: | |
681 | * `sort-by-original-order' keeps the order in which the items | |
682 | appear in the RSS file (please note that for immortal items, | |
683 | which have been removed from the news feed, there is no original | |
684 | order), | |
685 | * `sort-by-time' looks at the time at which an item has been seen | |
686 | the first time. The most recent item is put at top, | |
687 | * `sort-by-title' will put the items in an alphabetical order." | |
688 | :type '(choice | |
689 | (const :tag "Keep original order" sort-by-original-order) | |
690 | (const :tag "Sort by time" sort-by-time) | |
691 | (const :tag "Sort by title" sort-by-title)) | |
692 | :set 'newsticker--set-customvar | |
693 | :group 'newsticker-layout) | |
694 | ||
695 | (defcustom newsticker-hide-old-items-in-newsticker-buffer | |
696 | nil | |
697 | "Decides whether to automatically hide old items in the *newsticker* buffer. | |
698 | If set to t old items will be completely folded and only new items | |
699 | will show up in the *newsticker* buffer. Otherwise old as well as new | |
700 | items will be visible." | |
701 | :type 'boolean | |
702 | :set 'newsticker--set-customvar | |
703 | :group 'newsticker-layout) | |
704 | ||
705 | (defcustom newsticker-show-descriptions-of-new-items | |
706 | t | |
707 | "Whether to automatically show descriptions of new items in *newsticker*. | |
708 | If set to t old items will be folded and new items will be | |
709 | unfolded. Otherwise old as well as new items will be folded." | |
710 | :type 'boolean | |
711 | :set 'newsticker--set-customvar | |
712 | :group 'newsticker-layout) | |
713 | ||
714 | (defcustom newsticker-heading-format | |
715 | "%l | |
716 | %t %d %s" | |
717 | "Format string for feed headings. | |
718 | The following printf-like specifiers can be used: | |
719 | %d The date the feed was retrieved. See `newsticker-date-format'. | |
720 | %l The logo (image) of the feed. Most RSS feeds provide a small | |
721 | image as logo. Newsticker can display them, if Emacs can -- | |
722 | see `image-types' for a list of supported image types. | |
723 | %L The logo (image) of the feed. If the logo is not available | |
724 | the title of the feed is used. | |
725 | %s The statistical data of the feed. See `newsticker-statistics-format'. | |
726 | %t The title of the feed, i.e. its name." | |
727 | :type 'string | |
728 | :set 'newsticker--set-customvar | |
729 | :group 'newsticker-layout) | |
730 | ||
731 | (defcustom newsticker-item-format | |
732 | "%t %d" | |
733 | "Format string for news item headlines. | |
734 | The following printf-like specifiers can be used: | |
735 | %d The date the item was (first) retrieved. See `newsticker-date-format'. | |
736 | %l The logo (image) of the feed. Most RSS feeds provide a small | |
737 | image as logo. Newsticker can display them, if Emacs can -- | |
738 | see `image-types' for a list of supported image types. | |
739 | %L The logo (image) of the feed. If the logo is not available | |
740 | the title of the feed is used. | |
741 | %t The title of the item." | |
742 | :type 'string | |
743 | :set 'newsticker--set-customvar | |
744 | :group 'newsticker-layout) | |
745 | ||
746 | (defcustom newsticker-desc-format | |
747 | "%d %c" | |
748 | "Format string for news descriptions (contents). | |
749 | The following printf-like specifiers can be used: | |
750 | %c The contents (description) of the item. | |
751 | %d The date the item was (first) retrieved. See `newsticker-date-format'." | |
752 | :type 'string | |
753 | :set 'newsticker--set-customvar | |
754 | :group 'newsticker-layout) | |
755 | ||
756 | (defcustom newsticker-date-format | |
757 | "(%A, %H:%M)" | |
758 | "Format for the date part in item and feed lines. | |
759 | See `format-time-string' for a list of valid specifiers." | |
760 | :type 'string | |
761 | :set 'newsticker--set-customvar | |
762 | :group 'newsticker-layout) | |
763 | ||
764 | (defcustom newsticker-statistics-format | |
765 | "[%n + %i + %o + %O = %a]" | |
766 | "Format for the statistics part in feed lines. | |
767 | The following printf-like specifiers can be used: | |
768 | %a The number of all items in the feed. | |
769 | %i The number of immortal items in the feed. | |
770 | %n The number of new items in the feed. | |
771 | %o The number of old items in the feed. | |
772 | %O The number of obsolete items in the feed." | |
773 | :type 'string | |
774 | :set 'newsticker--set-customvar | |
775 | :group 'newsticker-layout) | |
776 | ||
777 | (defcustom newsticker-show-all-rss-elements | |
778 | nil | |
779 | "Show all RSS elements." | |
780 | :type 'boolean | |
781 | ;;:set 'newsticker--set-customvar | |
782 | :group 'newsticker-layout) | |
783 | ||
784 | ;; image related things | |
785 | (defcustom newsticker-enable-logo-manipulations | |
786 | t | |
787 | "If non-nil newsticker manipulates logo images. | |
788 | This enables the following image properties: heuristic mask for all | |
789 | logos, and laplace-conversion for images without new items." | |
790 | :type 'boolean | |
791 | :group 'newsticker-layout) | |
792 | ||
793 | ||
794 | ;; rendering | |
795 | (defcustom newsticker-justification | |
796 | 'left | |
797 | "How to fill item descriptions. | |
798 | If non-nil newsticker calls `fill-region' to wrap long lines in | |
799 | item descriptions. However, if an item description contains HTML | |
800 | text and `newsticker-html-renderer' is non-nil, filling is not | |
801 | done." | |
802 | :type '(choice :tag "Justification" | |
803 | (const :tag "No filling" nil) | |
804 | (const :tag "Left" left) | |
805 | (const :tag "Right" right) | |
806 | (const :tag "Center" center) | |
807 | (const :tag "Full" full)) | |
808 | :set 'newsticker--set-customvar | |
809 | :group 'newsticker-layout) | |
810 | ||
811 | (defcustom newsticker-use-full-width | |
812 | t | |
813 | "Decides whether to use the full window width when filling. | |
814 | If non-nil newsticker sets `fill-column' so that the whole | |
815 | window is used when filling. See also `newsticker-justification'." | |
816 | :type 'boolean | |
817 | :set 'newsticker--set-customvar | |
818 | :group 'newsticker-layout) | |
819 | ||
820 | (defcustom newsticker-html-renderer | |
821 | nil | |
822 | "Function for rendering HTML contents. | |
823 | If non-nil, newsticker.el will call this function whenever it finds | |
824 | HTML-like tags in item descriptions. Possible functions are, for | |
825 | example, `w3m-region', `w3-region', and (if you have htmlr.el installed) | |
826 | `newsticker-htmlr-render'. | |
827 | ||
828 | In order to make sure that the HTML renderer is loaded when you | |
829 | run newsticker, you should add one of the following statements to | |
830 | your .emacs. If you use w3m, | |
831 | ||
832 | (autoload 'w3m-region \"w3m\" | |
833 | \"Render region in current buffer and replace with result.\" t) | |
834 | ||
835 | or, if you use w3, | |
836 | ||
837 | (require 'w3-auto) | |
838 | ||
839 | or, if you use htmlr | |
840 | ||
841 | (require 'htmlr)" | |
842 | :type '(choice :tag "Function" | |
843 | (const :tag "None" nil) | |
844 | (const :tag "w3" w3-region) | |
845 | (const :tag "w3m" w3m-region) | |
846 | (const :tag "htmlr" newsticker-htmlr-render)) | |
847 | :set 'newsticker--set-customvar | |
848 | :group 'newsticker-layout) | |
849 | ||
850 | ||
851 | ;; faces | |
852 | (defgroup newsticker-faces nil | |
853 | "Settings for the faces of the RSS reader." | |
854 | :group 'newsticker-layout) | |
855 | ||
856 | (defface newsticker-feed-face | |
857 | '((((class color) (background dark)) | |
858 | (:family "helvetica" :bold t :height 1.2 :foreground "misty rose")) | |
859 | (((class color) (background light)) | |
860 | (:family "helvetica" :bold t :height 1.2 :foreground "black"))) | |
861 | "Face for news feeds." | |
862 | :group 'newsticker-faces) | |
863 | ||
864 | (defface newsticker-new-item-face | |
865 | '((((class color) (background dark)) | |
866 | (:family "helvetica" :bold t)) | |
867 | (((class color) (background light)) | |
868 | (:family "helvetica" :bold t))) | |
869 | "Face for old news items." | |
870 | :group 'newsticker-faces) | |
871 | ||
872 | (defface newsticker-old-item-face | |
873 | '((((class color) (background dark)) | |
874 | (:family "helvetica" :bold t :foreground "orange3")) | |
875 | (((class color) (background light)) | |
876 | (:family "helvetica" :bold t :foreground "red4"))) | |
877 | "Face for old news items." | |
878 | :group 'newsticker-faces) | |
879 | ||
880 | (defface newsticker-immortal-item-face | |
881 | '((((class color) (background dark)) | |
882 | (:family "helvetica" :bold t :italic t :foreground "orange")) | |
883 | (((class color) (background light)) | |
884 | (:family "helvetica" :bold t :italic t :foreground "blue"))) | |
885 | "Face for immortal news items." | |
886 | :group 'newsticker-faces) | |
887 | ||
888 | (defface newsticker-obsolete-item-face | |
889 | '((((class color) (background dark)) | |
890 | (:family "helvetica" :bold t :strike-through t)) | |
891 | (((class color) (background light)) | |
892 | (:family "helvetica" :bold t :strike-through t))) | |
893 | "Face for old news items." | |
894 | :group 'newsticker-faces) | |
895 | ||
896 | (defface newsticker-date-face | |
897 | '((((class color) (background dark)) | |
898 | (:family "helvetica" :italic t :height 0.8)) | |
899 | (((class color) (background light)) | |
900 | (:family "helvetica" :italic t :height 0.8))) | |
901 | "Face for newsticker dates." | |
902 | :group 'newsticker-faces) | |
903 | ||
904 | (defface newsticker-statistics-face | |
905 | '((((class color) (background dark)) | |
906 | (:family "helvetica" :italic t :height 0.8)) | |
907 | (((class color) (background light)) | |
908 | (:family "helvetica" :italic t :height 0.8))) | |
909 | "Face for newsticker dates." | |
910 | :group 'newsticker-faces) | |
911 | ||
912 | (defface newsticker-enclosure-face | |
913 | '((((class color) (background dark)) | |
914 | (:bold t :background "orange")) | |
915 | (((class color) (background light)) | |
916 | (:bold t :background "orange"))) | |
917 | "Face for enclosed elements." | |
918 | :group 'newsticker-faces) | |
919 | ||
920 | (defface newsticker-extra-face | |
921 | '((((class color) (background dark)) | |
922 | (:italic t :foreground "gray50" :height 0.8)) | |
923 | (((class color) (background light)) | |
924 | (:italic t :foreground "gray50" :height 0.8))) | |
925 | "Face for newsticker dates." | |
926 | :group 'newsticker-faces) | |
927 | ||
928 | ;; (defface newsticker-default-face | |
929 | ;; '((((class color) (background dark)) | |
930 | ;; (:inherit default)) | |
931 | ;; (((class color) (background light)) | |
932 | ;; (:inherit default))) | |
933 | ;; "Face for the description of news items." | |
934 | ;; ;;:set 'newsticker--set-customvar | |
935 | ;; :group 'newsticker-faces) | |
936 | ||
937 | ||
938 | ;; customization group ticker | |
939 | (defgroup newsticker-ticker nil | |
940 | "Settings for the RSS ticker." | |
941 | :group 'newsticker) | |
942 | ||
943 | (defcustom newsticker-display-interval | |
944 | 0.3 | |
945 | "Time interval for displaying news items in the echo area (seconds). | |
946 | If equal or less than 0 no messages are shown in the echo area. For | |
947 | smooth display (see `newsticker-scroll-smoothly') a value of 0.3 seems | |
948 | reasonable. For non-smooth display a value of 10 is a good starting | |
949 | point." | |
950 | :type 'number | |
951 | :set 'newsticker--set-customvar | |
952 | :group 'newsticker-ticker) | |
953 | ||
954 | (defcustom newsticker-scroll-smoothly | |
955 | t | |
956 | "Decides whether to flash or scroll news items. | |
957 | If t the news headlines are scrolled (more-or-less) smoothly in the echo | |
958 | area. If nil one headline after another is displayed in the echo area. | |
959 | The variable `newsticker-display-interval' determines how fast this | |
960 | display moves/changes and whether headlines are shown in the echo area | |
961 | at all. If you change `newsticker-scroll-smoothly' you should also change | |
962 | `newsticker-display-interval'." | |
963 | :type 'boolean | |
964 | :group 'newsticker-ticker) | |
965 | ||
966 | (defcustom newsticker-hide-immortal-items-in-echo-area | |
967 | t | |
968 | "Decides whether to show immortal/non-expiring news items in the ticker. | |
969 | If t the echo area will not show immortal items. See also | |
970 | `newsticker-hide-old-items-in-echo-area." | |
971 | :type 'boolean | |
972 | :set 'newsticker--set-customvar | |
973 | :group 'newsticker-ticker) | |
e77274b7 | 974 | |
5629e04f RS |
975 | (defcustom newsticker-hide-old-items-in-echo-area |
976 | t | |
977 | "Decides whether to show only the newest news items in the ticker. | |
978 | If t the echo area will show only new items, i.e. only items which have | |
979 | been added between the last two retrievals." | |
980 | :type 'boolean | |
981 | :set 'newsticker--set-customvar | |
982 | :group 'newsticker-ticker) | |
983 | ||
984 | (defcustom newsticker-hide-obsolete-items-in-echo-area | |
985 | t | |
986 | "Decides whether to show obsolete items items in the ticker. | |
987 | If t the echo area will not show obsolete items. See also | |
988 | `newsticker-hide-old-items-in-echo-area." | |
989 | :type 'boolean | |
990 | :set 'newsticker--set-customvar | |
991 | :group 'newsticker-ticker) | |
992 | ||
993 | (defgroup newsticker-hooks nil | |
994 | "Settings for newsticker hooks." | |
995 | :group 'newsticker) | |
996 | ||
997 | (defcustom newsticker-start-hook | |
998 | nil | |
999 | "Hook run when starting newsticker. | |
1000 | This hook is run at the very end of `newsticker-start'." | |
1001 | :options '(newsticker-start-ticker) | |
1002 | :type 'hook | |
1003 | :group 'newsticker-hooks) | |
1004 | ||
1005 | (defcustom newsticker-stop-hook | |
1006 | nil | |
1007 | "Hook run when stopping newsticker. | |
1008 | This hook is run at the very end of `newsticker-stop'." | |
1009 | :options nil | |
1010 | :type 'hook | |
1011 | :group 'newsticker-hooks) | |
1012 | ||
1013 | (defcustom newsticker-new-item-functions | |
1014 | nil | |
1015 | "List of functions run after a new headline has been retrieved. | |
1016 | Each function is called with the following three arguments: | |
1017 | FEED the name of the corresponding news feed, | |
1018 | TITLE the title of the headline, | |
1019 | DESC the decoded description of the headline. | |
1020 | ||
1021 | See `newsticker-download-images', and | |
1022 | `newsticker-download-enclosures' for sample functions. | |
1023 | ||
1024 | Please note that these functions are called only once for a | |
1025 | headline after it has been retrieved for the first time." | |
1026 | :type 'hook | |
1027 | :options '(newsticker-download-images | |
1028 | newsticker-download-enclosures) | |
1029 | :group 'newsticker-hooks) | |
1030 | ||
1031 | (defcustom newsticker-select-item-hook | |
1032 | 'newsticker--buffer-make-item-completely-visible | |
1033 | "List of functions run after a headline has been selected. | |
1034 | Each function is called after one of `newsticker-next-item', | |
1035 | `newsticker-next-new-item', `newsticker-previous-item', | |
1036 | `newsticker-previous-new-item' has been called. | |
1037 | ||
1038 | The default value 'newsticker--buffer-make-item-completely-visible | |
1039 | assures that the current item is always completely visible." | |
1040 | :type 'hook | |
1041 | :options '(newsticker--buffer-make-item-completely-visible) | |
1042 | :group 'newsticker-hooks) | |
1043 | ||
1044 | (defcustom newsticker-select-feed-hook | |
1045 | 'newsticker--buffer-make-item-completely-visible | |
1046 | "List of functions run after a feed has been selected. | |
1047 | Each function is called after one of `newsticker-next-feed', and | |
1048 | `newsticker-previous-feed' has been called. | |
1049 | ||
1050 | The default value 'newsticker--buffer-make-item-completely-visible | |
1051 | assures that the current feed is completely visible." | |
1052 | :type 'hook | |
1053 | :options '(newsticker--buffer-make-item-completely-visible) | |
1054 | :group 'newsticker-hooks) | |
1055 | ||
1056 | (defcustom newsticker-buffer-change-hook | |
1057 | 'newsticker-w3m-show-inline-images | |
1058 | "List of functions run after the newsticker buffer has been updated. | |
1059 | Each function is called after `newsticker-buffer-update' has been called. | |
1060 | ||
1061 | The default value '`newsticker-w3m-show-inline-images' loads inline | |
1062 | images." | |
1063 | :type 'hook | |
1064 | :group 'newsticker-hooks) | |
1065 | ||
1066 | (defcustom newsticker-narrow-hook | |
1067 | 'newsticker-w3m-show-inline-images | |
1068 | "List of functions run after narrowing in newsticker buffer has changed. | |
1069 | Each function is called after | |
1070 | `newsticker-toggle-auto-narrow-to-feed' or | |
1071 | `newsticker-toggle-auto-narrow-to-item' has been called. | |
1072 | ||
1073 | The default value '`newsticker-w3m-show-inline-images' loads inline | |
1074 | images." | |
1075 | :type 'hook | |
1076 | :group 'newsticker-hooks) | |
1077 | ||
1078 | (defgroup newsticker-miscellaneous nil | |
1079 | "Miscellaneous newsticker settings." | |
1080 | :group 'newsticker) | |
1081 | ||
1082 | (defcustom newsticker-cache-filename | |
1083 | "~/.newsticker-cache" | |
1084 | "Name of the newsticker cache file." | |
1085 | :type 'string | |
1086 | :group 'newsticker-miscellaneous) | |
1087 | ||
1088 | (defcustom newsticker-imagecache-dirname | |
1089 | "~/.newsticker-images" | |
1090 | "Name of the directory where newsticker stores cached images." | |
1091 | :type 'string | |
1092 | :group 'newsticker-miscellaneous) | |
1093 | ||
1094 | ;; debugging | |
1095 | (defcustom newsticker-debug | |
1096 | nil | |
1097 | "Enables some features needed for debugging newsticker.el. | |
1098 | ||
1099 | If set to t newsticker.el will print lots of debugging messages, and the | |
1100 | buffers *newsticker-wget-<feed>* will not be closed." | |
1101 | :type 'boolean | |
1102 | ;;:set 'newsticker--set-customvar | |
1103 | :group 'newsticker-miscellaneous) | |
1104 | ||
1105 | ;; ====================================================================== | |
1106 | ;;; Compatibility section, XEmacs, Emacs | |
1107 | ;; ====================================================================== | |
1108 | (unless (fboundp 'time-add) | |
1109 | (require 'time-date);;FIXME | |
1110 | (defun time-add (t1 t2) | |
1111 | (seconds-to-time (+ (time-to-seconds t1) (time-to-seconds t2))))) | |
1112 | ||
1113 | (unless (fboundp 'match-string-no-properties) | |
1114 | (defalias 'match-string-no-properties 'match-string)) | |
1115 | ||
1116 | (unless (fboundp 'replace-regexp-in-string) | |
1117 | (defun replace-regexp-in-string (re rp st) | |
1118 | (save-match-data ;; apparently XEmacs needs save-match-data | |
1119 | (replace-in-string st re rp)))) | |
1120 | ||
1121 | ;; copied from subr.el | |
1122 | (unless (fboundp 'add-to-invisibility-spec) | |
1123 | (defun add-to-invisibility-spec (arg) | |
1124 | "Add elements to `buffer-invisibility-spec'. | |
1125 | See documentation for `buffer-invisibility-spec' for the kind of elements | |
1126 | that can be added." | |
1127 | (if (eq buffer-invisibility-spec t) | |
1128 | (setq buffer-invisibility-spec (list t))) | |
1129 | (setq buffer-invisibility-spec | |
1130 | (cons arg buffer-invisibility-spec)))) | |
1131 | ||
1132 | ;; copied from subr.el | |
1133 | (unless (fboundp 'remove-from-invisibility-spec) | |
1134 | (defun remove-from-invisibility-spec (arg) | |
1135 | "Remove elements from `buffer-invisibility-spec'." | |
1136 | (if (consp buffer-invisibility-spec) | |
1137 | (setq buffer-invisibility-spec (delete arg buffer-invisibility-spec))))) | |
1138 | ||
1139 | ;; ====================================================================== | |
1140 | ;;; Internal variables | |
1141 | ;; ====================================================================== | |
1142 | (defvar newsticker--display-timer nil | |
1143 | "Timer for newsticker display.") | |
1144 | (defvar newsticker--retrieval-timer-list nil | |
1145 | "List of timers for news retrieval. | |
1146 | This is an alist, each element consisting of (feed-name . timer)") | |
1147 | (defvar newsticker--item-list nil | |
1148 | "List of newsticker items.") | |
1149 | (defvar newsticker--item-position 0 | |
1150 | "Actual position in list of newsticker items.") | |
1151 | (defvar newsticker--prev-message "There was no previous message yet!" | |
1152 | "Last message that the newsticker displayed.") | |
1153 | (defvar newsticker--scrollable-text "" | |
1154 | "The text which is scrolled smoothly in the echo area.") | |
1155 | (defvar newsticker--buffer-uptodate-p nil | |
1156 | "Tells whether the newsticker buffer is up to date.") | |
1157 | (defvar newsticker--latest-update-time (current-time) | |
1158 | "The time at which the latest news arrived.") | |
1159 | ||
1160 | (defvar newsticker--cache nil "Cached newsticker data. | |
1161 | This is a list of the form | |
1162 | ||
1163 | ((label1 | |
1164 | (title description link time age index preformatted-contents | |
1165 | preformatted-title) | |
1166 | ...) | |
1167 | (label2 | |
1168 | (title description link time age index preformatted-contents | |
1169 | preformatted-title) | |
1170 | ...) | |
1171 | ...) | |
1172 | ||
1173 | where LABEL is a symbol. TITLE, DESCRIPTION, and LINK are | |
1174 | strings. TIME is a time value as returned by `current-time'. | |
1175 | AGE is a symbol: 'new, 'old, 'immortal, and 'obsolete denote | |
1176 | ordinary news items, whereas 'feed denotes an item which is not a | |
1177 | headline but describes the feed itself. INDEX denotes the | |
1178 | original position of the item -- used for restoring the original | |
1179 | order. PREFORMATTED-CONTENTS and PREFORMATTED-TITLE hold the | |
1180 | formatted contents of the item's description and title. This | |
1181 | speeds things up if HTML rendering is used, which is rather | |
1182 | slow.") | |
1183 | ||
1184 | (defvar newsticker--auto-narrow-to-feed nil | |
1185 | "Automatically narrow to current news feed. | |
1186 | If non-nil only the items of the current news feed are visible.") | |
1187 | ||
1188 | (defvar newsticker--auto-narrow-to-item nil | |
1189 | "Automatically narrow to current news item. | |
1190 | If non-nil only the current headline is visible.") | |
1191 | ||
1192 | (defconst newsticker--error-headline | |
1193 | "[COULD NOT DOWNLOAD HEADLINES!]" | |
1194 | "Title of error headline which will be inserted if news retrieval fails.") | |
1195 | ||
1196 | ;; ====================================================================== | |
1197 | ;;; Toolbar | |
1198 | ;; ====================================================================== | |
1199 | (defconst newsticker--next-item-image | |
1200 | (if (fboundp 'create-image) | |
1201 | (create-image "/* XPM */ | |
1202 | static char * next_xpm[] = { | |
1203 | \"24 24 42 1\", | |
1204 | \" c None\", | |
1205 | \". c #000000\", | |
1206 | \"+ c #7EB6DE\", | |
1207 | \"@ c #82BBE2\", | |
1208 | \"# c #85BEE4\", | |
1209 | \"$ c #88C1E7\", | |
1210 | \"% c #8AC3E8\", | |
1211 | \"& c #87C1E6\", | |
1212 | \"* c #8AC4E9\", | |
1213 | \"= c #8CC6EA\", | |
1214 | \"- c #8CC6EB\", | |
1215 | \"; c #88C2E7\", | |
1216 | \"> c #8BC5E9\", | |
1217 | \", c #8DC7EB\", | |
1218 | \"' c #87C0E6\", | |
1219 | \") c #8AC4E8\", | |
1220 | \"! c #8BC5EA\", | |
1221 | \"~ c #8BC4E9\", | |
1222 | \"{ c #88C1E6\", | |
1223 | \"] c #89C3E8\", | |
1224 | \"^ c #86BFE5\", | |
1225 | \"/ c #83BBE2\", | |
1226 | \"( c #82BBE1\", | |
1227 | \"_ c #86C0E5\", | |
1228 | \": c #87C0E5\", | |
1229 | \"< c #83BCE2\", | |
1230 | \"[ c #81B9E0\", | |
1231 | \"} c #81BAE1\", | |
1232 | \"| c #78B0D9\", | |
1233 | \"1 c #7BB3DB\", | |
1234 | \"2 c #7DB5DD\", | |
1235 | \"3 c #7DB6DD\", | |
1236 | \"4 c #72A9D4\", | |
1237 | \"5 c #75ACD6\", | |
1238 | \"6 c #76AED7\", | |
1239 | \"7 c #77AFD8\", | |
1240 | \"8 c #6BA1CD\", | |
1241 | \"9 c #6EA4CF\", | |
1242 | \"0 c #6FA6D1\", | |
1243 | \"a c #6298C6\", | |
1244 | \"b c #659BC8\", | |
1245 | \"c c #5C91C0\", | |
1246 | \" \", | |
1247 | \" \", | |
1248 | \" . \", | |
1249 | \" .. \", | |
1250 | \" .+. \", | |
1251 | \" .@#. \", | |
1252 | \" .#$%. \", | |
1253 | \" .&*=-. \", | |
1254 | \" .;>,,,. \", | |
1255 | \" .;>,,,=. \", | |
1256 | \" .')!==~;. \", | |
1257 | \" .#{]*%;^/. \", | |
1258 | \" .(#_':#<. \", | |
1259 | \" .+[@</}. \", | |
1260 | \" .|1232. \", | |
1261 | \" .4567. \", | |
1262 | \" .890. \", | |
1263 | \" .ab. \", | |
1264 | \" .c. \", | |
1265 | \" .. \", | |
1266 | \" . \", | |
1267 | \" \", | |
1268 | \" \", | |
1269 | \" \"}; | |
1270 | " | |
1271 | 'xpm t) | |
1272 | "Image for the next item button.")) | |
1273 | ||
1274 | (defconst newsticker--previous-item-image | |
1275 | (if (fboundp 'create-image) | |
1276 | (create-image "/* XPM */ | |
1277 | static char * previous_xpm[] = { | |
1278 | \"24 24 39 1\", | |
1279 | \" c None\", | |
1280 | \". c #000000\", | |
1281 | \"+ c #7BB3DB\", | |
1282 | \"@ c #83BCE2\", | |
1283 | \"# c #7FB8DF\", | |
1284 | \"$ c #89C2E7\", | |
1285 | \"% c #86BFE5\", | |
1286 | \"& c #83BBE2\", | |
1287 | \"* c #8CC6EA\", | |
1288 | \"= c #8BC4E9\", | |
1289 | \"- c #88C2E7\", | |
1290 | \"; c #85BEE4\", | |
1291 | \"> c #8DC7EB\", | |
1292 | \", c #89C3E8\", | |
1293 | \"' c #8AC4E8\", | |
1294 | \") c #8BC5EA\", | |
1295 | \"! c #88C1E6\", | |
1296 | \"~ c #8AC4E9\", | |
1297 | \"{ c #8AC3E8\", | |
1298 | \"] c #86C0E5\", | |
1299 | \"^ c #87C0E6\", | |
1300 | \"/ c #87C0E5\", | |
1301 | \"( c #82BBE2\", | |
1302 | \"_ c #81BAE1\", | |
1303 | \": c #7FB7DF\", | |
1304 | \"< c #7DB6DD\", | |
1305 | \"[ c #7DB5DD\", | |
1306 | \"} c #7CB4DC\", | |
1307 | \"| c #79B1DA\", | |
1308 | \"1 c #76ADD7\", | |
1309 | \"2 c #77AFD8\", | |
1310 | \"3 c #73AAD4\", | |
1311 | \"4 c #70A7D1\", | |
1312 | \"5 c #6EA5D0\", | |
1313 | \"6 c #6CA2CE\", | |
1314 | \"7 c #689ECB\", | |
1315 | \"8 c #6399C7\", | |
1316 | \"9 c #6095C4\", | |
1317 | \"0 c #5C90C0\", | |
1318 | \" \", | |
1319 | \" \", | |
1320 | \" . \", | |
1321 | \" .. \", | |
1322 | \" .+. \", | |
1323 | \" .@#. \", | |
1324 | \" .$%&. \", | |
1325 | \" .*=-;. \", | |
1326 | \" .>>*,%. \", | |
1327 | \" .>>>*,%. \", | |
1328 | \" .')**=-;. \", | |
1329 | \" .;!,~{-%&. \", | |
1330 | \" .;]^/;@#. \", | |
1331 | \" .(@&_:+. \", | |
1332 | \" .<[}|1. \", | |
1333 | \" .2134. \", | |
1334 | \" .567. \", | |
1335 | \" .89. \", | |
1336 | \" .0. \", | |
1337 | \" .. \", | |
1338 | \" . \", | |
1339 | \" \", | |
1340 | \" \", | |
1341 | \" \"}; | |
1342 | " | |
1343 | 'xpm t) | |
1344 | "Image for the previous item button.")) | |
1345 | ||
1346 | (defconst newsticker--previous-feed-image | |
1347 | (if (fboundp 'create-image) | |
1348 | (create-image "/* XPM */ | |
1349 | static char * prev_feed_xpm[] = { | |
1350 | \"24 24 52 1\", | |
1351 | \" c None\", | |
1352 | \". c #000000\", | |
1353 | \"+ c #70A7D2\", | |
1354 | \"@ c #75ADD6\", | |
1355 | \"# c #71A8D3\", | |
1356 | \"$ c #79B1DA\", | |
1357 | \"% c #7BB3DB\", | |
1358 | \"& c #7DB5DD\", | |
1359 | \"* c #83BBE2\", | |
1360 | \"= c #7EB6DE\", | |
1361 | \"- c #78B0D9\", | |
1362 | \"; c #7FB7DE\", | |
1363 | \"> c #88C2E7\", | |
1364 | \", c #85BEE4\", | |
1365 | \"' c #80B9E0\", | |
1366 | \") c #80B8DF\", | |
1367 | \"! c #8CC6EA\", | |
1368 | \"~ c #89C3E8\", | |
1369 | \"{ c #86BFE5\", | |
1370 | \"] c #81BAE1\", | |
1371 | \"^ c #7CB4DC\", | |
1372 | \"/ c #7FB8DF\", | |
1373 | \"( c #8DC7EB\", | |
1374 | \"_ c #7BB3DC\", | |
1375 | \": c #7EB7DE\", | |
1376 | \"< c #8BC4E9\", | |
1377 | \"[ c #8AC4E9\", | |
1378 | \"} c #8AC3E8\", | |
1379 | \"| c #87C0E6\", | |
1380 | \"1 c #87C0E5\", | |
1381 | \"2 c #83BCE2\", | |
1382 | \"3 c #75ACD6\", | |
1383 | \"4 c #7FB7DF\", | |
1384 | \"5 c #77AED8\", | |
1385 | \"6 c #71A8D2\", | |
1386 | \"7 c #70A7D1\", | |
1387 | \"8 c #76ADD7\", | |
1388 | \"9 c #6CA2CE\", | |
1389 | \"0 c #699FCC\", | |
1390 | \"a c #73AAD4\", | |
1391 | \"b c #6BA1CD\", | |
1392 | \"c c #669CC9\", | |
1393 | \"d c #6298C5\", | |
1394 | \"e c #689ECB\", | |
1395 | \"f c #6499C7\", | |
1396 | \"g c #6095C3\", | |
1397 | \"h c #5C91C0\", | |
1398 | \"i c #5E93C2\", | |
1399 | \"j c #5B90C0\", | |
1400 | \"k c #588CBC\", | |
1401 | \"l c #578CBC\", | |
1402 | \"m c #5589BA\", | |
1403 | \" \", | |
1404 | \" \", | |
1405 | \" ... . \", | |
1406 | \" .+. .. \", | |
1407 | \" .@. .#. \", | |
1408 | \" .$. .%@. \", | |
1409 | \" .&. .*=-. \", | |
1410 | \" .;. .>,'%. \", | |
1411 | \" .). .!~{]^. \", | |
1412 | \" ./. .(!~{]_. \", | |
1413 | \" .:. .!!<>,'%. \", | |
1414 | \" .&. .~[}>{*=-. \", | |
1415 | \" .$. .|1,2/%@. \", | |
1416 | \" .3. .*]4%56. \", | |
1417 | \" .7. .^$8#9. \", | |
1418 | \" .0. .a7bc. \", | |
1419 | \" .d. .efg. \", | |
1420 | \" .h. .ij. \", | |
1421 | \" .k. .l. \", | |
1422 | \" .m. .. \", | |
1423 | \" ... . \", | |
1424 | \" \", | |
1425 | \" \", | |
1426 | \" \"}; | |
1427 | " | |
1428 | 'xpm t) | |
1429 | "Image for the previous feed button.")) | |
1430 | ||
1431 | (defconst newsticker--next-feed-image | |
1432 | (if (fboundp 'create-image) | |
1433 | (create-image "/* XPM */ | |
1434 | static char * next_feed_xpm[] = { | |
1435 | \"24 24 57 1\", | |
1436 | \" c None\", | |
1437 | \". c #000000\", | |
1438 | \"+ c #6CA2CE\", | |
1439 | \"@ c #75ADD6\", | |
1440 | \"# c #71A8D3\", | |
1441 | \"$ c #79B1DA\", | |
1442 | \"% c #7EB7DE\", | |
1443 | \"& c #7DB5DD\", | |
1444 | \"* c #81BAE1\", | |
1445 | \"= c #85BEE4\", | |
1446 | \"- c #78B0D9\", | |
1447 | \"; c #7FB7DE\", | |
1448 | \"> c #83BCE3\", | |
1449 | \", c #87C1E6\", | |
1450 | \"' c #8AC4E9\", | |
1451 | \") c #7BB3DB\", | |
1452 | \"! c #80B8DF\", | |
1453 | \"~ c #88C2E7\", | |
1454 | \"{ c #8BC5E9\", | |
1455 | \"] c #8DC7EB\", | |
1456 | \"^ c #7CB4DC\", | |
1457 | \"/ c #7FB8DF\", | |
1458 | \"( c #84BDE3\", | |
1459 | \"_ c #7BB3DC\", | |
1460 | \": c #83BCE2\", | |
1461 | \"< c #87C0E6\", | |
1462 | \"[ c #8AC4E8\", | |
1463 | \"} c #8BC5EA\", | |
1464 | \"| c #8CC6EA\", | |
1465 | \"1 c #88C1E6\", | |
1466 | \"2 c #89C3E8\", | |
1467 | \"3 c #8AC3E8\", | |
1468 | \"4 c #7EB6DE\", | |
1469 | \"5 c #82BBE1\", | |
1470 | \"6 c #86C0E5\", | |
1471 | \"7 c #87C0E5\", | |
1472 | \"8 c #75ACD6\", | |
1473 | \"9 c #7AB2DA\", | |
1474 | \"0 c #81B9E0\", | |
1475 | \"a c #82BBE2\", | |
1476 | \"b c #71A8D2\", | |
1477 | \"c c #70A7D1\", | |
1478 | \"d c #74ACD6\", | |
1479 | \"e c #699FCC\", | |
1480 | \"f c #6EA5D0\", | |
1481 | \"g c #72A9D4\", | |
1482 | \"h c #669CC9\", | |
1483 | \"i c #6298C5\", | |
1484 | \"j c #679DCA\", | |
1485 | \"k c #6BA1CD\", | |
1486 | \"l c #6095C3\", | |
1487 | \"m c #5C91C0\", | |
1488 | \"n c #5F94C2\", | |
1489 | \"o c #5B90C0\", | |
1490 | \"p c #588CBC\", | |
1491 | \"q c #578CBC\", | |
1492 | \"r c #5589BA\", | |
1493 | \" \", | |
1494 | \" \", | |
1495 | \" . ... \", | |
1496 | \" .. .+. \", | |
1497 | \" .@. .#. \", | |
1498 | \" .$%. .@. \", | |
1499 | \" .&*=. .-. \", | |
1500 | \" .;>,'. .). \", | |
1501 | \" .!=~{]. .^. \", | |
1502 | \" ./(~{]]. ._. \", | |
1503 | \" .%:<[}||. .). \", | |
1504 | \" .&*=12'3~. .-. \", | |
1505 | \" .$45=6<7. .@. \", | |
1506 | \" .8940a:. .b. \", | |
1507 | \" .cd-)&. .+. \", | |
1508 | \" .efg8. .h. \", | |
1509 | \" .ijk. .l. \", | |
1510 | \" .mn. .o. \", | |
1511 | \" .p. .q. \", | |
1512 | \" .. .r. \", | |
1513 | \" . ... \", | |
1514 | \" \", | |
1515 | \" \", | |
1516 | \" \"}; | |
1517 | " | |
1518 | 'xpm t) | |
1519 | "Image for the next feed button.")) | |
1520 | ||
1521 | (defconst newsticker--mark-read-image | |
1522 | (if (fboundp 'create-image) | |
1523 | (create-image "/* XPM */ | |
1524 | static char * mark_read_xpm[] = { | |
1525 | \"24 24 44 1\", | |
1526 | \" c None\", | |
1527 | \". c #C20000\", | |
1528 | \"+ c #BE0000\", | |
1529 | \"@ c #C70000\", | |
1530 | \"# c #CE0000\", | |
1531 | \"$ c #C90000\", | |
1532 | \"% c #BD0000\", | |
1533 | \"& c #CB0000\", | |
1534 | \"* c #D10000\", | |
1535 | \"= c #D70000\", | |
1536 | \"- c #D30000\", | |
1537 | \"; c #CD0000\", | |
1538 | \"> c #C60000\", | |
1539 | \", c #D40000\", | |
1540 | \"' c #DA0000\", | |
1541 | \") c #DE0000\", | |
1542 | \"! c #DB0000\", | |
1543 | \"~ c #D60000\", | |
1544 | \"{ c #D00000\", | |
1545 | \"] c #DC0000\", | |
1546 | \"^ c #E00000\", | |
1547 | \"/ c #E40000\", | |
1548 | \"( c #E10000\", | |
1549 | \"_ c #DD0000\", | |
1550 | \": c #D80000\", | |
1551 | \"< c #E50000\", | |
1552 | \"[ c #E70000\", | |
1553 | \"} c #E60000\", | |
1554 | \"| c #E20000\", | |
1555 | \"1 c #E90000\", | |
1556 | \"2 c #E80000\", | |
1557 | \"3 c #E30000\", | |
1558 | \"4 c #DF0000\", | |
1559 | \"5 c #D90000\", | |
1560 | \"6 c #CC0000\", | |
1561 | \"7 c #C10000\", | |
1562 | \"8 c #C30000\", | |
1563 | \"9 c #BF0000\", | |
1564 | \"0 c #B90000\", | |
1565 | \"a c #BC0000\", | |
1566 | \"b c #BB0000\", | |
1567 | \"c c #B80000\", | |
1568 | \"d c #B50000\", | |
1569 | \"e c #B70000\", | |
1570 | \" \", | |
1571 | \" \", | |
1572 | \" \", | |
1573 | \" . + \", | |
1574 | \" +@# $.% \", | |
1575 | \" &*= -;> \", | |
1576 | \" ,') !~{ \", | |
1577 | \" ]^/ (_: \", | |
1578 | \" (<[ }|) \", | |
1579 | \" <[1 2<| \", | |
1580 | \" }222[< \", | |
1581 | \" }}}< \", | |
1582 | \" 333| \", | |
1583 | \" _4^4)] \", | |
1584 | \" ~:' 5=- \", | |
1585 | \" 6{- *#$ \", | |
1586 | \" 7>$ @89 \", | |
1587 | \" 0a+ %bc \", | |
1588 | \" ddc edd \", | |
1589 | \" ddd ddd \", | |
1590 | \" d d \", | |
1591 | \" \", | |
1592 | \" \", | |
1593 | \" \"}; | |
1594 | " | |
1595 | 'xpm t) | |
1596 | "Image for the next feed button.")) | |
1597 | ||
1598 | (defconst newsticker--mark-immortal-image | |
1599 | (if (fboundp 'create-image) | |
1600 | (create-image "/* XPM */ | |
1601 | static char * mark_immortal_xpm[] = { | |
1602 | \"24 24 93 2\", | |
1603 | \" c None\", | |
1604 | \". c #171717\", | |
1605 | \"+ c #030303\", | |
1606 | \"@ c #000000\", | |
1607 | \"# c #181818\", | |
1608 | \"$ c #090909\", | |
1609 | \"% c #FFC960\", | |
1610 | \"& c #FFCB61\", | |
1611 | \"* c #FFCB62\", | |
1612 | \"= c #FFC961\", | |
1613 | \"- c #FFC75F\", | |
1614 | \"; c #FFC65E\", | |
1615 | \"> c #FFCA61\", | |
1616 | \", c #FFCD63\", | |
1617 | \"' c #FFCF65\", | |
1618 | \") c #FFD065\", | |
1619 | \"! c #FFCE64\", | |
1620 | \"~ c #FFC35C\", | |
1621 | \"{ c #FFC45D\", | |
1622 | \"] c #FFD166\", | |
1623 | \"^ c #FFD267\", | |
1624 | \"/ c #FFD368\", | |
1625 | \"( c #FFD167\", | |
1626 | \"_ c #FFC05A\", | |
1627 | \": c #010101\", | |
1628 | \"< c #040404\", | |
1629 | \"[ c #FFCC62\", | |
1630 | \"} c #FFD569\", | |
1631 | \"| c #FFD56A\", | |
1632 | \"1 c #FFC860\", | |
1633 | \"2 c #FFC25B\", | |
1634 | \"3 c #FFBB56\", | |
1635 | \"4 c #020202\", | |
1636 | \"5 c #060606\", | |
1637 | \"6 c #FFC15B\", | |
1638 | \"7 c #FFC85F\", | |
1639 | \"8 c #FFD469\", | |
1640 | \"9 c #FFD66A\", | |
1641 | \"0 c #FFBC57\", | |
1642 | \"a c #1B1B1B\", | |
1643 | \"b c #070707\", | |
1644 | \"c c #FFBA55\", | |
1645 | \"d c #FFB451\", | |
1646 | \"e c #FFB954\", | |
1647 | \"f c #FFB350\", | |
1648 | \"g c #FFB652\", | |
1649 | \"h c #FFBE58\", | |
1650 | \"i c #FFCD64\", | |
1651 | \"j c #FFD066\", | |
1652 | \"k c #FFC059\", | |
1653 | \"l c #FFB14E\", | |
1654 | \"m c #0B0B0B\", | |
1655 | \"n c #FFBB55\", | |
1656 | \"o c #FFC15A\", | |
1657 | \"p c #FFB552\", | |
1658 | \"q c #FFAD4B\", | |
1659 | \"r c #080808\", | |
1660 | \"s c #FFAF4C\", | |
1661 | \"t c #FFB853\", | |
1662 | \"u c #FFA948\", | |
1663 | \"v c #050505\", | |
1664 | \"w c #FFB04E\", | |
1665 | \"x c #FFB753\", | |
1666 | \"y c #FFBC56\", | |
1667 | \"z c #FFC55D\", | |
1668 | \"A c #FFC55E\", | |
1669 | \"B c #FFC45C\", | |
1670 | \"C c #FFBD57\", | |
1671 | \"D c #FFB854\", | |
1672 | \"E c #FFB34F\", | |
1673 | \"F c #FFAB4A\", | |
1674 | \"G c #FFA545\", | |
1675 | \"H c #FFAA49\", | |
1676 | \"I c #FFB04D\", | |
1677 | \"J c #FFB551\", | |
1678 | \"K c #FFBF58\", | |
1679 | \"L c #FFB24F\", | |
1680 | \"M c #FFAC4A\", | |
1681 | \"N c #FFA646\", | |
1682 | \"O c #FFA344\", | |
1683 | \"P c #FFA848\", | |
1684 | \"Q c #FFB14F\", | |
1685 | \"R c #FFAF4D\", | |
1686 | \"S c #FFA546\", | |
1687 | \"T c #FFA243\", | |
1688 | \"U c #FFA445\", | |
1689 | \"V c #FFAE4C\", | |
1690 | \"W c #FFA444\", | |
1691 | \"X c #FFA142\", | |
1692 | \"Y c #FF9F41\", | |
1693 | \"Z c #0A0A0A\", | |
1694 | \"` c #FF9E40\", | |
1695 | \" . c #FF9F40\", | |
1696 | \" \", | |
1697 | \" \", | |
1698 | \" \", | |
1699 | \" . + @ @ + # \", | |
1700 | \" $ @ % & * * = - + + \", | |
1701 | \" @ ; > , ' ) ' ! * - ~ @ \", | |
1702 | \" @ { > ! ] ^ / / ( ' * ; _ : \", | |
1703 | \" < _ ; [ ) / } | } / ] , 1 2 3 4 \", | |
1704 | \" 5 6 7 , ] 8 9 9 9 } ^ ! = ~ 0 a \", | |
1705 | \" b c 6 - , ] 8 9 9 9 } ^ ! % ~ 0 d 5 \", | |
1706 | \" : e _ ; * ) / 8 } } / ] , 1 2 3 f 5 \", | |
1707 | \" : g h { = i j ^ / ^ ] ! * ; k e l m \", | |
1708 | \" : f n o ; > , ' ) ' ! * - 2 0 p q r \", | |
1709 | \" : s g 0 6 ; % > * * = - ~ h t l u r \", | |
1710 | \" v u w x y k ~ z A z B o C D E F G b \", | |
1711 | \" 5 H I J e 0 h K h C c x L M N . \", | |
1712 | \" 4 O P q Q d g x g J L R H S T < \", | |
1713 | \" @ T U P F q V q M H N W X + \", | |
1714 | \" @ Y T O W G G W O X Y @ \", | |
1715 | \" 4 Z ` Y Y Y .` 4 4 \", | |
1716 | \" 5 : : @ @ Z \", | |
1717 | \" \", | |
1718 | \" \", | |
1719 | \" \"}; | |
1720 | " | |
1721 | 'xpm t) | |
1722 | "Image for the next feed button.")) | |
1723 | ||
1724 | ||
1725 | (defconst newsticker--narrow-image | |
1726 | (if (fboundp 'create-image) | |
1727 | (create-image "/* XPM */ | |
1728 | static char * narrow_xpm[] = { | |
1729 | \"24 24 48 1\", | |
1730 | \" c None\", | |
1731 | \". c #000000\", | |
1732 | \"+ c #969696\", | |
1733 | \"@ c #9E9E9E\", | |
1734 | \"# c #A4A4A4\", | |
1735 | \"$ c #AAAAAA\", | |
1736 | \"% c #AEAEAE\", | |
1737 | \"& c #B1B1B1\", | |
1738 | \"* c #B3B3B3\", | |
1739 | \"= c #B4B4B4\", | |
1740 | \"- c #B2B2B2\", | |
1741 | \"; c #AFAFAF\", | |
1742 | \"> c #ABABAB\", | |
1743 | \", c #A6A6A6\", | |
1744 | \"' c #A0A0A0\", | |
1745 | \") c #989898\", | |
1746 | \"! c #909090\", | |
1747 | \"~ c #73AAD4\", | |
1748 | \"{ c #7AB2DA\", | |
1749 | \"] c #7FB8DF\", | |
1750 | \"^ c #84BDE3\", | |
1751 | \"/ c #88C2E7\", | |
1752 | \"( c #8BC5E9\", | |
1753 | \"_ c #8DC7EB\", | |
1754 | \": c #8CC6EA\", | |
1755 | \"< c #89C3E8\", | |
1756 | \"[ c #86BFE5\", | |
1757 | \"} c #81BAE1\", | |
1758 | \"| c #7BB3DC\", | |
1759 | \"1 c #75ACD6\", | |
1760 | \"2 c #6DA4CF\", | |
1761 | \"3 c #979797\", | |
1762 | \"4 c #A3A3A3\", | |
1763 | \"5 c #A8A8A8\", | |
1764 | \"6 c #ADADAD\", | |
1765 | \"7 c #ACACAC\", | |
1766 | \"8 c #A9A9A9\", | |
1767 | \"9 c #A5A5A5\", | |
1768 | \"0 c #9A9A9A\", | |
1769 | \"a c #929292\", | |
1770 | \"b c #8C8C8C\", | |
1771 | \"c c #808080\", | |
1772 | \"d c #818181\", | |
1773 | \"e c #838383\", | |
1774 | \"f c #848484\", | |
1775 | \"g c #858585\", | |
1776 | \"h c #868686\", | |
1777 | \"i c #828282\", | |
1778 | \" \", | |
1779 | \" \", | |
1780 | \" \", | |
1781 | \" .................. \", | |
1782 | \" .+@#$%&*=*-;>,')!. \", | |
1783 | \" .................. \", | |
1784 | \" \", | |
1785 | \" \", | |
1786 | \" .................. \", | |
1787 | \" .~{]^/(___:<[}|12. \", | |
1788 | \" .................. \", | |
1789 | \" \", | |
1790 | \" \", | |
1791 | \" .................. \", | |
1792 | \" .!3@45>666789'0ab. \", | |
1793 | \" .................. \", | |
1794 | \" \", | |
1795 | \" \", | |
1796 | \" .................. \", | |
1797 | \" .cccdefghhgficccc. \", | |
1798 | \" .................. \", | |
1799 | \" \", | |
1800 | \" \", | |
1801 | \" \"}; | |
1802 | " | |
1803 | 'xpm t) | |
1804 | "Image for the next feed button.")) | |
1805 | ||
1806 | (defconst newsticker--get-all-image | |
1807 | (if (fboundp 'create-image) | |
1808 | (create-image "/* XPM */ | |
1809 | static char * get_all_xpm[] = { | |
1810 | \"24 24 70 1\", | |
1811 | \" c None\", | |
1812 | \". c #000000\", | |
1813 | \"+ c #F3DA00\", | |
1814 | \"@ c #F5DF00\", | |
1815 | \"# c #F7E300\", | |
1816 | \"$ c #F9E700\", | |
1817 | \"% c #FAEA00\", | |
1818 | \"& c #FBEC00\", | |
1819 | \"* c #FBED00\", | |
1820 | \"= c #FCEE00\", | |
1821 | \"- c #FAEB00\", | |
1822 | \"; c #F9E800\", | |
1823 | \"> c #F8E500\", | |
1824 | \", c #F6E000\", | |
1825 | \"' c #F4DB00\", | |
1826 | \") c #F1D500\", | |
1827 | \"! c #EFD000\", | |
1828 | \"~ c #B7CA00\", | |
1829 | \"{ c #BFD100\", | |
1830 | \"] c #C5D700\", | |
1831 | \"^ c #CBDB00\", | |
1832 | \"/ c #CFDF00\", | |
1833 | \"( c #D2E200\", | |
1834 | \"_ c #D4E400\", | |
1835 | \": c #D3E300\", | |
1836 | \"< c #D0E000\", | |
1837 | \"[ c #CCDD00\", | |
1838 | \"} c #C7D800\", | |
1839 | \"| c #C1D300\", | |
1840 | \"1 c #BACC00\", | |
1841 | \"2 c #B1C500\", | |
1842 | \"3 c #A8BC00\", | |
1843 | \"4 c #20A900\", | |
1844 | \"5 c #22AF00\", | |
1845 | \"6 c #24B500\", | |
1846 | \"7 c #26B900\", | |
1847 | \"8 c #27BC00\", | |
1848 | \"9 c #27BE00\", | |
1849 | \"0 c #28BF00\", | |
1850 | \"a c #27BD00\", | |
1851 | \"b c #26BA00\", | |
1852 | \"c c #25B600\", | |
1853 | \"d c #23B100\", | |
1854 | \"e c #21AB00\", | |
1855 | \"f c #1FA400\", | |
1856 | \"g c #1C9B00\", | |
1857 | \"h c #21AA00\", | |
1858 | \"i c #24B300\", | |
1859 | \"j c #25B800\", | |
1860 | \"k c #25B700\", | |
1861 | \"l c #24B400\", | |
1862 | \"m c #23B000\", | |
1863 | \"n c #1FA500\", | |
1864 | \"o c #1D9E00\", | |
1865 | \"p c #20A800\", | |
1866 | \"q c #21AC00\", | |
1867 | \"r c #23B200\", | |
1868 | \"s c #22AD00\", | |
1869 | \"t c #1D9F00\", | |
1870 | \"u c #20A700\", | |
1871 | \"v c #1EA100\", | |
1872 | \"w c #1C9C00\", | |
1873 | \"x c #1DA000\", | |
1874 | \"y c #1B9800\", | |
1875 | \"z c #1A9600\", | |
1876 | \"A c #1A9700\", | |
1877 | \"B c #1A9500\", | |
1878 | \"C c #199200\", | |
1879 | \"D c #189100\", | |
1880 | \"E c #178C00\", | |
1881 | \" \", | |
1882 | \" \", | |
1883 | \" \", | |
1884 | \" \", | |
1885 | \" ................... \", | |
1886 | \" .+@#$%&*=*&-;>,')!. \", | |
1887 | \" ................... \", | |
1888 | \" \", | |
1889 | \" ................... \", | |
1890 | \" .~{]^/(___:<[}|123. \", | |
1891 | \" ................... \", | |
1892 | \" \", | |
1893 | \" ................... \", | |
1894 | \" .45678909abcdefg. \", | |
1895 | \" .h5icj7jklmeno. \", | |
1896 | \" .pq5drrmshft. \", | |
1897 | \" .fu4h4pnvw. \", | |
1898 | \" .oxvxtwy. \", | |
1899 | \" .zAAzB. \", | |
1900 | \" .CCD. \", | |
1901 | \" .E. \", | |
1902 | \" . \", | |
1903 | \" \", | |
1904 | \" \"}; | |
1905 | " | |
1906 | 'xpm t) | |
1907 | "Image for the next feed button.")) | |
1908 | ||
1909 | ||
1910 | (defconst newsticker--update-image | |
1911 | (if (fboundp 'create-image) | |
1912 | (create-image "/* XPM */ | |
1913 | static char * update_xpm[] = { | |
1914 | \"24 24 37 1\", | |
1915 | \" c None\", | |
1916 | \". c #076D00\", | |
1917 | \"+ c #0A8600\", | |
1918 | \"@ c #0A8800\", | |
1919 | \"# c #098400\", | |
1920 | \"$ c #087200\", | |
1921 | \"% c #087900\", | |
1922 | \"& c #098500\", | |
1923 | \"* c #098100\", | |
1924 | \"= c #087600\", | |
1925 | \"- c #097E00\", | |
1926 | \"; c #097F00\", | |
1927 | \"> c #0A8700\", | |
1928 | \", c #0A8C00\", | |
1929 | \"' c #097C00\", | |
1930 | \") c #098300\", | |
1931 | \"! c #0A8900\", | |
1932 | \"~ c #0A8E00\", | |
1933 | \"{ c #0B9200\", | |
1934 | \"] c #087700\", | |
1935 | \"^ c #076E00\", | |
1936 | \"/ c #076C00\", | |
1937 | \"( c #076B00\", | |
1938 | \"_ c #076A00\", | |
1939 | \": c #076900\", | |
1940 | \"< c #076800\", | |
1941 | \"[ c #066700\", | |
1942 | \"} c #066500\", | |
1943 | \"| c #066400\", | |
1944 | \"1 c #066300\", | |
1945 | \"2 c #066600\", | |
1946 | \"3 c #066200\", | |
1947 | \"4 c #076700\", | |
1948 | \"5 c #065E00\", | |
1949 | \"6 c #066100\", | |
1950 | \"7 c #065F00\", | |
1951 | \"8 c #066000\", | |
1952 | \" \", | |
1953 | \" \", | |
1954 | \" \", | |
1955 | \" . +@@@+# \", | |
1956 | \" $% &@ +* \", | |
1957 | \" =-# ; \", | |
1958 | \" %*>, ' \", | |
1959 | \" ')!~{ = \", | |
1960 | \" ]$ \", | |
1961 | \" ^ ^ \", | |
1962 | \" . . \", | |
1963 | \" / ( \", | |
1964 | \" _ : \", | |
1965 | \" < [ \", | |
1966 | \" } | \", | |
1967 | \" [[ \", | |
1968 | \" 1 $.:23 \", | |
1969 | \" 3 4}35 \", | |
1970 | \" 6 655 \", | |
1971 | \" 76 85 55 \", | |
1972 | \" 5555555 5 \", | |
1973 | \" \", | |
1974 | \" \", | |
1975 | \" \"}; | |
1976 | " | |
1977 | 'xpm t) | |
1978 | "Image for the update button.")) | |
1979 | ||
1980 | (defconst newsticker--browse-image | |
1981 | (if (fboundp 'create-image) | |
1982 | (create-image "/* XPM */ | |
1983 | static char * visit_xpm[] = { | |
1984 | \"24 24 39 1\", | |
1985 | \" c None\", | |
1986 | \". c #000000\", | |
1987 | \"+ c #FFFFFF\", | |
1988 | \"@ c #00E63D\", | |
1989 | \"# c #00E83E\", | |
1990 | \"$ c #00E73D\", | |
1991 | \"% c #00E93E\", | |
1992 | \"& c #00E63C\", | |
1993 | \"* c #00E53C\", | |
1994 | \"= c #00E23B\", | |
1995 | \"- c #00E33B\", | |
1996 | \"; c #00E83D\", | |
1997 | \"> c #00E13A\", | |
1998 | \", c #00DD38\", | |
1999 | \"' c #00DE38\", | |
2000 | \") c #00E23A\", | |
2001 | \"! c #00E43C\", | |
2002 | \"~ c #00DF39\", | |
2003 | \"{ c #00DB37\", | |
2004 | \"] c #00D634\", | |
2005 | \"^ c #00D734\", | |
2006 | \"/ c #00E039\", | |
2007 | \"( c #00DC37\", | |
2008 | \"_ c #00D835\", | |
2009 | \": c #00D332\", | |
2010 | \"< c #00CD2F\", | |
2011 | \"[ c #00DB36\", | |
2012 | \"} c #00D433\", | |
2013 | \"| c #00CF30\", | |
2014 | \"1 c #00DA36\", | |
2015 | \"2 c #00D936\", | |
2016 | \"3 c #00D533\", | |
2017 | \"4 c #00D131\", | |
2018 | \"5 c #00CE2F\", | |
2019 | \"6 c #00CC2F\", | |
2020 | \"7 c #00CA2D\", | |
2021 | \"8 c #00C62B\", | |
2022 | \"9 c #00C52A\", | |
2023 | \"0 c #00BE27\", | |
2024 | \" \", | |
2025 | \" \", | |
2026 | \" . \", | |
2027 | \" .+. \", | |
2028 | \" .+++. \", | |
2029 | \" .++.++. \", | |
2030 | \" .++.@.++. \", | |
2031 | \" .++.##$.++. \", | |
2032 | \" .++.%%%#&.++. \", | |
2033 | \" .++.$%%%#*=.++. \", | |
2034 | \" .++.-@;##$*>,.++. \", | |
2035 | \" .++.')!&@@*=~{].++. \", | |
2036 | \" .++.^{~>---)/(_:<.++. \", | |
2037 | \" .++.^[,~/~'(_}|.++. \", | |
2038 | \" .++.]_1[12^:|.++. \", | |
2039 | \" .++.:}33:45.++. \", | |
2040 | \" .++.<5567.++. \", | |
2041 | \" .++.889.++. \", | |
2042 | \" .++.0.++. \", | |
2043 | \" .++.++. \", | |
2044 | \" .+++. \", | |
2045 | \" .+. \", | |
2046 | \" . \", | |
2047 | \" \"}; | |
2048 | " | |
2049 | 'xpm t) | |
2050 | "Image for the browse button.")) | |
2051 | ||
2052 | ||
2053 | (defvar newsticker-tool-bar-map | |
2054 | (if (featurep 'xemacs) | |
2055 | nil | |
2056 | (let ((tool-bar-map (make-sparse-keymap))) | |
2057 | (define-key tool-bar-map [newsticker-sep-1] | |
2058 | (list 'menu-item "--double-line")) | |
2059 | (define-key tool-bar-map [newsticker-browse-url] | |
2060 | (list 'menu-item "newsticker-browse-url" 'newsticker-browse-url | |
2061 | :visible t | |
2062 | :help "Browse URL for item at point" | |
2063 | :image newsticker--browse-image)) | |
2064 | (define-key tool-bar-map [newsticker-buffer-force-update] | |
2065 | (list 'menu-item "newsticker-buffer-force-update" | |
2066 | 'newsticker-buffer-force-update | |
2067 | :visible t | |
2068 | :help "Update newsticker buffer" | |
2069 | :image newsticker--update-image | |
2070 | :enable '(not newsticker--buffer-uptodate-p))) | |
2071 | (define-key tool-bar-map [newsticker-get-all-news] | |
2072 | (list 'menu-item "newsticker-get-all-news" 'newsticker-get-all-news | |
2073 | :visible t | |
2074 | :help "Get news for all feeds" | |
2075 | :image newsticker--get-all-image)) | |
2076 | (define-key tool-bar-map [newsticker-mark-item-at-point-as-read] | |
2077 | (list 'menu-item "newsticker-mark-item-at-point-as-read" | |
2078 | 'newsticker-mark-item-at-point-as-read | |
2079 | :visible t | |
2080 | :image newsticker--mark-read-image | |
2081 | :help "Mark current item as read" | |
2082 | :enable '(newsticker-item-not-old-p))) | |
2083 | (define-key tool-bar-map [newsticker-mark-item-at-point-as-immortal] | |
2084 | (list 'menu-item "newsticker-mark-item-at-point-as-immortal" | |
2085 | 'newsticker-mark-item-at-point-as-immortal | |
2086 | :visible t | |
2087 | :image newsticker--mark-immortal-image | |
2088 | :help "Mark current item as immortal" | |
2089 | :enable '(newsticker-item-not-immortal-p))) | |
2090 | (define-key tool-bar-map [newsticker-toggle-auto-narrow-to-feed] | |
2091 | (list 'menu-item "newsticker-toggle-auto-narrow-to-feed" | |
2092 | 'newsticker-toggle-auto-narrow-to-feed | |
2093 | :visible t | |
2094 | :help "Toggle visibility of other feeds" | |
2095 | :image newsticker--narrow-image)) | |
2096 | (define-key tool-bar-map [newsticker-next-feed] | |
2097 | (list 'menu-item "newsticker-next-feed" 'newsticker-next-feed | |
2098 | :visible t | |
2099 | :help "Go to next feed" | |
2100 | :image newsticker--next-feed-image | |
2101 | :enable '(newsticker-next-feed-available-p))) | |
2102 | (define-key tool-bar-map [newsticker-next-item] | |
2103 | (list 'menu-item "newsticker-next-item" 'newsticker-next-item | |
2104 | :visible t | |
2105 | :help "Go to next item" | |
2106 | :image newsticker--next-item-image | |
2107 | :enable '(newsticker-next-item-available-p))) | |
2108 | (define-key tool-bar-map [newsticker-previous-item] | |
2109 | (list 'menu-item "newsticker-previous-item" 'newsticker-previous-item | |
2110 | :visible t | |
2111 | :help "Go to previous item" | |
2112 | :image newsticker--previous-item-image | |
2113 | :enable '(newsticker-previous-item-available-p))) | |
2114 | (define-key tool-bar-map [newsticker-previous-feed] | |
2115 | (list 'menu-item "newsticker-previous-feed" 'newsticker-previous-feed | |
2116 | :visible t | |
2117 | :help "Go to previous feed" | |
2118 | :image newsticker--previous-feed-image | |
2119 | :enable '(newsticker-previous-feed-available-p))) | |
2120 | ;; standard icons / actions | |
2121 | (tool-bar-add-item "close" | |
2122 | 'newsticker-close-buffer | |
2123 | 'newsticker-close-buffer | |
2124 | :help "Close newsticker buffer") | |
2125 | (tool-bar-add-item "preferences" | |
2126 | 'newsticker-customize | |
2127 | 'newsticker-customize | |
2128 | :help "Customize newsticker") | |
2129 | tool-bar-map))) | |
2130 | ||
2131 | ;; ====================================================================== | |
2132 | ;;; Newsticker mode | |
2133 | ;; ====================================================================== | |
2134 | ||
2135 | (define-derived-mode newsticker-mode fundamental-mode | |
2136 | "NewsTicker" | |
2137 | "Viewing RSS news feeds in Emacs." | |
2138 | (set (make-local-variable 'tool-bar-map) newsticker-tool-bar-map) | |
2139 | (set (make-local-variable 'imenu-sort-function) nil) | |
2140 | (set (make-local-variable 'scroll-conservatively) 999) | |
2141 | (setq imenu-create-index-function 'newsticker--imenu-create-index) | |
2142 | (setq imenu-default-goto-function 'newsticker--imenu-goto) | |
2143 | (setq buffer-read-only t) | |
2144 | (auto-fill-mode -1) ;; turn auto-fill off! | |
2145 | (font-lock-mode -1) ;; turn off font-lock!! | |
2146 | (set (make-local-variable 'font-lock-defaults) nil) | |
2147 | (set (make-local-variable 'line-move-ignore-invisible) t) | |
2148 | (setq mode-line-format | |
2149 | (list "-" | |
2150 | 'mode-line-mule-info | |
2151 | 'mode-line-modified | |
2152 | 'mode-line-frame-identification | |
2153 | " Newsticker (" | |
2154 | '(newsticker--buffer-uptodate-p | |
2155 | "up to date" | |
2156 | "NEED UPDATE") | |
2157 | ") -- " | |
2158 | '(:eval (newsticker--buffer-get-feed-title-at-point)) | |
2159 | ": " | |
2160 | '(:eval (newsticker--buffer-get-item-title-at-point)) | |
2161 | " %-")) | |
2162 | (unless newsticker-show-all-rss-elements | |
2163 | (add-to-invisibility-spec 'extra)) | |
2164 | (newsticker--buffer-set-uptodate nil)) | |
2165 | ||
2166 | ;; refine its mode-map | |
2167 | (define-key newsticker-mode-map "sO" 'newsticker-show-old-items) | |
2168 | (define-key newsticker-mode-map "hO" 'newsticker-hide-old-items) | |
2169 | (define-key newsticker-mode-map "sa" 'newsticker-show-all-desc) | |
2170 | (define-key newsticker-mode-map "ha" 'newsticker-hide-all-desc) | |
2171 | (define-key newsticker-mode-map "sf" 'newsticker-show-feed-desc) | |
2172 | (define-key newsticker-mode-map "hf" 'newsticker-hide-feed-desc) | |
2173 | (define-key newsticker-mode-map "so" 'newsticker-show-old-item-desc) | |
2174 | (define-key newsticker-mode-map "ho" 'newsticker-hide-old-item-desc) | |
2175 | (define-key newsticker-mode-map "sn" 'newsticker-show-new-item-desc) | |
2176 | (define-key newsticker-mode-map "hn" 'newsticker-hide-new-item-desc) | |
2177 | (define-key newsticker-mode-map "se" 'newsticker-show-entry) | |
2178 | (define-key newsticker-mode-map "he" 'newsticker-hide-entry) | |
2179 | (define-key newsticker-mode-map "sx" 'newsticker-show-extra) | |
2180 | (define-key newsticker-mode-map "hx" 'newsticker-hide-extra) | |
2181 | ||
2182 | (define-key newsticker-mode-map " " 'scroll-up) | |
2183 | (define-key newsticker-mode-map "q" 'newsticker-close-buffer) | |
2184 | (define-key newsticker-mode-map "p" 'newsticker-previous-item) | |
2185 | (define-key newsticker-mode-map "P" 'newsticker-previous-new-item) | |
2186 | (define-key newsticker-mode-map "F" 'newsticker-previous-feed) | |
2187 | (define-key newsticker-mode-map "\t" 'newsticker-next-item) | |
2188 | (define-key newsticker-mode-map "n" 'newsticker-next-item) | |
2189 | (define-key newsticker-mode-map "N" 'newsticker-next-new-item) | |
2190 | (define-key newsticker-mode-map "f" 'newsticker-next-feed) | |
2191 | (define-key newsticker-mode-map "M" 'newsticker-mark-all-items-as-read) | |
2192 | (define-key newsticker-mode-map "m" | |
2193 | 'newsticker-mark-all-items-at-point-as-read) | |
2194 | (define-key newsticker-mode-map "o" 'newsticker-mark-item-at-point-as-read) | |
2195 | (define-key newsticker-mode-map "G" 'newsticker-get-all-news) | |
2196 | (define-key newsticker-mode-map "g" 'newsticker-get-news-at-point) | |
2197 | (define-key newsticker-mode-map "u" 'newsticker-buffer-update) | |
2198 | (define-key newsticker-mode-map "U" 'newsticker-buffer-force-update) | |
2199 | (define-key newsticker-mode-map "a" 'newsticker-add-url) | |
2200 | ||
2201 | (define-key newsticker-mode-map "i" | |
2202 | 'newsticker-mark-item-at-point-as-immortal) | |
2203 | ||
2204 | (define-key newsticker-mode-map "xf" 'newsticker-toggle-auto-narrow-to-feed) | |
2205 | (define-key newsticker-mode-map "xi" 'newsticker-toggle-auto-narrow-to-item) | |
2206 | ||
2207 | ;; maps for the clickable portions | |
2208 | (defvar newsticker--url-keymap (make-sparse-keymap) | |
2209 | "Key map for click-able headings in the newsticker buffer.") | |
2210 | (define-key newsticker--url-keymap [mouse-2] | |
2211 | 'newsticker-mouse-browse-url) | |
2212 | (define-key newsticker--url-keymap "\n" | |
2213 | 'newsticker-browse-url) | |
2214 | (define-key newsticker--url-keymap "\C-m" | |
2215 | 'newsticker-browse-url) | |
2216 | (define-key newsticker--url-keymap [(control return)] | |
2217 | 'newsticker-handle-url) | |
2218 | ||
2219 | ;; newsticker menu | |
2220 | (defvar newsticker-menu (make-sparse-keymap "Newsticker")) | |
2221 | ||
2222 | (define-key newsticker-menu [newsticker-browse-url] | |
2223 | '("Browse URL for item at point" . newsticker-browse-url)) | |
2224 | (define-key newsticker-menu [newsticker-separator-1] | |
2225 | '("--")) | |
2226 | (define-key newsticker-menu [newsticker-buffer-update] | |
2227 | '("Update buffer" . newsticker-buffer-update)) | |
2228 | (define-key newsticker-menu [newsticker-separator-2] | |
2229 | '("--")) | |
2230 | (define-key newsticker-menu [newsticker-get-all-news] | |
2231 | '("Get news from all feeds" . newsticker-get-all-news)) | |
2232 | (define-key newsticker-menu [newsticker-get-news-at-point] | |
2233 | '("Get news from feed at point" . newsticker-get-news-at-point)) | |
2234 | (define-key newsticker-menu [newsticker-separator-3] | |
2235 | '("--")) | |
2236 | (define-key newsticker-menu [newsticker-mark-all-items-as-read] | |
2237 | '("Mark all items as read" . newsticker-mark-all-items-as-read)) | |
2238 | (define-key newsticker-menu [newsticker-mark-all-items-at-point-as-read] | |
2239 | '("Mark all items in feed at point as read" . | |
2240 | newsticker-mark-all-items-at-point-as-read)) | |
2241 | (define-key newsticker-menu [newsticker-mark-item-at-point-as-read] | |
2242 | '("Mark item at point as read" . | |
2243 | newsticker-mark-item-at-point-as-read)) | |
2244 | (define-key newsticker-menu [newsticker-mark-item-at-point-as-immortal] | |
2245 | '("Toggle immortality for item at point" . | |
2246 | newsticker-mark-item-at-point-as-immortal)) | |
2247 | (define-key newsticker-menu [newsticker-separator-4] | |
2248 | '("--")) | |
2249 | (define-key newsticker-menu [newsticker-hide-old-items] | |
2250 | '("Hide old items" . newsticker-hide-old-items)) | |
2251 | (define-key newsticker-menu [newsticker-show-old-items] | |
2252 | '("Show old items" . newsticker-show-old-items)) | |
2253 | (define-key newsticker-menu [newsticker-next-item] | |
2254 | '("Go to next item" . newsticker-next-item)) | |
2255 | (define-key newsticker-menu [newsticker-previous-item] | |
2256 | '("Go to previous item" . newsticker-previous-item)) | |
2257 | ||
2258 | ;; bind menu to mouse | |
2259 | (define-key newsticker-mode-map [down-mouse-3] newsticker-menu) | |
2260 | ;; Put menu in menu-bar | |
2261 | (define-key newsticker-mode-map [menu-bar Newsticker] | |
2262 | (cons "Newsticker" newsticker-menu)) | |
2263 | ||
2264 | ||
2265 | ;; ====================================================================== | |
2266 | ;;; shortcuts | |
2267 | ;; ====================================================================== | |
2268 | (defsubst newsticker--title (item) | |
2269 | "Return title of ITEM." | |
2270 | (nth 0 item)) | |
2271 | (defsubst newsticker--desc (item) | |
2272 | "Return description of ITEM." | |
2273 | (nth 1 item)) | |
2274 | (defsubst newsticker--link (item) | |
2275 | "Return link of ITEM." | |
2276 | (nth 2 item)) | |
2277 | (defsubst newsticker--time (item) | |
2278 | "Return time of ITEM." | |
2279 | (nth 3 item)) | |
2280 | (defsubst newsticker--age (item) | |
2281 | "Return age of ITEM." | |
2282 | (nth 4 item)) | |
2283 | (defsubst newsticker--pos (item) | |
2284 | "Return position/index of ITEM." | |
2285 | (nth 5 item)) | |
2286 | (defsubst newsticker--preformatted-contents (item) | |
2287 | "Return pre-formatted text of ITEM." | |
2288 | (nth 6 item)) | |
2289 | (defsubst newsticker--preformatted-title (item) | |
2290 | "Return pre-formatted title of ITEM." | |
2291 | (nth 7 item)) | |
2292 | (defsubst newsticker--extra (item) | |
2293 | "Return extra attributes of ITEM." | |
2294 | (nth 8 item)) | |
2295 | (defsubst newsticker--guid (item) | |
2296 | "Return guid of ITEM." | |
2297 | (let ((guid (assoc 'guid (newsticker--extra item)))) | |
2298 | (if (stringp guid) | |
2299 | guid | |
2300 | (car (xml-node-children guid))))) | |
2301 | (defsubst newsticker--enclosure (item) | |
2302 | "Return enclosure element of ITEM in the form \(...FIXME...\)or nil." | |
2303 | (let ((enclosure (assoc 'enclosure (newsticker--extra item)))) | |
2304 | (if enclosure | |
2305 | (xml-node-attributes enclosure)))) | |
2306 | ||
2307 | ;; ====================================================================== | |
2308 | ;;; User fun | |
2309 | ;; ====================================================================== | |
2310 | ||
2311 | (defun newsticker-start (&optional do-not-complain-if-running) | |
2312 | "Start the newsticker. | |
2313 | Start the timers for display and retrieval. If the newsticker, i.e. the | |
2314 | timers, are running already a warning message is printed unless | |
2315 | DO-NOT-COMPLAIN-IF-RUNNING is not nil. | |
2316 | Run `newsticker-start-hook' if newsticker was not running already." | |
2317 | (interactive) | |
2318 | (let ((running (newsticker-running-p))) | |
2319 | ;; read old cache if it exists and newsticker is not running | |
2320 | (unless running | |
2321 | (let* ((coding-system-for-read 'utf-8) | |
2322 | (buf (find-file-noselect newsticker-cache-filename))) | |
2323 | (when buf | |
2324 | (set-buffer buf) | |
2325 | (goto-char (point-min)) | |
2326 | (condition-case nil | |
2327 | (setq newsticker--cache (read buf)) | |
2328 | (error | |
2329 | (message "Error while reading newsticker cache file!") | |
2330 | (setq newsticker--cache nil)))))) | |
2331 | ;; start retrieval timers -- for sake of simplicity we will start | |
2332 | ;; one timer for each feed | |
2333 | (mapc (lambda (item) | |
2334 | (let* ((feed-name (car item)) | |
2335 | (start-time (nth 2 item)) | |
2336 | (interval (or (nth 3 item) | |
2337 | newsticker-retrieval-interval)) | |
2338 | (timer (assoc (car item) | |
2339 | newsticker--retrieval-timer-list))) | |
2340 | (if timer | |
2341 | (or do-not-complain-if-running | |
2342 | (message "Timer for %s is running already!" | |
2343 | feed-name)) | |
2344 | (newsticker--debug-msg "Starting timer for %s: %s, %d" | |
2345 | feed-name start-time interval) | |
2346 | ;; do not repeat retrieval if interval not positive | |
2347 | (if (<= interval 0) | |
2348 | (setq interval nil)) | |
2349 | ;; Suddenly XEmacs doesn't like start-time 0 | |
2350 | (if (or (not start-time) | |
2351 | (and (numberp start-time) (= start-time 0))) | |
2352 | (setq start-time 1)) | |
2353 | (message "start-time %s" start-time) | |
2354 | (setq timer (run-at-time start-time interval | |
2355 | 'newsticker-get-news feed-name)) | |
2356 | (if interval | |
2357 | (add-to-list 'newsticker--retrieval-timer-list | |
2358 | (cons feed-name timer)))))) | |
2359 | (append newsticker-url-list-defaults newsticker-url-list)) | |
2360 | (unless running | |
2361 | (run-hooks 'newsticker-start-hook) | |
2362 | (message "Newsticker started!")))) | |
2363 | ||
2364 | (defun newsticker-start-ticker () | |
2365 | "Start newsticker's ticker (but not the news retrieval. | |
2366 | Start display timer for the actual ticker if wanted and not | |
2367 | running already." | |
2368 | (interactive) | |
2369 | (if (and (> newsticker-display-interval 0) | |
2370 | (not newsticker--display-timer)) | |
2371 | (setq newsticker--display-timer | |
2372 | (run-at-time newsticker-display-interval | |
2373 | newsticker-display-interval | |
2374 | 'newsticker--display-tick)))) | |
e77274b7 | 2375 | |
5629e04f RS |
2376 | (defun newsticker-stop () |
2377 | "Stop the newsticker and the newsticker-ticker. | |
2378 | Cancel the timers for display and retrieval. Run `newsticker-stop-hook' | |
2379 | if newsticker has been running." | |
2380 | (interactive) | |
2381 | (newsticker--cache-update t) | |
2382 | (newsticker-stop-ticker) | |
2383 | (when (newsticker-running-p) | |
2384 | (mapc (lambda (name-and-timer) | |
2385 | (cancel-timer (cdr name-and-timer))) | |
2386 | newsticker--retrieval-timer-list) | |
2387 | (setq newsticker--retrieval-timer-list nil) | |
2388 | (run-hooks 'newsticker-stop-hook) | |
2389 | (message "Newsticker stopped!"))) | |
2390 | ||
2391 | (defun newsticker-stop-ticker () | |
2392 | "Stop newsticker's ticker (but not the news retrieval)." | |
2393 | (interactive) | |
2394 | (when newsticker--display-timer | |
2395 | (cancel-timer newsticker--display-timer) | |
2396 | (setq newsticker--display-timer nil))) | |
2397 | ||
2398 | ;; the functions we need for retrieval and display | |
2399 | (defun newsticker-show-news () | |
2400 | "Switch to newsticker buffer. You may want to bind this to a key." | |
2401 | (interactive) | |
2402 | (newsticker-start t) ;; will start only if not running | |
2403 | (newsticker-buffer-update) | |
2404 | (switch-to-buffer "*newsticker*")) | |
2405 | ||
2406 | (defun newsticker-buffer-force-update () | |
2407 | "Update the newsticker buffer, even if not necessary." | |
2408 | (interactive) | |
2409 | (newsticker-buffer-update t)) | |
2410 | ||
2411 | (defun newsticker-buffer-update (&optional force) | |
2412 | "Update the *newsticker* buffer. | |
2413 | Unless FORCE is t this is donly only if necessary, i.e. when the | |
2414 | *newsticker* buffer is not up-to-date." | |
2415 | (interactive) | |
2416 | ;; bring cache data into proper order.... | |
2417 | (newsticker--cache-sort) | |
2418 | ;; fill buffer | |
2419 | (save-excursion | |
2420 | (let ((buf (get-buffer "*newsticker*"))) | |
2421 | (if buf | |
2422 | (switch-to-buffer buf) | |
2423 | (switch-to-buffer (get-buffer-create "*newsticker*")) | |
2424 | (newsticker--buffer-set-uptodate nil))) | |
2425 | (when (or force | |
2426 | (not newsticker--buffer-uptodate-p)) | |
2427 | (message "Preparing newsticker buffer...") | |
2428 | (setq buffer-undo-list t) | |
2429 | (let ((inhibit-read-only t)) | |
2430 | (set-buffer-modified-p nil) | |
2431 | (erase-buffer) | |
2432 | (newsticker-mode) | |
2433 | ;; Emacs 21.3.50 does not care if we turn off auto-fill in the | |
2434 | ;; definition of newsticker-mode, so we do it here (again) | |
2435 | (auto-fill-mode -1) | |
e77274b7 | 2436 | |
5629e04f RS |
2437 | (set-buffer-file-coding-system 'utf-8) |
2438 | ||
2439 | (if newsticker-use-full-width | |
2440 | (set (make-local-variable 'fill-column) (1- (window-width)))) | |
2441 | (newsticker--buffer-insert-all-items) | |
2442 | ||
2443 | ;; FIXME: needed for methods buffer in ecb | |
2444 | ;; (set-visited-file-name "*newsticker*") | |
2445 | ||
2446 | (set-buffer-modified-p nil) | |
2447 | (newsticker-hide-all-desc) | |
2448 | (if newsticker-hide-old-items-in-newsticker-buffer | |
2449 | (newsticker-hide-old-items)) | |
2450 | (if newsticker-show-descriptions-of-new-items | |
2451 | (newsticker-show-new-item-desc)) | |
2452 | ) | |
2453 | (message "")) | |
2454 | (newsticker--buffer-set-uptodate t) | |
2455 | (run-hooks 'newsticker-buffer-change-hook))) | |
2456 | ||
2457 | (defun newsticker-get-all-news () | |
2458 | "Launch retrieval of news from all configured newsticker sites. | |
2459 | This does NOT start the retrieval timers." | |
2460 | (interactive) | |
2461 | ;; launch retrieval of news | |
2462 | (mapc (lambda (item) | |
2463 | (newsticker-get-news (car item))) | |
2464 | (append newsticker-url-list-defaults newsticker-url-list))) | |
2465 | ||
2466 | (defun newsticker-get-news-at-point () | |
2467 | "Launch retrieval of news for the feed point is in. | |
2468 | This does NOT start the retrieval timers." | |
2469 | (interactive) | |
2470 | ;; launch retrieval of news | |
2471 | (let ((feed (get-text-property (point) 'feed))) | |
2472 | (when feed | |
2473 | (newsticker--debug-msg "Getting news for %s" (symbol-name feed)) | |
2474 | (newsticker-get-news (symbol-name feed))))) | |
2475 | ||
2476 | (defun newsticker-add-url (url name) | |
2477 | "Add given URL under given NAME to `newsticker-url-list'. | |
2478 | If URL is nil it is searched at point." | |
2479 | (interactive | |
2480 | (list | |
2481 | (read-string "URL: " | |
2482 | (save-excursion | |
2483 | (end-of-line) | |
2484 | (and | |
2485 | (re-search-backward | |
2486 | "http://" | |
2487 | (if (> (point) (+ (point-min) 100)) | |
2488 | (- (point) 100) | |
2489 | (point-min)) | |
2490 | t) | |
2491 | (re-search-forward | |
2492 | "http://[-a-zA-Z0-9&/_.]*" | |
2493 | (if (< (point) (- (point-max) 200)) | |
2494 | (+ (point) 200) | |
2495 | (point-max)) | |
2496 | t) | |
2497 | (buffer-substring-no-properties (match-beginning 0) | |
2498 | (match-end 0))))) | |
2499 | (read-string "Name: "))) | |
2500 | (add-to-list 'newsticker-url-list (list name url nil nil nil) t) | |
2501 | (customize-variable 'newsticker-url-list)) | |
2502 | ||
2503 | (defun newsticker-w3m-show-inline-images () | |
2504 | "Show inline images in visible text ranges. | |
2505 | In-line images in invisible text ranges are hidden. This function | |
2506 | calls `w3m-toggle-inline-image'. It works only if | |
2507 | `newsticker-html-renderer' is set to `w3m-region'" | |
2508 | (interactive) | |
2509 | (if (eq newsticker-html-renderer 'w3m-region) | |
2510 | (let ((inhibit-read-only t)) | |
2511 | (save-excursion | |
2512 | (save-restriction | |
2513 | (widen) | |
2514 | (goto-char (point-min)) | |
2515 | (let ((pos (point))) | |
2516 | (while pos | |
2517 | (setq pos (next-single-property-change pos 'w3m-image)) | |
2518 | (when pos | |
2519 | (goto-char pos) | |
2520 | (when (get-text-property pos 'w3m-image) | |
2521 | (let ((invis (newsticker--lists-intersect-p | |
2522 | (get-text-property (1- (point)) 'invisible) | |
2523 | buffer-invisibility-spec))) | |
2524 | (if invis | |
2525 | (w3m-remove-image | |
2526 | pos (next-single-property-change pos 'w3m-image)) | |
2527 | (w3m-toggle-inline-image t)))))))))))) | |
e77274b7 | 2528 | |
5629e04f RS |
2529 | ;; ====================================================================== |
2530 | ;;; keymap stuff | |
2531 | ;; ====================================================================== | |
2532 | (defun newsticker-close-buffer () | |
2533 | "Close the newsticker buffer." | |
2534 | (interactive) | |
2535 | (newsticker--cache-update t) | |
2536 | (bury-buffer)) | |
2537 | ||
2538 | (defun newsticker-next-new-item (&optional do-not-wrap-at-eob) | |
2539 | "Go to next new news item. | |
2540 | If no new item is found behind point, search is continued at | |
2541 | beginning of buffer unless optional argument DO-NOT-WRAP-AT-EOB | |
2542 | is non-nil." | |
2543 | (interactive) | |
2544 | (widen) | |
2545 | (let ((go-ahead t)) | |
2546 | (while go-ahead | |
2547 | (unless (newsticker--buffer-goto '(item) 'new) | |
2548 | ;; found nothing -- wrap | |
2549 | (unless do-not-wrap-at-eob | |
2550 | (goto-char (point-min)) | |
2551 | (newsticker-next-new-item t)) | |
2552 | (setq go-ahead nil)) | |
2553 | (unless (newsticker--lists-intersect-p | |
2554 | (get-text-property (point) 'invisible) | |
2555 | buffer-invisibility-spec) | |
2556 | ;; this item is invisible -- continue search | |
2557 | (setq go-ahead nil)))) | |
2558 | (run-hooks 'newsticker-select-item-hook) | |
2559 | (point)) | |
2560 | ||
2561 | (defun newsticker-previous-new-item (&optional do-not-wrap-at-bob) | |
2562 | "Go to previous new news item. | |
2563 | If no new item is found before point, search is continued at | |
2564 | beginning of buffer unless optional argument DO-NOT-WRAP-AT-BOB | |
2565 | is non-nil." | |
2566 | (interactive) | |
2567 | (widen) | |
2568 | (let ((go-ahead t)) | |
2569 | (while go-ahead | |
2570 | (unless (newsticker--buffer-goto '(item) 'new t) | |
2571 | (unless do-not-wrap-at-bob | |
2572 | (goto-char (point-max)) | |
2573 | (newsticker--buffer-goto '(item) 'new t))) | |
2574 | (unless (newsticker--lists-intersect-p | |
2575 | (get-text-property (point) 'invisible) | |
2576 | buffer-invisibility-spec) | |
2577 | (setq go-ahead nil)))) | |
2578 | (run-hooks 'newsticker-select-item-hook) | |
2579 | (point)) | |
2580 | ||
2581 | (defun newsticker-next-item (&optional do-not-wrap-at-eob) | |
2582 | "Go to next news item. | |
2583 | Return new buffer position. | |
2584 | If no item is found below point, search is continued at beginning | |
2585 | of buffer unless optional argument DO-NOT-WRAP-AT-EOB is | |
2586 | non-nil." | |
2587 | (interactive) | |
2588 | (widen) | |
2589 | (let ((go-ahead t) | |
2590 | (search-list '(item))) | |
2591 | (if newsticker--auto-narrow-to-item | |
2592 | (setq search-list '(item feed))) | |
2593 | (while go-ahead | |
2594 | (unless (newsticker--buffer-goto search-list) | |
2595 | ;; found nothing -- wrap | |
2596 | (unless do-not-wrap-at-eob | |
2597 | (goto-char (point-min))) | |
2598 | (setq go-ahead nil)) | |
2599 | (unless (newsticker--lists-intersect-p | |
2600 | (get-text-property (point) 'invisible) | |
2601 | buffer-invisibility-spec) | |
2602 | (setq go-ahead nil)))) | |
2603 | (run-hooks 'newsticker-select-item-hook) | |
2604 | (point)) | |
2605 | ||
2606 | (defun newsticker-previous-item (&optional do-not-wrap-at-bob) | |
2607 | "Go to previous news item. | |
2608 | Return new buffer position. | |
2609 | If no item is found before point, search is continued at | |
2610 | beginning of buffer unless optional argument DO-NOT-WRAP-AT-BOB | |
2611 | is non-nil." | |
2612 | (interactive) | |
2613 | (widen) | |
2614 | (let ((go-ahead t) | |
2615 | (search-list '(item))) | |
2616 | (if newsticker--auto-narrow-to-item | |
2617 | (setq search-list '(item feed))) | |
2618 | (when (bobp) | |
2619 | (unless do-not-wrap-at-bob | |
2620 | (goto-char (point-max)))) | |
2621 | (while go-ahead | |
2622 | (if (newsticker--buffer-goto search-list nil t) | |
2623 | (unless (newsticker--lists-intersect-p | |
2624 | (get-text-property (point) 'invisible) | |
2625 | buffer-invisibility-spec) | |
2626 | (setq go-ahead nil)) | |
2627 | (goto-char (point-min)) | |
2628 | (setq go-ahead nil)))) | |
2629 | (run-hooks 'newsticker-select-item-hook) | |
2630 | (point)) | |
2631 | ||
2632 | (defun newsticker-next-feed () | |
2633 | "Go to next news feed. | |
2634 | Return new buffer position." | |
2635 | (interactive) | |
2636 | (widen) | |
2637 | (newsticker--buffer-goto '(feed)) | |
2638 | (run-hooks 'newsticker-select-feed-hook) | |
2639 | (point)) | |
2640 | ||
2641 | (defun newsticker-previous-feed () | |
2642 | "Go to previous news feed. | |
2643 | Return new buffer position." | |
2644 | (interactive) | |
2645 | (widen) | |
2646 | (newsticker--buffer-goto '(feed) nil t) | |
2647 | (run-hooks 'newsticker-select-feed-hook) | |
2648 | (point)) | |
2649 | ||
2650 | (defun newsticker-mark-all-items-at-point-as-read () | |
2651 | "Mark all items as read and clear ticker contents." | |
2652 | (interactive) | |
2653 | (when (or newsticker--buffer-uptodate-p | |
2654 | (y-or-n-p | |
2655 | "Buffer is not up to date -- really mark items as read? ")) | |
2656 | (let ((feed (get-text-property (point) 'feed)) | |
2657 | (pos (point))) | |
2658 | (when feed | |
2659 | (message "Marking all items as read for %s" (symbol-name feed)) | |
2660 | (newsticker--cache-replace-age newsticker--cache feed 'new 'old) | |
2661 | (newsticker--cache-replace-age newsticker--cache feed 'obsolete 'old) | |
2662 | (newsticker--cache-update) | |
2663 | (newsticker--buffer-set-uptodate nil) | |
2664 | (newsticker--ticker-text-setup) | |
2665 | (newsticker-buffer-update) | |
2666 | ;; go back to where we came frome | |
2667 | (goto-char pos) | |
2668 | (end-of-line) | |
2669 | (newsticker--buffer-goto '(feed) nil t))))) | |
2670 | ||
2671 | (defun newsticker-mark-item-at-point-as-read (&optional respect-immortality) | |
2672 | "Mark item at point as read. | |
2673 | If optional argument RESPECT-IMMORTALITY is not nil immortal items do | |
2674 | not get changed." | |
2675 | (interactive) | |
2676 | (when (or newsticker--buffer-uptodate-p | |
2677 | (y-or-n-p | |
2678 | "Buffer is not up to date -- really mark this item as read? ")) | |
2679 | (let ((feed (get-text-property (point) 'feed)) | |
2680 | (item nil)) | |
2681 | (when feed | |
2682 | (save-excursion | |
2683 | (newsticker--buffer-beginning-of-item) | |
2684 | (let ((inhibit-read-only t) | |
2685 | (age (get-text-property (point) 'nt-age)) | |
2686 | (title (get-text-property (point) 'nt-title)) | |
2687 | (guid (get-text-property (point) 'nt-guid)) | |
2688 | (nt-desc (get-text-property (point) 'nt-desc)) | |
2689 | (pos (save-excursion (newsticker--buffer-end-of-item)))) | |
2690 | (when (or (eq age 'new) | |
2691 | (eq age 'obsolete) | |
2692 | (and (eq age 'immortal) | |
2693 | (not respect-immortality))) | |
2694 | ;; find item | |
2695 | (setq item (newsticker--cache-contains newsticker--cache | |
2696 | feed title nt-desc | |
2697 | nil nil guid)) | |
2698 | ;; mark as old | |
2699 | (when item | |
2700 | (setcar (nthcdr 4 item) 'old) | |
2701 | (newsticker--do-forget-preformatted item)) | |
2702 | ;; clean up ticker | |
2703 | (if (or (and (eq age 'new) | |
2704 | newsticker-hide-immortal-items-in-echo-area) | |
2705 | (and (memq age '(old immortal)) | |
2706 | (not | |
2707 | (eq newsticker-hide-old-items-in-newsticker-buffer | |
2708 | newsticker-hide-immortal-items-in-echo-area)))) | |
2709 | (newsticker--ticker-text-remove feed title)) | |
2710 | ;; set faces etc. | |
2711 | (save-excursion | |
2712 | (save-restriction | |
2713 | (widen) | |
2714 | (put-text-property (point) pos 'nt-age 'old) | |
2715 | (newsticker--buffer-set-faces (point) pos))) | |
2716 | (set-buffer-modified-p nil)))) | |
2717 | ;; move forward | |
2718 | (newsticker-next-item t))))) | |
2719 | ||
2720 | (defun newsticker-mark-item-at-point-as-immortal () | |
2721 | "Mark item at point as read." | |
2722 | (interactive) | |
2723 | (when (or newsticker--buffer-uptodate-p | |
2724 | (y-or-n-p | |
2725 | "Buffer is not up to date -- really mark this item as read? ")) | |
2726 | (let ((feed (get-text-property (point) 'feed)) | |
2727 | (item nil)) | |
2728 | (when feed | |
2729 | (save-excursion | |
2730 | (newsticker--buffer-beginning-of-item) | |
2731 | (let ((inhibit-read-only t) | |
2732 | (oldage (get-text-property (point) 'nt-age)) | |
2733 | (title (get-text-property (point) 'nt-title)) | |
2734 | (guid (get-text-property (point) 'nt-guid)) | |
2735 | (pos (save-excursion (newsticker--buffer-end-of-item)))) | |
2736 | (let ((newage 'immortal)) | |
2737 | (if (eq oldage 'immortal) | |
2738 | (setq newage 'old)) | |
2739 | (setq item (newsticker--cache-contains newsticker--cache | |
2740 | feed title nil nil nil | |
2741 | guid)) | |
2742 | ;; change age | |
2743 | (when item | |
2744 | (setcar (nthcdr 4 item) newage) | |
2745 | (newsticker--do-forget-preformatted item)) | |
2746 | (if (or (and (eq newage 'immortal) | |
2747 | newsticker-hide-immortal-items-in-echo-area) | |
2748 | (and (eq newage 'obsolete) | |
2749 | newsticker-hide-obsolete-items-in-echo-area) | |
2750 | (and (eq oldage 'immortal) | |
2751 | (not | |
2752 | (eq newsticker-hide-old-items-in-newsticker-buffer | |
2753 | newsticker-hide-immortal-items-in-echo-area)))) | |
2754 | (newsticker--ticker-text-remove feed title) | |
2755 | (newsticker--ticker-text-setup)) | |
2756 | (save-excursion | |
2757 | (save-restriction | |
2758 | (widen) | |
2759 | (put-text-property (point) pos 'nt-age newage) | |
2760 | (if (eq newage 'immortal) | |
2761 | (put-text-property (point) pos 'nt-age 'immortal) | |
2762 | (put-text-property (point) pos 'nt-age 'old)) | |
2763 | (newsticker--buffer-set-faces (point) pos)))))) | |
2764 | (if item | |
2765 | (newsticker-next-item t)))))) | |
2766 | ||
2767 | (defun newsticker-mark-all-items-as-read () | |
2768 | "Mark all items as read and clear ticker contents." | |
2769 | (interactive) | |
2770 | (when (or newsticker--buffer-uptodate-p | |
2771 | (y-or-n-p | |
2772 | "Buffer is not up to date -- really mark items as read? ")) | |
2773 | (newsticker--cache-replace-age newsticker--cache 'any 'new 'old) | |
2774 | (newsticker--buffer-set-uptodate nil) | |
2775 | (newsticker--ticker-text-setup) | |
2776 | (newsticker--cache-update) | |
2777 | (newsticker-buffer-update))) | |
2778 | ||
2779 | (defun newsticker-hide-extra () | |
2780 | "Hide the extra elements of items." | |
2781 | (interactive) | |
2782 | (newsticker--buffer-hideshow 'extra nil) | |
2783 | (newsticker--buffer-redraw)) | |
2784 | ||
2785 | (defun newsticker-show-extra () | |
2786 | "Show the extra elements of items." | |
2787 | (interactive) | |
2788 | (newsticker--buffer-hideshow 'extra t) | |
2789 | (newsticker--buffer-redraw)) | |
2790 | ||
2791 | (defun newsticker-hide-old-item-desc () | |
2792 | "Hide the description of old items." | |
2793 | (interactive) | |
2794 | (newsticker--buffer-hideshow 'desc-old nil) | |
2795 | (newsticker--buffer-redraw)) | |
e77274b7 | 2796 | |
5629e04f RS |
2797 | (defun newsticker-show-old-item-desc () |
2798 | "Show the description of old items." | |
2799 | (interactive) | |
2800 | (newsticker--buffer-hideshow 'item-old t) | |
2801 | (newsticker--buffer-hideshow 'desc-old t) | |
2802 | (newsticker--buffer-redraw)) | |
2803 | ||
2804 | (defun newsticker-hide-new-item-desc () | |
2805 | "Hide the description of new items." | |
2806 | (interactive) | |
2807 | (newsticker--buffer-hideshow 'desc-new nil) | |
2808 | (newsticker--buffer-hideshow 'desc-immortal nil) | |
2809 | (newsticker--buffer-hideshow 'desc-obsolete nil) | |
2810 | (newsticker--buffer-redraw)) | |
2811 | ||
2812 | (defun newsticker-show-new-item-desc () | |
2813 | "Show the description of new items." | |
2814 | (interactive) | |
2815 | (newsticker--buffer-hideshow 'desc-new t) | |
2816 | (newsticker--buffer-hideshow 'desc-immortal t) | |
2817 | (newsticker--buffer-hideshow 'desc-obsolete t) | |
2818 | (newsticker--buffer-redraw)) | |
2819 | ||
2820 | (defun newsticker-hide-feed-desc () | |
2821 | "Hide the description of feeds." | |
2822 | (interactive) | |
2823 | (newsticker--buffer-hideshow 'desc-feed nil) | |
2824 | (newsticker--buffer-redraw)) | |
2825 | ||
2826 | (defun newsticker-show-feed-desc () | |
2827 | "Show the description of old items." | |
2828 | (interactive) | |
2829 | (newsticker--buffer-hideshow 'desc-feed t) | |
2830 | (newsticker--buffer-redraw)) | |
2831 | ||
2832 | (defun newsticker-hide-all-desc () | |
2833 | "Hide the descriptions of feeds and all items." | |
2834 | (interactive) | |
2835 | (newsticker--buffer-hideshow 'desc-feed nil) | |
2836 | (newsticker--buffer-hideshow 'desc-immortal nil) | |
2837 | (newsticker--buffer-hideshow 'desc-obsolete nil) | |
2838 | (newsticker--buffer-hideshow 'desc-new nil) | |
2839 | (newsticker--buffer-hideshow 'desc-old nil) | |
2840 | (newsticker--buffer-redraw)) | |
2841 | ||
2842 | (defun newsticker-show-all-desc () | |
2843 | "Show the descriptions of feeds and all items." | |
2844 | (interactive) | |
2845 | (newsticker--buffer-hideshow 'desc-feed t) | |
2846 | (newsticker--buffer-hideshow 'desc-immortal t) | |
2847 | (newsticker--buffer-hideshow 'desc-obsolete t) | |
2848 | (newsticker--buffer-hideshow 'desc-new t) | |
2849 | (newsticker--buffer-hideshow 'desc-old t) | |
2850 | (newsticker--buffer-redraw)) | |
2851 | ||
2852 | (defun newsticker-hide-old-items () | |
2853 | "Hide old items." | |
2854 | (interactive) | |
2855 | (newsticker--buffer-hideshow 'desc-old nil) | |
2856 | (newsticker--buffer-hideshow 'item-old nil) | |
2857 | (newsticker--buffer-redraw)) | |
2858 | ||
2859 | (defun newsticker-show-old-items () | |
2860 | "Show old items." | |
2861 | (interactive) | |
2862 | (newsticker--buffer-hideshow 'desc-old t) | |
2863 | (newsticker--buffer-hideshow 'item-old t) | |
2864 | (newsticker--buffer-redraw)) | |
2865 | ||
2866 | (defun newsticker-hide-entry () | |
2867 | "Hide description of entry at point." | |
2868 | (interactive) | |
2869 | (save-excursion | |
e77274b7 | 2870 | (let* (pos1 pos2 |
5629e04f RS |
2871 | (inhibit-read-only t) |
2872 | inv-prop org-inv-prop | |
2873 | is-invisible) | |
2874 | (newsticker--buffer-beginning-of-item) | |
2875 | (newsticker--buffer-goto '(desc)) | |
2876 | (setq pos1 (max (point-min) (1- (point)))) | |
2877 | (newsticker--buffer-goto '(extra feed item)) | |
2878 | (setq pos2 (max (point-min) (1- (point)))) | |
2879 | (setq inv-prop (get-text-property pos1 'invisible)) | |
2880 | (setq org-inv-prop (get-text-property pos1 'org-invisible)) | |
2881 | (cond ((eq inv-prop t) | |
2882 | ;; do nothing | |
2883 | ) | |
2884 | ((eq org-inv-prop nil) | |
2885 | (add-text-properties pos1 pos2 (list 'invisible t | |
2886 | 'org-invisible inv-prop))) | |
2887 | (t | |
2888 | ;; toggle | |
2889 | (add-text-properties pos1 pos2 (list 'invisible org-inv-prop)) | |
2890 | (remove-text-properties pos1 pos2 '(org-invisible)))))) | |
2891 | (newsticker--buffer-redraw)) | |
2892 | ||
2893 | (defun newsticker-show-entry () | |
2894 | "Show description of entry at point." | |
2895 | (interactive) | |
2896 | (save-excursion | |
e77274b7 | 2897 | (let* (pos1 pos2 |
5629e04f RS |
2898 | (inhibit-read-only t) |
2899 | inv-prop org-inv-prop | |
2900 | is-invisible) | |
2901 | (newsticker--buffer-beginning-of-item) | |
2902 | (newsticker--buffer-goto '(desc)) | |
2903 | (setq pos1 (max (point-min) (1- (point)))) | |
2904 | (newsticker--buffer-goto '(extra feed item)) | |
2905 | (setq pos2 (max (point-min) (1- (point)))) | |
2906 | (setq inv-prop (get-text-property pos1 'invisible)) | |
2907 | (setq org-inv-prop (get-text-property pos1 'org-invisible)) | |
2908 | (cond ((eq org-inv-prop nil) | |
2909 | (add-text-properties pos1 pos2 (list 'invisible nil | |
2910 | 'org-invisible inv-prop))) | |
2911 | (t | |
2912 | ;; toggle | |
2913 | (add-text-properties pos1 pos2 (list 'invisible org-inv-prop)) | |
2914 | (remove-text-properties pos1 pos2 '(org-invisible)))))) | |
2915 | (newsticker--buffer-redraw)) | |
2916 | ||
2917 | (defun newsticker-toggle-auto-narrow-to-feed () | |
2918 | "Toggle narrowing to current news feed. | |
2919 | If auto-narrowing is active, only news item of the current feed | |
2920 | are visible." | |
2921 | (interactive) | |
2922 | (newsticker-set-auto-narrow-to-feed (not newsticker--auto-narrow-to-feed))) | |
2923 | ||
2924 | (defun newsticker-set-auto-narrow-to-feed (value) | |
2925 | "Turn narrowing to current news feed on or off. | |
2926 | If VALUE is nil, auto-narrowing is turned off, otherwise it is turned on." | |
2927 | (interactive) | |
2928 | (setq newsticker--auto-narrow-to-item nil) | |
2929 | (setq newsticker--auto-narrow-to-feed value) | |
2930 | (widen) | |
2931 | (run-hooks 'newsticker-narrow-hook)) | |
2932 | ||
2933 | (defun newsticker-toggle-auto-narrow-to-item () | |
2934 | "Toggle narrowing to current news item. | |
2935 | If auto-narrowing is active, only one item of the current feed | |
2936 | is visible." | |
2937 | (interactive) | |
2938 | (newsticker-set-auto-narrow-to-item (not newsticker--auto-narrow-to-item))) | |
2939 | ||
2940 | (defun newsticker-set-auto-narrow-to-item (value) | |
2941 | "Turn narrowing to current news item on or off. | |
2942 | If VALUE is nil, auto-narrowing is turned off, otherwise it is turned on." | |
2943 | (interactive) | |
2944 | (setq newsticker--auto-narrow-to-feed nil) | |
2945 | (setq newsticker--auto-narrow-to-item value) | |
2946 | (widen) | |
2947 | (run-hooks 'newsticker-narrow-hook)) | |
2948 | ||
2949 | (defun newsticker-customize () | |
2950 | "Open the newsticker customization group." | |
2951 | (interactive) | |
2952 | (customize-group "newsticker")) | |
2953 | ||
2954 | (defun newsticker-next-feed-available-p () | |
2955 | "Return t if position is before last feed, nil otherwise." | |
2956 | (save-excursion | |
2957 | (let ((p (point))) | |
2958 | (newsticker--buffer-goto '(feed)) | |
2959 | (not (= p (point)))))) | |
2960 | ||
2961 | (defun newsticker-previous-feed-available-p () | |
2962 | "Return t if position is behind first feed, nil otherwise." | |
2963 | (save-excursion | |
2964 | (let ((p (point))) | |
2965 | (newsticker--buffer-goto '(feed) nil t) | |
2966 | (not (= p (point)))))) | |
2967 | ||
2968 | (defun newsticker-next-item-available-p () | |
2969 | "Return t if position is before last feed, nil otherwise." | |
2970 | (save-excursion | |
2971 | (catch 'result | |
2972 | (while (< (point) (point-max)) | |
2973 | (unless (newsticker--buffer-goto '(item)) | |
2974 | (throw 'result nil)) | |
2975 | (unless (newsticker--lists-intersect-p | |
2976 | (get-text-property (point) 'invisible) | |
2977 | buffer-invisibility-spec) | |
2978 | (throw 'result t)))))) | |
2979 | ||
2980 | (defun newsticker-previous-item-available-p () | |
2981 | "Return t if position is behind first item, nil otherwise." | |
2982 | (save-excursion | |
2983 | (catch 'result | |
2984 | (while (> (point) (point-min)) | |
2985 | (unless (newsticker--buffer-goto '(item) nil t) | |
2986 | (throw 'result nil)) | |
2987 | (unless (newsticker--lists-intersect-p | |
2988 | (get-text-property (point) 'invisible) | |
2989 | buffer-invisibility-spec) | |
2990 | (throw 'result t)))))) | |
2991 | ||
2992 | (defun newsticker-item-not-old-p () | |
2993 | "Return t if there is an item at point which is not old, nil otherwise." | |
2994 | (when (get-text-property (point) 'feed) | |
2995 | (save-excursion | |
2996 | (newsticker--buffer-beginning-of-item) | |
2997 | (let ((age (get-text-property (point) 'nt-age))) | |
2998 | (and (memq age '(new immortal obsolete)) t))))) | |
2999 | ||
3000 | (defun newsticker-item-not-immortal-p () | |
3001 | "Return t if there is an item at point which is not immortal, nil otherwise." | |
3002 | (when (get-text-property (point) 'feed) | |
3003 | (save-excursion | |
3004 | (newsticker--buffer-beginning-of-item) | |
3005 | (let ((age (get-text-property (point) 'nt-age))) | |
3006 | (and (memq age '(new old obsolete)) t))))) | |
3007 | ||
3008 | ;; ====================================================================== | |
3009 | ;;; local stuff | |
3010 | ;; ====================================================================== | |
3011 | (defun newsticker-running-p () | |
3012 | "Check whether newsticker is running. | |
3013 | Return t if newsticker is running, nil otherwise. Newsticker is | |
3014 | considered to be running if the newsticker timer list is not empty." | |
3015 | (> (length newsticker--retrieval-timer-list) 0)) | |
3016 | ||
3017 | (defun newsticker-ticker-running-p () | |
3018 | "Check whether newsticker's actual ticker is running. | |
3019 | Return t if ticker is running, nil otherwise. Newsticker is | |
3020 | considered to be running if the newsticker timer list is not | |
3021 | empty." | |
3022 | (timerp newsticker--display-timer)) | |
3023 | ||
3024 | ;; ====================================================================== | |
3025 | ;;; local stuff | |
3026 | ;; ====================================================================== | |
3027 | (defun newsticker-get-news (feed-name) | |
3028 | "Get news from the site FEED-NAME and load feed logo. | |
3029 | FEED-NAME must be a string which occurs as the label (i.e. the first element) | |
3030 | in an element of `newsticker-url-list' or `newsticker-url-list-defaults'." | |
3031 | (newsticker--debug-msg "%s: Getting news for %s" | |
3032 | (format-time-string "%A, %H:%M" (current-time)) | |
3033 | feed-name) | |
3034 | (let* ((buffername (concat " *newsticker-wget-" feed-name "*")) | |
3035 | (item (or (assoc feed-name newsticker-url-list) | |
3036 | (assoc feed-name newsticker-url-list-defaults) | |
3037 | (error | |
3038 | "Cannot get news for %s: Check newsticker-url-list" | |
3039 | feed-name))) | |
3040 | (url (cadr item)) | |
3041 | (wget-arguments (or (car (cdr (cdr (cdr (cdr item))))) | |
3042 | newsticker-wget-arguments))) | |
3043 | (save-excursion | |
3044 | (set-buffer (get-buffer-create buffername)) | |
3045 | (erase-buffer) | |
3046 | ;; throw an error if there is an old wget-process around | |
3047 | (if (get-process feed-name) | |
3048 | (error "Another wget-process is running for %s" feed-name)) | |
3049 | ;; start wget | |
3050 | (let* ((args (append wget-arguments (list url))) | |
3051 | (proc (apply 'start-process feed-name buffername | |
3052 | newsticker-wget-name args))) | |
3053 | (set-process-coding-system proc 'no-conversion 'no-conversion) | |
3054 | (set-process-sentinel proc 'newsticker--sentinel))))) | |
3055 | ||
e77274b7 | 3056 | |
5629e04f RS |
3057 | (defun newsticker-mouse-browse-url (event) |
3058 | "Call `browse-url' for the link of the item at which the EVENT occurred." | |
3059 | (interactive "e") | |
3060 | (save-excursion | |
3061 | (switch-to-buffer (window-buffer (posn-window (event-end event)))) | |
3062 | (let ((url (get-text-property (posn-point (event-end event)) | |
3063 | 'nt-link))) | |
3064 | (when url | |
3065 | (browse-url url) | |
3066 | (save-excursion | |
3067 | (goto-char (posn-point (event-end event))) | |
3068 | (if newsticker-automatically-mark-visited-items-as-old | |
3069 | (newsticker-mark-item-at-point-as-read t))))))) | |
3070 | ||
3071 | (defun newsticker-browse-url () | |
3072 | "Call `browse-url' for the link of the item at point." | |
3073 | (interactive) | |
3074 | (let ((url (get-text-property (point) 'nt-link))) | |
3075 | (when url | |
3076 | (browse-url url) | |
3077 | (if newsticker-automatically-mark-visited-items-as-old | |
3078 | (newsticker-mark-item-at-point-as-read t))))) | |
3079 | ||
3080 | (defvar newsticker-open-url-history | |
3081 | '("wget" "xmms" "realplay") | |
3082 | "...") | |
3083 | ||
3084 | (defun newsticker-handle-url () | |
3085 | "Ask for a program to open the link of the item at point." | |
3086 | (interactive) | |
3087 | (let ((url (get-text-property (point) 'nt-link))) | |
3088 | (when url | |
3089 | (let ((prog (read-string "Open url with: " nil | |
3090 | 'newsticker-open-url-history))) | |
3091 | (when prog | |
3092 | (message "%s %s" prog url) | |
3093 | (start-process prog prog prog url) | |
3094 | (if newsticker-automatically-mark-visited-items-as-old | |
3095 | (newsticker-mark-item-at-point-as-read t))))))) | |
3096 | ||
3097 | (defun newsticker--sentinel (process event) | |
3098 | "Sentinel for extracting news titles from an RDF buffer. | |
3099 | Argument PROCESS is the process which has just changed its state. | |
3100 | Argument EVENT tells what has happened to the process." | |
3101 | (let* ((p-status (process-status process)) | |
3102 | (exit-status (process-exit-status process)) | |
3103 | (time (current-time)) | |
3104 | (name (process-name process)) | |
3105 | (name-symbol (intern name)) | |
3106 | (something-was-added nil)) | |
3107 | ;; catch known errors (zombie processes, rubbish-xml etc. | |
3108 | ;; if an error occurs the news feed is not updated! | |
3109 | (catch 'oops | |
3110 | (unless (and (eq p-status 'exit) | |
3111 | (= exit-status 0)) | |
3112 | (setq newsticker--cache | |
3113 | (newsticker--cache-add | |
3114 | newsticker--cache | |
3115 | name-symbol | |
3116 | newsticker--error-headline | |
3117 | (format | |
3118 | (concat "%s: Newsticker could not retrieve news from %s.\n" | |
3119 | "Return status: `%s'\n" | |
3120 | "Command was `%s'") | |
3121 | (format-time-string "%A, %H:%M" (current-time)) | |
3122 | name event (process-command process)) | |
3123 | "" | |
3124 | (current-time) | |
3125 | 'new | |
3126 | 0 nil)) | |
3127 | (message "%s: Error while retrieving news from %s" | |
3128 | (format-time-string "%A, %H:%M" (current-time)) | |
3129 | (process-name process)) | |
3130 | (throw 'oops nil)) | |
3131 | (let* ((coding-system nil) | |
3132 | (node-list | |
3133 | (save-current-buffer | |
3134 | (set-buffer (process-buffer process)) | |
3135 | ;; a very very dirty workaround to overcome the | |
3136 | ;; problems with the newest (20030621) xml.el: | |
3137 | ;; remove all unnecessary whitespace | |
3138 | (goto-char (point-min)) | |
3139 | (while (re-search-forward ">[ \t\r\n]+<" nil t) | |
3140 | (replace-match "><" nil t)) | |
3141 | ;; and another brutal workaround (20031105)! For some | |
3142 | ;; reason the xml parser does not like the colon in the | |
3143 | ;; doctype name "rdf:RDF" | |
3144 | (goto-char (point-min)) | |
3145 | (if (re-search-forward "<!DOCTYPE[ \t\n]+rdf:RDF" nil t) | |
3146 | (replace-match "<!DOCTYPE rdfColonRDF" nil t)) | |
3147 | ;; finally.... ~##^°!!!!! | |
3148 | (goto-char (point-min)) | |
3149 | (while (search-forward "\r\n" nil t) | |
3150 | (replace-match "\n" nil t)) | |
3151 | ;; still more brutal workarounds (20040309)! The xml | |
3152 | ;; parser does not like doctype rss | |
3153 | (goto-char (point-min)) | |
3154 | (if (re-search-forward "<!DOCTYPE[ \t\n]+rss[ \t\n]*>" nil t) | |
3155 | (replace-match "" nil t)) | |
3156 | ;; And another one (20050618)! (Fixed in GNU Emacs 22.0.50.18) | |
3157 | ;; Remove comments to avoid this xml-parsing bug: | |
3158 | ;; "XML files can have only one toplevel tag" | |
3159 | (goto-char (point-min)) | |
3160 | (while (search-forward "<!--" nil t) | |
3161 | (let ((start (match-beginning 0))) | |
3162 | (unless (search-forward "-->" nil t) | |
3163 | (error "Can't find end of comment")) | |
e77274b7 | 3164 | (delete-region start (point)))) |
5629e04f RS |
3165 | ;; And another one (20050702)! If description is HTML |
3166 | ;; encoded and starts with a `<', wrap the whole | |
3167 | ;; description in a CDATA expression. This happened for | |
3168 | ;; http://www.thefreedictionary.com/_/WoD/rss.aspx?type=quote | |
3169 | (goto-char (point-min)) | |
3170 | (while (re-search-forward | |
3171 | "<description>\\(<img.*?\\)</description>" nil t) | |
3172 | (replace-match | |
3173 | "<description><![CDATA[ \\1 ]]></description>")) | |
3174 | ;; | |
3175 | (set-buffer-modified-p nil) | |
3176 | (goto-char (point-min)) | |
3177 | (if (re-search-forward "encoding=\"\\([^\"]+\\)\"" | |
3178 | nil t) | |
3179 | (setq coding-system (intern | |
3180 | (downcase(match-string 1))))) | |
3181 | (condition-case errordata | |
3182 | ;; The xml parser might fail | |
3183 | ;; or the xml might be bugged | |
3184 | (xml-parse-region (point-min) (point-max)) | |
3185 | (error (message "Could not parse %s: %s" | |
3186 | (buffer-name) (cadr errordata)) | |
3187 | (throw 'oops nil))))) | |
3188 | (topnode (car node-list)) | |
3189 | (channelnode (car (xml-get-children topnode 'channel))) | |
3190 | (imageurl nil) | |
3191 | (position 0)) | |
3192 | ;; mark all items as obsolete | |
3193 | (newsticker--cache-replace-age newsticker--cache | |
3194 | name-symbol | |
3195 | 'new 'obsolete-new) | |
3196 | (newsticker--cache-replace-age newsticker--cache | |
3197 | name-symbol | |
3198 | 'old 'obsolete-old) | |
3199 | (newsticker--cache-replace-age newsticker--cache | |
3200 | name-symbol | |
3201 | 'feed 'obsolete-old) | |
3202 | ;; gather the news | |
3203 | (if (eq (xml-node-name topnode) 'rss) | |
3204 | ;; this is RSS 0.91 or something similar | |
3205 | ;; all items are inside the channel node | |
3206 | (setq topnode channelnode)) | |
3207 | (setq imageurl | |
3208 | (car (xml-node-children | |
3209 | (car (xml-get-children | |
3210 | (car (xml-get-children | |
3211 | topnode | |
3212 | 'image)) | |
3213 | 'url))))) | |
3214 | (let ((title (or (car (xml-node-children (car (xml-get-children | |
3215 | channelnode 'title)))) | |
3216 | "[untitled]")) | |
3217 | (link (or (car (xml-node-children (car (xml-get-children | |
3218 | channelnode 'link)))) | |
3219 | "")) | |
3220 | (desc (or (car (xml-node-children (car (xml-get-children | |
3221 | channelnode | |
3222 | 'content:encoded)))) | |
3223 | (car (xml-node-children (car (xml-get-children | |
3224 | channelnode | |
3225 | 'description)))) | |
3226 | "[No description available]")) | |
3227 | (old-item nil)) | |
3228 | ;; check coding system | |
3229 | (setq coding-system | |
3230 | (condition-case nil | |
3231 | (check-coding-system coding-system) | |
3232 | (coding-system-error | |
3233 | (message "newsticker.el: %s %s %s %s" | |
3234 | "ignoring coding system " | |
3235 | coding-system | |
3236 | " for " | |
3237 | name) | |
3238 | nil))) | |
3239 | ;; apply coding system | |
3240 | (when coding-system | |
3241 | (setq title (newsticker--decode-coding-string title coding-system)) | |
3242 | (if desc | |
3243 | (setq desc (newsticker--decode-coding-string desc | |
3244 | coding-system))) | |
3245 | (setq link (newsticker--decode-coding-string link coding-system))) | |
3246 | ;; decode numeric entities | |
3247 | (setq title (newsticker--decode-numeric-entities title)) | |
3248 | (setq desc (newsticker--decode-numeric-entities desc)) | |
3249 | (setq link (newsticker--decode-numeric-entities link)) | |
3250 | ;; remove whitespace from title, desc, and link | |
3251 | (setq title (newsticker--remove-whitespace title)) | |
3252 | (setq desc (newsticker--remove-whitespace desc)) | |
3253 | (setq link (newsticker--remove-whitespace link)) | |
3254 | ||
3255 | ;; handle the feed itself | |
3256 | (unless (newsticker--cache-contains newsticker--cache | |
3257 | name-symbol title | |
3258 | desc link 'feed) | |
3259 | (setq something-was-added t)) | |
3260 | (setq newsticker--cache | |
3261 | (newsticker--cache-add | |
3262 | newsticker--cache name-symbol | |
3263 | title desc link time 'feed position | |
3264 | (xml-node-children channelnode) | |
3265 | 'feed time)) | |
3266 | ;; gather all items for this feed | |
3267 | (mapc (lambda (node) | |
3268 | (when (eq (xml-node-name node) 'item) | |
3269 | (setq position (1+ position)) | |
3270 | (setq title (or (car (xml-node-children | |
3271 | (car (xml-get-children | |
3272 | node 'title)))) | |
3273 | "[untitled]")) | |
3274 | (setq link (or (car (xml-node-children | |
3275 | (car (xml-get-children | |
3276 | node 'link)))) | |
3277 | "")) | |
3278 | (setq desc (or | |
3279 | (car (xml-node-children | |
3280 | (car (xml-get-children | |
3281 | node 'content:encoded)))) | |
3282 | (car (xml-node-children | |
3283 | (car (xml-get-children | |
3284 | node 'description)))))) | |
3285 | ;; use pubDate value if present | |
3286 | (setq time (or (newsticker--decode-rfc822-date | |
3287 | (car (xml-node-children | |
3288 | (car (xml-get-children | |
3289 | node 'pubDate))))) | |
3290 | time)) | |
3291 | ;; use dc:date value if present | |
3292 | (setq time (or (newsticker--decode-iso8601-date | |
3293 | (car (xml-node-children | |
3294 | (car (xml-get-children | |
3295 | node 'dc:date))))) | |
3296 | time)) | |
3297 | ;; It happened that the title or description | |
3298 | ;; contained evil HTML code that confused the | |
3299 | ;; xml parser. Therefore: | |
3300 | (unless (stringp title) | |
3301 | (setq title (prin1-to-string title))) | |
3302 | (unless (or (stringp desc) (not desc)) | |
3303 | (setq desc (prin1-to-string desc))) | |
3304 | ;; ignore items with empty title AND empty desc | |
3305 | (when (or (> (length title) 0) | |
3306 | (> (length desc) 0)) | |
3307 | ;; apply coding system | |
3308 | (when coding-system | |
3309 | (setq title (newsticker--decode-coding-string | |
3310 | title coding-system)) | |
3311 | (if desc | |
3312 | (setq desc (newsticker--decode-coding-string desc | |
3313 | coding-system))) | |
3314 | (setq link (newsticker--decode-coding-string | |
3315 | link coding-system))) | |
3316 | ;; decode numeric entities | |
3317 | (setq title (newsticker--decode-numeric-entities title)) | |
3318 | (when desc | |
3319 | (setq desc (newsticker--decode-numeric-entities desc))) | |
3320 | (setq link (newsticker--decode-numeric-entities link)) | |
3321 | ;; remove whitespace from title, desc, and link | |
3322 | (setq title (newsticker--remove-whitespace title)) | |
3323 | (setq desc (newsticker--remove-whitespace desc)) | |
3324 | (setq link (newsticker--remove-whitespace link)) | |
3325 | ;; add data to cache | |
3326 | ;; do we have this item already? | |
3327 | (let* ((tguid (assoc 'guid (xml-node-children node))) | |
3328 | (guid (if (stringp tguid) | |
3329 | tguid | |
3330 | (car (xml-node-children tguid))))) | |
e77274b7 | 3331 | ;;(message "guid=%s" guid) |
5629e04f RS |
3332 | (setq old-item |
3333 | (newsticker--cache-contains newsticker--cache | |
3334 | name-symbol title | |
3335 | desc link nil guid))) | |
3336 | ;; add this item, or mark it as old, or do nothing | |
3337 | (let ((age1 'new) | |
3338 | (age2 'old) | |
3339 | (item-new-p nil)) | |
3340 | (if old-item | |
3341 | (let ((prev-age (newsticker--age old-item))) | |
3342 | (unless | |
3343 | newsticker-automatically-mark-items-as-old | |
3344 | (if (eq prev-age 'obsolete-old) | |
3345 | (setq age2 'old) | |
3346 | (setq age2 'new))) | |
3347 | (if (eq prev-age 'immortal) | |
3348 | (setq age2 'immortal))) | |
3349 | ;; item was not there | |
3350 | (setq item-new-p t) | |
3351 | (setq something-was-added t)) | |
3352 | (setq newsticker--cache | |
3353 | (newsticker--cache-add | |
3354 | newsticker--cache name-symbol title desc link | |
3355 | time age1 position (xml-node-children node) | |
3356 | age2)) | |
3357 | (when item-new-p | |
3358 | (let ((item (newsticker--cache-contains | |
3359 | newsticker--cache | |
3360 | name-symbol title | |
3361 | desc link nil))) | |
3362 | (if newsticker-auto-mark-filter | |
3363 | (newsticker--run-auto-mark-filter name item)) | |
3364 | (run-hook-with-args | |
3365 | 'newsticker-new-item-functions name item))))))) | |
3366 | (xml-get-children topnode 'item))) | |
3367 | ;; Remove those old items from cache which have been removed from | |
3368 | ;; the feed | |
3369 | (newsticker--cache-replace-age newsticker--cache | |
3370 | name-symbol 'obsolete-old 'deleteme) | |
3371 | (newsticker--cache-remove newsticker--cache name-symbol | |
3372 | 'deleteme) | |
3373 | ;; Remove those new items from cache which have been removed from | |
3374 | ;; the feed. Or keep them as `obsolete' | |
3375 | (if (not newsticker-keep-obsolete-items) | |
3376 | (newsticker--cache-remove newsticker--cache | |
3377 | name-symbol 'obsolete-new) | |
3378 | (setq newsticker--cache | |
3379 | (newsticker--cache-mark-expired | |
3380 | newsticker--cache name-symbol 'obsolete 'obsolete-expired | |
3381 | newsticker-obsolete-item-max-age)) | |
3382 | (newsticker--cache-remove newsticker--cache | |
3383 | name-symbol 'obsolete-expired) | |
3384 | (newsticker--cache-replace-age newsticker--cache | |
3385 | name-symbol 'obsolete-new | |
3386 | 'obsolete)) | |
3387 | ;; bring cache data into proper order.... | |
3388 | ;; (newsticker--cache-sort) | |
3389 | ;; setup scrollable text | |
3390 | (newsticker--ticker-text-setup) | |
3391 | (setq newsticker--latest-update-time (current-time)) | |
3392 | (when something-was-added | |
3393 | ;; FIXME: should we care about removed items as well? | |
3394 | (newsticker--cache-update) | |
3395 | (newsticker--buffer-set-uptodate nil)) | |
3396 | ;; kill the process buffer if wanted | |
3397 | (unless newsticker-debug | |
3398 | (kill-buffer (process-buffer process))) | |
3399 | ;; launch retrieval of image | |
3400 | (when (and imageurl | |
3401 | (string-match "%l" newsticker-heading-format)) | |
3402 | (newsticker--image-get name imageurl)))))) | |
e77274b7 | 3403 | |
5629e04f RS |
3404 | (defun newsticker--display-tick () |
3405 | "Called from the display timer. | |
3406 | This function calls a display function, according to the variable | |
3407 | `newsticker-scroll-smoothly'." | |
3408 | (if newsticker-scroll-smoothly | |
3409 | (newsticker--display-scroll) | |
3410 | (newsticker--display-jump))) | |
3411 | ||
3412 | (defsubst newsticker--echo-area-clean-p () | |
3413 | "Check whether somebody is using the echo area / minibuffer. | |
3414 | Return t if echo area and minibuffer are unused." | |
3415 | (not (or (active-minibuffer-window) | |
3416 | (and (current-message) | |
3417 | (not (string= (current-message) | |
3418 | newsticker--prev-message)))))) | |
3419 | ||
3420 | (defun newsticker--display-jump () | |
3421 | "Called from the display timer. | |
3422 | This function displays the next ticker item in the echo area, unless | |
3423 | there is another message displayed or the minibuffer is active." | |
3424 | (let ((message-log-max nil));; prevents message text from being logged | |
3425 | (when (newsticker--echo-area-clean-p) | |
3426 | (setq newsticker--item-position (1+ newsticker--item-position)) | |
3427 | (when (>= newsticker--item-position (length newsticker--item-list)) | |
3428 | (setq newsticker--item-position 0)) | |
3429 | (setq newsticker--prev-message | |
3430 | (nth newsticker--item-position newsticker--item-list)) | |
8603cb4f | 3431 | (message "%s" newsticker--prev-message)))) |
5629e04f RS |
3432 | |
3433 | (defun newsticker--display-scroll () | |
3434 | "Called from the display timer. | |
3435 | This function scrolls the ticker items in the echo area, unless | |
3436 | there is another message displayed or the minibuffer is active." | |
3437 | (when (newsticker--echo-area-clean-p) | |
3438 | (let* ((width (- (frame-width) 1)) | |
3439 | (message-log-max nil);; prevents message text from being logged | |
3440 | (i newsticker--item-position) | |
3441 | subtext | |
3442 | (s-text newsticker--scrollable-text) | |
3443 | (l (length s-text))) | |
3444 | ;; don't show anything if there is nothing to show | |
3445 | (unless (< (length s-text) 1) | |
3446 | ;; repeat the ticker string if it is shorter than frame width | |
3447 | (while (< (length s-text) width) | |
3448 | (setq s-text (concat s-text s-text))) | |
3449 | ;; get the width of the printed string | |
3450 | (setq l (length s-text)) | |
3451 | (cond ((< i (- l width)) | |
3452 | (setq subtext (substring s-text i (+ i width)))) | |
3453 | (t | |
3454 | (setq subtext (concat | |
3455 | (substring s-text i l) | |
3456 | (substring s-text 0 (- width (- l i))))))) | |
3457 | ;; Take care of multibyte strings, for which (string-width) is | |
3458 | ;; larger than (length). | |
3459 | ;; Actually, such strings may be smaller than (frame-width) | |
3460 | ;; because return values of (string-width) are too large: | |
3461 | ;; (string-width "<japanese character>") => 2 | |
3462 | (let ((t-width (1- (length subtext)))) | |
3463 | (while (> (string-width subtext) width) | |
3464 | (setq subtext (substring subtext 0 t-width)) | |
3465 | (setq t-width (1- t-width)))) | |
3466 | ;; show the ticker text and save current position | |
8603cb4f | 3467 | (message "%s" subtext) |
5629e04f RS |
3468 | (setq newsticker--prev-message subtext) |
3469 | (setq newsticker--item-position (1+ i)) | |
3470 | (when (>= newsticker--item-position l) | |
3471 | (setq newsticker--item-position 0)))))) | |
3472 | ||
3473 | ;; ====================================================================== | |
3474 | ;;; misc | |
3475 | ;; ====================================================================== | |
3476 | (defun newsticker--decode-coding-string (string coding-system) | |
3477 | "Wrapper around `decode-coding-string'. | |
3478 | This functions passes the arguments STRING and CODING-SYSTEM to | |
3479 | `decode-coding-string'. If the decoding is successful the | |
3480 | decoded string is returned, otherwise the unmodified input string | |
3481 | is returned." | |
3482 | (condition-case nil | |
3483 | (decode-coding-string string coding-system) | |
3484 | (error | |
3485 | (message "Cannot decode encoded string `%s'" string) | |
3486 | string))) | |
3487 | ||
3488 | (defun newsticker--decode-numeric-entities (string) | |
3489 | "Decode SGML numeric entities by their respective utf characters. | |
3490 | This function replaces numeric entities in the input STRING and | |
3491 | returns the modified string. For example \"*\" gets replaced | |
3492 | by \"*\"." | |
3493 | (let ((start 0)) | |
3494 | (while (string-match "&#\\([0-9]+\\);" string start) | |
3495 | (condition-case nil | |
3496 | (setq string (replace-match | |
3497 | (string (read (substring string (match-beginning 1) | |
3498 | (match-end 1)))) | |
3499 | nil nil string)) | |
3500 | (error nil)) | |
3501 | (setq start (1+ (match-beginning 0)))) | |
3502 | string)) | |
3503 | ||
3504 | (defun newsticker--remove-whitespace (string) | |
3505 | "Remove leading and trailing whitespace from STRING." | |
3506 | ;; we must have ...+ but not ...* in the regexps otherwise xemacs loops | |
3507 | ;; endlessly... | |
3508 | (when string | |
3509 | (replace-regexp-in-string | |
3510 | "[ \t\r\n]+$" "" | |
3511 | (replace-regexp-in-string "^[ \t\r\n]+" "" string)))) | |
3512 | ||
3513 | (defun newsticker--do-forget-preformatted (item) | |
3514 | "Forget all cached pre-formatted data. | |
3515 | Remove the pre-formatted from `newsticker--cache'." | |
3516 | (if (nthcdr 7 item) | |
3517 | (setcar (nthcdr 7 item) nil)) | |
3518 | (if (nthcdr 6 item) | |
3519 | (setcar (nthcdr 6 item) nil))) | |
3520 | ||
3521 | (defun newsticker--forget-preformatted () | |
3522 | "Forget all cached pre-formatted data. | |
3523 | Remove the pre-formatted from `newsticker--cache'." | |
3524 | (mapc (lambda (feed) | |
3525 | (mapc 'newsticker--do-forget-preformatted | |
3526 | (cdr feed))) | |
3527 | newsticker--cache) | |
3528 | (newsticker--buffer-set-uptodate nil)) | |
3529 | ||
3530 | (defun newsticker--debug-msg (string &rest args) | |
3531 | "Print newsticker debug messages. | |
3532 | This function calls `message' with arguments STRING and ARGS, if | |
3533 | `newsticker-debug' is non-nil." | |
3534 | (and newsticker-debug | |
3535 | ;;(not (active-minibuffer-window)) | |
3536 | ;;(not (current-message)) | |
3537 | (apply 'message string args))) | |
3538 | ||
3539 | (defun newsticker--decode-iso8601-date (iso8601-string) | |
3540 | "Return ISO8601-STRING in format like `decode-time'. | |
3541 | Converts from ISO-8601 to Emacs representation. If ISO8601-STRING | |
3542 | Examples: | |
3543 | 2004-09-17T05:09:49+00:00 | |
3544 | 2004-09-17T05:09+00:00 | |
3545 | 2004-09-17T05:09:49 | |
3546 | 2004-09-17T05:09 | |
3547 | 2004-09-17 | |
3548 | 2004-09 | |
3549 | 2004" | |
3550 | (if iso8601-string | |
3551 | (when (string-match | |
3552 | (concat | |
3553 | "\\([0-9]\\{4\\}\\)" | |
3554 | "\\(-\\([0-9]\\{2\\}\\)" | |
3555 | "\\(-\\([0-9]\\{2\\}\\)" | |
3556 | "\\(T" | |
3557 | "\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)" | |
3558 | "\\(:\\([0-9]\\{2\\}\\)\\)?" | |
3559 | "\\(\\([-+Z]\\)\\(\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)?" | |
3560 | "\\)?\\)?\\)?") | |
3561 | iso8601-string) | |
3562 | (let ((year (read (match-string 1 iso8601-string))) | |
3563 | (month (read (match-string 3 iso8601-string))) | |
3564 | (day (read (match-string 5 iso8601-string))) | |
3565 | (hour (read (or (match-string 7 iso8601-string) | |
3566 | "0"))) | |
3567 | (minute (read (or (match-string 8 iso8601-string) | |
3568 | "0"))) | |
3569 | ;;(second (read (or (match-string 10 iso8601-string) | |
3570 | ;; "0"))) | |
3571 | (sign (match-string 12 iso8601-string)) | |
3572 | (offset-hour (read (or (match-string 14 iso8601-string) | |
3573 | "0"))) | |
3574 | (offset-minute (read (or (match-string 15 iso8601-string) | |
3575 | "0"))) | |
3576 | (second 0)) | |
3577 | (cond ((string= sign "+") | |
3578 | (setq hour (- hour offset-hour)) | |
3579 | (setq minute (- minute offset-minute))) | |
3580 | ((string= sign "-") | |
3581 | (setq hour (+ hour offset-hour)) | |
3582 | (setq minute (+ minute offset-minute)))) | |
3583 | ;; if UTC subtract current-time-zone offset | |
3584 | ;;(setq second (+ (car (current-time-zone)) second))) | |
3585 | ||
3586 | (condition-case nil | |
3587 | (encode-time second minute hour day month year t) | |
3588 | (error | |
3589 | (message "Cannot decode \"%s\"" iso8601-string) | |
3590 | nil)))) | |
3591 | nil)) | |
3592 | ||
3593 | (defun newsticker--decode-rfc822-date (rfc822-string) | |
3594 | "Return RFC822-STRING in format like `decode-time'. | |
3595 | Converts from RFC822 to Emacs representation. | |
3596 | Examples: | |
3597 | Sat, 07 Sep 2002 00:00:01 GMT | |
3598 | 07 Sep 2002 00:00:01 GMT" | |
3599 | (if rfc822-string | |
3600 | (when (string-match | |
3601 | (concat | |
3602 | "\\s-*" | |
3603 | ;; week day | |
3604 | "\\(\\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\)\\s-*,?\\)\\s-+" | |
3605 | ;; day | |
3606 | "\\([0-9]\\{1,2\\}\\)\\s-+" | |
3607 | ;; month | |
3608 | "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|" | |
3609 | "Sep\\|Oct\\|Nov\\|Dec\\)\\s-+" | |
3610 | ;; year | |
3611 | "\\([0-9]\\{2,4\\}\\)\\s-+" | |
3612 | ;; hour | |
3613 | "\\([0-9]\\{2\\}\\)" | |
3614 | ;; minute | |
3615 | ":\\([0-9]\\{2\\}\\)" | |
3616 | ;; second | |
3617 | "\\(:\\([0-9]\\{2\\}\\)\\)?" | |
3618 | ;; zone -- fixme | |
3619 | "\\(\\s-+.*\\)?") | |
3620 | rfc822-string) | |
3621 | (let ((day (read (match-string 3 rfc822-string))) | |
3622 | (month-name (match-string 4 rfc822-string)) | |
3623 | (month 0) | |
3624 | (year (read (match-string 5 rfc822-string))) | |
3625 | (hour (read (match-string 6 rfc822-string))) | |
3626 | (minute (read (match-string 7 rfc822-string))) | |
3627 | (second (read (or (match-string 9 rfc822-string) | |
3628 | "0"))) | |
3629 | ;;(zone (match-string 10 rfc822-string)) | |
3630 | ) | |
3631 | (condition-case error-data | |
3632 | (let ((i 1)) | |
3633 | (mapc (lambda (m) | |
3634 | (if (string= month-name m) | |
3635 | (setq month i)) | |
3636 | (setq i (1+ i))) | |
3637 | '("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" | |
3638 | "Sep" "Oct" "Nov" "Dec")) | |
3639 | (encode-time second minute hour day month year t)) | |
3640 | (error | |
3641 | (message "Cannot decode \"%s\": %s %s" rfc822-string | |
3642 | (car error-data) (cdr error-data)) | |
3643 | nil)))) | |
3644 | nil)) | |
3645 | ||
3646 | (defun newsticker--lists-intersect-p (list1 list2) | |
3647 | "Return t if LIST1 and LIST2 share elements." | |
3648 | (let ((result nil)) | |
3649 | (mapc (lambda (elt) | |
3650 | (if (memq elt list2) | |
3651 | (setq result t))) | |
3652 | list1) | |
3653 | result)) | |
3654 | ||
3655 | ;; ====================================================================== | |
3656 | ;;; images | |
3657 | ;; ====================================================================== | |
3658 | (defun newsticker--image-get (feed-name url) | |
3659 | "Get image of the news site FEED-NAME from URL. | |
3660 | If the image has been downloaded in the last 24h do nothing." | |
3661 | (let ((image-name (concat newsticker-imagecache-dirname "/" | |
3662 | feed-name))) | |
3663 | (if (and (file-exists-p image-name) | |
3664 | (time-less-p (current-time) | |
3665 | (time-add (nth 5 (file-attributes image-name)) | |
3666 | (seconds-to-time 86400)))) | |
3667 | (newsticker--debug-msg "%s: Getting image for %s skipped" | |
3668 | (format-time-string "%A, %H:%M" (current-time)) | |
3669 | feed-name) | |
3670 | ;; download | |
3671 | (newsticker--debug-msg "%s: Getting image for %s" | |
3672 | (format-time-string "%A, %H:%M" (current-time)) | |
3673 | feed-name) | |
3674 | (let* ((buffername (concat " *newsticker-wget-image-" feed-name "*")) | |
3675 | (item (or (assoc feed-name newsticker-url-list) | |
3676 | (assoc feed-name newsticker-url-list-defaults) | |
3677 | (error | |
3678 | "Cannot get news for %s: Check newsticker-url-list" | |
3679 | feed-name))) | |
3680 | (wget-arguments (or (car (cdr (cdr (cdr (cdr item))))) | |
3681 | newsticker-wget-arguments))) | |
3682 | (save-excursion | |
3683 | (set-buffer (get-buffer-create buffername)) | |
3684 | (erase-buffer) | |
3685 | ;; throw an error if there is an old wget-process around | |
3686 | (if (get-process feed-name) | |
3687 | (error "Another wget-process is running for image %s" | |
3688 | feed-name)) | |
3689 | ;; start wget | |
3690 | (let* ((args (append wget-arguments (list url))) | |
3691 | (proc (apply 'start-process feed-name buffername | |
3692 | newsticker-wget-name args))) | |
3693 | (set-process-coding-system proc 'no-conversion 'no-conversion) | |
3694 | (set-process-sentinel proc 'newsticker--image-sentinel))))))) | |
3695 | ||
3696 | (defun newsticker--image-sentinel (process event) | |
3697 | "Sentinel for image-retrieving PROCESS caused by EVENT." | |
3698 | (let* ((p-status (process-status process)) | |
3699 | (exit-status (process-exit-status process)) | |
3700 | (feed-name (process-name process))) | |
3701 | ;; catch known errors (zombie processes, rubbish-xml etc. | |
3702 | ;; if an error occurs the news feed is not updated! | |
3703 | (catch 'oops | |
3704 | (unless (and (eq p-status 'exit) | |
3705 | (= exit-status 0)) | |
3706 | (message "%s: Error while retrieving image from %s" | |
3707 | (format-time-string "%A, %H:%M" (current-time)) | |
3708 | feed-name) | |
3709 | (throw 'oops nil)) | |
3710 | (let (image-name) | |
3711 | (save-excursion | |
3712 | (set-buffer (process-buffer process)) | |
3713 | (setq image-name (concat newsticker-imagecache-dirname "/" | |
3714 | feed-name)) | |
3715 | (set-buffer-file-coding-system 'no-conversion) | |
3716 | ;; make sure the cache dir exists | |
3717 | (unless (file-directory-p newsticker-imagecache-dirname) | |
3718 | (make-directory newsticker-imagecache-dirname)) | |
3719 | ;; write and close buffer | |
3720 | (let ((require-final-newline nil) | |
3721 | (backup-inhibited t) | |
3722 | (coding-system-for-write 'no-conversion)) | |
3723 | (write-region nil nil image-name nil 'quiet)) | |
3724 | (set-buffer-modified-p nil) | |
3725 | (kill-buffer (current-buffer))))))) | |
3726 | ||
3727 | (defun newsticker--image-read (feed-name-symbol disabled) | |
3728 | "Read the cached image for FEED-NAME-SYMBOL from disk. | |
3729 | If DISABLED is non-nil the image will be converted to a disabled look | |
3730 | \(unless `newsticker-enable-logo-manipulations' is not t\). | |
3731 | Return the image." | |
3732 | (let ((image-name (concat newsticker-imagecache-dirname "/" | |
3733 | (symbol-name feed-name-symbol))) | |
3734 | (img nil)) | |
3735 | (when (file-exists-p image-name) | |
3736 | (condition-case error-data | |
3737 | (setq img (create-image | |
3738 | image-name nil nil | |
3739 | :conversion (and newsticker-enable-logo-manipulations | |
3740 | disabled | |
3741 | 'disabled) | |
3742 | :mask (and newsticker-enable-logo-manipulations | |
3743 | 'heuristic) | |
3744 | :ascent 70)) | |
3745 | (error | |
3746 | (message "Error: cannot create image: %s" | |
3747 | (cadr error-data))))) | |
3748 | img)) | |
3749 | ||
3750 | ;; ====================================================================== | |
3751 | ;;; imenu stuff | |
3752 | ;; ====================================================================== | |
3753 | (defun newsticker--imenu-create-index () | |
3754 | "Scan newsticker buffer and return an index for imenu." | |
3755 | (save-excursion | |
3756 | (goto-char (point-min)) | |
3757 | (let ((index-alist nil) | |
3758 | (feed-list nil) | |
3759 | (go-ahead t)) | |
3760 | (while go-ahead | |
3761 | (let ((type (get-text-property (point) 'nt-type)) | |
3762 | (title (get-text-property (point) 'nt-title))) | |
3763 | (cond ((eq type 'feed) | |
3764 | ;; we're on a feed heading | |
3765 | (when feed-list | |
3766 | (if index-alist | |
3767 | (nconc index-alist (list feed-list)) | |
3768 | (setq index-alist (list feed-list)))) | |
3769 | (setq feed-list (list title))) | |
3770 | (t | |
3771 | (nconc feed-list | |
3772 | (list (cons title (point))))))) | |
3773 | (setq go-ahead (newsticker--buffer-goto '(item feed)))) | |
3774 | (if index-alist | |
3775 | (nconc index-alist (list feed-list)) | |
3776 | (setq index-alist (list feed-list))) | |
3777 | index-alist))) | |
3778 | ||
3779 | (defun newsticker--imenu-goto (name pos &rest args) | |
3780 | "Go item NAME at position POS and show item. | |
3781 | ARGS are ignored." | |
3782 | (goto-char pos) | |
3783 | (newsticker-show-entry)) | |
3784 | ||
3785 | ;; ====================================================================== | |
3786 | ;;; buffer stuff | |
3787 | ;; ====================================================================== | |
3788 | (defun newsticker--buffer-set-uptodate (value) | |
3789 | "Set the uptodate-status of the newsticker buffer to VALUE. | |
3790 | The mode-line is changed accordingly." | |
3791 | (setq newsticker--buffer-uptodate-p value) | |
3792 | (let ((b (get-buffer "*newsticker*"))) | |
3793 | (when b | |
3794 | (save-excursion | |
3795 | (set-buffer b) | |
3796 | (if value | |
3797 | (setq mode-name "Newsticker -- up to date -- ") | |
3798 | (setq mode-name "Newsticker -- NEED UPDATE -- "))) | |
3799 | (sit-for 0)))) | |
3800 | ||
3801 | (defun newsticker--buffer-redraw () | |
3802 | "Sometimes (CVS) Emacs forgets to update the window..." | |
3803 | (if (fboundp 'force-window-update) | |
3804 | (force-window-update (current-buffer)) | |
3805 | (redraw-frame (selected-frame))) | |
3806 | (run-hooks 'newsticker-buffer-change-hook) | |
3807 | (sit-for 0)) | |
3808 | ||
3809 | (defun newsticker--buffer-insert-all-items () | |
3810 | "Insert all cached newsticker items into the current buffer. | |
3811 | Keeps order of feeds as given in `newsticker-url-list' and | |
3812 | `newsticker-url-list-defaults'." | |
3813 | (goto-char (point-min)) | |
3814 | (mapc (lambda (url-item) | |
3815 | (let* ((feed-name (car url-item)) | |
3816 | (feed-name-symbol (intern feed-name)) | |
3817 | (feed (assoc feed-name-symbol newsticker--cache)) | |
3818 | (items (cdr feed)) | |
3819 | (pos (point))) | |
3820 | (when feed | |
3821 | ;; insert the feed description | |
3822 | (mapc (lambda (item) | |
3823 | (when (eq (newsticker--age item) 'feed) | |
3824 | (newsticker--buffer-insert-item item | |
3825 | feed-name-symbol))) | |
3826 | items) | |
3827 | ;;insert the items | |
3828 | (mapc (lambda (item) | |
3829 | (if (memq (newsticker--age item) '(new immortal old | |
3830 | obsolete)) | |
3831 | (newsticker--buffer-insert-item item | |
3832 | feed-name-symbol))) | |
3833 | items) | |
3834 | (put-text-property pos (point) 'feed (car feed)) | |
e77274b7 | 3835 | |
5629e04f RS |
3836 | ;; insert empty line between feeds |
3837 | (let ((p (point))) | |
3838 | (insert "\n") | |
3839 | (put-text-property p (point) 'hard t))))) | |
3840 | (append newsticker-url-list newsticker-url-list-defaults)) | |
e77274b7 | 3841 | |
5629e04f RS |
3842 | (newsticker--buffer-set-faces (point-min) (point-max)) |
3843 | (newsticker--buffer-set-invisibility (point-min) (point-max)) | |
3844 | (goto-char (point-min))) | |
e77274b7 | 3845 | |
5629e04f RS |
3846 | (defun newsticker--buffer-insert-item (item &optional feed-name-symbol) |
3847 | "Insert a news item in the current buffer. | |
3848 | Insert the string PREFIX and a formatted representation of the | |
3849 | ITEM. The optional parameter FEED-NAME-SYMBOL determines how the | |
3850 | item is formatted and whether the item-retrieval time is added as | |
3851 | well." | |
3852 | ;; insert headline | |
3853 | (if (eq (newsticker--age item) 'feed) | |
3854 | (newsticker--buffer-do-insert-text item 'feed feed-name-symbol) | |
3855 | (newsticker--buffer-do-insert-text item 'item feed-name-symbol)) | |
3856 | ;; insert the description | |
3857 | (newsticker--buffer-do-insert-text item 'desc feed-name-symbol)) | |
3858 | ||
3859 | (defun newsticker--buffer-do-insert-text (item type feed-name-symbol) | |
3860 | "Actually insert contents of news item, format it, render it and all that. | |
3861 | ITEM is a news item, TYPE tells which part of the item shall be inserted, | |
3862 | FEED-NAME-SYMBOL tells to which feed this item belongs." | |
3863 | (let* ((pos (point)) | |
3864 | (format newsticker-desc-format) | |
3865 | (pos-date-start nil) | |
3866 | (pos-date-end nil) | |
3867 | (pos-stat-start nil) | |
3868 | (pos-stat-end nil) | |
3869 | (pos-text-start nil) | |
3870 | (pos-text-end nil) | |
3871 | (pos-extra-start nil) | |
3872 | (pos-extra-end nil) | |
3873 | (pos-enclosure-start nil) | |
3874 | (pos-enclosure-end nil) | |
3875 | (age (newsticker--age item)) | |
3876 | (preformatted-contents (newsticker--preformatted-contents item)) | |
3877 | (preformatted-title (newsticker--preformatted-title item))) | |
3878 | (cond ((and preformatted-contents | |
3879 | (not (eq (aref preformatted-contents 0) ?\n));; we must | |
3880 | ;; NOT have a line | |
3881 | ;; break! | |
3882 | (eq type 'desc)) | |
3883 | (insert preformatted-contents)) | |
3884 | ((and preformatted-title | |
3885 | (not (eq (aref preformatted-title 0) ?\n));; we must NOT have a | |
3886 | ;; line break! | |
3887 | (eq type 'item)) | |
3888 | (insert preformatted-title)) | |
3889 | (t | |
3890 | ;; item was not formatted before. | |
3891 | ;; Let's go. | |
3892 | (if (eq type 'item) | |
3893 | (setq format newsticker-item-format) | |
3894 | (if (eq type 'feed) | |
3895 | (setq format newsticker-heading-format))) | |
e77274b7 | 3896 | |
5629e04f RS |
3897 | (while (> (length format) 0) |
3898 | (let ((prefix (if (> (length format) 1) | |
3899 | (substring format 0 2) | |
3900 | ""))) | |
3901 | (cond ((string= "%c" prefix) | |
3902 | ;; contents | |
3903 | (when (newsticker--desc item) | |
3904 | (setq pos-text-start (point-marker)) | |
3905 | (insert (newsticker--desc item)) | |
3906 | (setq pos-text-end (point-marker))) | |
3907 | (setq format (substring format 2))) | |
3908 | ((string= "%d" prefix) | |
3909 | ;; date | |
3910 | (setq pos-date-start (point-marker)) | |
3911 | (if (newsticker--time item) | |
3912 | (insert (format-time-string newsticker-date-format | |
3913 | (newsticker--time item)))) | |
3914 | (setq pos-date-end (point-marker)) | |
3915 | (setq format (substring format 2))) | |
3916 | ((string= "%l" prefix) | |
3917 | ;; logo | |
3918 | (let ((disabled (cond ((eq (newsticker--age item) 'feed) | |
3919 | (= (newsticker--stat-num-items | |
3920 | feed-name-symbol 'new) 0)) | |
3921 | (t | |
3922 | (not (eq (newsticker--age item) | |
3923 | 'new)))))) | |
3924 | (let ((img (newsticker--image-read feed-name-symbol | |
3925 | disabled))) | |
3926 | (when img | |
3927 | (newsticker--insert-image img (car item))))) | |
3928 | (setq format (substring format 2))) | |
3929 | ((string= "%L" prefix) | |
3930 | ;; logo or title | |
3931 | (let ((disabled (cond ((eq (newsticker--age item) 'feed) | |
3932 | (= (newsticker--stat-num-items | |
3933 | feed-name-symbol 'new) 0)) | |
3934 | (t | |
3935 | (not (eq (newsticker--age item) | |
3936 | 'new)))))) | |
3937 | (let ((img (newsticker--image-read feed-name-symbol | |
3938 | disabled))) | |
3939 | (if img | |
3940 | (newsticker--insert-image img (car item)) | |
3941 | (when (car item) | |
3942 | (setq pos-text-start (point-marker)) | |
3943 | (if (eq (newsticker--age item) 'feed) | |
3944 | (insert (newsticker--title item)) | |
3945 | ;; FIXME: This is not the "real" title! | |
3946 | (insert (format "%s" | |
3947 | (car (newsticker--cache-get-feed | |
3948 | feed-name-symbol))))) | |
3949 | (setq pos-text-end (point-marker)))))) | |
3950 | (setq format (substring format 2))) | |
3951 | ((string= "%s" prefix) | |
3952 | ;; statistics | |
3953 | (setq pos-stat-start (point-marker)) | |
3954 | (if (eq (newsticker--age item) 'feed) | |
3955 | (insert (newsticker--buffer-statistics | |
3956 | feed-name-symbol))) | |
3957 | (setq pos-stat-end (point-marker)) | |
3958 | (setq format (substring format 2))) | |
3959 | ((string= "%t" prefix) | |
3960 | ;; title | |
3961 | (when (car item) | |
3962 | (setq pos-text-start (point-marker)) | |
3963 | (insert (car item)) | |
3964 | (setq pos-text-end (point-marker))) | |
3965 | (setq format (substring format 2))) | |
3966 | ((string-match "%." prefix) | |
3967 | ;; unknown specifier! | |
3968 | (insert prefix) | |
3969 | (setq format (substring format 2))) | |
3970 | ((string-match "^\\([^%]*\\)\\(.*\\)" format) ;; FIXME! | |
3971 | ;; everything else | |
3972 | (let ((p (point))) | |
3973 | (insert (substring format | |
3974 | (match-beginning 1) (match-end 1))) | |
3975 | ;; in case that the format string contained newlines | |
3976 | (put-text-property p (point) 'hard t)) | |
3977 | (setq format (substring format (match-beginning 2))))))) | |
e77274b7 | 3978 | |
5629e04f RS |
3979 | ;; decode HTML if possible... |
3980 | (let ((is-rendered-HTML nil)) | |
3981 | (when (and newsticker-html-renderer pos-text-start pos-text-end) | |
3982 | (condition-case error-data | |
3983 | (save-excursion | |
3984 | ;; check whether it is necessary to call html renderer | |
3985 | ;; (regexp inspired by htmlr.el) | |
3986 | (goto-char pos-text-start) | |
3987 | (when (re-search-forward | |
3988 | "</?[A-Za-z1-6]*\\|&#?[A-Za-z0-9]+;" pos-text-end t) | |
3989 | ;; (message "%s" (newsticker--title item)) | |
3990 | (let ((w3m-fill-column (if newsticker-use-full-width | |
3991 | -1 fill-column)) | |
3992 | (w3-maximum-line-length | |
3993 | (if newsticker-use-full-width nil fill-column))) | |
3994 | (save-excursion | |
3995 | (funcall newsticker-html-renderer pos-text-start | |
3996 | pos-text-end))) | |
5629e04f RS |
3997 | (cond ((eq newsticker-html-renderer 'w3m-region) |
3998 | (add-text-properties pos (point-max) | |
3999 | (list 'keymap | |
4000 | w3m-minor-mode-map))) | |
4001 | ((eq newsticker-html-renderer 'w3-region) | |
4002 | (add-text-properties pos (point-max) | |
4003 | (list 'keymap w3-mode-map)))) | |
4004 | (setq is-rendered-HTML t))) | |
4005 | (error | |
4006 | (message "Error: HTML rendering failed: %s, %s" | |
4007 | (car error-data) (cdr error-data))))) | |
4008 | (when (and newsticker-justification | |
4009 | (eq type 'desc) | |
4010 | (not is-rendered-HTML)) | |
4011 | (condition-case nil | |
4012 | (let ((use-hard-newlines t)) | |
4013 | (fill-region pos (point-max) newsticker-justification)) | |
4014 | (error nil)))) | |
4015 | ||
4016 | ;; remove leading and trailing newlines | |
4017 | (goto-char pos) | |
4018 | (unless (= 0 (skip-chars-forward " \t\r\n")) | |
4019 | (delete-region pos (point))) | |
4020 | (goto-char (point-max)) | |
4021 | (let ((end (point))) | |
4022 | (unless (= 0 (skip-chars-backward " \t\r\n" (1+ pos))) | |
4023 | (delete-region (point) end))) | |
4024 | (goto-char (point-max)) | |
4025 | ||
4026 | ;; closing newline | |
4027 | (unless nil ;;(eq pos (point)) | |
4028 | (insert "\n") | |
4029 | (put-text-property (1- (point)) (point) 'hard t)) | |
4030 | ||
4031 | ;; insert enclosure element | |
4032 | (when (eq type 'desc) | |
4033 | (setq pos-enclosure-start (point)) | |
4034 | (newsticker--buffer-insert-enclosure item) | |
4035 | (setq pos-enclosure-end (point))) | |
4036 | ||
4037 | ;; show extra elements | |
4038 | (when (eq type 'desc) | |
4039 | (goto-char (point-max)) | |
4040 | (setq pos-extra-start (point)) | |
4041 | (mapc (lambda (extra-element) | |
4042 | (unless (memq (car extra-element) | |
4043 | '(items link title description | |
4044 | content:encoded | |
4045 | dc:subject dc:date item guid | |
4046 | pubDate | |
4047 | enclosure)) | |
4048 | (newsticker--buffer-print-extra-element | |
4049 | extra-element))) | |
4050 | (newsticker--extra item)) | |
4051 | (setq pos-extra-end (point))) | |
4052 | ||
4053 | ;; text properties | |
4054 | (when (memq type '(feed item)) | |
4055 | (add-text-properties pos (1- (point)) | |
4056 | (list 'mouse-face 'highlight | |
4057 | 'nt-link (newsticker--link item) | |
4058 | 'help-echo | |
4059 | (format "mouse-2: visit item (%s)" | |
4060 | (newsticker--link item)) | |
4061 | 'keymap newsticker--url-keymap)) | |
4062 | (add-text-properties pos (point) | |
4063 | (list 'nt-title (newsticker--title item) | |
4064 | 'nt-desc (newsticker--desc item)))) | |
e77274b7 | 4065 | |
5629e04f RS |
4066 | (add-text-properties pos (point) |
4067 | (list 'nt-type type | |
4068 | 'nt-face type | |
4069 | 'nt-age age | |
4070 | 'nt-guid (newsticker--guid item))) | |
4071 | (when (and pos-date-start pos-date-end) | |
4072 | (put-text-property pos-date-start pos-date-end 'nt-face 'date)) | |
4073 | (when (and pos-stat-start pos-stat-end) | |
4074 | (put-text-property pos-stat-start pos-stat-end 'nt-face 'stat)) | |
4075 | (when (and pos-extra-start pos-extra-end) | |
4076 | (put-text-property pos-extra-start pos-extra-end | |
4077 | 'nt-face 'extra) | |
4078 | (put-text-property pos-extra-start pos-extra-end | |
4079 | 'nt-type 'extra)) | |
4080 | (when (and pos-enclosure-start pos-enclosure-end | |
4081 | (> pos-enclosure-end pos-enclosure-start)) | |
4082 | (put-text-property pos-enclosure-start (1- pos-enclosure-end) | |
4083 | 'nt-face 'enclosure)) | |
4084 | ||
4085 | ;; left margin | |
4086 | ;;(unless (memq type '(feed item)) | |
4087 | ;;(set-left-margin pos (1- (point)) 1)) | |
e77274b7 | 4088 | |
5629e04f RS |
4089 | ;; save rendered stuff |
4090 | (cond ((eq type 'desc) | |
4091 | ;; preformatted contents | |
4092 | (newsticker--cache-set-preformatted-contents | |
4093 | item (buffer-substring pos (point)))) | |
4094 | ((eq type 'item) | |
4095 | ;; preformatted title | |
4096 | (newsticker--cache-set-preformatted-title | |
4097 | item (buffer-substring pos (point))))))))) | |
4098 | ||
4099 | (defun newsticker--buffer-print-extra-element (extra-element) | |
4100 | "Insert EXTRA-ELEMENT in a pretty form into the current buffer." | |
4101 | (insert (format "%s:\t" (car extra-element))) | |
4102 | (let (;;(attributes (cadr extra-element)) ;FIXME!!!! | |
4103 | (contents (cddr extra-element))) | |
4104 | (cond ((listp contents) | |
4105 | (mapc (lambda (i) | |
4106 | (if (and (stringp i) | |
4107 | (string-match "^http://.*" i)) | |
4108 | (let ((pos (point))) | |
4109 | (insert i " ") ; avoid self-reference from the | |
4110 | ; nt-link thing | |
4111 | (add-text-properties | |
4112 | pos (point) | |
4113 | (list 'mouse-face 'highlight | |
4114 | 'nt-link i | |
4115 | 'help-echo | |
4116 | (format "mouse-2: visit (%s)" i) | |
4117 | 'keymap newsticker--url-keymap))) | |
4118 | (insert (format "%s" i)))) | |
4119 | contents)) | |
4120 | (t | |
4121 | (insert (format "%s" contents)))) | |
4122 | (insert "\n"))) | |
4123 | ||
4124 | (defun newsticker--buffer-insert-enclosure (item) | |
4125 | "Insert enclosure element of an RSS ITEM into the current buffer." | |
4126 | (let ((enclosure (newsticker--enclosure item)) | |
4127 | (beg (point))) | |
4128 | (when enclosure | |
4129 | (let ((url (cdr (assoc 'url enclosure))) | |
4130 | (length (cdr (assoc 'length enclosure))) | |
4131 | (type (cdr (assoc 'type enclosure)))) | |
4132 | (insert (format "Enclosed file (%s, %1.2f kBytes)" type | |
4133 | (/ (string-to-number length) 1024))) | |
4134 | (add-text-properties beg (point) | |
4135 | (list 'mouse-face 'highlight | |
4136 | 'nt-link url | |
4137 | 'help-echo (format | |
4138 | "mouse-2: visit (%s)" url) | |
4139 | 'keymap newsticker--url-keymap | |
4140 | 'nt-face 'enclosure | |
4141 | 'nt-type 'desc)) | |
4142 | (insert "\n"))))) | |
4143 | ||
4144 | (defun newsticker--buffer-statistics (feed-name-symbol) | |
4145 | "Return a statistic string for the feed given by FEED-NAME-SYMBOL. | |
4146 | See `newsticker-statistics-format'." | |
4147 | (let ((case-fold-search nil)) | |
4148 | (replace-regexp-in-string | |
4149 | "%a" | |
4150 | (format "%d" (newsticker--stat-num-items feed-name-symbol)) | |
4151 | (replace-regexp-in-string | |
4152 | "%i" | |
4153 | (format "%d" (newsticker--stat-num-items feed-name-symbol 'immortal)) | |
4154 | (replace-regexp-in-string | |
4155 | "%n" | |
4156 | (format "%d" (newsticker--stat-num-items feed-name-symbol 'new)) | |
4157 | (replace-regexp-in-string | |
4158 | "%o" | |
4159 | (format "%d" (newsticker--stat-num-items feed-name-symbol 'old)) | |
4160 | (replace-regexp-in-string | |
4161 | "%O" | |
4162 | (format "%d" (newsticker--stat-num-items feed-name-symbol 'obsolete)) | |
4163 | newsticker-statistics-format))))))) | |
4164 | ||
4165 | (defun newsticker--buffer-set-faces (start end) | |
4166 | "Add face properties according to mark property. | |
4167 | Scans the buffer between START and END." | |
4168 | (save-excursion | |
4169 | ;;(put-text-property start end 'face 'newsticker-default-face) | |
4170 | (goto-char start) | |
4171 | (let ((pos1 start) | |
4172 | (pos2 1) | |
4173 | (nt-face (get-text-property start 'nt-face)) | |
4174 | (nt-age (get-text-property start 'nt-age))) | |
4175 | (when nt-face | |
4176 | (setq pos2 (next-single-property-change (point) 'nt-face)) | |
4177 | (newsticker--set-face-properties pos1 pos2 nt-face nt-age) | |
4178 | (setq nt-face (get-text-property pos2 'nt-face)) | |
4179 | (setq pos1 pos2)) | |
4180 | (while (and (setq pos2 (next-single-property-change pos1 'nt-face)) | |
4181 | (<= pos2 end) | |
4182 | (> pos2 pos1)) | |
4183 | (newsticker--set-face-properties pos1 pos2 nt-face nt-age) | |
4184 | (setq nt-face (get-text-property pos2 'nt-face)) | |
4185 | (setq nt-age (get-text-property pos2 'nt-age)) | |
4186 | (setq pos1 pos2))))) | |
4187 | ||
4188 | (defun newsticker--buffer-set-invisibility (start end) | |
4189 | "Add invisibility properties according to nt-type property. | |
4190 | Scans the buffer between START and END. Sets the 'invisible | |
4191 | property to '(<nt-type>-<nt-age> <nt-type> <nt-age>)." | |
4192 | (save-excursion | |
4193 | ;; reset invisibility settings | |
4194 | (put-text-property start end 'invisible nil) | |
4195 | ;; let's go | |
4196 | (goto-char start) | |
4197 | (let ((pos1 start) | |
4198 | (pos2 1) | |
4199 | (nt-type (get-text-property start 'nt-type)) | |
4200 | (nt-age (get-text-property start 'nt-age))) | |
4201 | (when nt-type | |
4202 | (setq pos2 (next-single-property-change (point) 'nt-type)) | |
4203 | (put-text-property (max (point-min) pos1) (1- pos2) | |
4204 | 'invisible | |
4205 | (list (intern | |
e77274b7 JB |
4206 | (concat |
4207 | (symbol-name | |
5629e04f RS |
4208 | (if (eq nt-type 'extra) 'desc nt-type)) |
4209 | "-" | |
4210 | (symbol-name nt-age))) | |
4211 | nt-type | |
4212 | nt-age)) | |
4213 | (setq nt-type (get-text-property pos2 'nt-type)) | |
4214 | (setq pos1 pos2)) | |
4215 | (while (and (setq pos2 (next-single-property-change pos1 'nt-type)) | |
4216 | (<= pos2 end) | |
4217 | (> pos2 pos1)) | |
4218 | ;; must shift one char to the left in order to handle inivisible | |
4219 | ;; newlines, motion in invisible text areas and all that correctly | |
4220 | (put-text-property (1- pos1) (1- pos2) | |
4221 | 'invisible | |
4222 | (list (intern | |
e77274b7 JB |
4223 | (concat |
4224 | (symbol-name | |
5629e04f RS |
4225 | (if (eq nt-type 'extra) 'desc nt-type)) |
4226 | "-" | |
4227 | (symbol-name nt-age))) | |
4228 | nt-type | |
4229 | nt-age)) | |
4230 | (setq nt-type (get-text-property pos2 'nt-type)) | |
4231 | (setq nt-age (get-text-property pos2 'nt-age)) | |
4232 | (setq pos1 pos2))))) | |
4233 | ||
4234 | (defun newsticker--set-face-properties (pos1 pos2 nt-face age) | |
4235 | "Set the face for the text between the positions POS1 and POS2. | |
4236 | The face is chosen according the values of NT-FACE and AGE." | |
4237 | (let ((face (cond ((eq nt-face 'feed) | |
4238 | 'newsticker-feed-face) | |
4239 | ((eq nt-face 'item) | |
4240 | (cond ((eq age 'new) | |
4241 | 'newsticker-new-item-face) | |
4242 | ((eq age 'old) | |
4243 | 'newsticker-old-item-face) | |
4244 | ((eq age 'immortal) | |
4245 | 'newsticker-immortal-item-face) | |
4246 | ((eq age 'obsolete) | |
4247 | 'newsticker-obsolete-item-face))) | |
4248 | ((eq nt-face 'date) | |
4249 | 'newsticker-date-face) | |
4250 | ((eq nt-face 'stat) | |
4251 | 'newsticker-statistics-face) | |
4252 | ((eq nt-face 'extra) | |
4253 | 'newsticker-extra-face) | |
4254 | ((eq nt-face 'enclosure) | |
4255 | 'newsticker-enclosure-face)))) | |
4256 | (when face | |
4257 | (put-text-property pos1 (max pos1 pos2) 'face face)))) | |
e77274b7 | 4258 | |
5629e04f RS |
4259 | (defun newsticker--insert-image (img string) |
4260 | "Insert IMG with STRING at point. | |
4261 | This is a work-around for a strange behavior of Emacs versions before | |
4262 | 21.3.50. Images inserted with `insert-image' vanished after doing | |
4263 | `fill-region'." | |
4264 | ;; This should work: | |
4265 | ;;(insert-image img string) | |
4266 | ;; but it does not. Therefore we do this, which should be equivalent! | |
4267 | (let ((pos (point))) | |
4268 | ;;(insert string) | |
4269 | (insert ":-)") | |
4270 | (add-text-properties pos (point) (list 'display img)))) | |
4271 | ||
4272 | ;; ====================================================================== | |
4273 | ;;; HTML rendering | |
4274 | ;; ====================================================================== | |
4275 | (defun newsticker-htmlr-render (pos1 pos2) ; | |
4276 | "Replacement for `htmlr-render'. | |
4277 | Renders the HTML code in the region POS1 to POS2 using htmlr." | |
4278 | (let ((str (buffer-substring-no-properties pos1 pos2))) | |
4279 | (delete-region pos1 pos2) | |
4280 | (insert | |
4281 | (with-temp-buffer | |
4282 | (insert str) | |
4283 | (goto-char (point-min)) | |
4284 | ;; begin original htmlr-render | |
4285 | (htmlr-reset) | |
4286 | ;; something omitted here... | |
4287 | (while (< (point) (point-max)) | |
4288 | (htmlr-step)) | |
4289 | ;; end original htmlr-render | |
4290 | (newsticker--remove-whitespace (buffer-string)))))) | |
4291 | ||
4292 | ;; ====================================================================== | |
4293 | ;;; Functions working on the *newsticker* buffer | |
4294 | ;; ====================================================================== | |
4295 | (defun newsticker--buffer-make-item-completely-visible () | |
4296 | "Scroll buffer until current item is completely visible." | |
4297 | (switch-to-buffer (get-buffer-create "*newsticker*")) | |
4298 | (when newsticker--auto-narrow-to-feed | |
4299 | (let* ((min (or (save-excursion (newsticker--buffer-beginning-of-feed)) | |
4300 | (point-min))) | |
4301 | (max (or (save-excursion (newsticker--buffer-end-of-feed)) | |
4302 | (point-max)))) | |
4303 | (narrow-to-region min max))) | |
4304 | (when newsticker--auto-narrow-to-item | |
4305 | (let* ((min (or (save-excursion (newsticker--buffer-beginning-of-item)) | |
4306 | (point-min))) | |
4307 | (max (or (save-excursion (newsticker--buffer-end-of-item)) | |
4308 | (point-max)))) | |
4309 | (narrow-to-region min max))) | |
4310 | (sit-for 0) | |
4311 | ;; do not count lines and stuff because that does not work when images | |
4312 | ;; are displayed. Do it the simple way: | |
4313 | (save-excursion | |
4314 | (newsticker--buffer-end-of-item) | |
4315 | (unless (pos-visible-in-window-p) | |
4316 | (recenter -1))) | |
4317 | (unless (pos-visible-in-window-p) | |
4318 | (recenter 0))) | |
4319 | ||
4320 | (defun newsticker--buffer-get-feed-title-at-point () | |
4321 | "Return feed symbol of headline at point." | |
4322 | (format "%s" (or (get-text-property (point) 'feed) " "))) | |
4323 | ||
4324 | (defun newsticker--buffer-get-item-title-at-point () | |
4325 | "Return feed symbol of headline at point." | |
4326 | (format "%s" (or (get-text-property (point) 'nt-title) " "))) | |
4327 | ||
4328 | (defun newsticker--buffer-goto (types &optional age backwards) | |
4329 | "Search next occurrence of TYPES in current buffer. | |
4330 | TYPES is a list of symbols. If TYPES is found point is moved, if | |
4331 | not point is left unchanged. If optional parameter AGE is not | |
4332 | nil, the type AND the age must match. If BACKWARDS is t, search | |
4333 | backwards." | |
4334 | (let ((pos (save-excursion | |
4335 | (save-restriction | |
4336 | (widen) | |
4337 | (catch 'found | |
4338 | (let ((tpos (point))) | |
4339 | (while (setq tpos | |
4340 | (if backwards | |
4341 | (if (eq tpos (point-min)) | |
4342 | nil | |
4343 | (or (previous-single-property-change | |
4344 | tpos 'nt-type) | |
4345 | (point-min))) | |
4346 | (next-single-property-change | |
4347 | tpos 'nt-type))) | |
4348 | (and (memq (get-text-property tpos 'nt-type) types) | |
4349 | (or (not age) | |
4350 | (eq (get-text-property tpos 'nt-age) age)) | |
4351 | (throw 'found tpos))))))))) | |
4352 | (when pos | |
4353 | (goto-char pos)) | |
4354 | pos)) | |
4355 | ||
4356 | (defun newsticker--buffer-hideshow (mark-age onoff ) | |
4357 | "Hide or show items of type MARK-AGE. | |
4358 | If ONOFF is nil the item is hidden, otherwise it is shown." | |
4359 | (if onoff | |
4360 | (remove-from-invisibility-spec mark-age ) | |
4361 | (add-to-invisibility-spec mark-age))) | |
4362 | ||
4363 | (defun newsticker--buffer-beginning-of-item () | |
4364 | "Move point to the beginning of the item at point. | |
4365 | Return new position." | |
4366 | (if (bobp) | |
4367 | (point) | |
4368 | (let ((type (get-text-property (point) 'nt-type)) | |
4369 | (typebefore (get-text-property (1- (point)) 'nt-type))) | |
4370 | (if (and (memq type '(item feed)) | |
4371 | (not (eq type typebefore))) | |
4372 | (point) | |
4373 | (newsticker--buffer-goto '(item feed) nil t) | |
4374 | (point))))) | |
4375 | ||
4376 | (defun newsticker--buffer-beginning-of-feed () | |
4377 | "Move point to the beginning of the feed at point. | |
4378 | Return new position." | |
4379 | (if (bobp) | |
4380 | (point) | |
4381 | (let ((type (get-text-property (point) 'nt-type)) | |
4382 | (typebefore (get-text-property (1- (point)) 'nt-type))) | |
4383 | (if (and (memq type '(feed)) | |
4384 | (not (eq type typebefore))) | |
4385 | (point) | |
4386 | (newsticker--buffer-goto '(feed) nil t) | |
4387 | (point))))) | |
4388 | ||
4389 | (defun newsticker--buffer-end-of-item () | |
4390 | "Move point to the end of the item at point. | |
4391 | Take care: end of item is at the end of its last line!" | |
4392 | (when (newsticker--buffer-goto '(item feed nil)) | |
4393 | (point))) | |
4394 | ||
4395 | (defun newsticker--buffer-end-of-feed () | |
4396 | "Move point to the end of the last item of the feed at point. | |
4397 | Take care: end of item is at the end of its last line!" | |
4398 | (when (newsticker--buffer-goto '(feed nil)) | |
4399 | (backward-char 1) | |
4400 | (point))) | |
4401 | ||
4402 | ;; ====================================================================== | |
4403 | ;;; manipulation of ticker text | |
4404 | ;; ====================================================================== | |
4405 | (defun newsticker--ticker-text-setup () | |
4406 | "Build the ticker text which is scrolled or flashed in the echo area." | |
4407 | ;; reset scrollable text | |
4408 | (setq newsticker--scrollable-text "") | |
4409 | (setq newsticker--item-list nil) | |
4410 | (setq newsticker--item-position 0) | |
4411 | ;; build scrollable text from cache data | |
4412 | (let ((have-something nil)) | |
4413 | (mapc | |
4414 | (lambda (feed) | |
4415 | (let ((feed-name (symbol-name (car feed)))) | |
4416 | (let ((num-new (newsticker--stat-num-items (car feed) 'new)) | |
4417 | (num-old (newsticker--stat-num-items (car feed) 'old)) | |
4418 | (num-imm (newsticker--stat-num-items (car feed) 'immortal)) | |
4419 | (num-obs (newsticker--stat-num-items (car feed) 'obsolete))) | |
4420 | (when (or (> num-new 0) | |
4421 | (and (> num-old 0) | |
4422 | (not newsticker-hide-old-items-in-echo-area)) | |
4423 | (and (> num-imm 0) | |
4424 | (not newsticker-hide-immortal-items-in-echo-area)) | |
4425 | (and (> num-obs 0) | |
4426 | (not newsticker-hide-obsolete-items-in-echo-area))) | |
4427 | (setq have-something t) | |
4428 | (mapc | |
4429 | (lambda (item) | |
4430 | (let ((title (replace-regexp-in-string | |
4431 | "[\r\n]+" " " | |
4432 | (newsticker--title item))) | |
4433 | (age (newsticker--age item))) | |
4434 | (unless (string= title newsticker--error-headline) | |
4435 | (when | |
4436 | (or (eq age 'new) | |
4437 | (and (eq age 'old) | |
4438 | (not newsticker-hide-old-items-in-echo-area)) | |
4439 | (and (eq age 'obsolete) | |
4440 | (not | |
4441 | newsticker-hide-obsolete-items-in-echo-area)) | |
4442 | (and (eq age 'immortal) | |
4443 | (not | |
4444 | newsticker-hide-immortal-items-in-echo-area))) | |
4445 | (setq title (newsticker--remove-whitespace title)) | |
4446 | ;; add to flash list | |
4447 | (add-to-list 'newsticker--item-list | |
4448 | (concat feed-name ": " title) t) | |
4449 | ;; and to the scrollable text | |
4450 | (setq newsticker--scrollable-text | |
4451 | (concat newsticker--scrollable-text | |
4452 | " " feed-name ": " title " +++")))))) | |
4453 | (cdr feed)))))) | |
4454 | newsticker--cache) | |
4455 | (when have-something | |
4456 | (setq newsticker--scrollable-text | |
4457 | (concat "+++ " | |
4458 | (format-time-string "%A, %H:%M" | |
4459 | newsticker--latest-update-time) | |
4460 | " ++++++" newsticker--scrollable-text))))) | |
4461 | ||
4462 | (defun newsticker--ticker-text-remove (feed title) | |
4463 | "Remove the item of FEED with TITLE from the ticker text." | |
4464 | ;; reset scrollable text | |
4465 | (setq newsticker--item-position 0) | |
4466 | (let ((feed-name (symbol-name feed)) | |
4467 | (t-title (replace-regexp-in-string "[\r\n]+" " " title))) | |
4468 | ;; remove from flash list | |
4469 | (setq newsticker--item-list (remove (concat feed-name ": " t-title) | |
4470 | newsticker--item-list)) | |
4471 | ;; and from the scrollable text | |
4472 | (setq newsticker--scrollable-text | |
4473 | (replace-regexp-in-string | |
4474 | (regexp-quote (concat " " feed-name ": " t-title " +++")) | |
4475 | "" | |
4476 | newsticker--scrollable-text)) | |
4477 | (if (string-match (concat "^\\+\\+\\+ [A-Z][a-z]+, " | |
4478 | "[012]?[0-9]:[0-9][0-9] \\+\\+\\+\\+\\+\\+$") | |
4479 | newsticker--scrollable-text) | |
4480 | (setq newsticker--scrollable-text "")))) | |
4481 | ||
4482 | ;; ====================================================================== | |
4483 | ;;; manipulation of cached data | |
4484 | ;; ====================================================================== | |
4485 | (defun newsticker--cache-set-preformatted-contents (item contents) | |
4486 | "Set preformatted contents of ITEM to CONTENTS." | |
4487 | (if (nthcdr 6 item) | |
4488 | (setcar (nthcdr 6 item) contents) | |
4489 | (setcdr (nthcdr 5 item) (list contents)))) | |
4490 | ||
4491 | (defun newsticker--cache-set-preformatted-title (item title) | |
4492 | "Set preformatted title of ITEM to TITLE." | |
4493 | (if (nthcdr 7 item) | |
4494 | (setcar (nthcdr 7 item) title) | |
4495 | (setcdr (nthcdr 6 item) title))) | |
4496 | ||
4497 | (defun newsticker--cache-replace-age (data feed old-age new-age) | |
4498 | "Mark all items in DATA in FEED which carry age OLD-AGE with NEW-AGE. | |
4499 | If FEED is 'any it applies to all feeds. If OLD-AGE is 'any, | |
4500 | all marks are replaced by NEW-AGE. Removes all pre-formatted contents." | |
4501 | (mapc (lambda (a-feed) | |
4502 | (when (or (eq feed 'any) | |
4503 | (eq (car a-feed) feed)) | |
4504 | (let ((items (cdr a-feed))) | |
4505 | (mapc (lambda (item) | |
4506 | (when (or (eq old-age 'any) | |
4507 | (eq (newsticker--age item) old-age)) | |
4508 | (setcar (nthcdr 4 item) new-age) | |
4509 | (newsticker--do-forget-preformatted item))) | |
4510 | items)))) | |
4511 | data) | |
4512 | data) | |
4513 | ||
4514 | (defun newsticker--cache-mark-expired (data feed old-age new-age time) | |
4515 | "Mark all expired entries. | |
4516 | This function sets the age entries in DATA in the feed FEED. If | |
4517 | an item's age is OLD-AGE it is set to NEW-AGE if the item is | |
4518 | older than TIME." | |
4519 | (mapc | |
4520 | (lambda (a-feed) | |
4521 | (when (or (eq feed 'any) | |
4522 | (eq (car a-feed) feed)) | |
4523 | (let ((items (cdr a-feed))) | |
4524 | (mapc | |
4525 | (lambda (item) | |
4526 | (when (eq (newsticker--age item) old-age) | |
4527 | (let ((exp-time (time-add (newsticker--time item) | |
4528 | (seconds-to-time time)))) | |
4529 | (when (time-less-p exp-time (current-time)) | |
4530 | (newsticker--debug-msg | |
4531 | "Item `%s' from %s has expired on %s" | |
4532 | (newsticker--title item) | |
e77274b7 | 4533 | (format-time-string "%Y-%02m-%d, %H:%M" |
5629e04f RS |
4534 | (newsticker--time item)) |
4535 | (format-time-string "%Y-%02m-%d, %H:%M" exp-time)) | |
4536 | (setcar (nthcdr 4 item) new-age))))) | |
4537 | items)))) | |
4538 | data) | |
4539 | data) | |
4540 | ||
4541 | (defun newsticker--cache-contains (data feed title desc link age | |
4542 | &optional guid) | |
4543 | "Check DATA whether FEED contains an item with the given properties. | |
4544 | This function returns the contained item or nil if it is not | |
4545 | contained. | |
4546 | The properties which are checked are TITLE, DESC, LINK, AGE, and | |
4547 | GUID. In general all properties must match in order to return a | |
4548 | certain item, except for the following cases. | |
4549 | ||
4550 | If AGE equals 'feed the TITLE, DESCription and LINK do not | |
4551 | matter. If DESC is nil it is ignored as well. If | |
4552 | `newsticker-desc-comp-max' is non-nil, only the first | |
4553 | `newsticker-desc-comp-max' characters of DESC are taken into | |
4554 | account. | |
4555 | ||
4556 | If GUID is non-nil it is sufficient to match this value, and the | |
4557 | other properties are ignored." | |
4558 | (condition-case nil | |
4559 | (catch 'found | |
4560 | (when (and desc newsticker-desc-comp-max | |
4561 | (> (length desc) newsticker-desc-comp-max)) | |
4562 | (setq desc (substring desc 0 newsticker-desc-comp-max))) | |
4563 | (mapc | |
4564 | (lambda (this-feed) | |
4565 | (when (eq (car this-feed) feed) | |
4566 | (mapc (lambda (anitem) | |
4567 | (when (or | |
4568 | ;; global unique id can match | |
4569 | (and guid | |
4570 | (string= guid (newsticker--guid anitem))) | |
4571 | ;; or title, desc, etc. | |
4572 | (and | |
4573 | ;;(or (not (eq age 'feed)) | |
4574 | ;; (eq (newsticker--age anitem) 'feed)) | |
4575 | (string= (newsticker--title anitem) | |
4576 | title) | |
4577 | (or (not link) | |
4578 | (string= (newsticker--link anitem) | |
4579 | link)) | |
4580 | (or (not desc) | |
4581 | (if (and desc newsticker-desc-comp-max | |
4582 | (> (length (newsticker--desc anitem)) | |
4583 | newsticker-desc-comp-max)) | |
4584 | (string= (substring | |
4585 | (newsticker--desc anitem) | |
4586 | 0 newsticker-desc-comp-max) | |
4587 | desc) | |
4588 | (string= (newsticker--desc anitem) | |
4589 | desc))))) | |
4590 | (throw 'found anitem))) | |
4591 | (cdr this-feed)))) | |
4592 | data) | |
4593 | nil) | |
4594 | (error nil))) | |
4595 | ||
4596 | (defun newsticker--cache-add (data feed-name-symbol title desc link time age | |
4597 | position extra-elements | |
4598 | &optional updated-age updated-time | |
4599 | preformatted-contents | |
4600 | preformatted-title) | |
4601 | "Add another item to cache data. | |
4602 | Add to DATA in the FEED-NAME-SYMBOL an item with TITLE, DESC, | |
4603 | LINK, TIME, AGE, POSITION, and EXTRA-ELEMENTS. If this item is | |
4604 | contained already, its mark is set to UPDATED-AGE, its time is | |
4605 | set to UPDATED-TIME, and its pre-formatted contents is set to | |
4606 | PREFORMATTED-CONTENTS and PREFORMATTED-TITLE. Returns the age | |
4607 | which the item got." | |
4608 | (let ((item (newsticker--cache-contains data feed-name-symbol title | |
4609 | desc link age))) | |
4610 | (if item | |
4611 | ;; does exist already -- change age, update time and position | |
4612 | (progn | |
4613 | (if (nthcdr 5 item) | |
4614 | (setcar (nthcdr 5 item) position) | |
4615 | (setcdr (nthcdr 4 item) (list position))) | |
4616 | (setcar (nthcdr 4 item) updated-age) | |
4617 | (if updated-time | |
4618 | (setcar (nthcdr 3 item) updated-time)) | |
4619 | ;; replace cached pre-formatted contents | |
4620 | (newsticker--cache-set-preformatted-contents | |
4621 | item preformatted-contents) | |
4622 | (newsticker--cache-set-preformatted-title | |
4623 | item preformatted-title)) | |
4624 | ;; did not exist or age equals 'feed-name-symbol | |
4625 | (catch 'found | |
4626 | (mapc (lambda (this-feed) | |
4627 | (when (eq (car this-feed) feed-name-symbol) | |
4628 | (setcdr this-feed (nconc (cdr this-feed) | |
4629 | (list (list title desc link | |
4630 | time age position | |
4631 | preformatted-contents | |
4632 | preformatted-title | |
4633 | extra-elements)))) | |
4634 | (throw 'found this-feed))) | |
4635 | data) | |
4636 | ;; the feed is not contained | |
4637 | (add-to-list 'data (list feed-name-symbol | |
4638 | (list title desc link time age position | |
4639 | preformatted-contents | |
4640 | preformatted-title | |
4641 | extra-elements)) | |
4642 | t)))) | |
4643 | data) | |
4644 | ||
4645 | (defun newsticker--cache-remove (data feed-symbol age) | |
4646 | "Remove all entries from DATA in the feed FEED-SYMBOL with AGE. | |
4647 | FEED-SYMBOL may be 'any. Entries from old feeds, which are no longer in | |
4648 | `newsticker-url-list' or `newsticker-url-list-defaults', are removed as | |
4649 | well." | |
4650 | (let* ((pos data) | |
4651 | (feed (car pos)) | |
4652 | (last-pos nil)) | |
4653 | (while feed | |
4654 | (if (or (assoc (symbol-name (car feed)) newsticker-url-list) | |
4655 | (assoc (symbol-name (car feed)) newsticker-url-list-defaults)) | |
4656 | ;; feed is still valid=active | |
4657 | ;; (message "Keeping feed %s" (car feed)) | |
4658 | (if (or (eq feed-symbol 'any) | |
4659 | (eq feed-symbol (car feed))) | |
4660 | (let* ((item-pos (cdr feed)) | |
4661 | (item (car item-pos)) | |
4662 | (prev-pos nil)) | |
4663 | (while item | |
4664 | ;;(message "%s" (car item)) | |
4665 | (if (eq age (newsticker--age item)) | |
4666 | ;; remove this item | |
4667 | (progn | |
4668 | ;;(message "Removing item %s" (car item)) | |
4669 | (if prev-pos | |
4670 | (setcdr prev-pos (cdr item-pos)) | |
4671 | (setcdr feed (cdr item-pos)))) | |
4672 | ;;(message "Keeping item %s" (car item)) | |
4673 | (setq prev-pos item-pos)) | |
4674 | (setq item-pos (cdr item-pos)) | |
4675 | (setq item (car item-pos))))) | |
4676 | ;; feed is not active anymore | |
4677 | ;; (message "Removing feed %s" (car feed)) | |
4678 | (if last-pos | |
4679 | (setcdr last-pos (cdr pos)) | |
4680 | (setq data (cdr pos)))) | |
4681 | (setq last-pos pos) | |
4682 | (setq pos (cdr pos)) | |
4683 | (setq feed (car pos))))) | |
4684 | ||
4685 | ;; ====================================================================== | |
4686 | ;;; Sorting | |
4687 | ;; ====================================================================== | |
4688 | (defun newsticker--cache-item-compare-by-time (item1 item2) | |
4689 | "Compare two news items ITEM1 and ITEM2 by comparing their time values." | |
4690 | (catch 'result | |
4691 | (let ((age1 (newsticker--age item1)) | |
4692 | (age2 (newsticker--age item2))) | |
4693 | (if (not (eq age1 age2)) | |
4694 | (cond ((eq age1 'obsolete) | |
4695 | (throw 'result nil)) | |
4696 | ((eq age2 'obsolete) | |
4697 | (throw 'result t))))) | |
4698 | (let* ((time1 (newsticker--time item1)) | |
4699 | (time2 (newsticker--time item2))) | |
4700 | (cond ((< (nth 0 time1) (nth 0 time2)) | |
4701 | nil) | |
4702 | ((> (nth 0 time1) (nth 0 time2)) | |
4703 | t) | |
4704 | ((< (nth 1 time1) (nth 1 time2)) | |
4705 | nil) | |
4706 | ((> (nth 1 time1) (nth 1 time2)) | |
4707 | t) | |
4708 | ((< (or (nth 2 time1) 0) (or (nth 2 time2) 0)) | |
4709 | nil) | |
4710 | ((> (or (nth 2 time1) 0) (or (nth 2 time2) 0)) | |
4711 | t) | |
4712 | (t | |
4713 | nil))))) | |
4714 | ||
4715 | (defun newsticker--cache-item-compare-by-title (item1 item2) | |
4716 | "Compare ITEM1 and ITEM2 by comparing their titles." | |
4717 | (catch 'result | |
4718 | (let ((age1 (newsticker--age item1)) | |
4719 | (age2 (newsticker--age item2))) | |
4720 | (if (not (eq age1 age2)) | |
4721 | (cond ((eq age1 'obsolete) | |
4722 | (throw 'result nil)) | |
4723 | ((eq age2 'obsolete) | |
4724 | (throw 'result t))))) | |
4725 | (string< (newsticker--title item1) (newsticker--title item2)))) | |
4726 | ||
4727 | (defun newsticker--cache-item-compare-by-position (item1 item2) | |
4728 | "Compare ITEM1 and ITEM2 by comparing their original positions." | |
4729 | (catch 'result | |
4730 | (let ((age1 (newsticker--age item1)) | |
4731 | (age2 (newsticker--age item2))) | |
4732 | (if (not (eq age1 age2)) | |
4733 | (cond ((eq age1 'obsolete) | |
4734 | (throw 'result nil)) | |
4735 | ((eq age2 'obsolete) | |
4736 | (throw 'result t))))) | |
4737 | (< (or (newsticker--pos item1) 0) (or (newsticker--pos item2) 0)))) | |
4738 | ||
4739 | (defun newsticker--cache-sort () | |
4740 | "Sort the newsticker cache data." | |
4741 | (let ((sort-fun (cond ((eq newsticker-sort-method 'sort-by-time) | |
4742 | 'newsticker--cache-item-compare-by-time) | |
4743 | ((eq newsticker-sort-method 'sort-by-title) | |
4744 | 'newsticker--cache-item-compare-by-title) | |
4745 | ((eq newsticker-sort-method 'sort-by-original-order) | |
4746 | 'newsticker--cache-item-compare-by-position)))) | |
4747 | (mapc (lambda (feed-list) | |
4748 | (setcdr feed-list (sort (cdr feed-list) | |
4749 | sort-fun))) | |
4750 | newsticker--cache))) | |
e77274b7 | 4751 | |
5629e04f RS |
4752 | (defun newsticker--cache-update (&optional save) |
4753 | "Update newsticker cache file. | |
4754 | If optional argument SAVE is not nil the cache file is saved to disk." | |
4755 | (save-excursion | |
4756 | (let ((coding-system-for-write 'utf-8) | |
4757 | (buf (find-file-noselect newsticker-cache-filename))) | |
4758 | (when buf | |
4759 | (set-buffer buf) | |
4760 | (setq buffer-undo-list t) | |
4761 | (erase-buffer) | |
4762 | (insert ";; -*- coding: utf-8 -*-\n") | |
4763 | (insert (prin1-to-string newsticker--cache)) | |
4764 | (when save | |
4765 | (save-buffer)))))) | |
4766 | ||
4767 | (defun newsticker--cache-get-feed (feed) | |
4768 | "Return the cached data for the feed FEED. | |
4769 | FEED is a symbol!" | |
4770 | (assoc feed newsticker--cache)) | |
4771 | ||
4772 | ;; ====================================================================== | |
4773 | ;;; Statistics | |
4774 | ;; ====================================================================== | |
4775 | (defun newsticker--stat-num-items (feed &optional age) | |
4776 | "Return number of items in the given FEED which have the given AGE. | |
4777 | If AGE is nil, the total number items is returned." | |
4778 | (let ((items (cdr (newsticker--cache-get-feed feed))) | |
4779 | (num 0)) | |
4780 | (while items | |
4781 | (if age | |
4782 | (if (eq (newsticker--age (car items)) age) | |
4783 | (setq num (1+ num))) | |
4784 | (if (memq (newsticker--age (car items)) '(new old immortal obsolete)) | |
4785 | (setq num (1+ num)))) | |
4786 | (setq items (cdr items))) | |
4787 | num)) | |
4788 | ||
4789 | ;; ====================================================================== | |
4790 | ;;; OPML | |
4791 | ;; ====================================================================== | |
4792 | (defun newsticker-opml-export () | |
4793 | "OPML subscription export. | |
4794 | Export subscriptions to a buffer in OPML Format." | |
4795 | (interactive) | |
4796 | (with-current-buffer (get-buffer-create "*OPML Export*") | |
4797 | (set-buffer-file-coding-system 'utf-8) | |
4798 | (insert (concat | |
4799 | "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" | |
4800 | "<!-- OPML generated by Emacs newsticker.el -->\n" | |
4801 | "<opml version=\"1.0\">\n" | |
4802 | " <head>\n" | |
4803 | " <title>mySubscriptions</title>\n" | |
4804 | " <dateCreated>" (format-time-string "%a, %d %b %Y %T %z") | |
4805 | "</dateCreated>\n" | |
4806 | " <ownerEmail>" user-mail-address "</ownerEmail>\n" | |
4807 | " <ownerName>" (user-full-name) "</ownerName>\n" | |
4808 | " </head>\n" | |
4809 | " <body>\n")) | |
4810 | (mapc (lambda (sub) | |
4811 | (insert " <outline text=\"") | |
4812 | (insert (newsticker--title sub)) | |
4813 | (insert "\" xmlUrl=\"") | |
4814 | (insert (cadr sub)) | |
4815 | (insert "\"/>\n")) | |
4816 | (append newsticker-url-list newsticker-url-list-defaults)) | |
4817 | (insert " </body>\n</opml>\n")) | |
4818 | (pop-to-buffer "*OPML Export*") | |
4819 | (when (fboundp 'sgml-mode) | |
4820 | (sgml-mode))) | |
4821 | ||
4822 | (defun newsticker-opml-import (filename) | |
4823 | "Import OPML data from FILENAME." | |
4824 | (interactive "fOPML file: ") | |
4825 | (set-buffer (find-file-noselect filename)) | |
4826 | (goto-char (point-min)) | |
4827 | (let* ((node-list (xml-parse-region (point-min) (point-max))) | |
4828 | (body (car (xml-get-children (car node-list) 'body))) | |
4829 | (outlines (xml-get-children body 'outline))) | |
4830 | (mapc (lambda (outline) | |
4831 | (let ((name (xml-get-attribute outline 'text)) | |
4832 | (url (xml-get-attribute outline 'xmlUrl))) | |
4833 | (add-to-list 'newsticker-url-list | |
4834 | (list name url nil nil nil) t))) | |
4835 | outlines)) | |
4836 | (customize-variable 'newsticker-url-list)) | |
e77274b7 | 4837 | |
5629e04f RS |
4838 | ;; ====================================================================== |
4839 | ;;; Auto marking | |
4840 | ;; ====================================================================== | |
4841 | (defun newsticker--run-auto-mark-filter (feed item) | |
4842 | "Automatically mark an item as old or immortal. | |
4843 | This function checks the variable `newsticker-auto-mark-filter' | |
4844 | for an entry that matches FEED and ITEM." | |
4845 | (let ((case-fold-search t)) | |
4846 | (mapc (lambda (filter) | |
4847 | (let ((filter-feed (car filter)) | |
4848 | (old-list (nth 1 filter)) | |
4849 | (imm-list (nth 2 filter))) | |
4850 | (when (string-match filter-feed feed) | |
4851 | (newsticker--do-run-auto-mark-filter item 'old old-list) | |
4852 | (newsticker--do-run-auto-mark-filter item 'immortal imm-list)))) | |
4853 | newsticker-auto-mark-filter))) | |
4854 | ||
4855 | (defun newsticker--do-run-auto-mark-filter (item age list) | |
4856 | "Actually compare ITEM AGE LIST against `newsticker-auto-mark-filter'." | |
4857 | (mapc (lambda (pattern) | |
4858 | (when (string-match pattern (newsticker--title item)) | |
4859 | (setcar (nthcdr 4 item) age))) | |
4860 | list)) | |
4861 | ||
4862 | ||
4863 | ;; ====================================================================== | |
4864 | ;;; hook samples | |
4865 | ;; ====================================================================== | |
4866 | (defun newsticker-new-item-functions-sample (feed item) | |
4867 | "Demonstrate the use of the `newsticker-new-item-functions' hook. | |
4868 | This function just prints out the values of the FEED and title of the ITEM." | |
4869 | (message (concat "newsticker-new-item-functions-sample: feed=`%s', " | |
4870 | "title=`%s'") | |
4871 | feed (newsticker--title item))) | |
4872 | ||
4873 | (defun newsticker-download-images (feed item) | |
4874 | "Download the first image. | |
4875 | If FEED equals \"imagefeed\" download the first image URL found | |
4876 | in the description=contents of ITEM to the directory | |
4877 | \"~/tmp/newsticker/FEED/TITLE\" where TITLE is the title of the item." | |
4878 | (when (string= feed "imagefeed") | |
4879 | (let ((title (newsticker--title item)) | |
4880 | (desc (newsticker--desc item))) | |
4881 | (when (string-match "<img src=\"\\(http://[^ \"]+\\)\"" desc) | |
4882 | (let ((url (substring desc (match-beginning 1) (match-end 1))) | |
4883 | (temp-dir (concat "~/tmp/newsticker/" feed "/" title)) | |
4884 | (org-dir default-directory)) | |
4885 | (unless (file-directory-p temp-dir) | |
4886 | (make-directory temp-dir t)) | |
4887 | (cd temp-dir) | |
4888 | (message "Getting image %s" url) | |
4889 | (apply 'start-process "wget-image" | |
4890 | " *newsticker-wget-download-images*" | |
4891 | newsticker-wget-name | |
4892 | (list url)) | |
4893 | (cd org-dir)))))) | |
4894 | ||
4895 | (defun newsticker-download-enclosures (feed item) | |
4896 | "In all FEEDs download the enclosed object of the news ITEM. | |
4897 | The object is saved to the directory \"~/tmp/newsticker/FEED/TITLE\", which | |
4898 | is created if it does not exist. TITLE is the title of the news | |
4899 | item. Argument FEED is ignored. | |
4900 | This function is suited for adding it to `newsticker-new-item-functions'." | |
4901 | (let ((title (newsticker--title item)) | |
4902 | (enclosure (newsticker--enclosure item))) | |
4903 | (when enclosure | |
4904 | (let ((url (cdr (assoc 'url enclosure))) | |
4905 | (temp-dir (concat "~/tmp/newsticker/" feed "/" title)) | |
4906 | (org-dir default-directory)) | |
4907 | (unless (file-directory-p temp-dir) | |
4908 | (make-directory temp-dir t)) | |
4909 | (cd temp-dir) | |
4910 | (message "Getting enclosure %s" url) | |
4911 | (apply 'start-process "wget-enclosure" | |
4912 | " *newsticker-wget-download-enclosures*" | |
4913 | newsticker-wget-name | |
4914 | (list url)) | |
4915 | (cd org-dir))))) | |
4916 | ||
4917 | ||
4918 | (provide 'newsticker) | |
4919 | ||
115f219d | 4920 | ;; arch-tag: ab761dfa-67bc-4207-bc64-4307271dc381 |
5629e04f | 4921 | ;;; newsticker.el ends here |