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