newst-plainview.el 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. ;;; newst-plainview.el --- Single buffer frontend for newsticker.
  2. ;; Copyright (C) 2003-2012 Free Software Foundation, Inc.
  3. ;; Author: Ulf Jasper <ulf.jasper@web.de>
  4. ;; Filename: newst-plainview.el
  5. ;; URL: http://www.nongnu.org/newsticker
  6. ;; Time-stamp: "13. Mai 2011, 19:28:34 (ulf)"
  7. ;; Package: newsticker
  8. ;; ======================================================================
  9. ;; This file is part of GNU Emacs.
  10. ;; GNU Emacs is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  20. ;; ======================================================================
  21. ;;; Commentary:
  22. ;; See newsticker.el
  23. ;; ======================================================================
  24. ;;; Code:
  25. (require 'newst-ticker)
  26. (require 'newst-reader)
  27. (require 'derived)
  28. (require 'xml)
  29. ;; Silence warnings
  30. (defvar w3-mode-map)
  31. (defvar w3m-minor-mode-map)
  32. ;; ======================================================================
  33. ;;; Customization
  34. ;; ======================================================================
  35. (defgroup newsticker-plainview nil
  36. "Settings for the simple plain view reader.
  37. See also `newsticker-plainview-hooks'."
  38. :group 'newsticker-reader)
  39. (defun newsticker--set-customvar-buffer (symbol value)
  40. "Set newsticker-variable SYMBOL value to VALUE.
  41. Calls all actions which are necessary in order to make the new
  42. value effective."
  43. (if (or (not (boundp symbol))
  44. (equal (symbol-value symbol) value))
  45. (set symbol value)
  46. ;; something must have changed
  47. (set symbol value)
  48. (newsticker--buffer-set-uptodate nil)))
  49. (defun newsticker--set-customvar-sorting (symbol value)
  50. "Set newsticker-variable SYMBOL value to VALUE.
  51. Calls all actions which are necessary in order to make the new
  52. value effective."
  53. (if (or (not (boundp symbol))
  54. (equal (symbol-value symbol) value))
  55. (set symbol value)
  56. ;; something must have changed
  57. (set symbol value)
  58. (message "Applying new sort method...")
  59. (when (fboundp 'newsticker--cache-sort) (newsticker--cache-sort))
  60. (when (fboundp 'newsticker--buffer-set-uptodate)
  61. (newsticker--buffer-set-uptodate nil))
  62. (message "Applying new sort method...done")))
  63. (defcustom newsticker-sort-method
  64. 'sort-by-original-order
  65. "Sort method for news items.
  66. The following sort methods are available:
  67. * `sort-by-original-order' keeps the order in which the items
  68. appear in the headline file (please note that for immortal items,
  69. which have been removed from the news feed, there is no original
  70. order),
  71. * `sort-by-time' looks at the time at which an item has been seen
  72. the first time. The most recent item is put at top,
  73. * `sort-by-title' will put the items in an alphabetical order."
  74. :type '(choice
  75. (const :tag "Keep original order" sort-by-original-order)
  76. (const :tag "Sort by time" sort-by-time)
  77. (const :tag "Sort by title" sort-by-title))
  78. :set 'newsticker--set-customvar-sorting
  79. :group 'newsticker-plainview)
  80. (defcustom newsticker-heading-format
  81. "%l
  82. %t %d %s"
  83. "Format string for feed headings.
  84. The following printf-like specifiers can be used:
  85. %d The date the feed was retrieved. See `newsticker-date-format'.
  86. %l The logo (image) of the feed. Most news feeds provide a small
  87. image as logo. Newsticker can display them, if Emacs can --
  88. see `image-types' for a list of supported image types.
  89. %L The logo (image) of the feed. If the logo is not available
  90. the title of the feed is used.
  91. %s The statistical data of the feed. See `newsticker-statistics-format'.
  92. %t The title of the feed, i.e. its name."
  93. :type 'string
  94. :set 'newsticker--set-customvar-formatting
  95. :group 'newsticker-plainview)
  96. (defcustom newsticker-item-format
  97. "%t %d"
  98. "Format string for news item headlines.
  99. The following printf-like specifiers can be used:
  100. %d The date the item was (first) retrieved. See `newsticker-date-format'.
  101. %l The logo (image) of the feed. Most news feeds provide a small
  102. image as logo. Newsticker can display them, if Emacs can --
  103. see `image-types' for a list of supported image types.
  104. %L The logo (image) of the feed. If the logo is not available
  105. the title of the feed is used.
  106. %t The title of the item."
  107. :type 'string
  108. :set 'newsticker--set-customvar-formatting
  109. :group 'newsticker-plainview)
  110. (defcustom newsticker-desc-format
  111. "%d %c"
  112. "Format string for news descriptions (contents).
  113. The following printf-like specifiers can be used:
  114. %c The contents (description) of the item.
  115. %d The date the item was (first) retrieved. See
  116. `newsticker-date-format'."
  117. :type 'string
  118. :set 'newsticker--set-customvar-formatting
  119. :group 'newsticker-plainview)
  120. (defcustom newsticker-statistics-format
  121. "[%n + %i + %o + %O = %a]"
  122. "Format for the statistics part in feed lines.
  123. The following printf-like specifiers can be used:
  124. %a The number of all items in the feed.
  125. %i The number of immortal items in the feed.
  126. %n The number of new items in the feed.
  127. %o The number of old items in the feed.
  128. %O The number of obsolete items in the feed."
  129. :type 'string
  130. :set 'newsticker--set-customvar-formatting
  131. :group 'newsticker-plainview)
  132. ;; ======================================================================
  133. ;; faces
  134. (defface newsticker-new-item-face
  135. '((((class color) (background dark))
  136. (:family "sans" :bold t))
  137. (((class color) (background light))
  138. (:family "sans" :bold t)))
  139. "Face for new news items."
  140. :group 'newsticker-faces)
  141. (defface newsticker-old-item-face
  142. '((((class color) (background dark))
  143. (:family "sans" :bold t :foreground "orange3"))
  144. (((class color) (background light))
  145. (:family "sans" :bold t :foreground "red4")))
  146. "Face for old news items."
  147. :group 'newsticker-faces)
  148. (defface newsticker-immortal-item-face
  149. '((((class color) (background dark))
  150. (:family "sans" :bold t :italic t :foreground "orange"))
  151. (((class color) (background light))
  152. (:family "sans" :bold t :italic t :foreground "blue")))
  153. "Face for immortal news items."
  154. :group 'newsticker-faces)
  155. (defface newsticker-obsolete-item-face
  156. '((((class color) (background dark))
  157. (:family "sans" :bold t :strike-through t))
  158. (((class color) (background light))
  159. (:family "sans" :bold t :strike-through t)))
  160. "Face for old news items."
  161. :group 'newsticker-faces)
  162. (defface newsticker-date-face
  163. '((((class color) (background dark))
  164. (:family "sans" :italic t :height 0.8))
  165. (((class color) (background light))
  166. (:family "sans" :italic t :height 0.8)))
  167. "Face for newsticker dates."
  168. :group 'newsticker-faces)
  169. (defface newsticker-statistics-face
  170. '((((class color) (background dark))
  171. (:family "sans" :italic t :height 0.8))
  172. (((class color) (background light))
  173. (:family "sans" :italic t :height 0.8)))
  174. "Face for newsticker dates."
  175. :group 'newsticker-faces)
  176. (defface newsticker-default-face
  177. '((((class color) (background dark))
  178. (:inherit default))
  179. (((class color) (background light))
  180. (:inherit default)))
  181. "Face for the description of news items."
  182. ;;:set 'newsticker--set-customvar
  183. :group 'newsticker-faces)
  184. (defcustom newsticker-hide-old-items-in-newsticker-buffer
  185. nil
  186. "Decides whether to automatically hide old items in the *newsticker* buffer.
  187. If set to t old items will be completely folded and only new
  188. items will show up in the *newsticker* buffer. Otherwise old as
  189. well as new items will be visible."
  190. :type 'boolean
  191. :set 'newsticker--set-customvar-buffer
  192. :group 'newsticker-plainview)
  193. (defcustom newsticker-show-descriptions-of-new-items
  194. t
  195. "Whether to automatically show descriptions of new items in *newsticker*.
  196. If set to t old items will be folded and new items will be
  197. unfolded. Otherwise old as well as new items will be folded."
  198. :type 'boolean
  199. :set 'newsticker--set-customvar-buffer
  200. :group 'newsticker-plainview)
  201. (defcustom newsticker-show-all-news-elements
  202. nil
  203. "Show all news elements."
  204. :type 'boolean
  205. ;;:set 'newsticker--set-customvar
  206. :group 'newsticker-plainview)
  207. ;; ======================================================================
  208. ;; hooks
  209. (defgroup newsticker-plainview-hooks nil
  210. "Settings for newsticker hooks which apply to plainview only."
  211. :group 'newsticker-hooks)
  212. (defcustom newsticker-select-item-hook
  213. 'newsticker--buffer-make-item-completely-visible
  214. "List of functions run after a headline has been selected.
  215. Each function is called after one of `newsticker-next-item',
  216. `newsticker-next-new-item', `newsticker-previous-item',
  217. `newsticker-previous-new-item' has been called.
  218. The default value 'newsticker--buffer-make-item-completely-visible
  219. assures that the current item is always completely visible."
  220. :type 'hook
  221. :options '(newsticker--buffer-make-item-completely-visible)
  222. :group 'newsticker-plainview-hooks)
  223. (defcustom newsticker-select-feed-hook
  224. 'newsticker--buffer-make-item-completely-visible
  225. "List of functions run after a feed has been selected.
  226. Each function is called after one of `newsticker-next-feed', and
  227. `newsticker-previous-feed' has been called.
  228. The default value 'newsticker--buffer-make-item-completely-visible
  229. assures that the current feed is completely visible."
  230. :type 'hook
  231. :options '(newsticker--buffer-make-item-completely-visible)
  232. :group 'newsticker-plainview-hooks)
  233. (defcustom newsticker-buffer-change-hook
  234. 'newsticker-w3m-show-inline-images
  235. "List of functions run after the newsticker buffer has been updated.
  236. Each function is called after `newsticker-buffer-update' has been called.
  237. The default value '`newsticker-w3m-show-inline-images' loads inline
  238. images."
  239. :type 'hook
  240. :group 'newsticker-plainview-hooks)
  241. (defcustom newsticker-narrow-hook
  242. 'newsticker-w3m-show-inline-images
  243. "List of functions run after narrowing in newsticker buffer has changed.
  244. Each function is called after
  245. `newsticker-toggle-auto-narrow-to-feed' or
  246. `newsticker-toggle-auto-narrow-to-item' has been called.
  247. The default value '`newsticker-w3m-show-inline-images' loads inline
  248. images."
  249. :type 'hook
  250. :group 'newsticker-plainview-hooks)
  251. ;; ======================================================================
  252. ;;; Toolbar
  253. ;; ======================================================================
  254. (defvar newsticker--plainview-tool-bar-map
  255. (if (featurep 'xemacs)
  256. nil
  257. (if (boundp 'tool-bar-map)
  258. (let ((tool-bar-map (make-sparse-keymap)))
  259. (tool-bar-add-item "newsticker/prev-feed"
  260. 'newsticker-previous-feed
  261. 'newsticker-previous-feed
  262. :help "Go to previous feed"
  263. :enable '(newsticker-previous-feed-available-p))
  264. (tool-bar-add-item "newsticker/prev-item"
  265. 'newsticker-previous-item
  266. 'newsticker-previous-item
  267. :help "Go to previous item"
  268. :enable '(newsticker-previous-item-available-p))
  269. (tool-bar-add-item "newsticker/next-item"
  270. 'newsticker-next-item
  271. 'newsticker-next-item
  272. :help "Go to next item"
  273. :enable '(newsticker-next-item-available-p))
  274. (tool-bar-add-item "newsticker/next-feed"
  275. 'newsticker-next-feed
  276. 'newsticker-next-feed
  277. :help "Go to next feed"
  278. :enable '(newsticker-next-feed-available-p))
  279. (tool-bar-add-item "newsticker/narrow"
  280. 'newsticker-toggle-auto-narrow-to-feed
  281. 'newsticker-toggle-auto-narrow-to-feed
  282. :help "Toggle visibility of other feeds")
  283. (tool-bar-add-item "newsticker/mark-immortal"
  284. 'newsticker-mark-item-at-point-as-immortal
  285. 'newsticker-mark-item-at-point-as-immortal
  286. :help "Mark current item as immortal"
  287. :enable '(newsticker-item-not-immortal-p))
  288. (tool-bar-add-item "newsticker/mark-read"
  289. 'newsticker-mark-item-at-point-as-read
  290. 'newsticker-mark-item-at-point-as-read
  291. :help "Mark current item as read"
  292. :enable '(newsticker-item-not-old-p))
  293. (tool-bar-add-item "newsticker/get-all-news"
  294. 'newsticker-get-all-news
  295. 'newsticker-get-all-news
  296. :help "Get news for all feeds")
  297. (tool-bar-add-item "newsticker/update"
  298. 'newsticker-buffer-force-update
  299. 'newsticker-buffer-force-update
  300. :help "Update newsticker buffer"
  301. :enable '(not newsticker--buffer-uptodate-p))
  302. (tool-bar-add-item "newsticker/browse-url"
  303. 'newsticker-browse-url
  304. 'newsticker-browse-url
  305. :help "Browse URL for item at point")
  306. ;; standard icons / actions
  307. (define-key tool-bar-map [newsticker-sep-1]
  308. (list 'menu-item "--double-line"))
  309. (tool-bar-add-item "close"
  310. 'newsticker-close-buffer
  311. 'newsticker-close-buffer
  312. :help "Close newsticker buffer")
  313. (tool-bar-add-item "preferences"
  314. 'newsticker-customize
  315. 'newsticker-customize
  316. :help "Customize newsticker")
  317. tool-bar-map))))
  318. ;; ======================================================================
  319. ;;; Newsticker mode
  320. ;; ======================================================================
  321. ;; newsticker menu
  322. (defvar newsticker-menu
  323. (let ((map (make-sparse-keymap "Newsticker")))
  324. (define-key map [newsticker-browse-url]
  325. '("Browse URL for item at point" . newsticker-browse-url))
  326. (define-key map [newsticker-separator-1]
  327. '("--"))
  328. (define-key map [newsticker-buffer-update]
  329. '("Update buffer" . newsticker-buffer-update))
  330. (define-key map [newsticker-separator-2]
  331. '("--"))
  332. (define-key map [newsticker-get-all-news]
  333. '("Get news from all feeds" . newsticker-get-all-news))
  334. (define-key map [newsticker-get-news-at-point]
  335. '("Get news from feed at point" . newsticker-get-news-at-point))
  336. (define-key map [newsticker-separator-3]
  337. '("--"))
  338. (define-key map [newsticker-mark-all-items-as-read]
  339. '("Mark all items as read" . newsticker-mark-all-items-as-read))
  340. (define-key map [newsticker-mark-all-items-at-point-as-read]
  341. '("Mark all items in feed at point as read" .
  342. newsticker-mark-all-items-at-point-as-read))
  343. (define-key map [newsticker-mark-item-at-point-as-read]
  344. '("Mark item at point as read" .
  345. newsticker-mark-item-at-point-as-read))
  346. (define-key map [newsticker-mark-item-at-point-as-immortal]
  347. '("Toggle immortality for item at point" .
  348. newsticker-mark-item-at-point-as-immortal))
  349. (define-key map [newsticker-separator-4]
  350. '("--"))
  351. (define-key map [newsticker-toggle-auto-narrow-to-item]
  352. '("Narrow to single item" . newsticker-toggle-auto-narrow-to-item))
  353. (define-key map [newsticker-toggle-auto-narrow-to-feed]
  354. '("Narrow to single news feed" . newsticker-toggle-auto-narrow-to-feed))
  355. (define-key map [newsticker-hide-old-items]
  356. '("Hide old items" . newsticker-hide-old-items))
  357. (define-key map [newsticker-show-old-items]
  358. '("Show old items" . newsticker-show-old-items))
  359. (define-key map [newsticker-next-item]
  360. '("Go to next item" . newsticker-next-item))
  361. (define-key map [newsticker-previous-item]
  362. '("Go to previous item" . newsticker-previous-item))
  363. map))
  364. (defvar newsticker-mode-map
  365. (let ((map (make-keymap)))
  366. (define-key map "sO" 'newsticker-show-old-items)
  367. (define-key map "hO" 'newsticker-hide-old-items)
  368. (define-key map "sa" 'newsticker-show-all-desc)
  369. (define-key map "ha" 'newsticker-hide-all-desc)
  370. (define-key map "sf" 'newsticker-show-feed-desc)
  371. (define-key map "hf" 'newsticker-hide-feed-desc)
  372. (define-key map "so" 'newsticker-show-old-item-desc)
  373. (define-key map "ho" 'newsticker-hide-old-item-desc)
  374. (define-key map "sn" 'newsticker-show-new-item-desc)
  375. (define-key map "hn" 'newsticker-hide-new-item-desc)
  376. (define-key map "se" 'newsticker-show-entry)
  377. (define-key map "he" 'newsticker-hide-entry)
  378. (define-key map "sx" 'newsticker-show-extra)
  379. (define-key map "hx" 'newsticker-hide-extra)
  380. (define-key map " " 'scroll-up-command)
  381. (define-key map "q" 'newsticker-close-buffer)
  382. (define-key map "p" 'newsticker-previous-item)
  383. (define-key map "P" 'newsticker-previous-new-item)
  384. (define-key map "F" 'newsticker-previous-feed)
  385. (define-key map "\t" 'newsticker-next-item)
  386. (define-key map "n" 'newsticker-next-item)
  387. (define-key map "N" 'newsticker-next-new-item)
  388. (define-key map "f" 'newsticker-next-feed)
  389. (define-key map "M" 'newsticker-mark-all-items-as-read)
  390. (define-key map "m"
  391. 'newsticker-mark-all-items-at-point-as-read-and-redraw)
  392. (define-key map "o"
  393. 'newsticker-mark-item-at-point-as-read)
  394. (define-key map "O"
  395. 'newsticker-mark-all-items-at-point-as-read)
  396. (define-key map "G" 'newsticker-get-all-news)
  397. (define-key map "g" 'newsticker-get-news-at-point)
  398. (define-key map "u" 'newsticker-buffer-update)
  399. (define-key map "U" 'newsticker-buffer-force-update)
  400. (define-key map "a" 'newsticker-add-url)
  401. (define-key map "i"
  402. 'newsticker-mark-item-at-point-as-immortal)
  403. (define-key map "xf"
  404. 'newsticker-toggle-auto-narrow-to-feed)
  405. (define-key map "xi"
  406. 'newsticker-toggle-auto-narrow-to-item)
  407. ;; Bind menu to mouse.
  408. (define-key map [down-mouse-3] newsticker-menu)
  409. ;; Put menu in menu-bar.
  410. (define-key map [menu-bar Newsticker]
  411. (cons "Newsticker" newsticker-menu))
  412. map))
  413. (define-derived-mode newsticker-mode fundamental-mode
  414. "NewsTicker"
  415. "Viewing news feeds in Emacs."
  416. (if (boundp 'tool-bar-map)
  417. (set (make-local-variable 'tool-bar-map)
  418. newsticker--plainview-tool-bar-map))
  419. (set (make-local-variable 'imenu-sort-function) nil)
  420. (set (make-local-variable 'scroll-conservatively) 999)
  421. (setq imenu-create-index-function 'newsticker--imenu-create-index)
  422. (setq imenu-default-goto-function 'newsticker--imenu-goto)
  423. (setq buffer-read-only t)
  424. (auto-fill-mode -1) ;; turn auto-fill off!
  425. (font-lock-mode -1) ;; turn off font-lock!!
  426. (set (make-local-variable 'font-lock-defaults) nil)
  427. (set (make-local-variable 'line-move-ignore-invisible) t)
  428. (setq mode-line-format
  429. (list "-"
  430. 'mode-line-mule-info
  431. 'mode-line-modified
  432. 'mode-line-frame-identification
  433. " Newsticker ("
  434. '(newsticker--buffer-uptodate-p
  435. "up to date"
  436. "NEED UPDATE")
  437. ") "
  438. '(:eval (format "[%d]" (length newsticker--process-ids)))
  439. " -- "
  440. '(:eval (newsticker--buffer-get-feed-title-at-point))
  441. ": "
  442. '(:eval (newsticker--buffer-get-item-title-at-point))
  443. " %-"))
  444. (add-to-invisibility-spec 't)
  445. (unless newsticker-show-all-news-elements
  446. (add-to-invisibility-spec 'extra))
  447. (newsticker--buffer-set-uptodate nil))
  448. ;; maps for the clickable portions
  449. (defvar newsticker--url-keymap
  450. (let ((map (make-sparse-keymap)))
  451. (define-key map [mouse-1] 'newsticker-mouse-browse-url)
  452. (define-key map [mouse-2] 'newsticker-mouse-browse-url)
  453. (define-key map "\n" 'newsticker-browse-url)
  454. (define-key map "\C-m" 'newsticker-browse-url)
  455. (define-key map [(control return)] 'newsticker-handle-url)
  456. map)
  457. "Key map for click-able headings in the newsticker buffer.")
  458. ;; ======================================================================
  459. ;;; User fun
  460. ;; ======================================================================
  461. ;;;###autoload
  462. (defun newsticker-plainview ()
  463. "Start newsticker plainview."
  464. (interactive)
  465. (newsticker-buffer-update t)
  466. (switch-to-buffer "*newsticker*"))
  467. (defun newsticker-buffer-force-update ()
  468. "Update the newsticker buffer, even if not necessary."
  469. (interactive)
  470. (newsticker-buffer-update t))
  471. (defun newsticker-buffer-update (&optional force)
  472. "Update the *newsticker* buffer.
  473. Unless FORCE is t this is done only if necessary, i.e. when the
  474. *newsticker* buffer is not up-to-date."
  475. (interactive)
  476. ;; bring cache data into proper order....
  477. (newsticker--cache-sort)
  478. ;; fill buffer
  479. (save-excursion
  480. (let ((buf (get-buffer "*newsticker*")))
  481. (if buf
  482. (switch-to-buffer buf)
  483. (switch-to-buffer (get-buffer-create "*newsticker*"))
  484. (newsticker--buffer-set-uptodate nil)))
  485. (when (or force
  486. (not newsticker--buffer-uptodate-p))
  487. (message "Preparing newsticker buffer...")
  488. (setq buffer-undo-list t)
  489. (let ((inhibit-read-only t))
  490. (set-buffer-modified-p nil)
  491. (erase-buffer)
  492. (newsticker-mode)
  493. ;; Emacs 21.3.50 does not care if we turn off auto-fill in the
  494. ;; definition of newsticker-mode, so we do it here (again)
  495. (auto-fill-mode -1)
  496. (set-buffer-file-coding-system 'utf-8)
  497. (if newsticker-use-full-width
  498. (set (make-local-variable 'fill-column) (1- (window-width))))
  499. (newsticker--buffer-insert-all-items)
  500. ;; FIXME: needed for methods buffer in ecb
  501. ;; (set-visited-file-name "*newsticker*")
  502. (set-buffer-modified-p nil)
  503. (newsticker-hide-all-desc)
  504. (if newsticker-hide-old-items-in-newsticker-buffer
  505. (newsticker-hide-old-items))
  506. (if newsticker-show-descriptions-of-new-items
  507. (newsticker-show-new-item-desc))
  508. )
  509. (message ""))
  510. (newsticker--buffer-set-uptodate t)
  511. (run-hooks 'newsticker-buffer-change-hook)))
  512. (defun newsticker-get-news-at-point ()
  513. "Launch retrieval of news for the feed point is in.
  514. This does NOT start the retrieval timers."
  515. (interactive)
  516. ;; launch retrieval of news
  517. (let ((feed (get-text-property (point) 'feed)))
  518. (when feed
  519. (newsticker--debug-msg "Getting news for %s" (symbol-name feed))
  520. (newsticker-get-news (symbol-name feed)))))
  521. (unless (fboundp 'declare-function) (defmacro declare-function (&rest r)))
  522. (declare-function w3m-toggle-inline-image "ext:w3m" (&optional force no-cache))
  523. (defun newsticker-w3m-show-inline-images ()
  524. "Show inline images in visible text ranges.
  525. In-line images in invisible text ranges are hidden. This function
  526. calls `w3m-toggle-inline-image'. It works only if
  527. `newsticker-html-renderer' is set to `w3m-region'."
  528. (interactive)
  529. (if (eq newsticker-html-renderer 'w3m-region)
  530. (let ((inhibit-read-only t))
  531. (save-excursion
  532. (save-restriction
  533. (widen)
  534. (goto-char (point-min))
  535. (let ((pos (point)))
  536. (while pos
  537. (setq pos (next-single-property-change pos 'w3m-image))
  538. (when pos
  539. (goto-char pos)
  540. (when (get-text-property pos 'w3m-image)
  541. (let ((invis (newsticker--lists-intersect-p
  542. (get-text-property (1- (point))
  543. 'invisible)
  544. buffer-invisibility-spec)))
  545. (unless (car (get-text-property (1- (point))
  546. 'display))
  547. (unless invis
  548. (w3m-toggle-inline-image t)))))))))))))
  549. ;; ======================================================================
  550. ;;; Keymap stuff
  551. ;; ======================================================================
  552. (defun newsticker-close-buffer ()
  553. "Close the newsticker buffer."
  554. (interactive)
  555. (newsticker--cache-update t)
  556. (bury-buffer))
  557. (defun newsticker-next-new-item (&optional do-not-wrap-at-eob)
  558. "Go to next new news item.
  559. If no new item is found behind point, search is continued at
  560. beginning of buffer unless optional argument DO-NOT-WRAP-AT-EOB
  561. is non-nil."
  562. (interactive)
  563. (widen)
  564. (let ((go-ahead t))
  565. (while go-ahead
  566. (unless (newsticker--buffer-goto '(item) 'new)
  567. ;; found nothing -- wrap
  568. (unless do-not-wrap-at-eob
  569. (goto-char (point-min))
  570. (newsticker-next-new-item t))
  571. (setq go-ahead nil))
  572. (unless (newsticker--lists-intersect-p
  573. (get-text-property (point) 'invisible)
  574. buffer-invisibility-spec)
  575. ;; this item is invisible -- continue search
  576. (setq go-ahead nil))))
  577. (run-hooks 'newsticker-select-item-hook)
  578. (point))
  579. (defun newsticker-previous-new-item (&optional do-not-wrap-at-bob)
  580. "Go to previous new news item.
  581. If no new item is found before point, search is continued at
  582. beginning of buffer unless optional argument DO-NOT-WRAP-AT-BOB
  583. is non-nil."
  584. (interactive)
  585. (widen)
  586. (let ((go-ahead t))
  587. (while go-ahead
  588. (unless (newsticker--buffer-goto '(item) 'new t)
  589. (unless do-not-wrap-at-bob
  590. (goto-char (point-max))
  591. (newsticker--buffer-goto '(item) 'new t)))
  592. (unless (newsticker--lists-intersect-p
  593. (get-text-property (point) 'invisible)
  594. buffer-invisibility-spec)
  595. (setq go-ahead nil))))
  596. (run-hooks 'newsticker-select-item-hook)
  597. (point))
  598. (defun newsticker-next-item (&optional do-not-wrap-at-eob)
  599. "Go to next news item.
  600. Return new buffer position.
  601. If no item is found below point, search is continued at beginning
  602. of buffer unless optional argument DO-NOT-WRAP-AT-EOB is
  603. non-nil."
  604. (interactive)
  605. (widen)
  606. (let ((go-ahead t)
  607. (search-list '(item)))
  608. (if newsticker--auto-narrow-to-item
  609. (setq search-list '(item feed)))
  610. (while go-ahead
  611. (unless (newsticker--buffer-goto search-list)
  612. ;; found nothing -- wrap
  613. (unless do-not-wrap-at-eob
  614. (goto-char (point-min)))
  615. (setq go-ahead nil))
  616. (unless (newsticker--lists-intersect-p
  617. (get-text-property (point) 'invisible)
  618. buffer-invisibility-spec)
  619. (setq go-ahead nil))))
  620. (run-hooks 'newsticker-select-item-hook)
  621. (force-mode-line-update)
  622. (point))
  623. (defun newsticker-next-item-same-feed ()
  624. "Go to next news item in the same feed.
  625. Return new buffer position. If no item is found below point or if
  626. auto-narrow-to-item is enabled, nil is returned."
  627. (interactive)
  628. (if newsticker--auto-narrow-to-item
  629. nil
  630. (let ((go-ahead t)
  631. (current-pos (point))
  632. (end-of-feed (save-excursion (newsticker--buffer-end-of-feed))))
  633. (while go-ahead
  634. (unless (newsticker--buffer-goto '(item))
  635. (setq go-ahead nil))
  636. (unless (newsticker--lists-intersect-p
  637. (get-text-property (point) 'invisible)
  638. buffer-invisibility-spec)
  639. (setq go-ahead nil)))
  640. (if (and (> (point) current-pos)
  641. (< (point) end-of-feed))
  642. (point)
  643. (goto-char current-pos)
  644. nil))))
  645. (defun newsticker-previous-item (&optional do-not-wrap-at-bob)
  646. "Go to previous news item.
  647. Return new buffer position.
  648. If no item is found before point, search is continued at
  649. beginning of buffer unless optional argument DO-NOT-WRAP-AT-BOB
  650. is non-nil."
  651. (interactive)
  652. (widen)
  653. (let ((go-ahead t)
  654. (search-list '(item)))
  655. (if newsticker--auto-narrow-to-item
  656. (setq search-list '(item feed)))
  657. (when (bobp)
  658. (unless do-not-wrap-at-bob
  659. (goto-char (point-max))))
  660. (while go-ahead
  661. (if (newsticker--buffer-goto search-list nil t)
  662. (unless (newsticker--lists-intersect-p
  663. (get-text-property (point) 'invisible)
  664. buffer-invisibility-spec)
  665. (setq go-ahead nil))
  666. (goto-char (point-min))
  667. (setq go-ahead nil))))
  668. (run-hooks 'newsticker-select-item-hook)
  669. (force-mode-line-update)
  670. (point))
  671. (defun newsticker-next-feed ()
  672. "Go to next news feed.
  673. Return new buffer position."
  674. (interactive)
  675. (widen)
  676. (newsticker--buffer-goto '(feed))
  677. (run-hooks 'newsticker-select-feed-hook)
  678. (force-mode-line-update)
  679. (point))
  680. (defun newsticker-previous-feed ()
  681. "Go to previous news feed.
  682. Return new buffer position."
  683. (interactive)
  684. (widen)
  685. (newsticker--buffer-goto '(feed) nil t)
  686. (run-hooks 'newsticker-select-feed-hook)
  687. (force-mode-line-update)
  688. (point))
  689. (defun newsticker-mark-all-items-at-point-as-read-and-redraw ()
  690. "Mark all items as read and clear ticker contents."
  691. (interactive)
  692. (when (or newsticker--buffer-uptodate-p
  693. (y-or-n-p
  694. "Buffer is not up to date -- really mark items as read? "))
  695. (newsticker-mark-all-items-of-feed-as-read
  696. (get-text-property (point) 'feed))))
  697. (defun newsticker-mark-all-items-of-feed-as-read (feed)
  698. "Mark all items of FEED as read, clear ticker, and redraw buffer."
  699. (when feed
  700. (let ((pos (point)))
  701. (message "Marking all items as read for %s" (symbol-name feed))
  702. (newsticker--cache-replace-age newsticker--cache feed 'new 'old)
  703. (newsticker--cache-replace-age newsticker--cache feed 'obsolete
  704. 'old)
  705. (newsticker--cache-update)
  706. (newsticker--buffer-set-uptodate nil)
  707. (newsticker--ticker-text-setup)
  708. (newsticker-buffer-update)
  709. ;; Go back to where we came from.
  710. (goto-char pos)
  711. (end-of-line)
  712. (newsticker--buffer-goto '(feed) nil t))))
  713. (defun newsticker-mark-all-items-at-point-as-read ()
  714. "Mark all items as read and clear ticker contents."
  715. (interactive)
  716. (when (or newsticker--buffer-uptodate-p
  717. (y-or-n-p
  718. "Buffer is not up to date -- really mark items as read? "))
  719. (newsticker--do-mark-item-at-point-as-read t)
  720. (while (newsticker-next-item-same-feed)
  721. (newsticker--do-mark-item-at-point-as-read t))
  722. (newsticker-next-item t)))
  723. (defun newsticker-mark-item-at-point-as-read (&optional respect-immortality)
  724. "Mark item at point as read and move to next item.
  725. If optional argument RESPECT-IMMORTALITY is not nil immortal items do
  726. not get changed."
  727. (interactive)
  728. (when (or newsticker--buffer-uptodate-p
  729. (y-or-n-p
  730. "Buffer is not up to date -- really mark this item as read? "))
  731. (newsticker--do-mark-item-at-point-as-read respect-immortality)
  732. ;; move forward
  733. (newsticker-next-item t)))
  734. (defun newsticker--do-mark-item-at-point-as-read (&optional respect-immortality)
  735. "Mark item at point as read.
  736. If optional argument RESPECT-IMMORTALITY is not nil immortal items do
  737. not get changed."
  738. (let ((feed (get-text-property (point) 'feed)))
  739. (when feed
  740. (save-excursion
  741. (newsticker--buffer-beginning-of-item)
  742. (let ((inhibit-read-only t)
  743. (age (get-text-property (point) 'nt-age))
  744. (title (get-text-property (point) 'nt-title))
  745. (guid (get-text-property (point) 'nt-guid))
  746. (nt-desc (get-text-property (point) 'nt-desc))
  747. (pos (save-excursion (newsticker--buffer-end-of-item)))
  748. item)
  749. (when (or (eq age 'new)
  750. (eq age 'obsolete)
  751. (and (eq age 'immortal)
  752. (not respect-immortality)))
  753. ;; find item
  754. (setq item (newsticker--cache-contains newsticker--cache
  755. feed title nt-desc
  756. nil nil guid))
  757. ;; mark as old
  758. (when item
  759. (setcar (nthcdr 4 item) 'old)
  760. (newsticker--do-forget-preformatted item))
  761. ;; clean up ticker
  762. (if (or (and (eq age 'new)
  763. newsticker-hide-immortal-items-in-echo-area)
  764. (and (memq age '(old immortal))
  765. (not
  766. (eq newsticker-hide-old-items-in-newsticker-buffer
  767. newsticker-hide-immortal-items-in-echo-area))))
  768. (newsticker--ticker-text-remove feed title))
  769. ;; set faces etc.
  770. (save-excursion
  771. (save-restriction
  772. (widen)
  773. (put-text-property (point) pos 'nt-age 'old)
  774. (newsticker--buffer-set-faces (point) pos)))
  775. (set-buffer-modified-p nil)))))))
  776. (defun newsticker-mark-item-at-point-as-immortal ()
  777. "Mark item at point as read."
  778. (interactive)
  779. (when (or newsticker--buffer-uptodate-p
  780. (y-or-n-p
  781. "Buffer is not up to date -- really mark this item as read? "))
  782. (let ((feed (get-text-property (point) 'feed))
  783. (item nil))
  784. (when feed
  785. (save-excursion
  786. (newsticker--buffer-beginning-of-item)
  787. (let ((inhibit-read-only t)
  788. (oldage (get-text-property (point) 'nt-age))
  789. (title (get-text-property (point) 'nt-title))
  790. (guid (get-text-property (point) 'nt-guid))
  791. (pos (save-excursion (newsticker--buffer-end-of-item))))
  792. (let ((newage 'immortal))
  793. (if (eq oldage 'immortal)
  794. (setq newage 'old))
  795. (setq item (newsticker--cache-contains newsticker--cache
  796. feed title nil nil nil
  797. guid))
  798. ;; change age
  799. (when item
  800. (setcar (nthcdr 4 item) newage)
  801. (newsticker--do-forget-preformatted item))
  802. (if (or (and (eq newage 'immortal)
  803. newsticker-hide-immortal-items-in-echo-area)
  804. (and (eq newage 'obsolete)
  805. newsticker-hide-obsolete-items-in-echo-area)
  806. (and (eq oldage 'immortal)
  807. (not
  808. (eq newsticker-hide-old-items-in-newsticker-buffer
  809. newsticker-hide-immortal-items-in-echo-area))))
  810. (newsticker--ticker-text-remove feed title)
  811. (newsticker--ticker-text-setup))
  812. (save-excursion
  813. (save-restriction
  814. (widen)
  815. (put-text-property (point) pos 'nt-age newage)
  816. (if (eq newage 'immortal)
  817. (put-text-property (point) pos 'nt-age 'immortal)
  818. (put-text-property (point) pos 'nt-age 'old))
  819. (newsticker--buffer-set-faces (point) pos))))))
  820. (if item
  821. (newsticker-next-item t))))))
  822. (defun newsticker-mark-all-items-as-read ()
  823. "Mark all items as read and clear ticker contents."
  824. (interactive)
  825. (when (or newsticker--buffer-uptodate-p
  826. (y-or-n-p
  827. "Buffer is not up to date -- really mark items as read? "))
  828. (newsticker--cache-replace-age newsticker--cache 'any 'new 'old)
  829. (newsticker--buffer-set-uptodate nil)
  830. (newsticker--ticker-text-setup)
  831. (newsticker--cache-update)
  832. (newsticker-buffer-update)))
  833. (defun newsticker-hide-extra ()
  834. "Hide the extra elements of items."
  835. (interactive)
  836. (newsticker--buffer-hideshow 'extra nil)
  837. (newsticker--buffer-redraw))
  838. (defun newsticker-show-extra ()
  839. "Show the extra elements of items."
  840. (interactive)
  841. (newsticker--buffer-hideshow 'extra t)
  842. (newsticker--buffer-redraw))
  843. (defun newsticker-hide-old-item-desc ()
  844. "Hide the description of old items."
  845. (interactive)
  846. (newsticker--buffer-hideshow 'desc-old nil)
  847. (newsticker--buffer-redraw))
  848. (defun newsticker-show-old-item-desc ()
  849. "Show the description of old items."
  850. (interactive)
  851. (newsticker--buffer-hideshow 'item-old t)
  852. (newsticker--buffer-hideshow 'desc-old t)
  853. (newsticker--buffer-redraw))
  854. (defun newsticker-hide-new-item-desc ()
  855. "Hide the description of new items."
  856. (interactive)
  857. (newsticker--buffer-hideshow 'desc-new nil)
  858. (newsticker--buffer-hideshow 'desc-immortal nil)
  859. (newsticker--buffer-hideshow 'desc-obsolete nil)
  860. (newsticker--buffer-redraw))
  861. (defun newsticker-show-new-item-desc ()
  862. "Show the description of new items."
  863. (interactive)
  864. (newsticker--buffer-hideshow 'desc-new t)
  865. (newsticker--buffer-hideshow 'desc-immortal t)
  866. (newsticker--buffer-hideshow 'desc-obsolete t)
  867. (newsticker--buffer-redraw))
  868. (defun newsticker-hide-feed-desc ()
  869. "Hide the description of feeds."
  870. (interactive)
  871. (newsticker--buffer-hideshow 'desc-feed nil)
  872. (newsticker--buffer-redraw))
  873. (defun newsticker-show-feed-desc ()
  874. "Show the description of old items."
  875. (interactive)
  876. (newsticker--buffer-hideshow 'desc-feed t)
  877. (newsticker--buffer-redraw))
  878. (defun newsticker-hide-all-desc ()
  879. "Hide the descriptions of feeds and all items."
  880. (interactive)
  881. (newsticker--buffer-hideshow 'desc-feed nil)
  882. (newsticker--buffer-hideshow 'desc-immortal nil)
  883. (newsticker--buffer-hideshow 'desc-obsolete nil)
  884. (newsticker--buffer-hideshow 'desc-new nil)
  885. (newsticker--buffer-hideshow 'desc-old nil)
  886. (newsticker--buffer-redraw))
  887. (defun newsticker-show-all-desc ()
  888. "Show the descriptions of feeds and all items."
  889. (interactive)
  890. (newsticker--buffer-hideshow 'desc-feed t)
  891. (newsticker--buffer-hideshow 'desc-immortal t)
  892. (newsticker--buffer-hideshow 'desc-obsolete t)
  893. (newsticker--buffer-hideshow 'desc-new t)
  894. (newsticker--buffer-hideshow 'desc-old t)
  895. (newsticker--buffer-redraw))
  896. (defun newsticker-hide-old-items ()
  897. "Hide old items."
  898. (interactive)
  899. (newsticker--buffer-hideshow 'desc-old nil)
  900. (newsticker--buffer-hideshow 'item-old nil)
  901. (newsticker--buffer-redraw))
  902. (defun newsticker-show-old-items ()
  903. "Show old items."
  904. (interactive)
  905. (newsticker--buffer-hideshow 'item-old t)
  906. (newsticker--buffer-redraw))
  907. (defun newsticker-hide-entry ()
  908. "Hide description of entry at point."
  909. (interactive)
  910. (save-excursion
  911. (let* (pos1 pos2
  912. (inhibit-read-only t)
  913. inv-prop org-inv-prop
  914. is-invisible)
  915. (newsticker--buffer-beginning-of-item)
  916. (newsticker--buffer-goto '(desc))
  917. (setq pos1 (max (point-min) (1- (point))))
  918. (newsticker--buffer-goto '(extra feed item nil))
  919. (setq pos2 (max (point-min) (1- (point))))
  920. (setq inv-prop (get-text-property pos1 'invisible))
  921. (setq org-inv-prop (get-text-property pos1 'org-invisible))
  922. (cond ((eq inv-prop t)
  923. ;; do nothing
  924. )
  925. ((eq org-inv-prop nil)
  926. (add-text-properties pos1 pos2
  927. (list 'invisible (list t)
  928. 'org-invisible inv-prop)))
  929. (t
  930. ;; toggle
  931. (add-text-properties pos1 pos2
  932. (list 'invisible org-inv-prop))
  933. (remove-text-properties pos1 pos2 '(org-invisible))))))
  934. (newsticker--buffer-redraw))
  935. (defun newsticker-show-entry ()
  936. "Show description of entry at point."
  937. (interactive)
  938. (save-excursion
  939. (let* (pos1 pos2
  940. (inhibit-read-only t)
  941. inv-prop org-inv-prop
  942. is-invisible)
  943. (newsticker--buffer-beginning-of-item)
  944. (newsticker--buffer-goto '(desc))
  945. (setq pos1 (max (point-min) (1- (point))))
  946. (newsticker--buffer-goto '(extra feed item))
  947. (setq pos2 (max (point-min) (1- (point))))
  948. (setq inv-prop (get-text-property pos1 'invisible))
  949. (setq org-inv-prop (get-text-property pos1 'org-invisible))
  950. (cond ((eq org-inv-prop nil)
  951. (add-text-properties pos1 pos2
  952. (list 'invisible nil
  953. 'org-invisible inv-prop)))
  954. (t
  955. ;; toggle
  956. (add-text-properties pos1 pos2
  957. (list 'invisible org-inv-prop))
  958. (remove-text-properties pos1 pos2 '(org-invisible))))))
  959. (newsticker--buffer-redraw))
  960. (defun newsticker-toggle-auto-narrow-to-feed ()
  961. "Toggle narrowing to current news feed.
  962. If auto-narrowing is active, only news item of the current feed
  963. are visible."
  964. (interactive)
  965. (newsticker-set-auto-narrow-to-feed
  966. (not newsticker--auto-narrow-to-feed)))
  967. (defun newsticker-set-auto-narrow-to-feed (value)
  968. "Turn narrowing to current news feed on or off.
  969. If VALUE is nil, auto-narrowing is turned off, otherwise it is turned on."
  970. (interactive)
  971. (setq newsticker--auto-narrow-to-item nil)
  972. (setq newsticker--auto-narrow-to-feed value)
  973. (widen)
  974. (newsticker--buffer-make-item-completely-visible)
  975. (run-hooks 'newsticker-narrow-hook))
  976. (defun newsticker-toggle-auto-narrow-to-item ()
  977. "Toggle narrowing to current news item.
  978. If auto-narrowing is active, only one item of the current feed
  979. is visible."
  980. (interactive)
  981. (newsticker-set-auto-narrow-to-item
  982. (not newsticker--auto-narrow-to-item)))
  983. (defun newsticker-set-auto-narrow-to-item (value)
  984. "Turn narrowing to current news item on or off.
  985. If VALUE is nil, auto-narrowing is turned off, otherwise it is turned on."
  986. (interactive)
  987. (setq newsticker--auto-narrow-to-feed nil)
  988. (setq newsticker--auto-narrow-to-item value)
  989. (widen)
  990. (newsticker--buffer-make-item-completely-visible)
  991. (run-hooks 'newsticker-narrow-hook))
  992. (defun newsticker-next-feed-available-p ()
  993. "Return t if position is before last feed, nil otherwise."
  994. (save-excursion
  995. (let ((p (point)))
  996. (newsticker--buffer-goto '(feed))
  997. (not (= p (point))))))
  998. (defun newsticker-previous-feed-available-p ()
  999. "Return t if position is behind first feed, nil otherwise."
  1000. (save-excursion
  1001. (let ((p (point)))
  1002. (newsticker--buffer-goto '(feed) nil t)
  1003. (not (= p (point))))))
  1004. (defun newsticker-next-item-available-p ()
  1005. "Return t if position is before last feed, nil otherwise."
  1006. (save-excursion
  1007. (catch 'result
  1008. (while (< (point) (point-max))
  1009. (unless (newsticker--buffer-goto '(item))
  1010. (throw 'result nil))
  1011. (unless (newsticker--lists-intersect-p
  1012. (get-text-property (point) 'invisible)
  1013. buffer-invisibility-spec)
  1014. (throw 'result t))))))
  1015. (defun newsticker-previous-item-available-p ()
  1016. "Return t if position is behind first item, nil otherwise."
  1017. (save-excursion
  1018. (catch 'result
  1019. (while (> (point) (point-min))
  1020. (unless (newsticker--buffer-goto '(item) nil t)
  1021. (throw 'result nil))
  1022. (unless (newsticker--lists-intersect-p
  1023. (get-text-property (point) 'invisible)
  1024. buffer-invisibility-spec)
  1025. (throw 'result t))))))
  1026. (defun newsticker-item-not-old-p ()
  1027. "Return t if there is an item at point which is not old, nil otherwise."
  1028. (when (get-text-property (point) 'feed)
  1029. (save-excursion
  1030. (newsticker--buffer-beginning-of-item)
  1031. (let ((age (get-text-property (point) 'nt-age)))
  1032. (and (memq age '(new immortal obsolete)) t)))))
  1033. (defun newsticker-item-not-immortal-p ()
  1034. "Return t if there is an item at point which is not immortal, nil otherwise."
  1035. (when (get-text-property (point) 'feed)
  1036. (save-excursion
  1037. (newsticker--buffer-beginning-of-item)
  1038. (let ((age (get-text-property (point) 'nt-age)))
  1039. (and (memq age '(new old obsolete)) t)))))
  1040. ;; ======================================================================
  1041. ;;; Imenu stuff
  1042. ;; ======================================================================
  1043. (defun newsticker--imenu-create-index ()
  1044. "Scan newsticker buffer and return an index for imenu."
  1045. (save-excursion
  1046. (goto-char (point-min))
  1047. (let ((index-alist nil)
  1048. (feed-list nil)
  1049. (go-ahead t))
  1050. (while go-ahead
  1051. (let ((type (get-text-property (point) 'nt-type))
  1052. (title (get-text-property (point) 'nt-title)))
  1053. (cond ((eq type 'feed)
  1054. ;; we're on a feed heading
  1055. (when feed-list
  1056. (if index-alist
  1057. (nconc index-alist (list feed-list))
  1058. (setq index-alist (list feed-list))))
  1059. (setq feed-list (list title)))
  1060. (t
  1061. (nconc feed-list
  1062. (list (cons title (point)))))))
  1063. (setq go-ahead (newsticker--buffer-goto '(item feed))))
  1064. (if index-alist
  1065. (nconc index-alist (list feed-list))
  1066. (setq index-alist (list feed-list)))
  1067. index-alist)))
  1068. (defun newsticker--imenu-goto (name pos &rest args)
  1069. "Go to item NAME at position POS and show item.
  1070. ARGS are ignored."
  1071. (goto-char pos)
  1072. ;; show headline
  1073. (newsticker--buffer-goto '(desc extra feed item))
  1074. (let* ((inhibit-read-only t)
  1075. (pos1 (max (point-min) (1- pos)))
  1076. (pos2 (max pos1 (1- (point))))
  1077. (inv-prop (get-text-property pos 'invisible))
  1078. (org-inv-prop (get-text-property pos 'org-invisible)))
  1079. (when (eq org-inv-prop nil)
  1080. (add-text-properties pos1 pos2 (list 'invisible nil
  1081. 'org-invisible inv-prop))))
  1082. ;; show desc
  1083. (newsticker-show-entry))
  1084. ;; ======================================================================
  1085. ;;; Buffer stuff
  1086. ;; ======================================================================
  1087. (defun newsticker--buffer-set-uptodate (value)
  1088. "Set the uptodate-status of the newsticker buffer to VALUE.
  1089. The mode-line is changed accordingly."
  1090. (setq newsticker--buffer-uptodate-p value)
  1091. (let ((b (get-buffer "*newsticker*")))
  1092. (when b
  1093. (with-current-buffer b
  1094. (setq mode-name (if value
  1095. "Newsticker -- up to date -- "
  1096. "Newsticker -- NEED UPDATE -- ")))
  1097. (force-mode-line-update 0))))
  1098. (defun newsticker--buffer-redraw ()
  1099. "Redraw the newsticker window."
  1100. (if (fboundp 'force-window-update)
  1101. (force-window-update (current-buffer))
  1102. (redraw-frame (selected-frame)))
  1103. (run-hooks 'newsticker-buffer-change-hook)
  1104. (sit-for 0))
  1105. (defun newsticker--buffer-insert-all-items ()
  1106. "Insert all cached newsticker items into the current buffer.
  1107. Keeps order of feeds as given in `newsticker-url-list' and
  1108. `newsticker-url-list-defaults'."
  1109. (goto-char (point-min))
  1110. (mapc (lambda (url-item)
  1111. (let* ((feed-name (car url-item))
  1112. (feed-name-symbol (intern feed-name))
  1113. (feed (assoc feed-name-symbol newsticker--cache))
  1114. (items (cdr feed))
  1115. (pos (point)))
  1116. (when feed
  1117. ;; insert the feed description
  1118. (mapc (lambda (item)
  1119. (when (eq (newsticker--age item) 'feed)
  1120. (newsticker--buffer-insert-item item
  1121. feed-name-symbol)))
  1122. items)
  1123. ;;insert the items
  1124. (mapc (lambda (item)
  1125. (if (memq (newsticker--age item) '(new immortal old
  1126. obsolete))
  1127. (newsticker--buffer-insert-item item
  1128. feed-name-symbol)))
  1129. items)
  1130. (put-text-property pos (point) 'feed (car feed))
  1131. ;; insert empty line between feeds
  1132. (let ((p (point)))
  1133. (insert "\n")
  1134. (put-text-property p (point) 'hard t)))))
  1135. (append newsticker-url-list newsticker-url-list-defaults))
  1136. (newsticker--buffer-set-faces (point-min) (point-max))
  1137. (newsticker--buffer-set-invisibility (point-min) (point-max))
  1138. (goto-char (point-min)))
  1139. (defun newsticker--buffer-insert-item (item &optional feed-name-symbol)
  1140. "Insert a news item in the current buffer.
  1141. Insert a formatted representation of the ITEM. The optional parameter
  1142. FEED-NAME-SYMBOL determines how the item is formatted and whether the
  1143. item-retrieval time is added as well."
  1144. ;; insert headline
  1145. (if (eq (newsticker--age item) 'feed)
  1146. (newsticker--buffer-do-insert-text item 'feed feed-name-symbol)
  1147. (newsticker--buffer-do-insert-text item 'item feed-name-symbol))
  1148. ;; insert the description
  1149. (newsticker--buffer-do-insert-text item 'desc feed-name-symbol))
  1150. (defun newsticker--buffer-do-insert-text (item type feed-name-symbol)
  1151. "Actually insert contents of news item, format it, render it and all that.
  1152. ITEM is a news item, TYPE tells which part of the item shall be inserted,
  1153. FEED-NAME-SYMBOL tells to which feed this item belongs."
  1154. (let* ((pos (point))
  1155. (format newsticker-desc-format)
  1156. (pos-date-start nil)
  1157. (pos-date-end nil)
  1158. (pos-stat-start nil)
  1159. (pos-stat-end nil)
  1160. (pos-text-start nil)
  1161. (pos-text-end nil)
  1162. (pos-extra-start nil)
  1163. (pos-extra-end nil)
  1164. (pos-enclosure-start nil)
  1165. (pos-enclosure-end nil)
  1166. (age (newsticker--age item))
  1167. (preformatted-contents (newsticker--preformatted-contents item))
  1168. (preformatted-title (newsticker--preformatted-title item)))
  1169. (cond ((and preformatted-contents
  1170. (not (eq (aref preformatted-contents 0) ?\n));; we must
  1171. ;; NOT have a line
  1172. ;; break!
  1173. (eq type 'desc))
  1174. (insert preformatted-contents))
  1175. ((and preformatted-title
  1176. (not (eq (aref preformatted-title 0) ?\n));; we must NOT have a
  1177. ;; line break!
  1178. (eq type 'item))
  1179. (insert preformatted-title))
  1180. (t
  1181. ;; item was not formatted before.
  1182. ;; Let's go.
  1183. (if (eq type 'item)
  1184. (setq format newsticker-item-format)
  1185. (if (eq type 'feed)
  1186. (setq format newsticker-heading-format)))
  1187. (while (> (length format) 0)
  1188. (let ((prefix (if (> (length format) 1)
  1189. (substring format 0 2)
  1190. "")))
  1191. (cond ((string= "%c" prefix)
  1192. ;; contents
  1193. (when (newsticker--desc item)
  1194. (setq pos-text-start (point-marker))
  1195. (insert (newsticker--desc item))
  1196. (setq pos-text-end (point-marker)))
  1197. (setq format (substring format 2)))
  1198. ((string= "%d" prefix)
  1199. ;; date
  1200. (setq pos-date-start (point-marker))
  1201. (if (newsticker--time item)
  1202. (insert (format-time-string newsticker-date-format
  1203. (newsticker--time item))))
  1204. (setq pos-date-end (point-marker))
  1205. (setq format (substring format 2)))
  1206. ((string= "%l" prefix)
  1207. ;; logo
  1208. (let ((disabled (cond ((eq (newsticker--age item) 'feed)
  1209. (= (newsticker--stat-num-items
  1210. feed-name-symbol 'new) 0))
  1211. (t
  1212. (not (eq (newsticker--age item)
  1213. 'new))))))
  1214. (let ((img (newsticker--image-read feed-name-symbol
  1215. disabled)))
  1216. (when img
  1217. (newsticker--insert-image img (car item)))))
  1218. (setq format (substring format 2)))
  1219. ((string= "%L" prefix)
  1220. ;; logo or title
  1221. (let ((disabled (cond ((eq (newsticker--age item) 'feed)
  1222. (= (newsticker--stat-num-items
  1223. feed-name-symbol 'new) 0))
  1224. (t
  1225. (not (eq (newsticker--age item)
  1226. 'new))))))
  1227. (let ((img (newsticker--image-read feed-name-symbol
  1228. disabled)))
  1229. (if img
  1230. (newsticker--insert-image img (car item))
  1231. (when (car item)
  1232. (setq pos-text-start (point-marker))
  1233. (if (eq (newsticker--age item) 'feed)
  1234. (insert (newsticker--title item))
  1235. ;; FIXME: This is not the "real" title!
  1236. (insert (format "%s"
  1237. (car (newsticker--cache-get-feed
  1238. feed-name-symbol)))))
  1239. (setq pos-text-end (point-marker))))))
  1240. (setq format (substring format 2)))
  1241. ((string= "%s" prefix)
  1242. ;; statistics
  1243. (setq pos-stat-start (point-marker))
  1244. (if (eq (newsticker--age item) 'feed)
  1245. (insert (newsticker--buffer-statistics
  1246. feed-name-symbol)))
  1247. (setq pos-stat-end (point-marker))
  1248. (setq format (substring format 2)))
  1249. ((string= "%t" prefix)
  1250. ;; title
  1251. (when (car item)
  1252. (setq pos-text-start (point-marker))
  1253. (insert (car item))
  1254. (setq pos-text-end (point-marker)))
  1255. (setq format (substring format 2)))
  1256. ((string-match "%." prefix)
  1257. ;; unknown specifier!
  1258. (insert prefix)
  1259. (setq format (substring format 2)))
  1260. ((string-match "^\\([^%]*\\)\\(.*\\)" format) ;; FIXME!
  1261. ;; everything else
  1262. (let ((p (point)))
  1263. (insert (substring format
  1264. (match-beginning 1) (match-end 1)))
  1265. ;; in case that the format string contained newlines
  1266. (put-text-property p (point) 'hard t))
  1267. (setq format (substring format (match-beginning 2)))))))
  1268. ;; decode HTML if possible...
  1269. (let ((is-rendered-HTML nil))
  1270. (when (and newsticker-html-renderer pos-text-start pos-text-end)
  1271. (condition-case error-data
  1272. (save-excursion
  1273. ;; check whether it is necessary to call html renderer
  1274. ;; (regexp inspired by htmlr.el)
  1275. (goto-char pos-text-start)
  1276. (when (re-search-forward
  1277. "</?[A-Za-z1-6]*\\|&#?[A-Za-z0-9]+;" pos-text-end t)
  1278. ;; (message "%s" (newsticker--title item))
  1279. (let ((w3m-fill-column (if newsticker-use-full-width
  1280. -1 fill-column))
  1281. (w3-maximum-line-length
  1282. (if newsticker-use-full-width nil fill-column)))
  1283. (save-excursion
  1284. (funcall newsticker-html-renderer pos-text-start
  1285. pos-text-end)))
  1286. (cond ((eq newsticker-html-renderer 'w3m-region)
  1287. (add-text-properties pos (point-max)
  1288. (list 'keymap
  1289. w3m-minor-mode-map)))
  1290. ((eq newsticker-html-renderer 'w3-region)
  1291. (add-text-properties pos (point-max)
  1292. (list 'keymap w3-mode-map))))
  1293. (setq is-rendered-HTML t)))
  1294. (error
  1295. (message "Error: HTML rendering failed: %s, %s"
  1296. (car error-data) (cdr error-data)))))
  1297. ;; After html rendering there might be chunks of blank
  1298. ;; characters between rendered text and date, statistics or
  1299. ;; whatever. Remove it
  1300. (when (and (eq type 'item) is-rendered-HTML)
  1301. (goto-char pos)
  1302. (while (re-search-forward "[ \t]*\n[ \t]*" nil t)
  1303. (replace-match " " nil nil))
  1304. (goto-char (point-max)))
  1305. (when (and newsticker-justification
  1306. (memq type '(item desc))
  1307. (not is-rendered-HTML))
  1308. (condition-case nil
  1309. (let ((use-hard-newlines t))
  1310. (fill-region pos (point-max) newsticker-justification))
  1311. (error nil))))
  1312. ;; remove leading and trailing newlines
  1313. (goto-char pos)
  1314. (unless (= 0 (skip-chars-forward " \t\r\n"))
  1315. (delete-region pos (point)))
  1316. (goto-char (point-max))
  1317. (let ((end (point)))
  1318. (unless (= 0 (skip-chars-backward " \t\r\n" (1+ pos)))
  1319. (delete-region (point) end)))
  1320. (goto-char (point-max))
  1321. ;; closing newline
  1322. (unless nil ;;(eq pos (point))
  1323. (insert "\n")
  1324. (put-text-property (1- (point)) (point) 'hard t))
  1325. ;; insert enclosure element
  1326. (when (eq type 'desc)
  1327. (setq pos-enclosure-start (point))
  1328. (newsticker--insert-enclosure item newsticker--url-keymap)
  1329. (setq pos-enclosure-end (point)))
  1330. ;; show extra elements
  1331. (when (eq type 'desc)
  1332. (goto-char (point-max))
  1333. (setq pos-extra-start (point))
  1334. (newsticker--print-extra-elements item newsticker--url-keymap)
  1335. (setq pos-extra-end (point)))
  1336. ;; text properties
  1337. (when (memq type '(feed item))
  1338. (add-text-properties pos (1- (point))
  1339. (list 'mouse-face 'highlight
  1340. 'nt-link (newsticker--link item)
  1341. 'help-echo
  1342. (format "mouse-2: visit item (%s)"
  1343. (newsticker--link item))
  1344. 'keymap newsticker--url-keymap))
  1345. (add-text-properties pos (point)
  1346. (list 'nt-title (newsticker--title item)
  1347. 'nt-desc (newsticker--desc item))))
  1348. (add-text-properties pos (point)
  1349. (list 'nt-type type
  1350. 'nt-face type
  1351. 'nt-age age
  1352. 'nt-guid (newsticker--guid item)))
  1353. (when (and pos-date-start pos-date-end)
  1354. (put-text-property pos-date-start pos-date-end 'nt-face 'date))
  1355. (when (and pos-stat-start pos-stat-end)
  1356. (put-text-property pos-stat-start pos-stat-end 'nt-face 'stat))
  1357. (when (and pos-extra-start pos-extra-end)
  1358. (put-text-property pos-extra-start pos-extra-end
  1359. 'nt-face 'extra)
  1360. (put-text-property pos-extra-start pos-extra-end
  1361. 'nt-type 'extra))
  1362. (when (and pos-enclosure-start pos-enclosure-end
  1363. (> pos-enclosure-end pos-enclosure-start))
  1364. (put-text-property pos-enclosure-start (1- pos-enclosure-end)
  1365. 'nt-face 'enclosure))
  1366. ;; left margin
  1367. ;;(unless (memq type '(feed item))
  1368. ;;(set-left-margin pos (1- (point)) 1))
  1369. ;; save rendered stuff
  1370. (cond ((eq type 'desc)
  1371. ;; preformatted contents
  1372. (newsticker--cache-set-preformatted-contents
  1373. item (buffer-substring pos (point))))
  1374. ((eq type 'item)
  1375. ;; preformatted title
  1376. (newsticker--cache-set-preformatted-title
  1377. item (buffer-substring pos (point)))))))))
  1378. (defun newsticker--buffer-statistics (feed-name-symbol)
  1379. "Return a statistic string for the feed given by FEED-NAME-SYMBOL.
  1380. See `newsticker-statistics-format'."
  1381. (let ((case-fold-search nil))
  1382. (replace-regexp-in-string
  1383. "%a"
  1384. (format "%d" (newsticker--stat-num-items feed-name-symbol))
  1385. (replace-regexp-in-string
  1386. "%i"
  1387. (format "%d" (newsticker--stat-num-items feed-name-symbol 'immortal))
  1388. (replace-regexp-in-string
  1389. "%n"
  1390. (format "%d" (newsticker--stat-num-items feed-name-symbol 'new))
  1391. (replace-regexp-in-string
  1392. "%o"
  1393. (format "%d" (newsticker--stat-num-items feed-name-symbol 'old))
  1394. (replace-regexp-in-string
  1395. "%O"
  1396. (format "%d" (newsticker--stat-num-items feed-name-symbol 'obsolete))
  1397. newsticker-statistics-format)))))))
  1398. (defun newsticker--buffer-set-faces (start end)
  1399. "Add face properties according to mark property.
  1400. Scans the buffer between START and END."
  1401. (save-excursion
  1402. (put-text-property start end 'face 'newsticker-default-face)
  1403. (goto-char start)
  1404. (let ((pos1 start)
  1405. (pos2 1)
  1406. (nt-face (get-text-property start 'nt-face))
  1407. (nt-age (get-text-property start 'nt-age)))
  1408. (when nt-face
  1409. (setq pos2 (next-single-property-change (point) 'nt-face))
  1410. (newsticker--set-face-properties pos1 pos2 nt-face nt-age)
  1411. (setq nt-face (get-text-property pos2 'nt-face))
  1412. (setq pos1 pos2))
  1413. (while (and (setq pos2 (next-single-property-change pos1 'nt-face))
  1414. (<= pos2 end)
  1415. (> pos2 pos1))
  1416. (newsticker--set-face-properties pos1 pos2 nt-face nt-age)
  1417. (setq nt-face (get-text-property pos2 'nt-face))
  1418. (setq nt-age (get-text-property pos2 'nt-age))
  1419. (setq pos1 pos2)))))
  1420. (defun newsticker--buffer-set-invisibility (start end)
  1421. "Add invisibility properties according to nt-type property.
  1422. Scans the buffer between START and END. Sets the 'invisible
  1423. property to '(<nt-type>-<nt-age> <nt-type> <nt-age>)."
  1424. (save-excursion
  1425. ;; reset invisibility settings
  1426. (put-text-property start end 'invisible nil)
  1427. ;; let's go
  1428. (goto-char start)
  1429. (let ((pos1 start)
  1430. (pos2 1)
  1431. (nt-type (get-text-property start 'nt-type))
  1432. (nt-age (get-text-property start 'nt-age)))
  1433. (when nt-type
  1434. (setq pos2 (next-single-property-change (point) 'nt-type))
  1435. (put-text-property (max (point-min) pos1) (1- pos2)
  1436. 'invisible
  1437. (list (intern
  1438. (concat
  1439. (symbol-name
  1440. (if (eq nt-type 'extra) 'desc nt-type))
  1441. "-"
  1442. (symbol-name nt-age)))
  1443. nt-type
  1444. nt-age))
  1445. (setq nt-type (get-text-property pos2 'nt-type))
  1446. (setq pos1 pos2))
  1447. (while (and (setq pos2 (next-single-property-change pos1 'nt-type))
  1448. (<= pos2 end)
  1449. (> pos2 pos1))
  1450. ;; must shift one char to the left in order to handle invisible
  1451. ;; newlines, motion in invisible text areas and all that correctly
  1452. (put-text-property (1- pos1) (1- pos2)
  1453. 'invisible
  1454. (list (intern
  1455. (concat
  1456. (symbol-name
  1457. (if (eq nt-type 'extra) 'desc nt-type))
  1458. "-"
  1459. (symbol-name nt-age)))
  1460. nt-type
  1461. nt-age))
  1462. (setq nt-type (get-text-property pos2 'nt-type))
  1463. (setq nt-age (get-text-property pos2 'nt-age))
  1464. (setq pos1 pos2)))))
  1465. (defun newsticker--set-face-properties (pos1 pos2 nt-face age)
  1466. "Set the face for the text between the positions POS1 and POS2.
  1467. The face is chosen according the values of NT-FACE and AGE."
  1468. (let ((face (cond ((eq nt-face 'feed)
  1469. 'newsticker-feed-face)
  1470. ((eq nt-face 'item)
  1471. (cond ((eq age 'new)
  1472. 'newsticker-new-item-face)
  1473. ((eq age 'old)
  1474. 'newsticker-old-item-face)
  1475. ((eq age 'immortal)
  1476. 'newsticker-immortal-item-face)
  1477. ((eq age 'obsolete)
  1478. 'newsticker-obsolete-item-face)))
  1479. ((eq nt-face 'date)
  1480. 'newsticker-date-face)
  1481. ((eq nt-face 'stat)
  1482. 'newsticker-statistics-face)
  1483. ((eq nt-face 'extra)
  1484. 'newsticker-extra-face)
  1485. ((eq nt-face 'enclosure)
  1486. 'newsticker-enclosure-face))))
  1487. (when face
  1488. (put-text-property pos1 (max pos1 pos2) 'face face))))
  1489. ;; ======================================================================
  1490. ;;; Functions working on the *newsticker* buffer
  1491. ;; ======================================================================
  1492. (defun newsticker--buffer-make-item-completely-visible ()
  1493. "Scroll buffer until current item is completely visible."
  1494. (when newsticker--auto-narrow-to-feed
  1495. (let* ((min (or (save-excursion (newsticker--buffer-beginning-of-feed))
  1496. (point-min)))
  1497. (max (or (save-excursion (newsticker--buffer-end-of-feed))
  1498. (point-max))))
  1499. (narrow-to-region min max)))
  1500. (when newsticker--auto-narrow-to-item
  1501. (let* ((min (or (save-excursion (newsticker--buffer-beginning-of-item))
  1502. (point-min)))
  1503. (max (or (save-excursion (newsticker--buffer-end-of-item))
  1504. (point-max))))
  1505. (narrow-to-region min max)))
  1506. (sit-for 0)
  1507. ;; do not count lines and stuff because that does not work when images
  1508. ;; are displayed. Do it the simple way:
  1509. (save-excursion
  1510. (newsticker--buffer-end-of-item)
  1511. (unless (pos-visible-in-window-p)
  1512. (recenter -1)))
  1513. (unless (pos-visible-in-window-p)
  1514. (recenter 0)))
  1515. (defun newsticker--buffer-get-feed-title-at-point ()
  1516. "Return feed symbol of headline at point."
  1517. (format "%s" (or (get-text-property (point) 'feed) " ")))
  1518. (defun newsticker--buffer-get-item-title-at-point ()
  1519. "Return feed symbol of headline at point."
  1520. (format "%s" (or (get-text-property (point) 'nt-title) " ")))
  1521. (defun newsticker--buffer-goto (types &optional age backwards)
  1522. "Search next occurrence of TYPES in current buffer.
  1523. TYPES is a list of symbols. If TYPES is found point is moved, if
  1524. not point is left unchanged. If optional parameter AGE is not
  1525. nil, the type AND the age must match. If BACKWARDS is t, search
  1526. backwards."
  1527. (let ((pos (save-excursion
  1528. (save-restriction
  1529. (widen)
  1530. (catch 'found
  1531. (let ((tpos (point)))
  1532. (while (setq tpos
  1533. (if backwards
  1534. (if (eq tpos (point-min))
  1535. nil
  1536. (or (previous-single-property-change
  1537. tpos 'nt-type)
  1538. (point-min)))
  1539. (next-single-property-change
  1540. tpos 'nt-type)))
  1541. (and (memq (get-text-property tpos 'nt-type) types)
  1542. (or (not age)
  1543. (eq (get-text-property tpos 'nt-age) age))
  1544. (throw 'found tpos)))))))))
  1545. (when pos
  1546. (goto-char pos))
  1547. pos))
  1548. (defun newsticker--buffer-hideshow (mark-age onoff)
  1549. "Hide or show items of type MARK-AGE.
  1550. If ONOFF is nil the item is hidden, otherwise it is shown."
  1551. (if onoff
  1552. (remove-from-invisibility-spec mark-age)
  1553. (add-to-invisibility-spec mark-age)))
  1554. (defun newsticker--buffer-beginning-of-item ()
  1555. "Move point to the beginning of the item at point.
  1556. Return new position."
  1557. (if (bobp)
  1558. (point)
  1559. (let ((type (get-text-property (point) 'nt-type))
  1560. (typebefore (get-text-property (1- (point)) 'nt-type)))
  1561. (if (and (memq type '(item feed))
  1562. (not (eq type typebefore)))
  1563. (point)
  1564. (newsticker--buffer-goto '(item feed) nil t)
  1565. (point)))))
  1566. (defun newsticker--buffer-beginning-of-feed ()
  1567. "Move point to the beginning of the feed at point.
  1568. Return new position."
  1569. (if (bobp)
  1570. (point)
  1571. (let ((type (get-text-property (point) 'nt-type))
  1572. (typebefore (get-text-property (1- (point)) 'nt-type)))
  1573. (if (and (memq type '(feed))
  1574. (not (eq type typebefore)))
  1575. (point)
  1576. (newsticker--buffer-goto '(feed) nil t)
  1577. (point)))))
  1578. (defun newsticker--buffer-end-of-item ()
  1579. "Move point to the end of the item at point.
  1580. Take care: end of item is at the end of its last line!"
  1581. (when (newsticker--buffer-goto '(item feed nil))
  1582. (point)))
  1583. (defun newsticker--buffer-end-of-feed ()
  1584. "Move point to the end of the last item of the feed at point.
  1585. Take care: end of item is at the end of its last line!"
  1586. (when (newsticker--buffer-goto '(feed nil))
  1587. (backward-char 1)
  1588. (point)))
  1589. ;; ======================================================================
  1590. ;;; misc
  1591. ;; ======================================================================
  1592. (defun newsticker-mouse-browse-url (event)
  1593. "Call `browse-url' for the link of the item at which the EVENT occurred."
  1594. (interactive "e")
  1595. (save-excursion
  1596. (switch-to-buffer (window-buffer (posn-window (event-end event))))
  1597. (let ((url (get-text-property (posn-point (event-end event))
  1598. 'nt-link)))
  1599. (when url
  1600. (browse-url url)
  1601. (save-excursion
  1602. (goto-char (posn-point (event-end event)))
  1603. (if newsticker-automatically-mark-visited-items-as-old
  1604. (newsticker-mark-item-at-point-as-read t)))))))
  1605. (defun newsticker-browse-url ()
  1606. "Call `browse-url' for the link of the item at point."
  1607. (interactive)
  1608. (let ((url (get-text-property (point) 'nt-link)))
  1609. (when url
  1610. (browse-url url)
  1611. (if newsticker-automatically-mark-visited-items-as-old
  1612. (newsticker-mark-item-at-point-as-read t)))))
  1613. (defvar newsticker-open-url-history
  1614. '("wget" "xmms" "realplay")
  1615. "...")
  1616. (defun newsticker-handle-url ()
  1617. "Ask for a program to open the link of the item at point."
  1618. (interactive)
  1619. (let ((url (get-text-property (point) 'nt-link)))
  1620. (when url
  1621. (let ((prog (read-string "Open url with: " nil
  1622. 'newsticker-open-url-history)))
  1623. (when prog
  1624. (message "%s %s" prog url)
  1625. (start-process prog prog prog url)
  1626. (if newsticker-automatically-mark-visited-items-as-old
  1627. (newsticker-mark-item-at-point-as-read t)))))))
  1628. ;; ======================================================================
  1629. ;;; Misc
  1630. ;; ======================================================================
  1631. (defun newsticker--cache-sort ()
  1632. "Sort the newsticker cache data."
  1633. (let ((sort-fun (cond ((eq newsticker-sort-method 'sort-by-time)
  1634. 'newsticker--cache-item-compare-by-time)
  1635. ((eq newsticker-sort-method 'sort-by-title)
  1636. 'newsticker--cache-item-compare-by-title)
  1637. ((eq newsticker-sort-method 'sort-by-original-order)
  1638. 'newsticker--cache-item-compare-by-position))))
  1639. (mapc (lambda (feed-list)
  1640. (setcdr feed-list (sort (cdr feed-list)
  1641. sort-fun)))
  1642. newsticker--cache)))
  1643. (provide 'newst-plainview)
  1644. ;;; newst-plainview.el ends here