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