Update.
[elisp.git] / emacs.el
index 0a8ca7d..6d4ffe8 100644 (file)
--- a/emacs.el
+++ b/emacs.el
@@ -34,9 +34,9 @@
 ;; (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 11")
+;; (set-default-font "Droid sans mono 13")
+;; (set-default-font "Opensans 10")
 
 (when (fboundp 'horizontal-scroll-bar-mode)
   (horizontal-scroll-bar-mode -1))
@@ -90,7 +90,8 @@
       )
 
 ;; Activate the dynamic completion of buffer names
-(iswitchb-mode 1)
+;; (iswitchb-mode 1)
+;; (load "lcomplete")
 
 ;; Save the minibuffer history
 (setq savehist-file (concat ff/emacs-dir "/savehist"))
@@ -327,6 +328,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()
@@ -581,6 +584,16 @@ load-warning buffer in case of failure."
 
 (define-key global-map [(meta up)] 'ff/scroll-down)
 (define-key global-map [(meta down)] 'ff/scroll-up)
+
+(define-key global-map [(meta shift up)]
+  (lambda () (interactive) (condition-case nil (scroll-down 10) (error nil))))
+
+(define-key global-map [(meta shift down)]
+  (lambda () (interactive) (condition-case nil (scroll-up 10) (error nil))))
+
+;; (define-key global-map [(meta shift up)] (lambda () (interactive) (ff/scroll-down 10)))
+;; (define-key global-map [(meta shift down)] 'ff/scroll-up)
+
 (define-key global-map [(meta p)] 'ff/scroll-down)
 (define-key global-map [(meta n)] 'ff/scroll-up)
 (define-key global-map [(meta right)] 'ff/scroll-left)
@@ -840,16 +853,20 @@ printer."
         )
     'unknown))
 
-(defun ff/sum-numbers (list-files prefix)
+(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 ()
   (condition-case nil
-      (/ (* 100 (ff/sum-numbers ff/battery-dirs "energy_now"))
-         (ff/sum-numbers ff/battery-dirs "energy_full"))
+      (/ (* 100 (ff/sum-values-from-files ff/battery-dirs "energy_now"))
+         (ff/sum-values-from-files ff/battery-dirs "energy_full"))
     (error -1))
   )
 
@@ -864,22 +881,23 @@ printer."
                                       (lambda (f) (string-to-number (ff/file-first-line f)))
                                       ff/temperature-files))
                          1000)))
+
               (if (> temp 50)
-                  (concat
-                   (let ((s (format "%dC " temp)))
-                     (if (> temp 70) (propertize s 'face
-                                                 'font-lock-warning-face)
-                       s))
-                   )
+                  (let ((s (format "%dC " temp)))
+                    (if (> temp 70)
+                        (propertize s 'face 'font-lock-warning-face)
+                      s)
+                    )
                 )
               )
 
             ;; The battery
 
             (pcase (ff/battery-state ff/battery-dirs)
-              (`charging (format "L%d%%" (ff/battery-percent)))
-              (`discharging (format "B%d%%" (ff/battery-percent)))
-              (code "L"))
+              (`charging (format "c%d%%" (ff/battery-percent)))
+              (`discharging (format "d%d%%" (ff/battery-percent)))
+              (`unknown "f")
+              (_ "?"))
 
             )
 
@@ -914,7 +932,7 @@ printer."
                    )
 
                  '(
-                   ("hostname" nil t nil "-v")
+                   ("hostname" nil t nil "-f")
                    ("acpi" nil t)
                    ("df" nil t nil "-h")
                    ;; ("mount" nil t)
@@ -965,6 +983,9 @@ printer."
                              ;;             " ")
                              ;;   )
 
+                             ,(if (ff/temp-and-battery-info-string)
+                                  '(concat (ff/temp-and-battery-info-string) " "))
+
                              (propertize (concat 24-hours ":" minutes
                                                  " "
                                                  dayname " "
@@ -974,9 +995,6 @@ printer."
 
                              load
 
-                             ,(if (ff/temp-and-battery-info-string)
-                                  '(concat " " (ff/temp-and-battery-info-string)))
-
                              )
 
  ;; display-time-format "%b %a %e %H:%M"
@@ -1010,10 +1028,13 @@ printer."
       (setq list (cdr list)))
     (switch-to-buffer found)))
 
-(define-key global-map [?\C-x right] 'ff/next-buffer)
-(define-key global-map [?\C-x left] 'ff/prev-buffer)
-(define-key global-map [?\C-'] 'ff/next-buffer)
-(define-key global-map [?\C-\;] 'ff/prev-buffer)
+;; (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 [(meta right)] 'ff/next-buffer)
+(define-key global-map [(meta left)] 'ff/prev-buffer)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; There is actually a decent terminal emulator in emacs!
@@ -1459,9 +1480,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 ()
@@ -1470,7 +1491,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}
@@ -1692,7 +1713,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;
 }
@@ -2159,28 +2180,6 @@ This may be a useful alternative binding for \\[delete-other-windows]
 
 ;; Closes the current \begin{}
 
-(when (ff/load-or-alert "longlines")
-
-  (setq longlines-show-hard-newlines t
-        longlines-auto-wrap t
-        ;; longlines-show-effect #("|\n" 0 2 (face escape-glyph))
-        ;; longlines-show-effect #("∴\n" 0 2 (face escape-glyph))
-        longlines-show-effect #("•\n" 0 2 (face escape-glyph))
-        ;; longlines-show-effect #("↵\n" 0 2 (face escape-glyph))
-        )
-
-  ;; (defun ff/auto-longlines ()
-  ;; (when (save-excursion
-  ;; (goto-char (point-min))
-  ;; (re-search-forward "^.\\{81,\\}$" nil t))
-  ;; (longlines-mode)
-  ;; (message "Switched on the lonlines mode automatically")
-  ;; ))
-
-  ;; (add-hook 'latex-mode-hook 'ff/auto-longlines)
-
-  )
-
 ;; Meta-/ remaped (completion)
 
 (define-key global-map [(shift right)] 'dabbrev-expand)
@@ -2210,19 +2209,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
@@ -2270,7 +2269,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)