Reset media/current-information when the song terminates (or if there is a player...
[elisp.git] / text-counters.el
1 ;; -*- mode: Emacs-Lisp; mode: rainbow; -*-
2
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 ;; This program is free software; you can redistribute it and/or         ;;
5 ;; modify it under the terms of the GNU General Public License as        ;;
6 ;; published by the Free Software Foundation; either version 3, or (at   ;;
7 ;; your option) any later version.                                       ;;
8 ;;                                                                       ;;
9 ;; This program is distributed in the hope that it will be useful, but   ;;
10 ;; WITHOUT ANY WARRANTY; without even the implied warranty of            ;;
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      ;;
12 ;; General Public License for more details.                              ;;
13 ;;                                                                       ;;
14 ;; You should have received a copy of the GNU General Public License     ;;
15 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.  ;;
16 ;;                                                                       ;;
17 ;; Written by and Copyright (C) Francois Fleuret                         ;;
18 ;; Contact <francois@fleuret.org> for comments & bug reports             ;;
19 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20
21 (defface tc/modeline-face
22   '((((background light)) (:foreground "blue4"))
23     (((background dark)) (:foreground "cyan")))
24   "The face for the alarm-vc modeline message.")
25
26 ;; Counts the number of words and characters between the previous and
27 ;; the next line of '-' (with at least four '-' in each line)
28
29 (defun tc/text-counters-string () (interactive)
30   (let ((a (save-excursion
31              (and (re-search-backward "^--.*--*$" nil t)
32                   (match-end 0))))
33         (b (save-excursion
34              (and (re-search-forward "^--.*--*$" nil t)
35                   (match-beginning 0)))))
36
37     (when (and a b)
38       (propertize (format "%dw %dc " (count-words a b) (- b a))
39                   'face 'tc/modeline-face)
40       )))
41
42 ;; Add the said counters into the modeline
43
44 (defun tc/add-text-counters-in-modeline () (interactive)
45   (add-to-list 'mode-line-buffer-identification '(:eval (tc/text-counters-string)))
46   )