Fixed an ugly bug when there are encoding problems with the ICE media infos.
[elisp.git] / emacs.el
index eb01f9b..ac9782c 100644 (file)
--- a/emacs.el
+++ b/emacs.el
 ;; Xft.antialias: true
 ;; Xft.rgba: rgb
 
-;; (set-default-font "Bitstream vera sans mono-12")
+;; (set-default-font "Inconsolata 15")
+
+(set-default-font "Bitstream vera sans mono-12")
 ;; (set-default-font "Liberation Mono-13")
-(set-default-font "Inconsolata 15")
-;;(set-default-font "DejaVu sans mono 11")
-;;(set-default-font "Droid sans mono 13")
-;;(set-default-font "Opensans 10")
+;; (set-default-font "DejaVu sans mono 15")
+;; (set-default-font "Droid sans mono 13")
+;; (set-default-font "Opensans 10")
 
 (when (fboundp 'horizontal-scroll-bar-mode)
   (horizontal-scroll-bar-mode -1))
@@ -328,6 +329,8 @@ load-warning buffer in case of failure."
 ;; What modes for what file extentions
 (add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
 
+(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
+
 (require 'org-table)
 
 (add-to-list 'auto-mode-alist '("\\.txt\\'" . (lambda()
@@ -337,6 +340,7 @@ load-warning buffer in case of failure."
                                                 (flyspell-mode))))
 
 (add-hook 'c++-mode-hook 'flyspell-prog-mode)
+(add-hook 'lua-mode-hook 'flyspell-prog-mode)
 (add-hook 'log-edit-mode-hook 'flyspell-mode)
 
 ;; I am a power-user
@@ -383,14 +387,6 @@ load-warning buffer in case of failure."
 ;; "tool" bar? Are you kidding?
 (when (fboundp 'tool-bar-mode) (tool-bar-mode -1))
 
-;; ;; If my own letter icon is here, use it and change its color
-;; (when (file-exists-p "~/local/share/emacs/letter.xbm")
-;; (setq-default display-time-mail-icon
-;; (find-image
-;; '((:type xbm
-;; :file "~/local/share/emacs/letter.xbm"
-;; :ascent center)))))
-
 ;; My funky setting of face colors. Basically, we switch to a sober
 ;; look and darken a bit the colors which need to (because of the
 ;; darker background)
@@ -405,76 +401,11 @@ load-warning buffer in case of failure."
 ;; Not the same in xterm (which is gray in my case) and in
 ;; X-window
 
-(unless window-system
-  ;;     (xterm-mouse-mode 1)
-  (ff/configure-faces
-   '((italic :underline nil)
-     (info-title-2 :foreground "green")
-     (font-lock-comment-delimiter-face :foreground "green")
-     (font-lock-comment-face :foreground "green")
-     (cperl-array-face :background "gray90" :foreground "blue" :weight 'bold)
-     (cperl-hash-face :background "gray90" :foreground "purple" :weight 'bold)
-     (diff-added :background "gray90" :foreground "green4" :weight 'bold)
-     (diff-removed :background "gray90" :foreground "red2" :weight 'bold)
-     (diff-changed :background "gray90" :foreground "blue" :weight 'bold)
-     (diff-file-header-face :background "white" :foreground "black"
-                            :weight 'bold)
-     (diff-header-face :background "white" :foreground "black")
-     (diff-hunk-header-face :background "white" :foreground "black")
-     (diff-indicator-removed :foreground "red" :weight 'bold)
-     (diff-removed :foreground "red" :weight 'bold)
-     (diff-indicator-added :foreground "blue" :weight 'bold)
-     (diff-added :foreground "blue" :weight 'bold)
-     (font-lock-string-face :foreground "green")
-     (font-lock-variable-name-face :foreground "blue")
-     (font-lock-constant-face :foreground "blue")
-     (font-lock-preprocessor-face :foreground "green")
-     (font-lock-function-name-face :foreground "cyan")
-     (flyspell-incorrect :foreground "red2")
-     (flyspell-duplicate :foreground "OrangeRed2")
-     (hl-line :background "white")
-     (sh-heredoc :foreground "black" :background "#fff0f0")
-     (sh-heredoc-face :foreground "black" :background "#fff0f0")
-     (font-lock-keyword-face :foreground "blue")
-     (highlight :background "darkseagreen3")
-     (isearch :background "orange" :foreground "black")
-     (isearch-lazy-highlight-face' :background "yellow" :foreground "black")
-     ;; (display-time-mail-face :background "white")
-     (show-paren-match-face :background "gold" :foreground "black")
-     (show-paren-mismatch-face :background "red" :foreground "black")
-     (trailing-whitespace :background "white")
-     (mode-line :background "cornflowerblue" :foreground "black" :box nil
-                :inverse-video nil)
-     (header-line :background "cornflowerblue" :foreground "black" :box nil
-                  :inverse-video nil)
-     (mode-line-inactive :background "gray60" :foreground "black" :box nil
-                         :inverse-video nil)
-     (region :background "white" :foreground "black")
-     (ff/date-info-face :foreground "white" :weight 'bold)
-     (ff/mail-alarm-face :foreground "red" :weight 'bold)
-     (selector/selection :background "yellow")
-     (gui-button-face :background "green" :foreground "white")
-     (enotes/information-face :foreground "cyan")
-
-     (file-name-shadow :foreground "black")
-     (shadow :foreground "black")
-     (warning :foreground "black" :background "red")
-     ))
-  )
-
-;; (list-colors-display (mapcar 'car color-name-rgb-alist))
-
-;; (ff/configure-faces '((default :background "black" :foreground "gray80")))
-;; (ff/configure-faces '((default :background "gray80" :foreground "black")))
-
 (when window-system
-  ;; (setq
-  ;; display-time-use-mail-icon t)
 
   (ff/configure-faces
    '(
      ;; (escape-glyph :foreground "#c0c0c0" :weight 'bold)
-
      (escape-glyph :foreground "green3" :weight 'bold)
      (default :background "gray90" :foreground "black")
      (cperl-array-face :background "gray90" :foreground "blue" :weight 'bold)
@@ -520,13 +451,74 @@ load-warning buffer in case of failure."
                          :inverse-video nil)
      ;; (fringe :background "black" :foreground "gray90")
      (fringe :background "gray80")
-     (ff/date-info-face :foreground "white" :weight 'bold)
-     (ff/mail-alarm-face :foreground "white" :background "red2")
+     (ff/date-info-face :foreground "white")
+     (ff/battery-info-face :foreground "black")
+     (ff/battery-info-alarm-face :foreground "red")
+     ;; (ff/mail-alarm-face :foreground "white" :background "red2")
      ;; (alarm-vc-face :foreground "black" :background "yellow" :weight 'normal)
      (gui-button-face :background "green" :foreground "black")
      ))
   )
 
+(unless window-system
+  ;; (xterm-mouse-mode 1)
+  (ff/configure-faces
+   '((italic :underline nil)
+     (info-title-2 :foreground "green")
+     (font-lock-comment-delimiter-face :foreground "green")
+     (font-lock-comment-face :foreground "green")
+     (cperl-array-face :background "gray90" :foreground "blue" :weight 'bold)
+     (cperl-hash-face :background "gray90" :foreground "purple" :weight 'bold)
+     (diff-added :background "gray90" :foreground "green4" :weight 'bold)
+     (diff-removed :background "gray90" :foreground "red2" :weight 'bold)
+     (diff-changed :background "gray90" :foreground "blue" :weight 'bold)
+     (diff-file-header-face :background "white" :foreground "black"
+                            :weight 'bold)
+     (diff-header-face :background "white" :foreground "black")
+     (diff-hunk-header-face :background "white" :foreground "black")
+     (diff-indicator-removed :foreground "red" :weight 'bold)
+     (diff-removed :foreground "red" :weight 'bold)
+     (diff-indicator-added :foreground "blue" :weight 'bold)
+     (diff-added :foreground "blue" :weight 'bold)
+     (font-lock-string-face :foreground "green")
+     (font-lock-variable-name-face :foreground "blue")
+     (font-lock-constant-face :foreground "blue")
+     (font-lock-preprocessor-face :foreground "green")
+     (font-lock-function-name-face :foreground "cyan")
+     (flyspell-incorrect :foreground "red2")
+     (flyspell-duplicate :foreground "OrangeRed2")
+     (hl-line :background "white")
+     (sh-heredoc :foreground "black" :background "#fff0f0")
+     (sh-heredoc-face :foreground "black" :background "#fff0f0")
+     (font-lock-keyword-face :foreground "blue")
+     (highlight :background "darkseagreen3")
+     (isearch :background "orange" :foreground "black")
+     (isearch-lazy-highlight-face' :background "yellow" :foreground "black")
+     ;; (display-time-mail-face :background "white")
+     (show-paren-match-face :background "gold" :foreground "black")
+     (show-paren-mismatch-face :background "red" :foreground "black")
+     (trailing-whitespace :background "white")
+     (mode-line :background "cornflowerblue" :foreground "black" :box nil
+                :inverse-video nil)
+     (header-line :background "cornflowerblue" :foreground "black" :box nil
+                  :inverse-video nil)
+     (mode-line-inactive :background "gray60" :foreground "black" :box nil
+                         :inverse-video nil)
+     (region :background "white" :foreground "black")
+     (ff/date-info-face :foreground "white" :weight 'bold)
+     (ff/battery-info-face :foreground "black")
+     (ff/battery-info-alarm-face :foreground "red")
+     ;; (ff/mail-alarm-face :foreground "red" :weight 'bold)
+     (selector/selection :background "yellow")
+     (gui-button-face :background "green" :foreground "white")
+     (enotes/information-face :foreground "cyan")
+
+     (file-name-shadow :foreground "black")
+     (shadow :foreground "black")
+     (warning :foreground "black" :background "red")
+     ))
+  )
+
 ;; When we are root, put the modeline in red
 
 (when (string= (user-real-login-name) "root")
@@ -608,13 +600,6 @@ load-warning buffer in case of failure."
 ;; Playing sounds
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-;; (defun ff/esd-sound (file)
-;;   "Plays a sound with the Enlighted sound daemon."
-;;   (interactive)
-;;   (process-kill-without-query (start-process-shell-command "esdplay"
-;;                                                            nil
-;;                                                            "esdplay" file)))
-
 (defun ff/alsa-sound (file)
   "Plays a sound with ALSA."
   (interactive)
@@ -854,7 +839,11 @@ printer."
 (defun ff/sum-values-from-files (list-files prefix)
   (apply '+
          (mapcar
-          (lambda (f) (string-to-number (ff/file-first-line (format "%s/%s" f prefix))))
+          (lambda (f)
+            (condition-case nil
+                (string-to-number (ff/file-first-line (format "%s/%s" f prefix)))
+              (error 0))
+            )
           list-files)))
 
 (defun ff/battery-percent ()
@@ -864,36 +853,54 @@ printer."
     (error -1))
   )
 
-(defun ff/temp-and-battery-info-string () (interactive)
+(defun ff/temp-info-string () (interactive)
        (condition-case nil
-           (concat
-
-            ;; The temperature
+           ;; The temperature
+
+           (let ((temp (/
+                        (apply 'max (mapcar
+                                     (lambda (f) (string-to-number (ff/file-first-line f)))
+                                     ff/temperature-files))
+                        1000)))
+
+             (if (> temp 50)
+                 (let ((s (format "%dC " temp)))
+                   (if (> temp 70)
+                       (propertize s 'face 'font-lock-warning-face)
+                     s)
+                   )
+               )
+             )
 
-            (let ((temp (/
-                         (apply 'max (mapcar
-                                      (lambda (f) (string-to-number (ff/file-first-line f)))
-                                      ff/temperature-files))
-                         1000)))
+         (error nil))
+       )
 
-              (if (> temp 50)
-                  (let ((s (format "%dC " temp)))
-                    (if (> temp 70)
-                        (propertize s 'face 'font-lock-warning-face)
-                      s)
-                    )
+(defun ff/battery-info-string () (interactive)
+       (condition-case nil
+           (pcase (ff/battery-state ff/battery-dirs)
+             ;; (`charging (format "c%d%%" (ff/battery-percent)))
+             ;; (`discharging (format "d%d%%" (ff/battery-percent)))
+             ;; (`unknown "f")
+
+             (`charging
+              (let ((p (ff/battery-percent)))
+                (if (> p 10)
+                    (propertize (format "↑%d%%" p) 'face 'ff/battery-info-face)
+                  (propertize (format "↑%d%%" p) 'face 'ff/battery-info-alarm-face))
                 )
               )
 
-            ;; The battery
-
-            (pcase (ff/battery-state ff/battery-dirs)
-              (`charging (format "c%d%%" (ff/battery-percent)))
-              (`discharging (format "d%d%%" (ff/battery-percent)))
-              (code "f"))
-
-            )
+             (`discharging
+              (let ((p (ff/battery-percent)))
+                (if (> p 10)
+                    (propertize (format "↓%d%%" p) 'face 'ff/battery-info-face)
+                  (propertize (format "↓%d%%" p) 'face 'ff/battery-info-alarm-face))
+                )
+              )
 
+             ;; (`unknown "✱")
+             (`unknown "F")
+             (_ "?"))
          (error nil))
        )
 
@@ -918,14 +925,14 @@ printer."
                         (propertize
                          (with-temp-buffer (apply 'call-process x)
                                            (buffer-string))
-                         'face '(:background "#c0c0ff"))
+                         'face '(:background "#d0d0ff"))
                       (with-temp-buffer (apply 'call-process x)
                                         (buffer-string))
                       ))
                    )
 
                  '(
-                   ("hostname" nil t nil "-v")
+                   ("hostname" nil t nil "-f")
                    ("acpi" nil t)
                    ("df" nil t nil "-h")
                    ;; ("mount" nil t)
@@ -941,52 +948,41 @@ printer."
          (set-buffer-modified-p nil)
          ))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Make a sound when there is new mail
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;; I do not like sounds anymore
-
-;; (setq ff/already-boinged-for-mail nil)
-
-;; (defun ff/boing-if-new-mail ()
-;; (if mail (when (not ff/already-boinged-for-mail)
-;; ;; (ff/play-sound-async "~/local/sounds/boing1.wav")
-;; ;; (ff/show-unspooled-mails)
-;; (setq ff/already-boinged-for-mail t))
-;; (setq ff/already-boinged-for-mail nil))
-;; )
-
-;; (add-hook 'display-time-hook 'ff/boing-if-new-mail)
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Display time
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (setq
 
- display-time-interval 15 ;; Check every 15s
+ display-time-interval 10 ;; Check every 10s
 
  display-time-string-forms `(
 
-                             ;; (if mail
-                             ;;     (concat " "
-                             ;;             (propertize " mail "
-                             ;;                         'face 'ff/mail-alarm-face)
-                             ;;             " ")
-                             ;;   )
+                             load
+
+                             " "
 
-                             (propertize (concat 24-hours ":" minutes
-                                                 " "
-                                                 dayname " "
-                                                 monthname " "
-                                                 day)
-                                         'face 'ff/date-info-face)
+                             ,@(when (ff/temp-info-string)
+                                 '((ff/temp-info-string)))
 
-                             load
+                             ,@(when (ff/battery-info-string)
+                                 '((ff/battery-info-string)))
+
+                                 ;; '((propertize
+                                    ;; (ff/battery-info-string)
+                                    ;; 'face 'ff/battery-info-face)))
 
-                             ,(if (ff/temp-and-battery-info-string)
-                                  '(concat " " (ff/temp-and-battery-info-string)))
+                             " "
+
+                             (propertize
+                              (concat ;;" ˌ"
+                               24-hours ":" minutes
+                               " "
+                               ;; dayname " "
+                               monthname " " day
+                               ;;"ˌ"
+                               )
+                              'face 'ff/date-info-face)
 
                              )
 
@@ -1023,8 +1019,11 @@ printer."
 
 ;; (define-key global-map [?\C-x right] 'ff/next-buffer)
 ;; (define-key global-map [?\C-x left] 'ff/prev-buffer)
-(define-key global-map [?\M-\]] 'ff/next-buffer)
-(define-key global-map [?\M-\[] 'ff/prev-buffer)
+;; (define-key global-map [?\M-\]] 'ff/next-buffer)
+;; (define-key global-map [?\M-\[] 'ff/prev-buffer)
+
+(define-key global-map [(meta right)] 'ff/next-buffer)
+(define-key global-map [(meta left)] 'ff/prev-buffer)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; There is actually a decent terminal emulator in emacs!
@@ -1470,9 +1469,9 @@ universal argument starts xfig even if the .fig does not exist"
        (let ((start (condition-case nil (region-beginning) (error (point))))
              (end (condition-case nil (region-end) (error (point)))))
          (goto-char end)
-         (insert "---------------------------- snip snip -------------------------------\n")
+         (insert "----------------------------- snip snip -----------------------------\n")
          (goto-char start)
-         (insert "---------------------------- snip snip -------------------------------\n")
+         (insert "----------------------------- snip snip -----------------------------\n")
          ))
 
 (defun ff/start-latex ()
@@ -1481,7 +1480,7 @@ universal argument starts xfig even if the .fig does not exist"
   (goto-char (point-min))
   (insert "%% -*- mode: latex; mode: reftex; mode: flyspell; coding: utf-8; tex-command: \"pdflatex.sh\" -*-
 
-\\documentclass[12pt]{article}
+\\documentclass[12pt,a4paper,twoside]{article}
 \\usepackage[a4paper,top=2.5cm,bottom=2cm,left=2.5cm,right=2.5cm]{geometry}
 \\usepackage[utf8]{inputenc}
 \\usepackage{amsmath}
@@ -1703,7 +1702,7 @@ int main(int argc, char **argv) {
 <head>
 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
 <title></title>
-<style>
+<style type=\"text/css\">
 p {
  color:#009900;
 }
@@ -1944,19 +1943,6 @@ a file in /tmp"
 (define-key global-map [f8] 'ff-find-other-file)
 (define-key global-map [(shift f8)] (lambda () (interactive) (ff-find-other-file t)))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Antiword, htmlize and boxquote
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-(autoload 'no-word "no-word")
-(add-to-list 'auto-mode-alist '("\\.doc\\'" . no-word))
-;; (add-to-list 'auto-mode-alist '("\\.DOC\\'" . no-word))
-
-(autoload 'htmlize-buffer "htmlize" nil t)
-
-(setq boxquote-top-and-tail "------------------")
-(autoload 'boxquote-region "boxquote" nil t)
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; The compilation hacks
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -2113,7 +2099,7 @@ This may be a useful alternative binding for \\[delete-other-windows]
            (while (re-search-forward "[0-9\.]+" nil t)
              (let ((value (string-to-number (buffer-substring (match-beginning 0) (match-end 0)))))
                (delete-region (match-beginning 0) (match-end 0))
-               (insert (format "%0.2f" value)))))))
+               (insert (format "%0.3f" value)))))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Keymaping
@@ -2199,19 +2185,19 @@ This may be a useful alternative binding for \\[delete-other-windows]
 ;; (define-key global-map [(control shift next)] 'previous-multiframe-window)
 
 ;; I have two screens sometime!
+;; (define-key global-map [(meta next)] 'other-frame)
+;; (define-key global-map [(meta prior)] (lambda () (interactive) (other-frame -1)))
 
-(define-key global-map [(meta next)] 'other-frame)
-(define-key global-map [(meta prior)] (lambda () (interactive) (other-frame -1)))
-
-(define-key global-map [(shift home)] 'delete-other-windows-vertically)
+;; (load "winner")
+(winner-mode 1)
+;; (define-key global-map [(shift backspace)] 'winner-undo)
 
+;; (define-key global-map [(shift home)] 'delete-other-windows-vertically)
 ;; (define-key global-map [(control +)] 'enlarge-window)
 ;; (define-key global-map [(control -)] 'shrink-window)
-
 ;; Goes to next/previous buffer
-
-(define-key global-map [(control prior)] 'ff/next-buffer)
-(define-key global-map [(control next)] 'ff/prev-buffer)
+;; (define-key global-map [(control prior)] 'ff/next-buffer)
+;; (define-key global-map [(control next)] 'ff/prev-buffer)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; If M-. on a symbol, show where it is defined in another window
@@ -2259,7 +2245,7 @@ next one. With universal argument, kill all killable buffers."
     (if (string-match ff/kill-this-buffer-and-delete-window-exceptions (buffer-name))
         (ff/next-buffer)
       (kill-this-buffer)))
-  ;; (unless (one-window-p t) (delete-window))
+  (unless (one-window-p t) (delete-window))
   )
 
 (define-key global-map [(control backspace)] 'ff/kill-this-buffer-and-delete-window)