1 ;;; newst-plainview.el --- Single buffer frontend for newsticker.
3 ;; Copyright (C) 2003-2014 Free Software Foundation, Inc.
5 ;; Author: Ulf Jasper <ulf.jasper@web.de>
6 ;; Filename: newst-plainview.el
7 ;; URL: http://www.nongnu.org/newsticker
8 ;; Time-stamp: "Mon 11-Feb-2013 20:27:11 gm on skiddaw"
11 ;; ======================================================================
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; ======================================================================
33 ;; ======================================================================
36 (require 'newst-ticker
)
37 (require 'newst-reader
)
43 (defvar w3m-minor-mode-map
)
45 ;; ======================================================================
47 ;; ======================================================================
48 (defgroup newsticker-plainview nil
49 "Settings for the simple plain view reader.
50 See also `newsticker-plainview-hooks'."
51 :group
'newsticker-reader
)
54 (defun newsticker--set-customvar-buffer (symbol value
)
55 "Set newsticker-variable SYMBOL value to VALUE.
56 Calls all actions which are necessary in order to make the new
58 (if (or (not (boundp symbol
))
59 (equal (symbol-value symbol
) value
))
61 ;; something must have changed
63 (newsticker--buffer-set-uptodate nil
)))
65 (defun newsticker--set-customvar-sorting (symbol value
)
66 "Set newsticker-variable SYMBOL value to VALUE.
67 Calls all actions which are necessary in order to make the new
69 (if (or (not (boundp symbol
))
70 (equal (symbol-value symbol
) value
))
72 ;; something must have changed
74 (message "Applying new sort method...")
75 (when (fboundp 'newsticker--cache-sort
) (newsticker--cache-sort))
76 (when (fboundp 'newsticker--buffer-set-uptodate
)
77 (newsticker--buffer-set-uptodate nil
))
78 (message "Applying new sort method...done")))
80 (defcustom newsticker-sort-method
81 'sort-by-original-order
82 "Sort method for news items.
83 The following sort methods are available:
84 * `sort-by-original-order' keeps the order in which the items
85 appear in the headline file (please note that for immortal items,
86 which have been removed from the news feed, there is no original
88 * `sort-by-time' looks at the time at which an item has been seen
89 the first time. The most recent item is put at top,
90 * `sort-by-title' will put the items in an alphabetical order."
92 (const :tag
"Keep original order" sort-by-original-order
)
93 (const :tag
"Sort by time" sort-by-time
)
94 (const :tag
"Sort by title" sort-by-title
))
95 :set
'newsticker--set-customvar-sorting
96 :group
'newsticker-plainview
)
98 (defcustom newsticker-heading-format
101 "Format string for feed headings.
102 The following printf-like specifiers can be used:
103 %d The date the feed was retrieved. See `newsticker-date-format'.
104 %l The logo (image) of the feed. Most news feeds provide a small
105 image as logo. Newsticker can display them, if Emacs can --
106 see `image-types' for a list of supported image types.
107 %L The logo (image) of the feed. If the logo is not available
108 the title of the feed is used.
109 %s The statistical data of the feed. See `newsticker-statistics-format'.
110 %t The title of the feed, i.e. its name."
112 :set
'newsticker--set-customvar-formatting
113 :group
'newsticker-plainview
)
115 (defcustom newsticker-item-format
117 "Format string for news item headlines.
118 The following printf-like specifiers can be used:
119 %d The date the item was (first) retrieved. See `newsticker-date-format'.
120 %l The logo (image) of the feed. Most news feeds provide a small
121 image as logo. Newsticker can display them, if Emacs can --
122 see `image-types' for a list of supported image types.
123 %L The logo (image) of the feed. If the logo is not available
124 the title of the feed is used.
125 %t The title of the item."
127 :set
'newsticker--set-customvar-formatting
128 :group
'newsticker-plainview
)
130 (defcustom newsticker-desc-format
132 "Format string for news descriptions (contents).
133 The following printf-like specifiers can be used:
134 %c The contents (description) of the item.
135 %d The date the item was (first) retrieved. See
136 `newsticker-date-format'."
138 :set
'newsticker--set-customvar-formatting
139 :group
'newsticker-plainview
)
141 (defcustom newsticker-statistics-format
142 "[%n + %i + %o + %O = %a]"
143 "Format for the statistics part in feed lines.
144 The following printf-like specifiers can be used:
145 %a The number of all items in the feed.
146 %i The number of immortal items in the feed.
147 %n The number of new items in the feed.
148 %o The number of old items in the feed.
149 %O The number of obsolete items in the feed."
151 :set
'newsticker--set-customvar-formatting
152 :group
'newsticker-plainview
)
155 ;; ======================================================================
158 (defface newsticker-new-item-face
'((t :weight bold
))
159 "Face for new news items."
160 :group
'newsticker-faces
)
162 (defface newsticker-old-item-face
163 '((default :weight bold
)
164 (((class color
) (background dark
)) :foreground
"orange3")
165 (((class color
) (background light
)) :foreground
"red4"))
166 "Face for old news items."
167 :group
'newsticker-faces
)
169 (defface newsticker-immortal-item-face
170 '((default :weight bold
:slant italic
)
171 (((class color
) (background dark
)) :foreground
"orange")
172 (((class color
) (background light
)) :foreground
"blue"))
173 "Face for immortal news items."
174 :group
'newsticker-faces
)
176 (defface newsticker-obsolete-item-face
177 '((t :weight bold
:strike-through t
))
178 "Face for old news items."
179 :group
'newsticker-faces
)
181 (defface newsticker-date-face
'((t :slant italic
:height
0.8))
182 "Face for newsticker dates."
183 :group
'newsticker-faces
)
185 (defface newsticker-statistics-face
'((t :slant italic
:height
0.8))
186 "Face for newsticker dates."
187 :group
'newsticker-faces
)
189 (defface newsticker-default-face
'((t))
190 "Face for the description of news items."
191 :group
'newsticker-faces
)
193 (defcustom newsticker-hide-old-items-in-newsticker-buffer
195 "Decides whether to automatically hide old items in the *newsticker* buffer.
196 If set to t old items will be completely folded and only new
197 items will show up in the *newsticker* buffer. Otherwise old as
198 well as new items will be visible."
200 :set
'newsticker--set-customvar-buffer
201 :group
'newsticker-plainview
)
203 (defcustom newsticker-show-descriptions-of-new-items
205 "Whether to automatically show descriptions of new items in *newsticker*.
206 If set to t old items will be folded and new items will be
207 unfolded. Otherwise old as well as new items will be folded."
209 :set
'newsticker--set-customvar-buffer
210 :group
'newsticker-plainview
)
212 (defcustom newsticker-show-all-news-elements
214 "Show all news elements."
216 ;;:set 'newsticker--set-customvar
217 :group
'newsticker-plainview
)
219 ;; ======================================================================
221 (defgroup newsticker-plainview-hooks nil
222 "Settings for newsticker hooks which apply to plainview only."
223 :group
'newsticker-hooks
)
225 (defcustom newsticker-select-item-hook
226 'newsticker--buffer-make-item-completely-visible
227 "List of functions run after a headline has been selected.
228 Each function is called after one of `newsticker-next-item',
229 `newsticker-next-new-item', `newsticker-previous-item',
230 `newsticker-previous-new-item' has been called.
232 The default value 'newsticker--buffer-make-item-completely-visible
233 assures that the current item is always completely visible."
235 :options
'(newsticker--buffer-make-item-completely-visible)
236 :group
'newsticker-plainview-hooks
)
238 (defcustom newsticker-select-feed-hook
239 'newsticker--buffer-make-item-completely-visible
240 "List of functions run after a feed has been selected.
241 Each function is called after one of `newsticker-next-feed', and
242 `newsticker-previous-feed' has been called.
244 The default value 'newsticker--buffer-make-item-completely-visible
245 assures that the current feed is completely visible."
247 :options
'(newsticker--buffer-make-item-completely-visible)
248 :group
'newsticker-plainview-hooks
)
250 (defcustom newsticker-buffer-change-hook
251 'newsticker-w3m-show-inline-images
252 "List of functions run after the newsticker buffer has been updated.
253 Each function is called after `newsticker-buffer-update' has been called.
255 The default value '`newsticker-w3m-show-inline-images' loads inline
258 :group
'newsticker-plainview-hooks
)
260 (defcustom newsticker-narrow-hook
261 'newsticker-w3m-show-inline-images
262 "List of functions run after narrowing in newsticker buffer has changed.
263 Each function is called after
264 `newsticker-toggle-auto-narrow-to-feed' or
265 `newsticker-toggle-auto-narrow-to-item' has been called.
267 The default value '`newsticker-w3m-show-inline-images' loads inline
270 :group
'newsticker-plainview-hooks
)
272 ;; ======================================================================
274 ;; ======================================================================
276 (defvar newsticker--plainview-tool-bar-map
277 (if (featurep 'xemacs
)
279 (if (boundp 'tool-bar-map
)
280 (let ((tool-bar-map (make-sparse-keymap)))
281 (tool-bar-add-item "newsticker/prev-feed"
282 'newsticker-previous-feed
283 'newsticker-previous-feed
284 :help
"Go to previous feed"
285 :enable
'(newsticker-previous-feed-available-p))
286 (tool-bar-add-item "newsticker/prev-item"
287 'newsticker-previous-item
288 'newsticker-previous-item
289 :help
"Go to previous item"
290 :enable
'(newsticker-previous-item-available-p))
291 (tool-bar-add-item "newsticker/next-item"
292 'newsticker-next-item
293 'newsticker-next-item
294 :help
"Go to next item"
295 :enable
'(newsticker-next-item-available-p))
296 (tool-bar-add-item "newsticker/next-feed"
297 'newsticker-next-feed
298 'newsticker-next-feed
299 :help
"Go to next feed"
300 :enable
'(newsticker-next-feed-available-p))
301 (tool-bar-add-item "newsticker/narrow"
302 'newsticker-toggle-auto-narrow-to-feed
303 'newsticker-toggle-auto-narrow-to-feed
304 :help
"Toggle visibility of other feeds")
305 (tool-bar-add-item "newsticker/mark-immortal"
306 'newsticker-mark-item-at-point-as-immortal
307 'newsticker-mark-item-at-point-as-immortal
308 :help
"Mark current item as immortal"
309 :enable
'(newsticker-item-not-immortal-p))
310 (tool-bar-add-item "newsticker/mark-read"
311 'newsticker-mark-item-at-point-as-read
312 'newsticker-mark-item-at-point-as-read
313 :help
"Mark current item as read"
314 :enable
'(newsticker-item-not-old-p))
315 (tool-bar-add-item "newsticker/get-all-news"
316 'newsticker-get-all-news
317 'newsticker-get-all-news
318 :help
"Get news for all feeds")
319 (tool-bar-add-item "newsticker/update"
320 'newsticker-buffer-force-update
321 'newsticker-buffer-force-update
322 :help
"Update newsticker buffer"
323 :enable
'(not newsticker--buffer-uptodate-p
))
324 (tool-bar-add-item "newsticker/browse-url"
325 'newsticker-browse-url
326 'newsticker-browse-url
327 :help
"Browse URL for item at point")
328 ;; standard icons / actions
329 (define-key tool-bar-map
[newsticker-sep-1
]
330 (list 'menu-item
"--double-line"))
331 (tool-bar-add-item "close"
332 'newsticker-close-buffer
333 'newsticker-close-buffer
334 :help
"Close newsticker buffer")
335 (tool-bar-add-item "preferences"
336 'newsticker-customize
337 'newsticker-customize
338 :help
"Customize newsticker")
341 ;; ======================================================================
343 ;; ======================================================================
347 (defvar newsticker-menu
348 (let ((map (make-sparse-keymap "Newsticker")))
350 (define-key map
[newsticker-browse-url
]
351 '("Browse URL for item at point" . newsticker-browse-url
))
352 (define-key map
[newsticker-separator-1
]
354 (define-key map
[newsticker-buffer-update
]
355 '("Update buffer" . newsticker-buffer-update
))
356 (define-key map
[newsticker-separator-2
]
358 (define-key map
[newsticker-get-all-news
]
359 '("Get news from all feeds" . newsticker-get-all-news
))
360 (define-key map
[newsticker-get-news-at-point
]
361 '("Get news from feed at point" . newsticker-get-news-at-point
))
362 (define-key map
[newsticker-separator-3
]
364 (define-key map
[newsticker-mark-all-items-as-read
]
365 '("Mark all items as read" . newsticker-mark-all-items-as-read
))
366 (define-key map
[newsticker-mark-all-items-at-point-as-read
]
367 '("Mark all items in feed at point as read" .
368 newsticker-mark-all-items-at-point-as-read
))
369 (define-key map
[newsticker-mark-item-at-point-as-read
]
370 '("Mark item at point as read" .
371 newsticker-mark-item-at-point-as-read
))
372 (define-key map
[newsticker-mark-item-at-point-as-immortal
]
373 '("Toggle immortality for item at point" .
374 newsticker-mark-item-at-point-as-immortal
))
375 (define-key map
[newsticker-separator-4
]
377 (define-key map
[newsticker-toggle-auto-narrow-to-item
]
378 '("Narrow to single item" . newsticker-toggle-auto-narrow-to-item
))
379 (define-key map
[newsticker-toggle-auto-narrow-to-feed
]
380 '("Narrow to single news feed" . newsticker-toggle-auto-narrow-to-feed
))
381 (define-key map
[newsticker-hide-old-items
]
382 '("Hide old items" . newsticker-hide-old-items
))
383 (define-key map
[newsticker-show-old-items
]
384 '("Show old items" . newsticker-show-old-items
))
385 (define-key map
[newsticker-next-item
]
386 '("Go to next item" . newsticker-next-item
))
387 (define-key map
[newsticker-previous-item
]
388 '("Go to previous item" . newsticker-previous-item
))
391 (defvar newsticker-mode-map
392 (let ((map (make-keymap)))
393 (define-key map
"sO" 'newsticker-show-old-items
)
394 (define-key map
"hO" 'newsticker-hide-old-items
)
395 (define-key map
"sa" 'newsticker-show-all-desc
)
396 (define-key map
"ha" 'newsticker-hide-all-desc
)
397 (define-key map
"sf" 'newsticker-show-feed-desc
)
398 (define-key map
"hf" 'newsticker-hide-feed-desc
)
399 (define-key map
"so" 'newsticker-show-old-item-desc
)
400 (define-key map
"ho" 'newsticker-hide-old-item-desc
)
401 (define-key map
"sn" 'newsticker-show-new-item-desc
)
402 (define-key map
"hn" 'newsticker-hide-new-item-desc
)
403 (define-key map
"se" 'newsticker-show-entry
)
404 (define-key map
"he" 'newsticker-hide-entry
)
405 (define-key map
"sx" 'newsticker-show-extra
)
406 (define-key map
"hx" 'newsticker-hide-extra
)
408 (define-key map
[?\S-\
] 'scroll-down-command
)
409 (define-key map
" " 'scroll-up-command
)
410 (define-key map
"q" 'newsticker-close-buffer
)
411 (define-key map
"p" 'newsticker-previous-item
)
412 (define-key map
"P" 'newsticker-previous-new-item
)
413 (define-key map
"F" 'newsticker-previous-feed
)
414 (define-key map
"\t" 'newsticker-next-item
)
415 (define-key map
"n" 'newsticker-next-item
)
416 (define-key map
"N" 'newsticker-next-new-item
)
417 (define-key map
"f" 'newsticker-next-feed
)
418 (define-key map
"M" 'newsticker-mark-all-items-as-read
)
420 'newsticker-mark-all-items-at-point-as-read-and-redraw
)
422 'newsticker-mark-item-at-point-as-read
)
424 'newsticker-mark-all-items-at-point-as-read
)
425 (define-key map
"G" 'newsticker-get-all-news
)
426 (define-key map
"g" 'newsticker-get-news-at-point
)
427 (define-key map
"u" 'newsticker-buffer-update
)
428 (define-key map
"U" 'newsticker-buffer-force-update
)
429 (define-key map
"a" 'newsticker-add-url
)
432 'newsticker-mark-item-at-point-as-immortal
)
435 'newsticker-toggle-auto-narrow-to-feed
)
437 'newsticker-toggle-auto-narrow-to-item
)
439 ;; Bind menu to mouse.
440 (define-key map
[down-mouse-3
] newsticker-menu
)
441 ;; Put menu in menu-bar.
442 (define-key map
[menu-bar Newsticker
]
443 (cons "Newsticker" newsticker-menu
))
447 (define-derived-mode newsticker-mode fundamental-mode
449 "Viewing news feeds in Emacs."
450 (if (boundp 'tool-bar-map
)
451 (set (make-local-variable 'tool-bar-map
)
452 newsticker--plainview-tool-bar-map
))
453 (set (make-local-variable 'imenu-sort-function
) nil
)
454 (set (make-local-variable 'scroll-conservatively
) 999)
455 (setq imenu-create-index-function
'newsticker--imenu-create-index
)
456 (setq imenu-default-goto-function
'newsticker--imenu-goto
)
457 (setq buffer-read-only t
)
458 (auto-fill-mode -
1) ;; turn auto-fill off!
459 (font-lock-mode -
1) ;; turn off font-lock!!
460 (set (make-local-variable 'font-lock-defaults
) nil
)
461 (set (make-local-variable 'line-move-ignore-invisible
) t
)
462 (setq mode-line-format
466 'mode-line-frame-identification
468 '(newsticker--buffer-uptodate-p
472 '(:eval
(format "[%d]" (length newsticker--process-ids
)))
474 '(:eval
(newsticker--buffer-get-feed-title-at-point))
476 '(:eval
(newsticker--buffer-get-item-title-at-point))
478 (add-to-invisibility-spec 't
)
479 (unless newsticker-show-all-news-elements
480 (add-to-invisibility-spec 'extra
))
481 (newsticker--buffer-set-uptodate nil
))
483 ;; maps for the clickable portions
484 (defvar newsticker--url-keymap
485 (let ((map (make-sparse-keymap)))
486 (define-key map
[mouse-1
] 'newsticker-mouse-browse-url
)
487 (define-key map
[mouse-2
] 'newsticker-mouse-browse-url
)
488 (define-key map
"\n" 'newsticker-browse-url
)
489 (define-key map
"\C-m" 'newsticker-browse-url
)
490 (define-key map
[(control return
)] 'newsticker-handle-url
)
492 "Key map for click-able headings in the newsticker buffer.")
495 ;; ======================================================================
497 ;; ======================================================================
499 (defun newsticker-plainview ()
500 "Start newsticker plainview."
502 (newsticker-buffer-update t
)
503 (switch-to-buffer "*newsticker*"))
505 (defun newsticker-buffer-force-update ()
506 "Update the newsticker buffer, even if not necessary."
508 (newsticker-buffer-update t
))
510 (defun newsticker-buffer-update (&optional force
)
511 "Update the *newsticker* buffer.
512 Unless FORCE is t this is done only if necessary, i.e. when the
513 *newsticker* buffer is not up-to-date."
515 ;; bring cache data into proper order....
516 (newsticker--cache-sort)
519 (let ((buf (get-buffer "*newsticker*")))
521 (switch-to-buffer buf
)
522 (switch-to-buffer (get-buffer-create "*newsticker*"))
523 (newsticker--buffer-set-uptodate nil
)))
525 (not newsticker--buffer-uptodate-p
))
526 (message "Preparing newsticker buffer...")
527 (setq buffer-undo-list t
)
528 (let ((inhibit-read-only t
))
529 (set-buffer-modified-p nil
)
532 ;; Emacs 21.3.50 does not care if we turn off auto-fill in the
533 ;; definition of newsticker-mode, so we do it here (again)
536 (set-buffer-file-coding-system 'utf-8
)
538 (if newsticker-use-full-width
539 (set (make-local-variable 'fill-column
) (1- (window-width))))
540 (newsticker--buffer-insert-all-items)
542 ;; FIXME: needed for methods buffer in ecb
543 ;; (set-visited-file-name "*newsticker*")
545 (set-buffer-modified-p nil
)
546 (newsticker-hide-all-desc)
547 (if newsticker-hide-old-items-in-newsticker-buffer
548 (newsticker-hide-old-items))
549 (if newsticker-show-descriptions-of-new-items
550 (newsticker-show-new-item-desc))
553 (newsticker--buffer-set-uptodate t
)
554 (run-hooks 'newsticker-buffer-change-hook
)))
556 (defun newsticker-get-news-at-point ()
557 "Launch retrieval of news for the feed point is in.
558 This does NOT start the retrieval timers."
560 ;; launch retrieval of news
561 (let ((feed (get-text-property (point) 'feed
)))
563 (newsticker--debug-msg "Getting news for %s" (symbol-name feed
))
564 (newsticker-get-news (symbol-name feed
)))))
566 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest r
)))
567 (declare-function w3m-toggle-inline-image
"ext:w3m" (&optional force no-cache
))
569 (defun newsticker-w3m-show-inline-images ()
570 "Show inline images in visible text ranges.
571 In-line images in invisible text ranges are hidden. This function
572 calls `w3m-toggle-inline-image'. It works only if
573 `newsticker-html-renderer' is set to `w3m-region'."
575 (if (eq newsticker-html-renderer
'w3m-region
)
576 (let ((inhibit-read-only t
))
580 (goto-char (point-min))
583 (setq pos
(next-single-property-change pos
'w3m-image
))
586 (when (get-text-property pos
'w3m-image
)
587 (let ((invis (newsticker--lists-intersect-p
588 (get-text-property (1- (point))
590 buffer-invisibility-spec
)))
591 (unless (car (get-text-property (1- (point))
594 (w3m-toggle-inline-image t
)))))))))))))
596 ;; ======================================================================
598 ;; ======================================================================
599 (defun newsticker-close-buffer ()
600 "Close the newsticker buffer."
602 (newsticker--cache-update t
)
605 (defun newsticker-next-new-item (&optional do-not-wrap-at-eob
)
606 "Go to next new news item.
607 If no new item is found behind point, search is continued at
608 beginning of buffer unless optional argument DO-NOT-WRAP-AT-EOB
614 (unless (newsticker--buffer-goto '(item) 'new
)
615 ;; found nothing -- wrap
616 (unless do-not-wrap-at-eob
617 (goto-char (point-min))
618 (newsticker-next-new-item t
))
620 (unless (newsticker--lists-intersect-p
621 (get-text-property (point) 'invisible
)
622 buffer-invisibility-spec
)
623 ;; this item is invisible -- continue search
624 (setq go-ahead nil
))))
625 (run-hooks 'newsticker-select-item-hook
)
628 (defun newsticker-previous-new-item (&optional do-not-wrap-at-bob
)
629 "Go to previous new news item.
630 If no new item is found before point, search is continued at
631 beginning of buffer unless optional argument DO-NOT-WRAP-AT-BOB
637 (unless (newsticker--buffer-goto '(item) 'new t
)
638 (unless do-not-wrap-at-bob
639 (goto-char (point-max))
640 (newsticker--buffer-goto '(item) 'new t
)))
641 (unless (newsticker--lists-intersect-p
642 (get-text-property (point) 'invisible
)
643 buffer-invisibility-spec
)
644 (setq go-ahead nil
))))
645 (run-hooks 'newsticker-select-item-hook
)
648 (defun newsticker-next-item (&optional do-not-wrap-at-eob
)
649 "Go to next news item.
650 Return new buffer position.
651 If no item is found below point, search is continued at beginning
652 of buffer unless optional argument DO-NOT-WRAP-AT-EOB is
657 (search-list '(item)))
658 (if newsticker--auto-narrow-to-item
659 (setq search-list
'(item feed
)))
661 (unless (newsticker--buffer-goto search-list
)
662 ;; found nothing -- wrap
663 (unless do-not-wrap-at-eob
664 (goto-char (point-min)))
666 (unless (newsticker--lists-intersect-p
667 (get-text-property (point) 'invisible
)
668 buffer-invisibility-spec
)
669 (setq go-ahead nil
))))
670 (run-hooks 'newsticker-select-item-hook
)
671 (force-mode-line-update)
674 (defun newsticker-next-item-same-feed ()
675 "Go to next news item in the same feed.
676 Return new buffer position. If no item is found below point or if
677 auto-narrow-to-item is enabled, nil is returned."
679 (if newsticker--auto-narrow-to-item
682 (current-pos (point))
683 (end-of-feed (save-excursion (newsticker--buffer-end-of-feed))))
685 (unless (newsticker--buffer-goto '(item))
687 (unless (newsticker--lists-intersect-p
688 (get-text-property (point) 'invisible
)
689 buffer-invisibility-spec
)
690 (setq go-ahead nil
)))
691 (if (and (> (point) current-pos
)
692 (< (point) end-of-feed
))
694 (goto-char current-pos
)
697 (defun newsticker-previous-item (&optional do-not-wrap-at-bob
)
698 "Go to previous news item.
699 Return new buffer position.
700 If no item is found before point, search is continued at
701 beginning of buffer unless optional argument DO-NOT-WRAP-AT-BOB
706 (search-list '(item)))
707 (if newsticker--auto-narrow-to-item
708 (setq search-list
'(item feed
)))
710 (unless do-not-wrap-at-bob
711 (goto-char (point-max))))
713 (if (newsticker--buffer-goto search-list nil t
)
714 (unless (newsticker--lists-intersect-p
715 (get-text-property (point) 'invisible
)
716 buffer-invisibility-spec
)
718 (goto-char (point-min))
719 (setq go-ahead nil
))))
720 (run-hooks 'newsticker-select-item-hook
)
721 (force-mode-line-update)
724 (defun newsticker-next-feed ()
725 "Go to next news feed.
726 Return new buffer position."
729 (newsticker--buffer-goto '(feed))
730 (run-hooks 'newsticker-select-feed-hook
)
731 (force-mode-line-update)
734 (defun newsticker-previous-feed ()
735 "Go to previous news feed.
736 Return new buffer position."
739 (newsticker--buffer-goto '(feed) nil t
)
740 (run-hooks 'newsticker-select-feed-hook
)
741 (force-mode-line-update)
744 (defun newsticker-mark-all-items-at-point-as-read-and-redraw ()
745 "Mark all items as read and clear ticker contents."
747 (when (or newsticker--buffer-uptodate-p
749 "Buffer is not up to date -- really mark items as read? "))
750 (newsticker-mark-all-items-of-feed-as-read
751 (get-text-property (point) 'feed
))))
753 (defun newsticker-mark-all-items-of-feed-as-read (feed)
754 "Mark all items of FEED as read, clear ticker, and redraw buffer."
757 (message "Marking all items as read for %s" (symbol-name feed
))
758 (newsticker--cache-replace-age newsticker--cache feed
'new
'old
)
759 (newsticker--cache-replace-age newsticker--cache feed
'obsolete
761 (newsticker--cache-update)
762 (newsticker--buffer-set-uptodate nil
)
763 (newsticker--ticker-text-setup)
764 (newsticker-buffer-update)
765 ;; Go back to where we came from.
768 (newsticker--buffer-goto '(feed) nil t
))))
770 (defun newsticker-mark-all-items-at-point-as-read ()
771 "Mark all items as read and clear ticker contents."
773 (when (or newsticker--buffer-uptodate-p
775 "Buffer is not up to date -- really mark items as read? "))
776 (newsticker--do-mark-item-at-point-as-read t
)
777 (while (newsticker-next-item-same-feed)
778 (newsticker--do-mark-item-at-point-as-read t
))
779 (newsticker-next-item t
)))
781 (defun newsticker-mark-item-at-point-as-read (&optional respect-immortality
)
782 "Mark item at point as read and move to next item.
783 If optional argument RESPECT-IMMORTALITY is not nil immortal items do
786 (when (or newsticker--buffer-uptodate-p
788 "Buffer is not up to date -- really mark this item as read? "))
789 (newsticker--do-mark-item-at-point-as-read respect-immortality
)
791 (newsticker-next-item t
)))
793 (defun newsticker--do-mark-item-at-point-as-read (&optional respect-immortality
)
794 "Mark item at point as read.
795 If optional argument RESPECT-IMMORTALITY is not nil immortal items do
797 (let ((feed (get-text-property (point) 'feed
)))
800 (newsticker--buffer-beginning-of-item)
801 (let ((inhibit-read-only t
)
802 (age (get-text-property (point) 'nt-age
))
803 (title (get-text-property (point) 'nt-title
))
804 (guid (get-text-property (point) 'nt-guid
))
805 (nt-desc (get-text-property (point) 'nt-desc
))
806 (pos (save-excursion (newsticker--buffer-end-of-item)))
808 (when (or (eq age
'new
)
810 (and (eq age
'immortal
)
811 (not respect-immortality
)))
813 (setq item
(newsticker--cache-contains newsticker--cache
818 (setcar (nthcdr 4 item
) 'old
)
819 (newsticker--do-forget-preformatted item
))
821 (if (or (and (eq age
'new
)
822 newsticker-hide-immortal-items-in-echo-area
)
823 (and (memq age
'(old immortal
))
825 (eq newsticker-hide-old-items-in-newsticker-buffer
826 newsticker-hide-immortal-items-in-echo-area
))))
827 (newsticker--ticker-text-remove feed title
))
832 (put-text-property (point) pos
'nt-age
'old
)
833 (newsticker--buffer-set-faces (point) pos
)))
834 (set-buffer-modified-p nil
)))))))
836 (defun newsticker-mark-item-at-point-as-immortal ()
837 "Mark item at point as read."
839 (when (or newsticker--buffer-uptodate-p
841 "Buffer is not up to date -- really mark this item as read? "))
842 (let ((feed (get-text-property (point) 'feed
))
846 (newsticker--buffer-beginning-of-item)
847 (let ((inhibit-read-only t
)
848 (oldage (get-text-property (point) 'nt-age
))
849 (title (get-text-property (point) 'nt-title
))
850 (guid (get-text-property (point) 'nt-guid
))
851 (pos (save-excursion (newsticker--buffer-end-of-item))))
852 (let ((newage 'immortal
))
853 (if (eq oldage
'immortal
)
855 (setq item
(newsticker--cache-contains newsticker--cache
856 feed title nil nil nil
860 (setcar (nthcdr 4 item
) newage
)
861 (newsticker--do-forget-preformatted item
))
862 (if (or (and (eq newage
'immortal
)
863 newsticker-hide-immortal-items-in-echo-area
)
864 (and (eq newage
'obsolete
)
865 newsticker-hide-obsolete-items-in-echo-area
)
866 (and (eq oldage
'immortal
)
868 (eq newsticker-hide-old-items-in-newsticker-buffer
869 newsticker-hide-immortal-items-in-echo-area
))))
870 (newsticker--ticker-text-remove feed title
)
871 (newsticker--ticker-text-setup))
875 (put-text-property (point) pos
'nt-age newage
)
876 (if (eq newage
'immortal
)
877 (put-text-property (point) pos
'nt-age
'immortal
)
878 (put-text-property (point) pos
'nt-age
'old
))
879 (newsticker--buffer-set-faces (point) pos
))))))
881 (newsticker-next-item t
))))))
883 (defun newsticker-mark-all-items-as-read ()
884 "Mark all items as read and clear ticker contents."
886 (when (or newsticker--buffer-uptodate-p
888 "Buffer is not up to date -- really mark items as read? "))
889 (newsticker--cache-replace-age newsticker--cache
'any
'new
'old
)
890 (newsticker--buffer-set-uptodate nil
)
891 (newsticker--ticker-text-setup)
892 (newsticker--cache-update)
893 (newsticker-buffer-update)))
895 (defun newsticker-hide-extra ()
896 "Hide the extra elements of items."
898 (newsticker--buffer-hideshow 'extra nil
)
899 (newsticker--buffer-redraw))
901 (defun newsticker-show-extra ()
902 "Show the extra elements of items."
904 (newsticker--buffer-hideshow 'extra t
)
905 (newsticker--buffer-redraw))
907 (defun newsticker-hide-old-item-desc ()
908 "Hide the description of old items."
910 (newsticker--buffer-hideshow 'desc-old nil
)
911 (newsticker--buffer-redraw))
913 (defun newsticker-show-old-item-desc ()
914 "Show the description of old items."
916 (newsticker--buffer-hideshow 'item-old t
)
917 (newsticker--buffer-hideshow 'desc-old t
)
918 (newsticker--buffer-redraw))
920 (defun newsticker-hide-new-item-desc ()
921 "Hide the description of new items."
923 (newsticker--buffer-hideshow 'desc-new nil
)
924 (newsticker--buffer-hideshow 'desc-immortal nil
)
925 (newsticker--buffer-hideshow 'desc-obsolete nil
)
926 (newsticker--buffer-redraw))
928 (defun newsticker-show-new-item-desc ()
929 "Show the description of new items."
931 (newsticker--buffer-hideshow 'desc-new t
)
932 (newsticker--buffer-hideshow 'desc-immortal t
)
933 (newsticker--buffer-hideshow 'desc-obsolete t
)
934 (newsticker--buffer-redraw))
936 (defun newsticker-hide-feed-desc ()
937 "Hide the description of feeds."
939 (newsticker--buffer-hideshow 'desc-feed nil
)
940 (newsticker--buffer-redraw))
942 (defun newsticker-show-feed-desc ()
943 "Show the description of old items."
945 (newsticker--buffer-hideshow 'desc-feed t
)
946 (newsticker--buffer-redraw))
948 (defun newsticker-hide-all-desc ()
949 "Hide the descriptions of feeds and all items."
951 (newsticker--buffer-hideshow 'desc-feed nil
)
952 (newsticker--buffer-hideshow 'desc-immortal nil
)
953 (newsticker--buffer-hideshow 'desc-obsolete nil
)
954 (newsticker--buffer-hideshow 'desc-new nil
)
955 (newsticker--buffer-hideshow 'desc-old nil
)
956 (newsticker--buffer-redraw))
958 (defun newsticker-show-all-desc ()
959 "Show the descriptions of feeds and all items."
961 (newsticker--buffer-hideshow 'desc-feed t
)
962 (newsticker--buffer-hideshow 'desc-immortal t
)
963 (newsticker--buffer-hideshow 'desc-obsolete t
)
964 (newsticker--buffer-hideshow 'desc-new t
)
965 (newsticker--buffer-hideshow 'desc-old t
)
966 (newsticker--buffer-redraw))
968 (defun newsticker-hide-old-items ()
971 (newsticker--buffer-hideshow 'desc-old nil
)
972 (newsticker--buffer-hideshow 'item-old nil
)
973 (newsticker--buffer-redraw))
975 (defun newsticker-show-old-items ()
978 (newsticker--buffer-hideshow 'item-old t
)
979 (newsticker--buffer-redraw))
981 (defun newsticker-hide-entry ()
982 "Hide description of entry at point."
986 (inhibit-read-only t
)
987 inv-prop org-inv-prop
989 (newsticker--buffer-beginning-of-item)
990 (newsticker--buffer-goto '(desc))
991 (setq pos1
(max (point-min) (1- (point))))
992 (newsticker--buffer-goto '(extra feed item nil
))
993 (setq pos2
(max (point-min) (1- (point))))
994 (setq inv-prop
(get-text-property pos1
'invisible
))
995 (setq org-inv-prop
(get-text-property pos1
'org-invisible
))
996 (cond ((eq inv-prop t
)
999 ((eq org-inv-prop nil
)
1000 (add-text-properties pos1 pos2
1001 (list 'invisible
(list t
)
1002 'org-invisible inv-prop
)))
1005 (add-text-properties pos1 pos2
1006 (list 'invisible org-inv-prop
))
1007 (remove-text-properties pos1 pos2
'(org-invisible))))))
1008 (newsticker--buffer-redraw))
1010 (defun newsticker-show-entry ()
1011 "Show description of entry at point."
1015 (inhibit-read-only t
)
1016 inv-prop org-inv-prop
1018 (newsticker--buffer-beginning-of-item)
1019 (newsticker--buffer-goto '(desc))
1020 (setq pos1
(max (point-min) (1- (point))))
1021 (newsticker--buffer-goto '(extra feed item
))
1022 (setq pos2
(max (point-min) (1- (point))))
1023 (setq inv-prop
(get-text-property pos1
'invisible
))
1024 (setq org-inv-prop
(get-text-property pos1
'org-invisible
))
1025 (cond ((eq org-inv-prop nil
)
1026 (add-text-properties pos1 pos2
1027 (list 'invisible nil
1028 'org-invisible inv-prop
)))
1031 (add-text-properties pos1 pos2
1032 (list 'invisible org-inv-prop
))
1033 (remove-text-properties pos1 pos2
'(org-invisible))))))
1034 (newsticker--buffer-redraw))
1036 (defun newsticker-toggle-auto-narrow-to-feed ()
1037 "Toggle narrowing to current news feed.
1038 If auto-narrowing is active, only news item of the current feed
1041 (newsticker-set-auto-narrow-to-feed
1042 (not newsticker--auto-narrow-to-feed
)))
1044 (defun newsticker-set-auto-narrow-to-feed (value)
1045 "Turn narrowing to current news feed on or off.
1046 If VALUE is nil, auto-narrowing is turned off, otherwise it is turned on."
1048 (setq newsticker--auto-narrow-to-item nil
)
1049 (setq newsticker--auto-narrow-to-feed value
)
1051 (newsticker--buffer-make-item-completely-visible)
1052 (run-hooks 'newsticker-narrow-hook
))
1054 (defun newsticker-toggle-auto-narrow-to-item ()
1055 "Toggle narrowing to current news item.
1056 If auto-narrowing is active, only one item of the current feed
1059 (newsticker-set-auto-narrow-to-item
1060 (not newsticker--auto-narrow-to-item
)))
1062 (defun newsticker-set-auto-narrow-to-item (value)
1063 "Turn narrowing to current news item on or off.
1064 If VALUE is nil, auto-narrowing is turned off, otherwise it is turned on."
1066 (setq newsticker--auto-narrow-to-feed nil
)
1067 (setq newsticker--auto-narrow-to-item value
)
1069 (newsticker--buffer-make-item-completely-visible)
1070 (run-hooks 'newsticker-narrow-hook
))
1072 (defun newsticker-next-feed-available-p ()
1073 "Return t if position is before last feed, nil otherwise."
1076 (newsticker--buffer-goto '(feed))
1077 (not (= p
(point))))))
1079 (defun newsticker-previous-feed-available-p ()
1080 "Return t if position is behind first feed, nil otherwise."
1083 (newsticker--buffer-goto '(feed) nil t
)
1084 (not (= p
(point))))))
1086 (defun newsticker-next-item-available-p ()
1087 "Return t if position is before last feed, nil otherwise."
1090 (while (< (point) (point-max))
1091 (unless (newsticker--buffer-goto '(item))
1092 (throw 'result nil
))
1093 (unless (newsticker--lists-intersect-p
1094 (get-text-property (point) 'invisible
)
1095 buffer-invisibility-spec
)
1096 (throw 'result t
))))))
1098 (defun newsticker-previous-item-available-p ()
1099 "Return t if position is behind first item, nil otherwise."
1102 (while (> (point) (point-min))
1103 (unless (newsticker--buffer-goto '(item) nil t
)
1104 (throw 'result nil
))
1105 (unless (newsticker--lists-intersect-p
1106 (get-text-property (point) 'invisible
)
1107 buffer-invisibility-spec
)
1108 (throw 'result t
))))))
1110 (defun newsticker-item-not-old-p ()
1111 "Return t if there is an item at point which is not old, nil otherwise."
1112 (when (get-text-property (point) 'feed
)
1114 (newsticker--buffer-beginning-of-item)
1115 (let ((age (get-text-property (point) 'nt-age
)))
1116 (and (memq age
'(new immortal obsolete
)) t
)))))
1118 (defun newsticker-item-not-immortal-p ()
1119 "Return t if there is an item at point which is not immortal, nil otherwise."
1120 (when (get-text-property (point) 'feed
)
1122 (newsticker--buffer-beginning-of-item)
1123 (let ((age (get-text-property (point) 'nt-age
)))
1124 (and (memq age
'(new old obsolete
)) t
)))))
1126 ;; ======================================================================
1128 ;; ======================================================================
1129 (defun newsticker--imenu-create-index ()
1130 "Scan newsticker buffer and return an index for imenu."
1132 (goto-char (point-min))
1133 (let ((index-alist nil
)
1137 (let ((type (get-text-property (point) 'nt-type
))
1138 (title (get-text-property (point) 'nt-title
)))
1139 (cond ((eq type
'feed
)
1140 ;; we're on a feed heading
1143 (nconc index-alist
(list feed-list
))
1144 (setq index-alist
(list feed-list
))))
1145 (setq feed-list
(list title
)))
1148 (list (cons title
(point)))))))
1149 (setq go-ahead
(newsticker--buffer-goto '(item feed
))))
1151 (nconc index-alist
(list feed-list
))
1152 (setq index-alist
(list feed-list
)))
1155 (defun newsticker--imenu-goto (name pos
&rest args
)
1156 "Go to item NAME at position POS and show item.
1160 (newsticker--buffer-goto '(desc extra feed item
))
1161 (let* ((inhibit-read-only t
)
1162 (pos1 (max (point-min) (1- pos
)))
1163 (pos2 (max pos1
(1- (point))))
1164 (inv-prop (get-text-property pos
'invisible
))
1165 (org-inv-prop (get-text-property pos
'org-invisible
)))
1166 (when (eq org-inv-prop nil
)
1167 (add-text-properties pos1 pos2
(list 'invisible nil
1168 'org-invisible inv-prop
))))
1170 (newsticker-show-entry))
1172 ;; ======================================================================
1174 ;; ======================================================================
1175 (defun newsticker--buffer-set-uptodate (value)
1176 "Set the uptodate-status of the newsticker buffer to VALUE.
1177 The mode-line is changed accordingly."
1178 (setq newsticker--buffer-uptodate-p value
)
1179 (let ((b (get-buffer "*newsticker*")))
1181 (with-current-buffer b
1182 (setq mode-name
(if value
1183 "Newsticker -- up to date -- "
1184 "Newsticker -- NEED UPDATE -- ")))
1185 (force-mode-line-update 0))))
1187 (defun newsticker--buffer-redraw ()
1188 "Redraw the newsticker window."
1189 (if (fboundp 'force-window-update
)
1190 (force-window-update (current-buffer))
1192 (run-hooks 'newsticker-buffer-change-hook
)
1195 (defun newsticker--buffer-insert-all-items ()
1196 "Insert all cached newsticker items into the current buffer.
1197 Keeps order of feeds as given in `newsticker-url-list' and
1198 `newsticker-url-list-defaults'."
1199 (goto-char (point-min))
1200 (mapc (lambda (url-item)
1201 (let* ((feed-name (car url-item
))
1202 (feed-name-symbol (intern feed-name
))
1203 (feed (assoc feed-name-symbol newsticker--cache
))
1207 ;; insert the feed description
1208 (mapc (lambda (item)
1209 (when (eq (newsticker--age item
) 'feed
)
1210 (newsticker--buffer-insert-item item
1214 (mapc (lambda (item)
1215 (if (memq (newsticker--age item
) '(new immortal old
1217 (newsticker--buffer-insert-item item
1220 (put-text-property pos
(point) 'feed
(car feed
))
1222 ;; insert empty line between feeds
1225 (put-text-property p
(point) 'hard t
)))))
1226 (append newsticker-url-list newsticker-url-list-defaults
))
1228 (newsticker--buffer-set-faces (point-min) (point-max))
1229 (newsticker--buffer-set-invisibility (point-min) (point-max))
1230 (goto-char (point-min)))
1232 (defun newsticker--buffer-insert-item (item &optional feed-name-symbol
)
1233 "Insert a news item in the current buffer.
1234 Insert a formatted representation of the ITEM. The optional parameter
1235 FEED-NAME-SYMBOL determines how the item is formatted and whether the
1236 item-retrieval time is added as well."
1238 (if (eq (newsticker--age item
) 'feed
)
1239 (newsticker--buffer-do-insert-text item
'feed feed-name-symbol
)
1240 (newsticker--buffer-do-insert-text item
'item feed-name-symbol
))
1241 ;; insert the description
1242 (newsticker--buffer-do-insert-text item
'desc feed-name-symbol
))
1244 (defun newsticker--buffer-do-insert-text (item type feed-name-symbol
)
1245 "Actually insert contents of news item, format it, render it and all that.
1246 ITEM is a news item, TYPE tells which part of the item shall be inserted,
1247 FEED-NAME-SYMBOL tells to which feed this item belongs."
1248 (let* ((pos (point))
1249 (format newsticker-desc-format
)
1250 (pos-date-start nil
)
1252 (pos-stat-start nil
)
1254 (pos-text-start nil
)
1256 (pos-extra-start nil
)
1258 (pos-enclosure-start nil
)
1259 (pos-enclosure-end nil
)
1260 (age (newsticker--age item
))
1261 (preformatted-contents (newsticker--preformatted-contents item
))
1262 (preformatted-title (newsticker--preformatted-title item
)))
1263 (cond ((and preformatted-contents
1264 (not (eq (aref preformatted-contents
0) ?
\n));; we must
1268 (insert preformatted-contents
))
1269 ((and preformatted-title
1270 (not (eq (aref preformatted-title
0) ?
\n));; we must NOT have a
1273 (insert preformatted-title
))
1275 ;; item was not formatted before.
1278 (setq format newsticker-item-format
)
1280 (setq format newsticker-heading-format
)))
1282 (while (> (length format
) 0)
1283 (let ((prefix (if (> (length format
) 1)
1284 (substring format
0 2)
1286 (cond ((string= "%c" prefix
)
1288 (when (newsticker--desc item
)
1289 (setq pos-text-start
(point-marker))
1290 (insert (newsticker--desc item
))
1291 (setq pos-text-end
(point-marker)))
1292 (setq format
(substring format
2)))
1293 ((string= "%d" prefix
)
1295 (setq pos-date-start
(point-marker))
1296 (if (newsticker--time item
)
1297 (insert (format-time-string newsticker-date-format
1298 (newsticker--time item
))))
1299 (setq pos-date-end
(point-marker))
1300 (setq format
(substring format
2)))
1301 ((string= "%l" prefix
)
1303 (let ((disabled (cond ((eq (newsticker--age item
) 'feed
)
1304 (= (newsticker--stat-num-items
1305 feed-name-symbol
'new
) 0))
1307 (not (eq (newsticker--age item
)
1309 (let ((img (newsticker--image-read feed-name-symbol
1312 (newsticker--insert-image img
(car item
)))))
1313 (setq format
(substring format
2)))
1314 ((string= "%L" prefix
)
1316 (let ((disabled (cond ((eq (newsticker--age item
) 'feed
)
1317 (= (newsticker--stat-num-items
1318 feed-name-symbol
'new
) 0))
1320 (not (eq (newsticker--age item
)
1322 (let ((img (newsticker--image-read feed-name-symbol
1325 (newsticker--insert-image img
(car item
))
1327 (setq pos-text-start
(point-marker))
1328 (if (eq (newsticker--age item
) 'feed
)
1329 (insert (newsticker--title item
))
1330 ;; FIXME: This is not the "real" title!
1331 (insert (format "%s"
1332 (car (newsticker--cache-get-feed
1333 feed-name-symbol
)))))
1334 (setq pos-text-end
(point-marker))))))
1335 (setq format
(substring format
2)))
1336 ((string= "%s" prefix
)
1338 (setq pos-stat-start
(point-marker))
1339 (if (eq (newsticker--age item
) 'feed
)
1340 (insert (newsticker--buffer-statistics
1342 (setq pos-stat-end
(point-marker))
1343 (setq format
(substring format
2)))
1344 ((string= "%t" prefix
)
1347 (setq pos-text-start
(point-marker))
1349 (setq pos-text-end
(point-marker)))
1350 (setq format
(substring format
2)))
1351 ((string-match "%." prefix
)
1352 ;; unknown specifier!
1354 (setq format
(substring format
2)))
1355 ((string-match "^\\([^%]*\\)\\(.*\\)" format
) ;; FIXME!
1358 (insert (substring format
1359 (match-beginning 1) (match-end 1)))
1360 ;; in case that the format string contained newlines
1361 (put-text-property p
(point) 'hard t
))
1362 (setq format
(substring format
(match-beginning 2)))))))
1364 ;; decode HTML if possible...
1365 (let ((is-rendered-HTML nil
))
1366 (when (and newsticker-html-renderer pos-text-start pos-text-end
)
1367 (condition-case error-data
1369 ;; check whether it is necessary to call html renderer
1370 ;; (regexp inspired by htmlr.el)
1371 (goto-char pos-text-start
)
1372 (when (re-search-forward
1373 "</?[A-Za-z1-6]*\\|&#?[A-Za-z0-9]+;" pos-text-end t
)
1374 ;; (message "%s" (newsticker--title item))
1375 (let ((w3m-fill-column (if newsticker-use-full-width
1377 (w3-maximum-line-length
1378 (if newsticker-use-full-width nil fill-column
)))
1380 (funcall newsticker-html-renderer pos-text-start
1382 (cond ((eq newsticker-html-renderer
'w3m-region
)
1383 (add-text-properties pos
(point-max)
1385 w3m-minor-mode-map
)))
1386 ((eq newsticker-html-renderer
'w3-region
)
1387 (add-text-properties pos
(point-max)
1388 (list 'keymap w3-mode-map
))))
1389 (setq is-rendered-HTML t
)))
1391 (message "Error: HTML rendering failed: %s, %s"
1392 (car error-data
) (cdr error-data
)))))
1393 ;; After html rendering there might be chunks of blank
1394 ;; characters between rendered text and date, statistics or
1395 ;; whatever. Remove it
1396 (when (and (eq type
'item
) is-rendered-HTML
)
1398 (while (re-search-forward "[ \t]*\n[ \t]*" nil t
)
1399 (replace-match " " nil nil
))
1400 (goto-char (point-max)))
1401 (when (and newsticker-justification
1402 (memq type
'(item desc
))
1403 (not is-rendered-HTML
))
1405 (let ((use-hard-newlines t
))
1406 (fill-region pos
(point-max) newsticker-justification
))
1409 ;; remove leading and trailing newlines
1411 (unless (= 0 (skip-chars-forward " \t\r\n"))
1412 (delete-region pos
(point)))
1413 (goto-char (point-max))
1414 (let ((end (point)))
1415 (unless (= 0 (skip-chars-backward " \t\r\n" (1+ pos
)))
1416 (delete-region (point) end
)))
1417 (goto-char (point-max))
1419 (unless nil
;;(eq pos (point))
1421 (put-text-property (1- (point)) (point) 'hard t
))
1423 ;; insert enclosure element
1424 (when (eq type
'desc
)
1425 (setq pos-enclosure-start
(point))
1426 (newsticker--insert-enclosure item newsticker--url-keymap
)
1427 (setq pos-enclosure-end
(point)))
1429 ;; show extra elements
1430 (when (eq type
'desc
)
1431 (goto-char (point-max))
1432 (setq pos-extra-start
(point))
1433 (newsticker--print-extra-elements item newsticker--url-keymap
)
1434 (setq pos-extra-end
(point)))
1437 (when (memq type
'(feed item
))
1438 (add-text-properties pos
(1- (point))
1439 (list 'mouse-face
'highlight
1440 'nt-link
(newsticker--link item
)
1442 (format "mouse-2: visit item (%s)"
1443 (newsticker--link item
))
1444 'keymap newsticker--url-keymap
))
1445 (add-text-properties pos
(point)
1446 (list 'nt-title
(newsticker--title item
)
1447 'nt-desc
(newsticker--desc item
))))
1449 (add-text-properties pos
(point)
1453 'nt-guid
(newsticker--guid item
)))
1454 (when (and pos-date-start pos-date-end
)
1455 (put-text-property pos-date-start pos-date-end
'nt-face
'date
))
1456 (when (and pos-stat-start pos-stat-end
)
1457 (put-text-property pos-stat-start pos-stat-end
'nt-face
'stat
))
1458 (when (and pos-extra-start pos-extra-end
)
1459 (put-text-property pos-extra-start pos-extra-end
1461 (put-text-property pos-extra-start pos-extra-end
1463 (when (and pos-enclosure-start pos-enclosure-end
1464 (> pos-enclosure-end pos-enclosure-start
))
1465 (put-text-property pos-enclosure-start
(1- pos-enclosure-end
)
1466 'nt-face
'enclosure
))
1469 ;;(unless (memq type '(feed item))
1470 ;;(set-left-margin pos (1- (point)) 1))
1472 ;; save rendered stuff
1473 (cond ((eq type
'desc
)
1474 ;; preformatted contents
1475 (newsticker--cache-set-preformatted-contents
1476 item
(buffer-substring pos
(point))))
1478 ;; preformatted title
1479 (newsticker--cache-set-preformatted-title
1480 item
(buffer-substring pos
(point)))))))))
1482 (defun newsticker--buffer-statistics (feed-name-symbol)
1483 "Return a statistic string for the feed given by FEED-NAME-SYMBOL.
1484 See `newsticker-statistics-format'."
1485 (let ((case-fold-search nil
))
1486 (replace-regexp-in-string
1488 (format "%d" (newsticker--stat-num-items feed-name-symbol
))
1489 (replace-regexp-in-string
1491 (format "%d" (newsticker--stat-num-items feed-name-symbol
'immortal
))
1492 (replace-regexp-in-string
1494 (format "%d" (newsticker--stat-num-items feed-name-symbol
'new
))
1495 (replace-regexp-in-string
1497 (format "%d" (newsticker--stat-num-items feed-name-symbol
'old
))
1498 (replace-regexp-in-string
1500 (format "%d" (newsticker--stat-num-items feed-name-symbol
'obsolete
))
1501 newsticker-statistics-format
)))))))
1503 (defun newsticker--buffer-set-faces (start end
)
1504 "Add face properties according to mark property.
1505 Scans the buffer between START and END."
1507 (put-text-property start end
'face
'newsticker-default-face
)
1511 (nt-face (get-text-property start
'nt-face
))
1512 (nt-age (get-text-property start
'nt-age
)))
1514 (setq pos2
(next-single-property-change (point) 'nt-face
))
1515 (newsticker--set-face-properties pos1 pos2 nt-face nt-age
)
1516 (setq nt-face
(get-text-property pos2
'nt-face
))
1518 (while (and (setq pos2
(next-single-property-change pos1
'nt-face
))
1521 (newsticker--set-face-properties pos1 pos2 nt-face nt-age
)
1522 (setq nt-face
(get-text-property pos2
'nt-face
))
1523 (setq nt-age
(get-text-property pos2
'nt-age
))
1524 (setq pos1 pos2
)))))
1526 (defun newsticker--buffer-set-invisibility (start end
)
1527 "Add invisibility properties according to nt-type property.
1528 Scans the buffer between START and END. Sets the 'invisible
1529 property to '(<nt-type>-<nt-age> <nt-type> <nt-age>)."
1531 ;; reset invisibility settings
1532 (put-text-property start end
'invisible nil
)
1537 (nt-type (get-text-property start
'nt-type
))
1538 (nt-age (get-text-property start
'nt-age
)))
1540 (setq pos2
(next-single-property-change (point) 'nt-type
))
1541 (put-text-property (max (point-min) pos1
) (1- pos2
)
1546 (if (eq nt-type
'extra
) 'desc nt-type
))
1548 (symbol-name nt-age
)))
1551 (setq nt-type
(get-text-property pos2
'nt-type
))
1553 (while (and (setq pos2
(next-single-property-change pos1
'nt-type
))
1556 ;; must shift one char to the left in order to handle invisible
1557 ;; newlines, motion in invisible text areas and all that correctly
1558 (put-text-property (1- pos1
) (1- pos2
)
1563 (if (eq nt-type
'extra
) 'desc nt-type
))
1565 (symbol-name nt-age
)))
1568 (setq nt-type
(get-text-property pos2
'nt-type
))
1569 (setq nt-age
(get-text-property pos2
'nt-age
))
1570 (setq pos1 pos2
)))))
1572 (defun newsticker--set-face-properties (pos1 pos2 nt-face age
)
1573 "Set the face for the text between the positions POS1 and POS2.
1574 The face is chosen according the values of NT-FACE and AGE."
1575 (let ((face (cond ((eq nt-face
'feed
)
1576 'newsticker-feed-face
)
1578 (cond ((eq age
'new
)
1579 'newsticker-new-item-face
)
1581 'newsticker-old-item-face
)
1583 'newsticker-immortal-item-face
)
1585 'newsticker-obsolete-item-face
)))
1587 'newsticker-date-face
)
1589 'newsticker-statistics-face
)
1590 ((eq nt-face
'extra
)
1591 'newsticker-extra-face
)
1592 ((eq nt-face
'enclosure
)
1593 'newsticker-enclosure-face
))))
1595 (put-text-property pos1
(max pos1 pos2
) 'face face
))))
1597 ;; ======================================================================
1598 ;;; Functions working on the *newsticker* buffer
1599 ;; ======================================================================
1600 (defun newsticker--buffer-make-item-completely-visible ()
1601 "Scroll buffer until current item is completely visible."
1602 (when newsticker--auto-narrow-to-feed
1603 (let* ((min (or (save-excursion (newsticker--buffer-beginning-of-feed))
1605 (max (or (save-excursion (newsticker--buffer-end-of-feed))
1607 (narrow-to-region min max
)))
1608 (when newsticker--auto-narrow-to-item
1609 (let* ((min (or (save-excursion (newsticker--buffer-beginning-of-item))
1611 (max (or (save-excursion (newsticker--buffer-end-of-item))
1613 (narrow-to-region min max
)))
1615 ;; do not count lines and stuff because that does not work when images
1616 ;; are displayed. Do it the simple way:
1618 (newsticker--buffer-end-of-item)
1619 (unless (pos-visible-in-window-p)
1621 (unless (pos-visible-in-window-p)
1624 (defun newsticker--buffer-get-feed-title-at-point ()
1625 "Return feed symbol of headline at point."
1626 (format "%s" (or (get-text-property (point) 'feed
) " ")))
1628 (defun newsticker--buffer-get-item-title-at-point ()
1629 "Return feed symbol of headline at point."
1630 (format "%s" (or (get-text-property (point) 'nt-title
) " ")))
1632 (defun newsticker--buffer-goto (types &optional age backwards
)
1633 "Search next occurrence of TYPES in current buffer.
1634 TYPES is a list of symbols. If TYPES is found point is moved, if
1635 not point is left unchanged. If optional parameter AGE is not
1636 nil, the type AND the age must match. If BACKWARDS is t, search
1638 (let ((pos (save-excursion
1642 (let ((tpos (point)))
1645 (if (eq tpos
(point-min))
1647 (or (previous-single-property-change
1650 (next-single-property-change
1652 (and (memq (get-text-property tpos
'nt-type
) types
)
1654 (eq (get-text-property tpos
'nt-age
) age
))
1655 (throw 'found tpos
)))))))))
1660 (defun newsticker--buffer-hideshow (mark-age onoff
)
1661 "Hide or show items of type MARK-AGE.
1662 If ONOFF is nil the item is hidden, otherwise it is shown."
1664 (remove-from-invisibility-spec mark-age
)
1665 (add-to-invisibility-spec mark-age
)))
1667 (defun newsticker--buffer-beginning-of-item ()
1668 "Move point to the beginning of the item at point.
1669 Return new position."
1672 (let ((type (get-text-property (point) 'nt-type
))
1673 (typebefore (get-text-property (1- (point)) 'nt-type
)))
1674 (if (and (memq type
'(item feed
))
1675 (not (eq type typebefore
)))
1677 (newsticker--buffer-goto '(item feed
) nil t
)
1680 (defun newsticker--buffer-beginning-of-feed ()
1681 "Move point to the beginning of the feed at point.
1682 Return new position."
1685 (let ((type (get-text-property (point) 'nt-type
))
1686 (typebefore (get-text-property (1- (point)) 'nt-type
)))
1687 (if (and (memq type
'(feed))
1688 (not (eq type typebefore
)))
1690 (newsticker--buffer-goto '(feed) nil t
)
1693 (defun newsticker--buffer-end-of-item ()
1694 "Move point to the end of the item at point.
1695 Take care: end of item is at the end of its last line!"
1696 (when (newsticker--buffer-goto '(item feed nil
))
1699 (defun newsticker--buffer-end-of-feed ()
1700 "Move point to the end of the last item of the feed at point.
1701 Take care: end of item is at the end of its last line!"
1702 (when (newsticker--buffer-goto '(feed nil
))
1706 ;; ======================================================================
1708 ;; ======================================================================
1710 (defun newsticker-mouse-browse-url (event)
1711 "Call `browse-url' for the link of the item at which the EVENT occurred."
1714 (switch-to-buffer (window-buffer (posn-window (event-end event
))))
1715 (let ((url (get-text-property (posn-point (event-end event
))
1720 (goto-char (posn-point (event-end event
)))
1721 (if newsticker-automatically-mark-visited-items-as-old
1722 (newsticker-mark-item-at-point-as-read t
)))))))
1724 (defun newsticker-browse-url ()
1725 "Call `browse-url' for the link of the item at point."
1727 (let ((url (get-text-property (point) 'nt-link
)))
1730 (if newsticker-automatically-mark-visited-items-as-old
1731 (newsticker-mark-item-at-point-as-read t
)))))
1733 (defvar newsticker-open-url-history
1734 '("wget" "xmms" "realplay")
1737 (defun newsticker-handle-url ()
1738 "Ask for a program to open the link of the item at point."
1740 (let ((url (get-text-property (point) 'nt-link
)))
1742 (let ((prog (read-string "Open url with: " nil
1743 'newsticker-open-url-history
)))
1745 (message "%s %s" prog url
)
1746 (start-process prog prog prog url
)
1747 (if newsticker-automatically-mark-visited-items-as-old
1748 (newsticker-mark-item-at-point-as-read t
)))))))
1751 ;; ======================================================================
1753 ;; ======================================================================
1755 (defun newsticker--cache-sort ()
1756 "Sort the newsticker cache data."
1757 (let ((sort-fun (cond ((eq newsticker-sort-method
'sort-by-time
)
1758 'newsticker--cache-item-compare-by-time
)
1759 ((eq newsticker-sort-method
'sort-by-title
)
1760 'newsticker--cache-item-compare-by-title
)
1761 ((eq newsticker-sort-method
'sort-by-original-order
)
1762 'newsticker--cache-item-compare-by-position
))))
1763 (mapc (lambda (feed-list)
1764 (setcdr feed-list
(sort (cdr feed-list
)
1766 newsticker--cache
)))
1768 (provide 'newst-plainview
)
1770 ;;; newst-plainview.el ends here