X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=elisp.git;a=blobdiff_plain;f=emacs.el;h=6d4ffe8cad3efe1ec8ebd8abe04975e600e9881a;hp=2c3691a4468667af4cfdf3d38898b488d9f4ff34;hb=41d67536a6418bc1b6259cc3f390b892cb931417;hpb=58e9269f2a02f5f1176142a9d7e81d79d757fb7e diff --git a/emacs.el b/emacs.el index 2c3691a..6d4ffe8 100644 --- a/emacs.el +++ b/emacs.el @@ -31,6 +31,21 @@ ;; Xft.antialias: true ;; Xft.rgba: rgb +;; (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") + +(when (fboundp 'horizontal-scroll-bar-mode) + (horizontal-scroll-bar-mode -1)) + +;; This is where I put most of my emacs-related files +(setq ff/emacs-dir "~/private/emacs") +(unless (file-exists-p ff/emacs-dir) + (mkdir ff/emacs-dir t)) + ;; Give the focus to the emacs window if we are under a windowing ;; system @@ -58,6 +73,10 @@ ;; Make all "yes or no" prompts be "y or n" instead (fset 'yes-or-no-p 'y-or-n-p) +;; The space bar acting as "yes" has been several times really +;; problematic. +(define-key query-replace-map (kbd "SPC") nil) + ;; Show the matching parenthesis and do it immediately, we are in a ;; hurry (setq show-paren-delay 0) @@ -71,10 +90,11 @@ ) ;; Activate the dynamic completion of buffer names -(iswitchb-mode 1) +;; (iswitchb-mode 1) +;; (load "lcomplete") ;; Save the minibuffer history -(setq savehist-file "~/private/emacs/savehist") +(setq savehist-file (concat ff/emacs-dir "/savehist")) (when (functionp 'savehist-mode) (savehist-mode 1)) ;; And allow minibuffer recursion @@ -255,7 +275,8 @@ load-warning buffer in case of failure." ;; Stop this crazy blinking cursor (blink-cursor-mode 0) -;; (setq blink-cursor-delay 0.25 +;; (setq blink-cursor-delay 0.05 +;; blink-cursor-blinks 0 ;; blink-cursor-interval 0.25) ;; (set-terminal-coding-system 'utf-8) @@ -283,8 +304,12 @@ load-warning buffer in case of failure." ;; This is the default coding system when toggle-input-method is ;; invoked (C-\) default-input-method "latin-1-prefix" + ;; do not put tabs when indenting indent-tabs-mode nil + ;; Stop indenting automatically, that's annoying + electric-indent-chars nil + ;; And yes, we have a fast display / connection / whatever baud-rate 524288 ;; baud-rate 10 @@ -303,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() @@ -385,8 +412,8 @@ load-warning buffer in case of failure." (ff/configure-faces '((italic :underline nil) (info-title-2 :foreground "green") - (font-lock-comment-delimiter-face :foreground "black") - (font-lock-comment-face :foreground "black") + (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) @@ -424,11 +451,16 @@ load-warning buffer in case of failure." :inverse-video nil) (mode-line-inactive :background "gray60" :foreground "black" :box nil :inverse-video nil) - (region :background "springgreen2") + (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") )) ) @@ -494,7 +526,7 @@ load-warning buffer in case of failure." (ff/mail-alarm-face :foreground "white" :background "red2") ;; (alarm-vc-face :foreground "black" :background "yellow" :weight 'normal) (gui-button-face :background "green" :foreground "black") - )) + )) ) ;; When we are root, put the modeline in red @@ -552,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) @@ -689,7 +731,8 @@ occurrences " ps-header-line-pad 0.3 ps-header-font-family 'Courier ps-header-title-font-size '(8.5 . 10) - ps-header-font-size '(6 . 7) + ;; ps-header-font-size '(6 . 7) + ps-header-font-size '(10 . 12) ps-font-size '(7 . 8) ) @@ -775,10 +818,12 @@ printer." ;; Dealing with the laptop battery ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defcustom ff/battery-dir "/sys/class/power_supply/BAT0" +(defcustom ff/battery-dirs '("/sys/class/power_supply/BAT0" + "/sys/class/power_supply/BAT1") "*Where to gather the battery information") -(defcustom ff/temperature-file "/sys/class/thermal/thermal_zone0/temp" +(defcustom ff/temperature-files '("/sys/class/thermal/thermal_zone0/temp" + "/sys/class/thermal/thermal_zone1/temp") "*Where to gather the thermal information") (defun ff/file-first-line (file) @@ -786,99 +831,122 @@ printer." (insert-file-contents-literally file) (buffer-substring (point-at-bol) (point-at-eol)))) -(defun ff/battery-percent (prefix) +(defun ff/battery-discharging (l) + (and l (or (string= (ff/file-first-line (concat (car l) "/status")) "Discharging") + (ff/battery-discharging (cdr l))))) + +;; If there is one "Discharging" among the states of all the +;; batteries, the global state is 'discharging. Otherwise, if there is +;; a "Charging", the state is 'charging. If none is true, it is +;; 'unknown +(defun ff/battery-state (l) + (if l + (let ((u (ff/file-first-line (concat (car l) "/status")))) + (if (string= u "Discharging") 'discharging + (let ((s (ff/battery-state (cdr l)))) + (if (eq s 'discharging) 'discharging + (if (or (eq s 'charging) (string= u "Charging")) + 'charging + 'unknown)) + ) + ) + ) + 'unknown)) + +(defun ff/sum-values-from-files (list-files prefix) + (apply '+ + (mapcar + (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 (string-to-number (ff/file-first-line (format "%s/%s_now" ff/battery-dir prefix)))) - (string-to-number (ff/file-first-line (format "%s/%s_full" ff/battery-dir prefix)))) + (/ (* 100 (ff/sum-values-from-files ff/battery-dirs "energy_now")) + (ff/sum-values-from-files ff/battery-dirs "energy_full")) (error -1)) ) -(defun ff/laptop-info-string () (interactive) - (condition-case nil - (concat - - ;; The temperature +(defun ff/temp-and-battery-info-string () (interactive) + (condition-case nil + (concat - (let ((temp (/ (string-to-number (ff/file-first-line ff/temperature-file)) 1000))) - (if (> temp 50) - (concat - (let ((s (format "%dC " temp))) - (if (> temp 70) (propertize s 'face - 'font-lock-warning-face) - s)) + ;; 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) + ) + ) ) - ) - ) - - ;; The battery - (let ((battery-status (ff/file-first-line (concat ff/battery-dir "/status")))) + ;; The battery - (cond - ((string= battery-status "Full") "L") + (pcase (ff/battery-state ff/battery-dirs) + (`charging (format "c%d%%" (ff/battery-percent))) + (`discharging (format "d%d%%" (ff/battery-percent))) + (`unknown "f") + (_ "?")) - ((string= battery-status "Charging") - (format "L%d%%" (max (ff/battery-percent "charge") - (ff/battery-percent "energy")))) - - ((string= battery-status "Discharging") - (let* ((c (max (ff/battery-percent "charge") - (ff/battery-percent "energy"))) - (s (format "B%d%%" c))) - (if (>= c 20) s (propertize s 'face 'font-lock-warning-face)))) - - (t battery-status) - - )) + ) + (error nil)) ) - (error nil)) - ) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun ff/system-info () (interactive) - (let ((buf (get-buffer-create "*system info*")) - (map (make-sparse-keymap))) - - (define-key map "q" 'kill-this-buffer) - (display-buffer buf) - (set-buffer buf) - (setq show-trailing-whitespace nil) - (erase-buffer) - - (let ((highlight nil)) - - (mapc (lambda (x) - (insert - (if (setq highlight (not highlight)) - (propertize - (with-temp-buffer (apply 'call-process x) - (buffer-string)) - 'face '(:background "#c0c0ff")) - (with-temp-buffer (apply 'call-process x) - (buffer-string)) - )) - ) - - '( - ("hostname" nil t nil "-v") - ("acpi" nil t) - ("df" nil t nil "-h") - ;; ("mount" nil t) - ("ifconfig" nil t) - ("ssh-add" nil t nil "-l") - ))) - - (goto-char (point-min)) - (while (re-search-forward "^$" nil t) (backward-delete-char 1)) - - (fit-window-to-buffer (get-buffer-window buf)) - (use-local-map map) - (set-buffer-modified-p nil) - )) + (let ((buf (get-buffer-create "*system info*")) + (map (make-sparse-keymap))) + + (define-key map "q" 'kill-this-buffer) + (display-buffer buf) + (set-buffer buf) + (setq show-trailing-whitespace nil) + (erase-buffer) + + (let ((highlight nil)) + + (mapc (lambda (x) + (insert + (if (setq highlight (not highlight)) + (propertize + (with-temp-buffer (apply 'call-process x) + (buffer-string)) + 'face '(:background "#c0c0ff")) + (with-temp-buffer (apply 'call-process x) + (buffer-string)) + )) + ) + + '( + ("hostname" nil t nil "-f") + ("acpi" nil t) + ("df" nil t nil "-h") + ;; ("mount" nil t) + ("ifconfig" nil t) + ("ssh-add" nil t nil "-l") + ))) + + (goto-char (point-min)) + (while (re-search-forward "^$" nil t) (backward-delete-char 1)) + + (fit-window-to-buffer (get-buffer-window buf)) + (use-local-map map) + (set-buffer-modified-p nil) + )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Make a sound when there is new mail @@ -915,6 +983,9 @@ printer." ;; " ") ;; ) + ,(if (ff/temp-and-battery-info-string) + '(concat (ff/temp-and-battery-info-string) " ")) + (propertize (concat 24-hours ":" minutes " " dayname " " @@ -924,9 +995,6 @@ printer." load - ,(if (ff/laptop-info-string) - '(concat " " (ff/laptop-info-string))) - ) ;; display-time-format "%b %a %e %H:%M" @@ -960,8 +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-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! @@ -970,15 +1043,15 @@ printer." (load "term") (defun ff/kill-associated-buffer (process str) (interactive) - (let ((buffer (process-buffer process))) - (kill-buffer buffer)) - (message "Process finished (%s)" (replace-regexp-in-string "\n$" "" str))) + (let ((buffer (process-buffer process))) + (kill-buffer buffer)) + (message "Process finished (%s)" (replace-regexp-in-string "\n$" "" str))) (defun ff/kill-associated-buffer-and-delete-windows (process str) (interactive) - (let ((buffer (process-buffer process))) - (delete-windows-on buffer) - (kill-buffer buffer)) - (message "Process finished (%s)" (replace-regexp-in-string "\n$" "" str))) + (let ((buffer (process-buffer process))) + (delete-windows-on buffer) + (kill-buffer buffer)) + (message "Process finished (%s)" (replace-regexp-in-string "\n$" "" str))) (defun ff/shell-new-buffer (buffername program &rest param) "Start a terminal-emulator in a new buffer with the shell PROGRAM, @@ -1191,14 +1264,9 @@ ff/known-address-face is used." ) (ff/configure-faces '((ff/robot-address-face :foreground "green4") - (ff/personal-address-face :foreground "blue2" :weight 'bold) + (ff/personal-address-face :foreground "dark magenta" :weight 'bold) (ff/important-address-face :foreground "red3" - ;; :foreground "blue2" - ;; :underline t - ;; :background "white" - ;; :foreground "green4" :weight 'bold - ;; :slant 'italic ))) ) @@ -1219,30 +1287,33 @@ ff/known-address-face is used." "The face to display the dates in the modeline.") (defun ff/secure-note-add () (interactive) - (find-file ff/secure-note-file) - ;; Adds a new entry (i.e. date and a bunch of empty lines) + (unless + (let ((b (find-buffer-visiting ff/secure-note-file))) + (and b (switch-to-buffer b))) + (find-file ff/secure-note-file) + ;; Adds a new entry (i.e. date and a bunch of empty lines) + (goto-char (point-min)) + (insert "-- " + (format-time-string "%Y %b %d %H:%M:%S" (current-time)) + " --\n\n") + (previous-line 1) + ) - (goto-char (point-min)) - (insert "-- " - (format-time-string "%Y %b %d %H:%M:%S" (current-time)) - " --\n\n") - (previous-line 1) + ;; Colorizes the dates - ;; Colorizes the dates + (save-excursion + (goto-char (point-min)) + (while (re-search-forward + "^-- [0-9]+ [a-z]+ [0-9]+ [0-9]+:[0-9]+:[0-9]+ -+$" + nil t) + (add-text-properties + (match-beginning 0) (1+ (match-end 0)) + '(face ff/secure-date rear-nonsticky t)))) - (save-excursion - (goto-char (point-min)) - (while (re-search-forward - "^-- [0-9]+ [a-z]+ [0-9]+ [0-9]+:[0-9]+:[0-9]+ -+$" - nil t) - (add-text-properties - (match-beginning 0) (1+ (match-end 0)) - '(face ff/secure-date rear-nonsticky t)))) - - (set-buffer-modified-p nil) - (setq buffer-undo-list nil) - ) + (set-buffer-modified-p nil) + (setq buffer-undo-list nil) + ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Spelling @@ -1406,13 +1477,13 @@ universal argument starts xfig even if the .fig does not exist" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun ff/snip () (interactive) - (let ((start (condition-case nil (region-beginning) (error (point)))) - (end (condition-case nil (region-end) (error (point))))) - (goto-char end) - (insert "---------------------------- snip snip -------------------------------\n") - (goto-char start) - (insert "---------------------------- snip snip -------------------------------\n") - )) + (let ((start (condition-case nil (region-beginning) (error (point)))) + (end (condition-case nil (region-end) (error (point))))) + (goto-char end) + (insert "----------------------------- snip snip -----------------------------\n") + (goto-char start) + (insert "----------------------------- snip snip -----------------------------\n") + )) (defun ff/start-latex () "Adds all that stuff to start a new LaTeX document." @@ -1420,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} @@ -1437,12 +1508,12 @@ universal argument starts xfig even if the .fig does not exist" \\def\\argmin{\\operatornamewithlimits{argmin}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Sans serif fonts -%% \\usepackage[T1]{fontenc} -%% \\usepackage[scaled]{helvet} -%% \\usepackage[cm]{sfmath} -%% \\renewcommand{\\ttdefault}{pcr} -%% \\renewcommand*\\familydefault{\\sfdefault} +%% Open sans font +%%\\usepackage[default]{opensans} +%%\\usepackage{cmbright} +%%\\renewcommand{\\familydefault}{fos} +%%\\renewcommand{\\seriesdefault}{l} +%%\\renewcommand{\\bfdefault}{sb} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% The \\todo command \\newcounter{nbdrafts} @@ -1506,12 +1577,12 @@ universal argument starts xfig even if the .fig does not exist" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun ff/remove-ip-header () (interactive) - (save-excursion - (goto-char (point-min)) - (when (and (re-search-forward "START_IP_HEADER" nil t) - (re-search-forward "END_IP_HEADER" nil t)) - (message "yep")) - )) + (save-excursion + (goto-char (point-min)) + (when (and (re-search-forward "START_IP_HEADER" nil t) + (re-search-forward "END_IP_HEADER" nil t)) + (message "yep")) + )) (defun ff/add-gpl () "Adds the GPL statements at the beginning of current buffer." @@ -1642,7 +1713,7 @@ int main(int argc, char **argv) { -