1 ;; -*- mode: Emacs-Lisp; mode: rainbow; -*-
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. ;;
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. ;;
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/>. ;;
17 ;; Written by and Copyright (C) Francois Fleuret ;;
18 ;; Contact <francois@fleuret.org> for comments & bug reports ;;
19 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21 ;; It's better to set the preferences in the .Xresources so that the
22 ;; window is not first displayed with the wrong options
25 ;; Emacs.verticalScrollBars: off
27 ;; Emacs.internalBorder: 1
28 ;; Emacs.FontBackend: xft
31 ;; Xft.antialias: true
34 ;; Give the focus to the emacs window if we are under a windowing
38 ;; (x-focus-frame nil)
39 (set-mouse-pixel-position (selected-frame) 4 4))
41 ;; Where I keep my own scripts
43 (add-to-list 'load-path "~/sources/gpl/elisp")
44 (add-to-list 'load-path "~/sources/elisp")
45 (add-to-list 'load-path "~/local/elisp")
47 ;; No, I do not like menus
51 (when (functionp 'fringe-mode) (fringe-mode '(0 . 0)))
52 ;; (when (functionp 'fringe-mode) (fringe-mode '(0 . 1)))
54 ;; And I do not like scrollbar neither
55 (when (functionp 'scroll-bar-mode) (scroll-bar-mode -1))
57 ;; Make all "yes or no" prompts be "y or n" instead
58 (fset 'yes-or-no-p 'y-or-n-p)
60 ;; Show the matching parenthesis and do it immediately, we are in a
62 (setq show-paren-delay 0)
65 ;; use colorization for all modes
66 (global-font-lock-mode t)
68 (setq font-lock-maximum-decoration 3
69 ;;'((latex-mode . 2) (t . 2))
72 ;; Activate the dynamic completion of buffer names
75 ;; Save the minibuffer history
76 (setq savehist-file "~/private/emacs/savehist")
77 (when (functionp 'savehist-mode) (savehist-mode 1))
79 ;; And allow minibuffer recursion
80 (setq enable-recursive-minibuffers t)
81 (minibuffer-depth-indicate-mode 1)
83 ;; I do not like tooltips
84 (when (functionp 'tooltip-mode) (tooltip-mode nil))
86 ;; Activate the dynamic completion in the mini-buffer
89 ;; (setq highlight-current-line-globally t
90 ;; highlight-current-line-ignore-regexp "Faces\\|Colors\\| \\*Mini\\|\\*media\\|INBOX")
92 ;; (highlight-current-line-minor-mode 1)
93 ;; (highlight-current-line-set-bg-color "gray75")
95 (defun ff/compile-when-needed (name)
96 "Compiles the given file only if needed. Adds .el if required, and
97 uses `load-path' to find it."
98 (if (not (string-match "\.el$" name))
99 (ff/compile-when-needed (concat name ".el"))
101 (let* ((src (concat dir "/" name)))
102 (when (file-newer-than-file-p src (concat src "c"))
103 (if (let ((byte-compile-verbose nil))
105 (byte-compile-file src)
107 (message (format "Compiled %s" src ))
108 (message (format "Failed compilation of %s" src))))))
111 ;; This is useful when using the same .emacs in many places
113 (defun ff/load-or-alert (name &optional compile-when-needed)
114 "Tries to load the specified file and insert a warning message in a
115 load-warning buffer in case of failure."
117 (when compile-when-needed (ff/compile-when-needed name))
119 (if (load name t nil) t
120 (let ((buf (get-buffer-create "*loading warnings*")))
123 (insert (propertize "Warning:" 'face 'font-lock-warning-face) " could not load '" name "'\n")
124 (fit-window-to-buffer (get-buffer-window buf))
125 (set-buffer-modified-p nil))
128 ;; This is the default in emacs 22.1 and later
129 ;; (auto-compression-mode 1)
131 ;; make emacs use the clipboard so that copy/paste works for other
132 ;; x-programs. I have no clue how all that clipboard thing works.
134 ;; (setq x-select-enable-clipboard t)
135 ;; (setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
136 ;; (setq x-select-enable-primary t)
137 ;; (setq x-select-enable-clipboard t)
138 ;; (global-set-key "\C-y" 'clipboard-yank)
146 ;; avoid GC as much as possible
147 gc-cons-threshold 2500000
149 ;; no startup message
150 inhibit-startup-screen t
152 ;; no message in the scratch buffer
153 initial-scratch-message nil
155 ;; do not fill my buffers, you fool
156 next-line-add-newlines nil
158 ;; keep the window focused on the messages during compilation
159 compilation-scroll-output t
161 ;; Keep the highlight on the compilation error
162 next-error-highlight t
164 ;; blink the screen instead of beeping
167 ;; take the CR when killing a line
170 ;; I prefer to move between lines as defined in the buffer, not
174 ;; I comment empty lines, too (does not seem to work, though)
175 comment-empty-lines t
177 ;; We want long lines to be truncated instead of displayed on several lines
179 ;; Show all lines, even if the window is not as large as the frame
180 ;; truncate-partial-width-windows nil
181 ;; truncate-partial-width-windows t
183 ;; Do not keep tracks of the autosaved files
184 auto-save-list-file-prefix nil
186 ;; Show me empty lines at the end of the buffer
187 default-indicate-empty-lines t
189 ;; Show me the region until I do something on it
190 transient-mark-mode t
192 ;; Do not color stuff which are clickable when hovering over it
195 ;; Don't bother me with questions even if "unsafe" local variables
197 enable-local-variables :all
199 ;; I have no problem with small windows
202 ;; I am not a fan of develock
203 develock-auto-enable nil
205 ;; I do not like women to open windows
206 woman-use-own-frame nil
208 ;; I am not that paranoid, contrary to what you think
209 epa-file-cache-passphrase-for-symmetric-encryption t
210 ;; And I like ascii files
213 tramp-default-method "ssh"
215 ;; I have no problem with files having their own local variables
218 mail-from-style 'angles
219 browse-url-mozilla-program "firefox"
221 mc-use-default-recipients t
223 ;; browse-url-new-window-flag t
229 temporary-file-directory "/tmp/"
230 vc-make-backup-files t
231 backup-directory-alist '((".*" . "~/misc/emacs.backups/"))
232 version-control t ;; Use backup files with numbers
235 delete-old-versions t
236 backup-by-copying-when-linked t
239 (setq tramp-backup-directory-alist backup-directory-alist)
241 (setq user-emacs-directory "~/misc/emacs.d/")
244 abbrev-file-name (concat user-emacs-directory "abbrev_defs")
245 server-auth-dir (concat user-emacs-directory "server/")
246 custom-theme-directory user-emacs-directory
249 ;; Stop this crazy blinking cursor
250 (blink-cursor-mode 0)
252 ;; (setq blink-cursor-delay 0.25
253 ;; blink-cursor-interval 0.25)
255 ;; (set-terminal-coding-system 'utf-8)
257 ;; (unless window-system
258 ;; (xterm-mouse-mode 1)
259 ;; (if (string= (getenv "TERM") "xterm-256color")
260 ;; (ff/load-or-alert "xterm-256color" t))
265 ;; Show white spaces at the end of lines
266 show-trailing-whitespace t
268 ;; Do not show the cursor in non-active window
269 cursor-in-non-selected-windows nil
274 ;; when on a TAB, the cursor has the TAB length
277 ;; This is the default coding system when toggle-input-method is
279 default-input-method "latin-1-prefix"
280 ;; do not put tabs when indenting
282 ;; And yes, we have a fast display / connection / whatever
286 ;; To keep the cursor always visible when it moves (thanks
288 redisplay-dont-pause t
290 ;; I want to see the keys I type instantaneously
294 ;; Show the column number
295 (column-number-mode 1)
297 ;; What modes for what file extentions
298 (add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
300 (add-to-list 'auto-mode-alist '("\\.txt\\'" . (lambda()
306 (add-hook 'c++-mode-hook 'flyspell-prog-mode)
307 (add-hook 'log-edit-mode-hook 'flyspell-mode)
311 (put 'narrow-to-region 'disabled nil)
312 (put 'upcase-region 'disabled nil)
313 (put 'downcase-region 'disabled nil)
314 ;; (put 'scroll-left 'disabled nil)
315 ;; (put 'scroll-right 'disabled nil)
317 ;; My selector is clearer than that
318 ;; (when (load "ido" t) (ido-mode t))
320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
322 ;; Makes buffer names more explicit then <2>, <3> etc. when there are
323 ;; several identical filenames
325 (when (load "uniquify" t)
326 (setq uniquify-buffer-name-style 'post-forward-angle-brackets))
328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
330 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
332 (when (boundp 'x-display-name)
336 ;; If the display is :0.0, we make the assumption that we are
337 ;; running the emacs locally, and we do not show the
338 ;; hostname. Otherwise, show @host.
340 frame-title-format (concat "emacs" ;;invocation-name
341 (unless (string= x-display-name ":0.0")
342 (concat "@" system-name))
345 ;; Use the same for the icone
347 icon-title-format frame-title-format
350 ;; "tool" bar? Are you kidding?
351 (when (fboundp 'tool-bar-mode) (tool-bar-mode -1))
353 ;; ;; If my own letter icon is here, use it and change its color
354 ;; (when (file-exists-p "~/local/share/emacs/letter.xbm")
355 ;; (setq-default display-time-mail-icon
358 ;; :file "~/local/share/emacs/letter.xbm"
359 ;; :ascent center)))))
361 ;; My funky setting of face colors. Basically, we switch to a sober
362 ;; look and darken a bit the colors which need to (because of the
363 ;; darker background)
365 (defun ff/configure-faces (fl)
366 "Set face attributes and create faces when necessary"
368 (unless (boundp (car f)) (make-empty-face (car f)))
369 (eval `(set-face-attribute (car f) nil ,@(cdr f))))
372 ;; Not the same in xterm (which is gray in my case) and in
375 (unless window-system
376 ;; (xterm-mouse-mode 1)
378 '((italic :underline nil)
379 (info-title-2 :foreground "green")
380 (cperl-array-face :background "gray90" :foreground "blue" :weight 'bold)
381 (cperl-hash-face :background "gray90" :foreground "purple" :weight 'bold)
382 (diff-added :background "gray90" :foreground "green4" :weight 'bold)
383 (diff-removed :background "gray90" :foreground "red2" :weight 'bold)
384 (diff-changed :background "gray90" :foreground "blue" :weight 'bold)
385 (diff-file-header-face :background "white" :foreground "black"
387 (diff-header-face :background "white" :foreground "black")
388 (diff-hunk-header-face :background "white" :foreground "black")
389 (diff-indicator-removed :foreground "red" :weight 'bold)
390 (diff-removed :foreground "red" :weight 'bold)
391 (diff-indicator-added :foreground "blue" :weight 'bold)
392 (diff-added :foreground "blue" :weight 'bold)
393 (font-lock-string-face :foreground "green")
394 (font-lock-variable-name-face :foreground "blue")
395 (font-lock-constant-face :foreground "blue")
396 (font-lock-function-name-face :foreground "blue")
397 (font-lock-preprocessor-face :foreground "green")
398 (font-lock-function-name-face :foreground "cyan")
399 (flyspell-incorrect-face :foreground "red2")
400 (flyspell-duplicate-face :foreground "OrangeRed2")
401 (hl-line :background "white")
402 (sh-heredoc :foreground "black" :background "#fff0f0")
403 (sh-heredoc-face :foreground "black" :background "#fff0f0")
404 (font-lock-keyword-face :foreground "blue")
405 (highlight :background "darkseagreen3")
406 (isearch :background "orange" :foreground "black")
407 (isearch-lazy-highlight-face' :background "yellow" :foreground "black")
408 ;; (display-time-mail-face :background "white")
409 (show-paren-match-face :background "gold" :foreground "black")
410 (show-paren-mismatch-face :background "red" :foreground "black")
411 (trailing-whitespace :background "white")
412 (mode-line :background "cornflowerblue" :foreground "black" :box nil
414 (header-line :background "cornflowerblue" :foreground "black" :box nil
416 (mode-line-inactive :background "gray60" :foreground "black" :box nil
418 (region :background "springgreen2")
419 (ff/date-info-face :foreground "white" :weight 'bold)
420 (ff/mail-alarm-face :foreground "red" :weight 'bold)
421 (gui-button-face :background "green" :foreground "white")
422 (enotes/information-face :foreground "cyan")
426 ;; (list-colors-display (mapcar 'car color-name-rgb-alist))
428 ;; (ff/configure-faces '((default :background "black" :foreground "gray80")))
429 ;; (ff/configure-faces '((default :background "gray80" :foreground "black")))
433 ;; display-time-use-mail-icon t)
437 ;; (escape-glyph :foreground "#c0c0c0" :weight 'bold)
438 (escape-glyph :foreground "green3" :weight 'bold)
439 (default :background "gray90" :foreground "black")
440 (cperl-array-face :background "gray90" :foreground "blue" :weight 'bold)
441 (cperl-hash-face :background "gray90" :foreground "purple" :weight 'bold)
442 (message-cited-text :foreground "red4")
443 (diff-mode :background "gray90" :weight 'bold)
444 (diff-added :background "gray90" :foreground "green4" :weight 'bold)
445 (diff-removed :background "gray90" :foreground "red2" :weight 'bold)
446 (diff-changed :background "gray90" :foreground "blue" :weight 'bold)
447 (diff-file-header :background "white" :foreground "black"
449 (diff-header :background "white" :foreground "black")
450 (diff-hunk-header :background "white" :foreground "black")
451 (font-lock-builtin-face :foreground "deeppink3")
452 (font-lock-string-face :foreground "dark olive green")
453 (font-lock-variable-name-face :foreground "sienna")
454 (font-lock-function-name-face :foreground "blue4" :weight 'bold)
455 ;; (font-lock-comment-delimiter-face :foreground "dark violet")
456 ;; (font-lock-comment-face :foreground "dark violet")
457 (flyspell-incorrect-face :foreground "red2")
458 (flyspell-duplicate-face :foreground "OrangeRed2")
459 (hl-line :background "white")
460 (sh-heredoc :foreground "black" :background "#fff0f0")
461 (sh-heredoc-face :foreground "black" :background "#fff0f0")
462 (header-line :background "gray65")
463 (highlight :background "turquoise")
464 (message-cited-text-face :foreground "firebrick")
465 (isearch :background "yellow" :foreground "black")
466 (isearch-lazy-highlight-face' :background "yellow3" :foreground "black")
467 (region :background "#b8b8e0" :foreground "black")
468 ;; (region :background "plum" :foreground "black")
469 (show-paren-match-face :background "gold" :foreground "black")
470 (show-paren-mismatch-face :background "red" :foreground "black")
471 (trailing-whitespace :background "gray65")
472 (cursor :inverse-video t)
473 (enotes/list-title-face :foreground "blue" :weight 'bold)
474 (mode-line :background "#b0b0ff" :foreground "black" :box nil
476 (header-line :background "cornflowerblue" :foreground "black" :box nil
478 (mode-line-inactive :background "#b0b0b0" :foreground "black" :box nil
480 ;; (fringe :background "black" :foreground "gray90")
481 (fringe :background "gray65")
482 (tex-verbatim :family "courrier")
483 (ff/date-info-face :foreground "white" :weight 'bold)
484 (ff/mail-alarm-face :foreground "white" :background "red2")
485 ;; (alarm-vc-face :foreground "black" :background "yellow" :weight 'normal)
489 ;; When we are root, put the modeline in red
491 (when (string= (user-real-login-name) "root")
493 '((mode-line :background "red3" :foreground "black" :box nil
497 ;; Why should I have to do this?
498 (add-hook 'sh-mode-hook
500 (set-face-attribute 'sh-heredoc nil
501 :foreground "#604000"
504 (set-face-attribute 'sh-heredoc-face nil
505 :foreground "#604000"
510 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
511 ;; Move the window on the buffer without moving the cursor
512 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
514 (defun ff/scroll-down ()
515 "Scroll the buffer down one line and keep the cursor at the same location."
521 (defun ff/scroll-up ()
522 "Scroll the buffer up one line and keep the cursor at the same location."
528 (defun ff/scroll-left ()
529 "Scroll the buffer left one column and keep the cursor at the same location."
535 (defun ff/scroll-right ()
536 "Scroll the buffer right one column and keep the cursor at the same location."
542 (define-key global-map [(meta up)] 'ff/scroll-down)
543 (define-key global-map [(meta down)] 'ff/scroll-up)
544 (define-key global-map [(meta p)] 'ff/scroll-down)
545 (define-key global-map [(meta n)] 'ff/scroll-up)
546 (define-key global-map [(meta right)] 'ff/scroll-left)
547 (define-key global-map [(meta left)] 'ff/scroll-right)
549 (defun ff/delete-trailing-whitespaces-and-indent ()
551 (delete-trailing-whitespace)
552 (indent-region (point-min) (point-max) nil))
554 (define-key global-map [(control c) (control q)] 'ff/delete-trailing-whitespaces-and-indent)
556 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
560 ;; (defun ff/esd-sound (file)
561 ;; "Plays a sound with the Enlighted sound daemon."
563 ;; (process-kill-without-query (start-process-shell-command "esdplay"
567 (defun ff/alsa-sound (file)
568 "Plays a sound with ALSA."
570 (process-kill-without-query (start-process-shell-command "aplay"
574 (if (and (boundp 'x-display-name) (string= x-display-name ":0.0"))
575 (defalias 'ff/play-sound-async 'ff/alsa-sound)
576 (defalias 'ff/play-sound-async 'ding))
578 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
579 ;; I comment stuff often, let's be efficient. shift + down comments
580 ;; the current line and goes down, and shift + up uncomments the line
581 ;; and goes up (they are not the dual of each other, but moving and
582 ;; then uncommenting would be very counter-intuitive).
583 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
585 (defun ff/comment-and-go-down (arg)
586 "Comments and goes down ARG lines."
589 (comment-region (point-at-bol) (point-at-eol)) (error nil))
591 (if (> arg 1) (ff/comment-and-go-down (1- arg))))
593 (defun ff/uncomment-and-go-up (arg)
594 "Uncomments and goes up ARG lines."
597 (uncomment-region (point-at-bol) (point-at-eol)) (error nil))
599 (if (> arg 1) (ff/uncomment-and-go-up (1- arg))))
601 (define-key global-map [(shift down)] 'ff/comment-and-go-down)
602 (define-key global-map [(shift up)] 'ff/uncomment-and-go-up)
604 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
605 ;; Counting various entities in text
606 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
608 (defun ff/count-char ()
609 "Prints the number of characters between the first previous \"--\"
610 and the firt next \"--\"."
612 (let ((from (save-excursion (re-search-backward "^--$\\|BEGIN_COUNT" nil t)))
613 (to (save-excursion (re-search-forward "^--$\\|END_COUNT" nil t))))
614 (if (and to from) (message "%d character(s)" (- to from 6))
615 (error "Can not find the -- delimiters"))))
617 (defun ff/count-words ()
618 "Print number of words between the first previous \"--\" and the
621 (let ((from (save-excursion (re-search-backward "^--$" nil t)))
622 (to (save-excursion (re-search-forward "^--$" nil t))))
627 (while (< (point) to)
628 (re-search-forward "\\w+\\W+")
629 (setq count (1+ count)))
630 (message "%d word(s)" count)))
631 (error "Can not find the -- delimiters"))))
633 (defun ff/word-occurences ()
634 "Display in a new buffer the list of words sorted by number of
638 (let ((buf (get-buffer-create "*word counting*"))
639 (map (make-sparse-keymap))
640 (nb (make-hash-table))
641 (st (make-hash-table))
644 ;; Collects all words in a hash table
647 (goto-char (point-min))
648 (while (re-search-forward "\\([\\-a-zA-Z\\\\]+\\)" nil t)
649 (let* ((s (downcase (match-string-no-properties 1)))
652 (puthash k (1+ (gethash k nb 0)) nb))))
654 ;; Creates the result buffer
656 (define-key map "q" 'kill-this-buffer)
659 (setq show-trailing-whitespace nil)
662 ;; Builds a list from the hash table
666 (setq result (cons (cons value (gethash key st)) result)))
669 ;; Sort and display it
672 (if (and (> (car x) 3)
673 ;; No leading backslash and at least four characters
674 (string-match "^[^\\]\\{4,\\}" (cdr x))
676 (insert (number-to-string (car x)) " " (cdr x) "\n")))
677 (sort result (lambda (a b) (> (car a) (car b)))))
679 ;; Adjust the window size and stuff
681 (fit-window-to-buffer (get-buffer-window buf))
683 (set-buffer-modified-p nil))
686 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
688 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
692 (setq ps-print-color-p nil
693 ps-paper-type 'letter
695 ;; ps-top-margin (* 1.75 56.692)
696 ;; ps-left-margin 56.692
697 ;; ps-bottom-margin 56.692
698 ;; ps-right-margin 56.692
700 ;; Simple header. Remove that silly frame shadow.
702 ps-print-header-frame nil
703 ps-header-line-pad 0.3
704 ps-header-font-family 'Courier
705 ps-header-title-font-size '(8.5 . 10)
706 ps-header-font-size '(6 . 7)
707 ps-font-size '(7 . 8)
710 (ps-put 'ps-header-frame-alist 'back-color 1.0)
711 (ps-put 'ps-header-frame-alist 'shadow-color 1.0)
712 (ps-put 'ps-header-frame-alist 'border-color 0.0)
713 (ps-put 'ps-header-frame-alist 'border-width 0.0)
715 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
717 ;; http://blog.tuxicity.se/elisp/emacs/2010/03/26/rename-file-and-buffer-in-emacs.htm
719 (defun rename-file-and-buffer ()
720 "Renames current buffer and file it is visiting."
722 (let ((name (buffer-name))
723 (filename (buffer-file-name)))
724 (if (not (and filename (file-exists-p filename)))
725 (message "Buffer '%s' is not visiting a file!" name)
726 (let ((new-name (read-file-name "New name: " filename)))
727 (cond ((get-buffer new-name)
728 (message "A buffer named '%s' already exists!" new-name))
730 (rename-file name new-name 1)
731 (rename-buffer new-name)
732 (set-visited-file-name new-name)
733 (set-buffer-modified-p nil)))))))
735 (global-set-key (kbd "C-c r") 'rename-file-and-buffer)
737 (defun ff/non-existing-filename (dir prefix suffix)
738 "Returns a filename of the form DIR/PREFIX[.n].SUFFIX whose file does
741 (f (concat prefix suffix)))
742 (while (file-exists-p (concat dir "/" f))
744 f (concat prefix "." (prin1-to-string n) suffix)))
747 (defun ff/print-buffer-or-region-with-faces (&optional file)
749 ;; I am fed up with spell checking highlights
750 (when (and flyspell-mode
751 ;; (or ispell-minor-mode flyspell-mode)
752 (not (y-or-n-p "The spell checking is on, still print ? ")))
753 (error "Printing cancelled, the spell-checking is on"))
757 (ps-print-region-with-faces (region-beginning) (region-end) file)
759 (ps-print-buffer-with-faces file)))
761 (defun ff/print-to-file (file)
762 "Prints the region if selected or the whole buffer in postscript
767 "PS file: " "/tmp/" nil nil
768 (ff/non-existing-filename
770 (replace-regexp-in-string "[^a-zA-Z0-9_.-]" "_" (file-name-nondirectory
774 (ff/print-buffer-or-region-with-faces file))
776 (defun ff/print-to-printer ()
777 "Prints the region if selected or the whole buffer to a postscript
780 (message "Printing to '%s'" (getenv "PRINTER"))
781 (ff/print-buffer-or-region-with-faces))
783 ;; Can you believe it? There is a "print" key on PC keyboards ...
785 (define-key global-map [(print)] 'ff/print-to-file)
786 (define-key global-map [(shift print)] 'ff/print-to-printer)
788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
789 ;; Dealing with the laptop battery
790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
792 (defcustom ff/battery-dir "/sys/class/power_supply/BAT0"
793 "*Where to gather the battery information")
795 (defcustom ff/temperature-file "/sys/class/thermal/thermal_zone0/temp"
796 "*Where to gather the thermal information")
798 (defun ff/file-first-line (file)
800 (insert-file-contents-literally file)
801 (buffer-substring (point-at-bol) (point-at-eol))))
803 (defun ff/battery-percent (prefix)
805 (/ (* 100 (string-to-number (ff/file-first-line (format "%s/%s_now" ff/battery-dir prefix))))
806 (string-to-number (ff/file-first-line (format "%s/%s_full" ff/battery-dir prefix))))
810 (defun ff/laptop-info-string () (interactive)
816 (let ((temp (/ (string-to-number (ff/file-first-line ff/temperature-file)) 1000)))
819 (let ((s (format "%dC " temp)))
820 (if (> temp 65) (propertize s 'face
821 'font-lock-warning-face)
829 (let ((battery-status (ff/file-first-line (concat ff/battery-dir "/status"))))
832 ((string= battery-status "Full") "L")
834 ((string= battery-status "Charging")
835 (format "L%d%%" (max (ff/battery-percent "charge")
836 (ff/battery-percent "energy"))))
838 ((string= battery-status "Discharging")
839 (let* ((c (max (ff/battery-percent "charge")
840 (ff/battery-percent "energy")))
841 (s (format "B%d%%" c)))
842 (if (>= c 20) s (propertize s 'face 'font-lock-warning-face))))
853 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
855 (defun ff/system-info () (interactive)
857 (let ((buf (get-buffer-create "*system info*"))
858 (map (make-sparse-keymap)))
860 (define-key map "q" 'kill-this-buffer)
863 (setq show-trailing-whitespace nil)
866 (let ((highlight nil))
870 (if (setq highlight (not highlight))
872 (with-temp-buffer (apply 'call-process x)
874 'face '(:background "#c0c0ff"))
875 (with-temp-buffer (apply 'call-process x)
881 ("hostname" nil t nil "-v")
883 ("df" nil t nil "-h")
886 ("ssh-add" nil t nil "-l")
889 (goto-char (point-min))
890 (while (re-search-forward "^$" nil t) (backward-delete-char 1))
892 (fit-window-to-buffer (get-buffer-window buf))
894 (set-buffer-modified-p nil)
897 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
898 ;; Make a sound when there is new mail
899 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
901 ;; I do not like sounds anymore
903 ;; (setq ff/already-boinged-for-mail nil)
905 ;; (defun ff/boing-if-new-mail ()
906 ;; (if mail (when (not ff/already-boinged-for-mail)
907 ;; ;; (ff/play-sound-async "~/local/sounds/boing1.wav")
908 ;; ;; (ff/show-unspooled-mails)
909 ;; (setq ff/already-boinged-for-mail t))
910 ;; (setq ff/already-boinged-for-mail nil))
913 ;; (add-hook 'display-time-hook 'ff/boing-if-new-mail)
915 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
917 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
921 display-time-interval 15 ;; Check every 15s
923 display-time-string-forms `(
927 ;; (propertize " mail "
928 ;; 'face 'ff/mail-alarm-face)
932 (propertize (concat 24-hours ":" minutes
937 'face 'ff/date-info-face)
941 ,(if (ff/laptop-info-string)
942 '(concat " " (ff/laptop-info-string)))
946 ;; display-time-format "%b %a %e %H:%M"
947 ;; display-time-mail-face nil
950 ;; Show the time, mail and stuff
953 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
954 ;; Moving through buffers
955 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
957 (defun ff/next-buffer ()
958 "Switches to the next buffer in cyclic order."
960 (let ((buffer (current-buffer)))
961 (switch-to-buffer (other-buffer buffer))
962 (bury-buffer buffer)))
964 (defun ff/prev-buffer ()
965 "Switches to the previous buffer in cyclic order."
967 (let ((list (nreverse (buffer-list)))
969 (while (and (not found) list)
970 (let ((buffer (car list)))
971 (if (and (not (get-buffer-window buffer))
972 (not (string-match "\\` " (buffer-name buffer))))
973 (setq found buffer)))
974 (setq list (cdr list)))
975 (switch-to-buffer found)))
977 (define-key global-map [?\C-x right] 'ff/next-buffer)
978 (define-key global-map [?\C-x left] 'ff/prev-buffer)
980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
981 ;; There is actually a decent terminal emulator in emacs!
982 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
986 (defun ff/kill-associated-buffer (process str) (interactive)
987 (let ((buffer (process-buffer process)))
988 (kill-buffer buffer))
989 (message "Process finished (%s)" (replace-regexp-in-string "\n$" "" str)))
991 (defun ff/kill-associated-buffer-and-delete-windows (process str) (interactive)
992 (let ((buffer (process-buffer process)))
993 (delete-windows-on buffer)
994 (kill-buffer buffer))
995 (message "Process finished (%s)" (replace-regexp-in-string "\n$" "" str)))
997 (defun ff/shell-new-buffer (buffername program &rest param)
998 "Start a terminal-emulator in a new buffer with the shell PROGRAM,
999 optionally invoked with the parameters PARAM. The process associated
1000 to the shell can be killed without query."
1007 (while (get-buffer (concat "*" bn "*"))
1009 bn (format "%s<%d>" buffername n)))
1011 (set-buffer (apply 'make-term (append (list bn program nil) param)))
1013 (setq show-trailing-whitespace nil)
1015 (message "C-c C-k term-char-mode, C-c C-j term-line-mode. \
1016 In line mode: M-p previous line, M-n next line.")
1018 ;; A standard setup of the face above is not enough, I have to
1019 ;; force them here. Since I have a gray90 background, I like
1024 '((term-green :foreground "green3")
1025 (term-cyan :foreground "cyan3")
1026 (term-default-fg-inv :foreground "gray90" :background "black")
1029 (term-set-escape-char ?\C-x)
1031 ;; I like the shell buffer and windows to be deleted when the
1032 ;; shell process terminates. It's a bit of a mess to acheive this.
1034 (let ((process (get-buffer-process (current-buffer))))
1035 (process-kill-without-query process)
1036 (set-process-sentinel process
1037 ;; 'ff/kill-associated-buffer-and-delete-windows
1038 'ff/kill-associated-buffer
1041 ;; (switch-to-buffer-other-window (concat "*" bn "*"))
1042 (switch-to-buffer (concat "*" bn "*"))
1045 (defcustom ff/default-bash-commands '("ssh")
1046 "*List of commands to be used for completion when invoking a new
1047 bash shell with `ff/bash-new-buffer'.")
1049 (defun ff/bash-new-buffer (universal)
1050 "Starts a bash in a new buffer. When invoked with a universal
1051 argument, asks for a command to execute in that bash shell. The list
1052 of commands in `ff/default-bash-commands' is used for auto-completion"
1056 (let ((cmd (completing-read
1058 (mapcar (lambda (x) (cons x t)) ff/default-bash-commands))))
1059 (ff/shell-new-buffer cmd "/bin/bash" "-c" cmd))
1061 (ff/shell-new-buffer "bash" "/bin/bash")))
1063 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1065 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1067 (setq ;; Always follow links if the file is under version control
1068 vc-follow-symlinks t
1071 (when (load "vc-git" nil t)
1072 (add-to-list 'vc-handled-backends 'GIT))
1074 ;; alarm-vc.el is one of my own scripts, check my web page
1076 (when (ff/load-or-alert "alarm-vc" t)
1077 (setq alarm-vc-mode-exceptions "^VM"))
1079 (when (ff/load-or-alert "git")
1080 (setq git-show-unknown nil)
1083 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1084 ;; Makes .sh and others files executable automagically
1085 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1087 ;; Please consider the security-related consequences of using it
1089 ;; (defun ff/make-shell-scripts-executable (&optional filename)
1090 ;; (setq filename (or filename (buffer-name)))
1091 ;; (when (and (string-match "\\.sh$\\|\\.pl$\\|\\.rb" filename)
1092 ;; (not (file-executable-p filename))
1094 ;; (set-file-modes filename 493)
1095 ;; (message "Made %s executable" filename)))
1097 ;; (add-hook 'after-save-hook 'ff/make-shell-scripts-executable)
1099 (add-hook 'after-save-hook
1100 'executable-make-buffer-file-executable-if-script-p)
1102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1103 ;; Cool stuff to navigate in emacs-lisp sources
1104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1108 (defun ff/goto-function-definition (&optional goback)
1109 "Go directly to the definition of the function at point. With
1110 goback argument, go back where we were."
1113 (if (not (and (boundp 'goto-function-history) goto-function-history))
1114 (error "We were nowhere, buddy")
1115 (message "Come back")
1116 (switch-to-buffer (car (car goto-function-history)))
1117 (goto-char (cdr (car goto-function-history)))
1118 (setq goto-function-history (cdr goto-function-history)))
1120 (let ((function (function-called-at-point)))
1122 (let ((location (find-function-search-for-symbol
1124 (symbol-file function))))
1125 (setq goto-function-history
1126 (cons (cons (current-buffer) (point))
1127 (and (boundp 'goto-function-history)
1128 goto-function-history)))
1129 (pop-to-buffer (car location))
1130 (goto-char (cdr location)))))))
1132 (define-key global-map [(meta g)] 'ff/goto-function-definition)
1133 (define-key global-map [(meta G)] (lambda () (interactive)
1134 (ff/goto-function-definition t)))
1136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1137 ;; The big stuff (bbdb, mailcrypt, etc.)
1138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1140 ;; Failsafe version if we can't load bbdb
1141 (defun ff/explicit-name (email) email)
1145 (when (ff/load-or-alert "bbdb")
1148 ;; Stop asking (if not t or nil, will not ask)
1149 bbdb-offer-save 'never
1150 ;; I hate when bbdb decides to mess up my windows
1152 ;; I have no problem with bbdb asking me if the sender email
1153 ;; does not match exactly the address we have in the database
1154 bbdb-quiet-about-name-mismatches 0
1155 ;; I have european friends, too
1156 bbdb-north-american-phone-numbers-p nil
1157 ;; To cycle through all possible addresses
1158 bbdb-complete-name-allow-cycling t
1159 ;; Cycle with full names only, not through all net-addresses alone too
1160 bbdb-dwim-net-address-allow-redundancy t
1161 ;; Do not add new addresses automatically
1162 bbdb-always-add-addresses nil
1165 (defface ff/known-address-face
1166 '((t (:foreground "blue2")))
1167 "The face to display known mail identities.")
1169 (defface ff/unknown-address-face
1170 '((t (:foreground "gray50")))
1171 "The face to display unknown mail identities.")
1173 (defun ff/explicit-name (email)
1174 "Returns a string identity for the first address in EMAIL. The
1175 identity is taken from bbdb if possible or from the address itself
1176 with mail-extract-address-components. The suffix \"& al.\" is added if
1177 there are more than one address.
1179 If no bbdb record is found, the name is propertized with the face
1180 ff/unknown-address-face. If a record is found and contains a note
1181 'face, the associated face is used, otherwise
1182 ff/known-address-face is used."
1185 (let* ((data (mail-extract-address-components email))
1188 (record (bbdb-search-simple nil net)))
1193 (propertize (bbdb-record-name record)
1195 (or (cdr (assoc 'face
1196 (bbdb-record-raw-notes record)))
1197 'ff/known-address-face))
1199 (propertize (or (and data (concat "<" net ">"))
1201 'face 'ff/unknown-address-face)
1203 (if (string-match "," (mail-strip-quoted-names email)) " & al.")
1207 (ff/configure-faces '((ff/robot-address-face :foreground "green4")
1208 (ff/personal-address-face :foreground "dark magenta"
1210 (ff/important-address-face :foreground "blue2"
1212 ;; :background "white"
1213 ;; :foreground "green4"
1220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1221 ;; An encrypted file to put secure stuff (passwords, ...)
1222 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1224 (when (ff/load-or-alert "mailcrypt")
1225 (mc-setversion "gpg")
1226 ;; Keep the passphrase for 10min
1227 (setq mc-passwd-timeout 600
1228 ff/secure-note-file "~/private/secure-notes.gpg")
1231 (defface ff/secure-date
1232 '((t (:background "gold" :weight bold)))
1233 "The face to display the dates in the modeline.")
1235 (defun ff/secure-note-add () (interactive)
1236 (find-file ff/secure-note-file)
1238 ;; Adds a new entry (i.e. date and a bunch of empty lines)
1240 (goto-char (point-min))
1242 (format-time-string "%Y %b %d %H:%M:%S" (current-time))
1243 " ------------------------------------------------\n\n")
1246 ;; Colorizes the dates
1249 (goto-char (point-min))
1250 (while (re-search-forward
1251 "^-+ [0-9]+ [a-z]+ [0-9]+ [0-9]+:[0-9]+:[0-9]+.+$"
1253 (add-text-properties
1254 (match-beginning 0) (match-end 0) '(face ff/secure-date))))
1256 (set-buffer-modified-p nil)
1257 (setq buffer-undo-list nil)
1260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1262 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1264 (setq ;; For french, aspell is far better than ispell
1265 ispell-program-name "aspell"
1266 ;; To avoid ispell errors in figure filenames, labels, references.
1267 ;; ispell-tex-skip-alists
1269 ;; (append (car ispell-tex-skip-alists)
1270 ;; '(("\\\\citep" ispell-tex-arg-end) ;; JMLR
1271 ;; ("\\\\cite" ispell-tex-arg-end)
1272 ;; ("\\\\nocite" ispell-tex-arg-end)
1273 ;; ("\\\\includegraphics" ispell-tex-arg-end)
1274 ;; ("\\\\author" ispell-tex-arg-end)
1275 ;; ("\\\\ref" ispell-tex-arg-end)
1276 ;; ("\\\\label" ispell-tex-arg-end)
1278 ;; (cadr ispell-tex-skip-alists))
1280 ;; So that reftex follows the text when moving in the summary
1281 reftex-toc-follow-mode nil
1282 ;; So that reftex visits files to follow
1283 reftex-revisit-to-follow t
1286 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1287 ;; Used in a \includegraphics runs xfig with the corresponding .fig
1288 ;; file or gimp with the corresponding bitmap picture
1289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1291 (defun ff/run-eps-edition (prefix rules &optional force)
1293 (let ((filename (concat prefix (car (car rules)))))
1294 (if (or force (file-exists-p filename))
1295 (start-process "latex-eps-editor" nil (cdr (car rules)) filename)
1296 (ff/run-eps-edition prefix (cdr rules) force)))
1297 (message "No original file found for %seps" prefix)))
1299 (defcustom ff/xdvi-for-latex-options nil
1300 "*Options to pass to xdvi when invoking `ff/run-viewer'")
1302 (defun ff/run-viewer (universal)
1304 "Starts an editor for the .eps at point (either xfig or gimp,
1305 depending with the original file it can find), or starts xdvi for
1306 the current .tex if no .eps is found at point. When run with a
1307 universal argument starts xfig even if the .fig does not exist"
1311 (if (and (save-excursion
1312 (and (re-search-backward "{" (point-at-bol) t)
1313 (or (re-search-forward "{\\([^{}]*.\\)eps}" (point-at-eol) t)
1314 (re-search-forward "{\\([^{}]*.\\)pdf}" (point-at-eol) t)
1315 (re-search-forward "{\\([^{}]*.\\)pdf_t}" (point-at-eol) t)
1316 (re-search-forward "{\\([^{}]*.\\)png}" (point-at-eol) t)
1317 (re-search-forward "{\\([^{}]*.\\)jpg}" (point-at-eol) t)
1319 (and (<= (match-beginning 1) (point))
1320 (>= (match-end 1) (- (point) 2))))
1322 (ff/run-eps-edition (match-string-no-properties 1)
1325 ("png" . "gimp") ("pgm" . "gimp") ("ppm" . "gimp")
1329 (if (not (and (buffer-file-name) (string-match "\\(.*\\)\.tex$"
1330 (buffer-file-name))))
1331 (message "Not a latex file!")
1332 (condition-case nil (kill-process xdvi-process) (error nil))
1333 (let ((dvi-name (concat (match-string 1 (buffer-file-name)) ".dvi")))
1334 (if (not (file-exists-p dvi-name)) (error "Can not find %s !" dvi-name)
1335 (message "Starting xdvi with %s" dvi-name)
1336 (setq xdvi-process (apply 'start-process
1337 (append '("xdvi-for-latex" nil "xdvi")
1338 ff/xdvi-for-latex-options
1340 (process-kill-without-query xdvi-process))))
1343 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1346 ;; When working on a tex file with other people, I can just change
1347 ;; ff/tex-command in the -*- part of the file so that I don't mess up
1348 ;; other's people configuration.
1350 (defadvice tex-file (around ff/set-my-own-tex-command () activate)
1352 (or (and (boundp 'ff/tex-command)
1357 ;; This is a bit hardcore, but really I can't bear the superscripts in
1358 ;; my emacs window and could not find another way to deactivate them.
1361 (defun tex-font-lock-suscript (pos) ())
1363 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1364 ;; Prevents many errors from beeping and makes the others play a nifty
1366 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1368 (defun ff/ring-bell ()
1369 (unless (memq this-command
1371 abort-recursive-edit
1374 backward-delete-char-untabify
1375 delete-backward-char
1376 minibuffer-complete-and-exit
1377 previous-line next-line
1378 backward-char forward-char
1379 scroll-up scroll-down
1380 enlarge-window-horizontally shrink-window-horizontally
1381 enlarge-window shrink-window
1384 ;; (message "command [%s]" (prin1-to-string this-command))
1385 ;; (ff/play-sound-async "~/local/sounds/short_la.wav")
1388 (setq ring-bell-function 'ff/ring-bell)
1390 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1391 ;; Past the content of the url currently in the kill-ring with
1393 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1395 (defun ff/insert-url (&optional url)
1396 "Downloads an URL with lynx and inserts it after the point."
1397 (interactive "MUrl: ")
1399 (message "Inserting %s" url)
1400 (insert (concat "from: " url "\n\n"))
1401 ;; (call-process "lynx" nil t nil "-nolist" "-dump" url))
1402 (call-process "w3m" nil t nil "-dump" url))
1405 (define-key global-map [(shift mouse-2)]
1406 (lambda () (interactive) (ff/insert-url (current-kill 0))))
1408 ;; lookup-dict is one of my own scripts, check my web page
1410 (when (ff/load-or-alert "lookup-dict" t)
1411 (define-key global-map [(control \?)] 'lookup-dict))
1413 ;; (defun ff/generate-password () (interactive)
1414 ;; (let ((c "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-"))
1415 ;; (nth (random (length c)) c))
1417 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1418 ;; Automatization of things I do often
1419 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1421 (defun ff/snip () (interactive)
1422 (let ((start (condition-case nil (region-beginning) (error (point))))
1423 (end (condition-case nil (region-end) (error (point)))))
1425 (insert "---------------------------- snip snip -------------------------------\n")
1427 (insert "---------------------------- snip snip -------------------------------\n")
1430 (defun ff/start-latex ()
1431 "Adds all that stuff to start a new LaTeX document."
1433 (goto-char (point-min))
1434 (insert "%% -*- mode: latex; mode: reftex; mode: flyspell; coding: utf-8; tex-command: \"pdflatex.sh\" -*-
1436 \\documentclass[12pt]{article}
1437 \\usepackage[a4paper,top=2.5cm,bottom=2cm,left=1.5cm,right=1.5cm]{geometry}
1438 \\usepackage[utf8]{inputenc}
1439 \\usepackage{amsmath}
1440 \\usepackage{amssymb}
1441 \\usepackage[pdftex]{graphicx}
1442 \\usepackage{microtype}
1443 \\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue,citecolor=blue]{hyperref}
1445 \\setlength{\\parindent}{0cm}
1446 \\setlength{\\parskip}{12pt}
1447 \\renewcommand{\\baselinestretch}{1.3}
1449 \\def\\argmax{\\operatornamewithlimits{argmax}}
1450 \\def\\argmin{\\operatornamewithlimits{argmin}}
1452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1454 %% \\usepackage[T1]{fontenc}
1455 %% \\usepackage[scaled]{helvet}
1456 %% \\usepackage[cm]{sfmath}
1457 %% \\renewcommand{\\ttdefault}{pcr}
1458 %% \\renewcommand*\\familydefault{\\sfdefault}
1459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1460 %% The \\todo command
1461 \\newcounter{nbdrafts}
1462 \\setcounter{nbdrafts}{0}
1464 \\newcommand{\\checknbdrafts}{
1465 \\ifnum \\thenbdrafts > 0
1466 \\@latex@warning@no@line{*WARNING* The document contains \\thenbdrafts \\space draft note(s)}
1468 \\newcommand{\\todo}[1]{\\addtocounter{nbdrafts}{1}{\\color{red} #1}}
1470 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1476 (goto-char (point-max))
1483 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1485 (defun ff/add-copyrights ()
1486 "Adds two lines for the (C) at the beginning of current buffer."
1489 (let ((comment-style 'plain))
1491 (goto-char (point-min))
1493 ;; If this is a script, put the copyrights after the first line
1495 (when (re-search-forward "^#!" nil t)
1499 (let ((start (point))
1500 (comment-style 'box))
1504 "\nSTART_IP_HEADER\n"
1506 (when (boundp 'user-full-name)
1507 (concat "\nWritten by " user-full-name "\n"))
1509 (when (boundp 'user-mail-address)
1510 (concat "Contact <" user-mail-address "> for comments & bug reports\n"))
1515 (comment-region start (point)))
1519 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1521 (defun ff/remove-ip-header () (interactive)
1523 (goto-char (point-min))
1524 (when (and (re-search-forward "START_IP_HEADER" nil t)
1525 (re-search-forward "END_IP_HEADER" nil t))
1529 (defun ff/add-gpl ()
1530 "Adds the GPL statements at the beginning of current buffer."
1532 (let ((comment-style 'box)
1537 ;; This program is free software; you can redistribute it and/or
1538 ;; modify it under the terms of the GNU General Public License
1539 ;; version 2 as published by the Free Software Foundation.
1541 ;; This program is distributed in the hope that it will be useful, but
1542 ;; WITHOUT ANY WARRANTY\; without even the implied warranty of
1543 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1544 ;; General Public License for more details.
1550 This program is free software: you can redistribute it and/or modify
1551 it under the terms of the version 3 of the GNU General Public License
1552 as published by the Free Software Foundation.
1554 This program is distributed in the hope that it will be useful, but
1555 WITHOUT ANY WARRANTY; without even the implied warranty of
1556 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1557 General Public License for more details.
1559 You should have received a copy of the GNU General Public License
1560 along with this program. If not, see <http://www.gnu.org/licenses/>.
1563 (when (boundp 'user-full-name)
1564 (concat "Written by and Copyright (C) " user-full-name "\n"))
1566 (when (boundp 'user-mail-address)
1567 (concat "Contact <" user-mail-address "> for comments & bug reports\n"))
1575 (goto-char (point-min))
1577 ;; If this is a script, put the gpl after the first line
1578 (when (re-search-forward "^#!" nil t)
1582 (let ((start (point)))
1584 (comment-region start (point)))
1587 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1589 (defun ff/start-c ()
1590 "Adds the header to start a C program."
1592 ;; (beginning-of-buffer)
1598 int main(int argc, char **argv) {
1605 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1607 (defun ff/start-c++ ()
1608 "Adds the header to start a C++ program."
1610 ;; (beginning-of-buffer)
1619 using namespace std;
1621 int main(int argc, char **argv) {
1628 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1630 (defun ff/headerize ()
1631 "Adds the #define HEADER_H, etc."
1633 (let ((flag-name (replace-regexp-in-string
1635 (upcase (file-name-nondirectory (buffer-file-name))))))
1636 (goto-char (point-max))
1637 (insert "\n#endif\n")
1638 (goto-char (point-min))
1639 (insert (concat "#ifndef " flag-name "\n"))
1640 (insert (concat "#define " flag-name "\n"))
1644 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1646 (defun ff/start-html ()
1647 "Adds all that stuff to start a new HTML file."
1649 (goto-char (point-min))
1650 (insert "<?xml version=\"1.0\" encoding=\"utf-8\"?>
1651 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1653 <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
1656 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
1662 (goto-char (point-max))
1670 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1672 ;; Insert a line showing all the variables written on the current line
1673 ;; and separated by commas
1675 (defun ff/cout-var (arg)
1676 "Invoked on a line with a list of variables names,
1677 it inserts a line which displays their values in cout, or cerr if
1678 the function is invoked with a universal arg"
1680 (let ((line (if arg "cerr" "cout")))
1681 (goto-char (point-at-bol))
1682 ;; Regexp syntax sucks moose balls, honnest. To match '[', just
1683 ;; put it as the first char in the [...] ... This leads to some
1684 ;; obvious things like the following
1685 (while (re-search-forward "\\([][a-zA-Z0-9_.:\(\)]+\\)" (point-at-eol) t)
1687 (concat line " << \" "
1688 (match-string 1) " = \" << " (match-string 1))))
1689 (goto-char (point-at-bol))
1691 (insert line " << endl\;\n")
1692 (indent-region (point-at-bol 0) (point-at-eol 0) nil)
1695 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1697 (defun ff/clean-article ()
1698 "Cleans up an article by removing the leading blanks on each line
1699 and refilling all the paragraphs."
1701 (let ((fill-column 92))
1702 (goto-char (point-min))
1703 (while (re-search-forward "^\\ +" nil t)
1704 (replace-match "" nil nil))
1705 (fill-individual-paragraphs (point-min) (point-max) t)))
1707 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1709 (defun ff/start-slide ()
1711 (insert "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1715 (save-excursion (insert "}{}
1725 (define-key latex-mode-map [(meta S)] 'ff/start-slide)
1726 (define-key latex-mode-map [(control c) (control a)] 'align-current)
1727 (define-key latex-mode-map [(control end)] 'tex-close-latex-block)
1728 (define-key latex-mode-map [(control tab)] 'ispell-complete-word)
1729 ;; Strange that I have to specify that
1730 ;; (setq paragraph-separate "[% \f]*$")
1731 ;; (setq paragraph-separate
1732 ;; (concat "[%]*\\|[\f%]\\|[ \t]*\\($\\|"
1734 ;; "\\\\" (regexp-opt (append
1735 ;; (mapcar 'car latex-section-alist)
1736 ;; '("begin" "label" "end" )) t)
1737 ;; "\\>\\|\\\\\\(" (regexp-opt '("item" "bibitem" "newline"
1738 ;; "noindent" "newpage" "footnote"
1739 ;; "marginpar" "parbox" "caption"))
1740 ;; "\\|\\$\\$\\|[a-z]*\\(space\\|skip\\|page[a-z]*\\)"
1741 ;; "\\>\\)[ \t]*\\($\\|%\\)\\)"))
1742 ;; (flyspell-mode 1)
1746 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1748 (defun ff/start-test-code ()
1750 (let ((start (point)))
1752 { // ******************************* START ***************************
1753 #warning Test code added on "
1754 (format-time-string "%04Y %b %02d %02H:%02M:%02S" (current-time))
1757 } // ******************************** END ****************************
1760 (indent-region start (point) nil))
1764 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1766 (defun ff/code-to-html () (interactive)
1768 (narrow-to-region (region-beginning) (region-end))
1769 (replace-string "\"" """ nil (point-min) (point-max))
1770 (replace-string " " " " nil (point-min) (point-max))
1771 (replace-string ">" ">" nil (point-min) (point-max))
1772 (replace-string "<" "<" nil (point-min) (point-max))
1773 (replace-string "\e" "^[" nil (point-min) (point-max))
1774 (replace-string "
\7f" "^?" nil (point-min) (point-max))
1775 (replace-string "
\1f" "^_" nil (point-min) (point-max))
1776 (replace-regexp "$" "<br />" nil (point-min) (point-max))
1780 (defun ff/downcase-html-tags () (interactive)
1782 (beginning-of-buffer)
1783 (while (re-search-forward "<\\([^>]+\\)>" nil t)
1784 (downcase-region (match-beginning 1) (match-end 1)))
1788 ;; If we enter html mode and there is no makefile around, create a
1789 ;; compilation command with tidy (this is cool stuff)
1791 (add-hook 'html-mode-hook
1793 (unless (or (not (buffer-file-name))
1794 (file-exists-p "makefile")
1795 (file-exists-p "Makefile"))
1796 (set (make-local-variable 'compile-command)
1797 (let ((fn (file-name-nondirectory buffer-file-name)))
1798 (format "tidy -utf8 %s > /tmp/%s" fn fn))))))
1800 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1802 (defun ff/count-words-region (beginning end)
1803 "Print number of words in the region.
1804 Words are defined as at least one word-constituent character
1805 followed by at least one character that is not a
1806 word-constituent. The buffer's syntax table determines which
1807 characters these are."
1810 (message "Counting words in region ... ")
1812 (goto-char beginning)
1814 (while (< (point) end)
1815 (re-search-forward "\\w+\\W+")
1816 (setq count (1+ count)))
1817 (cond ((zerop count) (message "The region does NOT have any word."))
1818 ((= 1 count) (message "The region has 1 word."))
1819 (t (message "The region has %d words." count))))))
1821 ;; (add-hook 'html-mode-hook 'flyspell-mode)
1823 (defun ff/tidy-html ()
1824 "Run tidy in on the content of the current buffer, put the result in
1827 (call-process-region (point-min) (point-max)
1830 (list nil (make-temp-file "/tmp/tidy-html."))))
1832 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1834 ;; Create the adequate embryo of a file if it does not exist
1836 (defun ff/start-file () (interactive)
1837 (let ((filename (buffer-file-name)))
1840 (when (string-match "\\.sh$" filename)
1842 (insert "#!/bin/bash\n\nset -e\n\n")
1844 (ff/add-copyrights))
1847 (when (string-match "\\.html$" filename)
1853 (when (string-match "\\.h$" filename)
1864 (when (string-match "\\.c$" filename)
1869 (when (string-match "\.\\(cc\\|cpp\\)$" filename)
1872 (let ((headername (replace-regexp-in-string "\\.\\(cc\\|cpp\\)$" ".h"
1874 (if (file-exists-p headername)
1875 (insert (concat "\n#include \"" (file-name-nondirectory headername) "\"\n"))
1879 (when (string-match "\\.tex$" filename)
1884 (set-buffer-modified-p nil)
1887 (if (>= emacs-major-version 22)
1888 (add-to-list 'find-file-not-found-functions 'ff/start-file)
1889 (add-to-list 'find-file-not-found-hooks 'ff/start-file))
1891 (when (>= emacs-major-version 24)
1892 (define-obsolete-function-alias 'make-local-hook 'ignore "21.1")
1893 (setq send-mail-function 'sendmail-send-it) ;; emacs 24.x stuff
1896 '(diff-added ((default (:background "gray90" :foreground "green4" :weight bold))))
1897 '(diff-removed ((default (:background "gray90" :foreground "red2" :weight bold))))
1898 '(diff-changed ((default (:background "gray90" :foreground "blue" :weight bold))))
1902 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1904 (define-key global-map [f8] 'ff-find-other-file)
1905 (define-key global-map [(shift f8)] (lambda () (interactive) (ff-find-other-file t)))
1907 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1908 ;; Antiword, htmlize and boxquote
1909 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1911 (autoload 'no-word "no-word")
1912 (add-to-list 'auto-mode-alist '("\\.doc\\'" . no-word))
1913 ;; (add-to-list 'auto-mode-alist '("\\.DOC\\'" . no-word))
1915 (autoload 'htmlize-buffer "htmlize" nil t)
1917 (setq boxquote-top-and-tail "------------------")
1918 (autoload 'boxquote-region "boxquote" nil t)
1920 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1921 ;; The compilation hacks
1922 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1924 ;; If we enter c++ mode and there is no makefile around, we create a
1925 ;; make command on the fly for the specific object file
1927 (add-hook 'c++-mode-hook
1929 (unless (or (file-exists-p "makefile") (file-exists-p "Makefile"))
1930 (set (make-local-variable 'compile-command)
1933 (file-name-sans-extension
1934 (file-name-nondirectory buffer-file-name)))))))
1936 ;; <f1> runs the compilation according to the compile-command (and
1937 ;; thus does not ask any confirmation), shows the compilation buffer
1938 ;; during compilation and delete all windows showing the compilation
1939 ;; buffer if the compilation ends with no error
1941 ;; <shift-f1> asks for a compilation command and runs the compilation
1942 ;; but does not restore the window configuration (i.e. the compilation
1943 ;; buffer's window will still be visible, as usual)
1945 ;; <f2> goes to the next compilation error (as C-x ` does on the
1946 ;; standard configuration)
1948 (defun ff/restore-windows-if-no-error (buffer msg)
1949 "Delete the windows showing the compilation buffer if msg
1950 matches \"^finished\"."
1952 (when (string-match "^finished" msg)
1953 ;; (delete-windows-on buffer)
1954 (if (boundp 'ff/window-configuration-before-compilation)
1955 (set-window-configuration ff/window-configuration-before-compilation))
1959 (add-to-list 'compilation-finish-functions 'ff/restore-windows-if-no-error)
1961 (defun ff/fast-compile ()
1962 "Compiles without asking anything."
1964 (let ((compilation-read-command nil))
1965 (setq ff/window-configuration-before-compilation (current-window-configuration))
1966 (compile compile-command)))
1968 (setq compilation-read-command t
1969 compile-command "make -j -k"
1970 compile-history '("make clean" "make DEBUG=yes -j -k" "make -j -k")
1973 (defun ff/universal-compile () (interactive)
1974 (funcall (or (cdr (assoc major-mode
1976 (latex-mode . tex-file)
1977 (html-mode . browse-url-of-buffer)
1978 ;; Here you can add other mode -> compile command
1980 'ff/fast-compile ;; And this is the failsafe
1983 (define-key global-map [f1] 'ff/universal-compile)
1984 (define-key global-map [(shift f1)] 'compile)
1985 (define-key global-map [f2] 'next-error)
1987 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1989 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1991 ;; (when (ff/load-or-alert "flyspell-timer" t)
1992 ;; (add-hook 'flyspell-mode-hook 'flyspell-timer-ensure-idle-timer))
1994 (defun ff/pick-dictionnary () (interactive)
1995 (when (and (boundp 'flyspell-mode) flyspell-mode)
1996 (if (and current-input-method (string-match "latin" current-input-method))
1997 (ispell-change-dictionary "francais")
1998 (ispell-change-dictionary "american"))
1999 ;; (flyspell-buffer)
2003 (defadvice toggle-input-method (after ff/switch-dictionnary nil activate)
2004 (ff/pick-dictionnary))
2006 ;; (add-hook 'message-mode-hook 'auto-fill-mode)
2007 ;; (add-hook 'message-mode-hook 'flyspell-mode)
2009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2010 ;; Delete all windows which are in the same "column", which means
2011 ;; whose xmin and xmax are bounded by the xmin and xmax of the
2012 ;; currently selected column
2013 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2015 ;; This is from emacs23 ! better than my old ff/delete-other-windows-in-column
2017 (unless (fboundp 'delete-other-windows-vertically)
2019 (defun delete-other-windows-vertically (&optional window)
2020 "Delete the windows in the same column with WINDOW, but not WINDOW itself.
2021 This may be a useful alternative binding for \\[delete-other-windows]
2022 if you often split windows horizontally."
2024 (let* ((window (or window (selected-window)))
2025 (edges (window-edges window))
2027 (while (not (eq (setq w (next-window w 1)) window))
2028 (let ((e (window-edges w)))
2029 (when (and (= (car e) (car edges))
2030 (= (caddr e) (caddr edges)))
2032 (mapc 'delete-window delenda)))
2035 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2037 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2041 (defun ff/entropy (l)
2046 (* (- x) (/ (log x) (log 2)))))
2051 ;; Usefull to deal with results in latex files
2053 (defun ff/round-floats-in-region () (interactive)
2056 (narrow-to-region (region-beginning) (region-end))
2057 (error (thing-at-point 'word)))
2059 (goto-char (point-min))
2060 (while (re-search-forward "[0-9\.]+" nil t)
2061 (let ((value (string-to-number (buffer-substring (match-beginning 0) (match-end 0)))))
2062 (delete-region (match-beginning 0) (match-end 0))
2063 (insert (format "%0.2f" value)))))))
2065 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2067 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2071 (define-key global-map [(shift iso-lefttab)] 'ispell-complete-word)
2072 ;; shift-tab going backward is kind of standard
2073 (define-key Info-mode-map [(shift iso-lefttab)] 'Info-prev-reference)
2075 ;; (define-key global-map [(control x) (control a)] 'auto-fill-mode)
2077 ;; Put back my keys, you thief!
2078 (define-key global-map [(home)] 'beginning-of-buffer)
2079 (define-key global-map [(end)] 'end-of-buffer)
2080 ;; (define-key global-map [(insertchar)] 'overwrite-mode)
2081 (define-key global-map [(delete)] 'delete-char)
2083 ;; Cool shortcuts to move to the end / beginning of block keen
2084 (define-key global-map [(control right)] 'forward-sexp)
2085 (define-key global-map [(control left)] 'backward-sexp)
2087 ;; Wheel mouse moves up and down 2 lines (and DO NOT BEEP when we are
2088 ;; out of the buffer)
2090 (define-key global-map [mouse-4]
2091 (lambda () (interactive) (condition-case nil (scroll-down 2) (error nil))))
2092 (define-key global-map [mouse-5]
2093 (lambda () (interactive) (condition-case nil (scroll-up 2) (error nil))))
2095 ;; with shift it goes faster
2096 (define-key global-map [(shift mouse-4)]
2097 (lambda () (interactive) (condition-case nil (scroll-down 50) (error nil))))
2098 (define-key global-map [(shift mouse-5)]
2099 (lambda () (interactive) (condition-case nil (scroll-up 50) (error nil))))
2101 ;; Meta-? shows the properties of the character at point
2102 (define-key global-map [(meta ??)]
2103 (lambda () (interactive)
2104 (message (prin1-to-string (text-properties-at (point))))))
2106 ;; Compiles the latex file in the current buffer
2108 (setq tex-start-commands "\\input")
2109 (define-key global-map [f3] 'tex-file)
2110 (define-key global-map [(shift f3)] 'tex-bibtex-file)
2112 ;; To run xdvi on the dvi associated to the .tex in the current
2113 ;; buffer, and to edit the .fig or bitmap image used to generate the
2116 (define-key global-map [f4] 'ff/run-viewer)
2118 ;; Closes the current \begin{}
2120 (when (ff/load-or-alert "longlines")
2122 (setq longlines-show-hard-newlines t
2123 longlines-auto-wrap t
2124 ;; longlines-show-effect #("|\n" 0 2 (face escape-glyph))
2125 ;; longlines-show-effect #("∴\n" 0 2 (face escape-glyph))
2126 longlines-show-effect #("•\n" 0 2 (face escape-glyph))
2127 ;; longlines-show-effect #("↵\n" 0 2 (face escape-glyph))
2130 ;; (defun ff/auto-longlines ()
2131 ;; (when (save-excursion
2132 ;; (goto-char (point-min))
2133 ;; (re-search-forward "^.\\{81,\\}$" nil t))
2135 ;; (message "Switched on the lonlines mode automatically")
2138 ;; (add-hook 'latex-mode-hook 'ff/auto-longlines)
2142 ;; Meta-/ remaped (completion)
2144 (define-key global-map [(shift right)] 'dabbrev-expand)
2145 (define-key global-map [(meta =)] 'dabbrev-expand)
2147 ;; Change the current window.
2149 (defun ff/next-same-frame-window () (interactive)
2150 (select-window (next-window (selected-window)
2151 (> (minibuffer-depth) 0)
2154 (defun ff/previous-same-frame-window () (interactive)
2155 (select-window (previous-window (selected-window)
2156 (> (minibuffer-depth) 0)
2159 (define-key global-map [(shift prior)] 'ff/next-same-frame-window)
2160 (define-key global-map [(shift next)] 'ff/previous-same-frame-window)
2162 (define-key global-map [(control })] 'enlarge-window-horizontally)
2163 (define-key global-map [(control {)] 'shrink-window-horizontally)
2164 (define-key global-map [(control \")] 'enlarge-window)
2165 (define-key global-map [(control :)] 'shrink-window)
2167 ;; (define-key global-map [(control shift prior)] 'next-multiframe-window)
2168 ;; (define-key global-map [(control shift next)] 'previous-multiframe-window)
2170 ;; I have two screens sometime!
2172 (define-key global-map [(meta next)] 'other-frame)
2173 (define-key global-map [(meta prior)] (lambda () (interactive) (other-frame -1)))
2175 (define-key global-map [(shift home)] 'delete-other-windows-vertically)
2177 ;; (define-key global-map [(control +)] 'enlarge-window)
2178 ;; (define-key global-map [(control -)] 'shrink-window)
2180 ;; Goes to next/previous buffer
2182 (define-key global-map [(control prior)] 'ff/next-buffer)
2183 (define-key global-map [(control next)] 'ff/prev-buffer)
2185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2186 ;; If M-. on a symbol, show where it is defined in another window
2187 ;; without giving focus, cycle if repeated.
2188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2190 (when (ff/load-or-alert "etags")
2192 (defun ff/find-tag-nofocus () (interactive)
2193 "Show in another window the definition of the current tag"
2194 (let ((tag (find-tag-default)))
2195 (display-buffer (find-tag-noselect tag (string= tag last-tag)))
2196 (message "Tag %s" tag)
2200 (define-key global-map [(meta .)] 'ff/find-tag-nofocus)
2203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2204 ;; Destroys the current buffer and its window if it's not the only one
2205 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2207 (defcustom ff/kill-this-buffer-and-delete-window-exceptions ""
2208 "*Regexp matching the buffer names which have to be kept when using
2209 `ff/kill-this-buffer-and-delete-window'.")
2211 (defun ff/kill-this-buffer-and-delete-window (universal)
2212 "Unless its name matches
2213 `ff/kill-this-buffer-and-delete-window-exceptions', kills the
2214 current buffer and deletes the current window if it's not the
2215 only one in the frame. If the buffer has to be kept, go to the
2216 next one. With universal argument, kill all killable buffers."
2219 (let ((nb-killed 0))
2221 (unless (string-match ff/kill-this-buffer-and-delete-window-exceptions
2224 (setq nb-killed (1+ nb-killed))
2227 (message "Killed %d buffer%s" nb-killed (if (> nb-killed 1) "s" "")))
2228 (if (string-match ff/kill-this-buffer-and-delete-window-exceptions (buffer-name))
2230 (kill-this-buffer)))
2231 ;; (unless (one-window-p t) (delete-window))
2234 (define-key global-map [(control backspace)] 'ff/kill-this-buffer-and-delete-window)
2235 ;; (define-key calc-mode-map [(control backspace)] 'calc-quit)
2238 (setq ff/kill-this-buffer-and-delete-window-exceptions
2239 "^ \\|\\*Messages\\*\\|\\*scratch\\*\\|\\*Group\\*\\|\\*-jabber-\\*\\|\\*-jabber-process-\\*\\|\\*media\\*")
2241 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2245 (defun ff/elisp-debug-on ()
2246 "Switches `debug-on-error' and `debug-on-quit'."
2249 (setq debug-on-error nil
2251 (setq debug-on-error t
2254 (message "elisp debug on")
2255 (message "elisp debug off")))
2257 (defun ff/create-dummy-buffer (&optional universal) (interactive "P")
2258 (find-file (concat "/tmp/" (ff/non-existing-filename "/tmp/" "dummy" "")))
2260 (if universal (ff/insert-url (current-kill 0)))
2261 (message "New dummy text-mode buffer"))
2263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2264 ;; Recentf to keep a list of recently visited files. I use it
2265 ;; exclusively with my selector.el
2266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2270 (setq recentf-exclude
2271 (append recentf-exclude
2272 '("enotes$" "secure-notes$" "media-playlists$"
2274 "svn-commit.tmp$" ".git/COMMIT_EDITMSG$"
2275 "\.bbl$" "\.aux$" "\.toc$"))
2276 recentf-max-saved-items 1000
2277 recentf-save-file "~/private/emacs/recentf"
2280 (when (boundp 'recentf-keep) (add-to-list 'recentf-keep 'file-remote-p))
2282 ;; Removes the link if we add the file itself (I am fed up with
2283 ;; duplicates because of vc-follow-symlinks)
2285 (defadvice recentf-add-file (before ff/remove-links (filename) activate)
2286 ;; If we are adding a filename corresponding to the last link we
2287 ;; have added, remove the latter
2288 (when (and recentf-list
2289 (file-symlink-p (car recentf-list))
2290 (string= filename (file-chase-links filename)))
2291 (setq recentf-list (cdr recentf-list))
2296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2297 ;; My front-end to mplayer
2298 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2300 ;; (ff/compile-when-needed "media/mplayer")
2301 ;; (ff/compile-when-needed "media")
2303 (when (ff/load-or-alert "media")
2305 (unless window-system
2308 (media/mode-string-face
2309 :foreground "blue4" :weight 'bold)
2311 (media/current-tune-face
2312 :foreground "black" :background "yellow" :weight 'normal)
2314 (media/instant-highlight-face
2315 :foreground "black" :background "orange" :weight 'normal)
2319 (define-key global-map [(meta \\)] 'media)
2321 (setq media/expert t
2322 media/add-current-song-to-interrupted-when-killing t
2323 media/duration-to-history 30
2324 media/history-size 1000
2325 media/playlist-file "~/private/emacs/media-playlists"
2326 media/mplayer/args '(
2330 "-subfont-osd-scale" "3"
2331 ;; "-stop-xscreensaver"
2334 media/mplayer/timing-request-period 5.0
2338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2342 ;; selector.el is one of my own scripts, check my web page
2344 (when (ff/load-or-alert "selector" t)
2345 ;; (define-key global-map [(shift return)] 'selector/quick-move-in-buffer)
2346 (define-key global-map [(control x) (control b)] 'selector/switch-buffer)
2348 (defun ff/visit-debpkg-file (&optional regexp)
2349 "This function lists all the files found with dpkg -S and
2350 proposes to visit them."
2351 (interactive "sPattern: ")
2357 (cons (selector/filename-to-string s) s))
2359 (shell-command-to-string (concat "dpkg -S " regexp " | awk '{print $2}'"))))
2362 "*selector find-file*"
2366 (add-hook 'selector/mode-hook (lambda () (setq truncate-lines t)))
2368 (defun ff/selector-insert-record-callback (r)
2369 (bbdb-display-records (list r))
2370 ;; Weird things will happen if you kill the buffer from which you
2371 ;; invoked ff/selector-mail-from-bbdb
2372 (insert (car (elt r 6)))
2375 (defun ff/selector-compose-mail-callback (r)
2376 (vm-compose-mail (car (elt r 6)))
2379 (defun ff/selector-mail-from-bbdb () (interactive)
2382 (lambda (r) (cons (concat (elt r 0)
2390 (if (string= mode-name "Mail")
2391 'ff/selector-insert-record-callback
2392 'ff/selector-compose-mail-callback)
2397 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2398 ;; A function to remove temporary alarm windows
2399 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2401 (defcustom ff/annoying-windows-regexp
2402 "\\*Messages\\*\\|\\*compilation\\*\\|\\*tex-shell\\*\\|\\*Help\\*\\|\\*info\\*\\|\\*Apropos\\*\\|\\*BBDB\\*\\|\\*.*-diff\\*"
2403 "The regexp matching the windows to be deleted by `ff/delete-annoying-windows'"
2406 (defun ff/delete-annoying-windows ()
2407 "Close all the windows showing buffers whose names match
2408 `ff/annoying-windows-regexp'."
2410 (when ff/annoying-windows-regexp
2412 (when (and (not (one-window-p w))
2413 (string-match ff/annoying-windows-regexp
2414 (buffer-name (window-buffer w))))
2418 (message "Removed annoying windows")
2422 (setq ff/annoying-windows-regexp
2423 (concat ff/annoying-windows-regexp
2424 "\\|\\*unspooled mails\\*\\|\\*enotes alarms\\*\\|\\*system info\\*"))
2426 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2427 ;; Some handy functions
2428 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2430 (defun ff/twin-horizontal-current-buffer () (interactive)
2431 (delete-other-windows)
2432 (split-window-horizontally)
2436 (defun ff/twin-vertical-current-buffer () (interactive)
2437 (delete-other-windows)
2438 (split-window-vertically)
2442 (defun ff/flyspell-mode (arg) (interactive "p")
2443 (if flyspell-mode (flyspell-mode -1)
2448 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2452 (defun ff/move-region-to-fridge () (interactive)
2453 "Cut the current region, paste it in a file called ./fridge
2454 with a time tag, and save this file"
2455 (unless (use-region-p) (error "No region selected"))
2456 (let ((bn (file-name-nondirectory (buffer-file-name))))
2457 (kill-region (region-beginning) (region-end))
2458 (with-current-buffer (find-file-noselect "fridge")
2459 (goto-char (point-max))
2461 (insert "######################################################################\n")
2463 (format-time-string "%Y %b %d %H:%M:%S" (current-time))
2469 (message "Region moved to fridge")
2474 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2478 (setq ff/map (make-sparse-keymap))
2479 (define-key global-map [(control \`)] ff/map)
2480 (define-key esc-map "`" ff/map)
2482 (defun ff/git-status (&optional dir) (interactive)
2483 (if (buffer-file-name)
2484 (git-status (file-name-directory (buffer-file-name)))
2485 (error "No file attached to this buffer")))
2487 (defun ff/insert-date () (interactive)
2488 (insert (format-time-string "\n * %Y %b %d %H:%M:%S\n\n" (current-time)))
2491 (define-key ff/map [(control g)] 'ff/git-status)
2492 (define-key ff/map [(control w)] 'server-edit)
2493 (define-key ff/map [(control d)] 'ff/elisp-debug-on)
2494 ;; (define-key ff/map "d" 'diary)
2495 (define-key ff/map "d" 'ff/insert-date)
2496 (define-key ff/map [(control \`)] 'ff/bash-new-buffer)
2497 (define-key ff/map [(control n)] 'enotes/show-all-notes)
2498 (define-key ff/map [(control s)] 'ff/secure-note-add)
2499 (define-key ff/map [(control t)] 'ff/start-test-code)
2500 (define-key ff/map [(control q)] 'ff/create-dummy-buffer)
2501 (define-key ff/map [(control a)] 'auto-fill-mode)
2502 (define-key ff/map [(control i)] 'ff/system-info)
2503 (define-key ff/map "w" 'ff/word-occurences)
2504 (define-key ff/map [(control c)] 'calendar)
2505 ;; (define-key ff/map [(control c)] (lambda () (interactive) (save-excursion (calendar))))
2506 (define-key ff/map [(control l)] 'goto-line)
2507 (define-key ff/map "l" 'longlines-mode)
2508 (define-key ff/map [(control o)] 'selector/quick-pick-recent)
2509 (define-key ff/map "s" 'selector/quick-move-in-buffer)
2510 (define-key ff/map "S" 'selector/search-sentence)
2511 (define-key ff/map "t" (lambda () (interactive) (find-file "~/private/TODO.txt")))
2512 (define-key ff/map "h" 'ff/tidy-html)
2513 (define-key ff/map "c" 'ff/count-char)
2514 (define-key ff/map [(control p)] 'ff/print-to-file)
2515 (define-key ff/map "P" 'ff/print-to-printer)
2516 (define-key ff/map [(control b)] 'bbdb)
2517 (define-key ff/map "m" 'ff/selector-mail-from-bbdb)
2518 (define-key ff/map [(control m)] 'woman)
2519 (define-key ff/map "b" 'bookmark-jump)
2520 (define-key ff/map [(control =)] 'calc)
2521 (define-key ff/map [(control shift b)]
2522 (lambda () (interactive)
2525 (define-key ff/map "f" 'ff/move-region-to-fridge)
2526 (define-key ff/map [(control f)] 'ff/flyspell-mode)
2528 (define-key ff/map [?\C-0] 'ff/delete-annoying-windows)
2529 (define-key ff/map "1" 'delete-other-windows)
2530 (define-key ff/map [?\C-1] 'delete-other-windows)
2531 (define-key ff/map "2" 'ff/twin-vertical-current-buffer)
2532 (define-key ff/map [?\C-2] 'ff/twin-vertical-current-buffer)
2533 (define-key ff/map "3" 'ff/twin-horizontal-current-buffer)
2534 (define-key ff/map [?\C-3] 'ff/twin-horizontal-current-buffer)
2536 (define-key ff/map " " 'delete-trailing-whitespace)
2538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2539 ;; Hacks so that all keys are functionnal in xterm and through ssh.
2540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2542 (unless window-system
2544 ;; One day I will understand these clipboard business. Until then,
2545 ;; so that it works in xterm (yes), let's use xclip. This is a bit
2548 ;; (defun ff/yank-with-xclip (&optional arg)
2549 ;; "Paste the content of the X clipboard with the xclip
2550 ;; command. Without ARG converts some of the '\\uxxxx' characters."
2551 ;; (interactive "P")
2552 ;; (with-temp-buffer
2553 ;; (shell-command "xclip -o" t)
2555 ;; (mapc (lambda (x) (replace-string (concat "\\u" (car x)) (cdr x) nil (point-min) (point-max)))
2556 ;; '(("fffd" . "??")
2567 ;; (kill-ring-save (point-min) (point-max)))
2571 ;; (define-key global-map [(meta y)] 'ff/yank-with-xclip)
2573 ;; (set-terminal-coding-system 'iso-latin-1)
2574 ;; (set-terminal-coding-system 'utf-8)
2576 ;; I have in my .Xressource
2578 ;; XTerm.VT100.translations: #override\n\
2579 ;; <Btn4Down>,<Btn4Up>:scroll-back(2,line)\n\
2580 ;; <Btn5Down>,<Btn5Up>:scroll-forw(2,line)\n\
2581 ;; Ctrl<Btn4Down>,Ctrl<Btn4Up>:scroll-back(1,page)\n\
2582 ;; Ctrl<Btn5Down>,Ctrl<Btn5Up>:scroll-forw(1,page)\n\
2583 ;; Shift<Btn4Down>,Shift<Btn4Up>:scroll-back(1,halfpage)\n\
2584 ;; Shift<Btn5Down>,Shift<Btn5Up>:scroll-forw(1,halfpage)\n\
2585 ;; Alt<KeyPress>:insert-eight-bit()\n\
2586 ;; !Shift<Key>BackSpace: string("
\7f")\n\
2587 ;; Ctrl<Key>BackSpace: string("\eOZ")\n\
2588 ;; Shift<Key>Prior: string("\e[5;2~")\n\
2589 ;; Shift<Key>Next: string("\e[6;2~")\n\
2590 ;; Shift Ctrl<Key>]: string("\eO}")\n\
2591 ;; Shift Ctrl<Key>[: string("\eO{")\n\
2592 ;; Shift Ctrl<Key>/: string("\eO?")\n\
2593 ;; Ctrl<Key>/: string("\eO/")\n\
2594 ;; Shift Ctrl<Key>=: string("\eO+")\n\
2595 ;; Ctrl<Key>=: string("\eO=")\n\
2596 ;; Shift Ctrl<Key>;: string("\eO:")\n\
2597 ;; Ctrl<Key>;: string("\eO;")\n\
2598 ;; Shift Ctrl<Key>`: string("\eO~")\n\
2599 ;; Ctrl<Key>`: string("\eO`")\n\
2600 ;; Shift Ctrl<Key>': string("\eO\\\"")\n\
2601 ;; Ctrl<Key>': string("\eO'")\n\
2602 ;; Shift Ctrl<Key>.: string("\eO>")\n\
2603 ;; Ctrl<Key>.: string("\eO.")\n\
2604 ;; Shift Ctrl<Key>\\,: string("\eO<")\n\
2605 ;; Ctrl<Key>\\,: string("\eO,")
2607 (define-key function-key-map "\e[2~" [insert])
2609 (define-key function-key-map "\e[Z" [S-iso-lefttab])
2611 (define-key function-key-map "\e[1;2A" [S-up])
2612 (define-key function-key-map "\e[1;2B" [S-down])
2613 (define-key function-key-map "\e[1;2C" [S-right])
2614 (define-key function-key-map "\e[1;2D" [S-left])
2615 (define-key function-key-map "\e[1;2F" [S-end])
2616 (define-key function-key-map "\e[1;2H" [S-home])
2618 (define-key function-key-map "\e[2;2~" [S-insert])
2619 (define-key function-key-map "\e[5;2~" [S-prior])
2620 (define-key function-key-map "\e[6;2~" [S-next])
2622 (define-key function-key-map "\e[1;2P" [S-f1])
2623 (define-key function-key-map "\e[1;2Q" [S-f2])
2624 (define-key function-key-map "\e[1;2R" [S-f3])
2625 (define-key function-key-map "\e[1;2S" [S-f4])
2626 (define-key function-key-map "\e[15;2~" [S-f5])
2627 (define-key function-key-map "\e[17;2~" [S-f6])
2628 (define-key function-key-map "\e[18;2~" [S-f7])
2629 (define-key function-key-map "\e[19;2~" [S-f8])
2630 (define-key function-key-map "\e[20;2~" [S-f9])
2631 (define-key function-key-map "\e[21;2~" [S-f10])
2633 (define-key function-key-map "\e[1;5A" [C-up])
2634 (define-key function-key-map "\e[1;5B" [C-down])
2635 (define-key function-key-map "\e[1;5C" [C-right])
2636 (define-key function-key-map "\e[1;5D" [C-left])
2637 (define-key function-key-map "\e[1;5F" [C-end])
2638 (define-key function-key-map "\e[1;5H" [C-home])
2640 (define-key function-key-map "\e[2;5~" [C-insert])
2641 (define-key function-key-map "\e[5;5~" [C-prior])
2642 (define-key function-key-map "\e[6;5~" [C-next])
2644 (define-key function-key-map "\e[1;9A" [M-up])
2645 (define-key function-key-map "\e[1;9B" [M-down])
2646 (define-key function-key-map "\e[1;9C" [M-right])
2647 (define-key function-key-map "\e[1;9D" [M-left])
2648 (define-key function-key-map "\e[1;9F" [M-end])
2649 (define-key function-key-map "\e[1;9H" [M-home])
2651 (define-key function-key-map "\e[2;9~" [M-insert])
2652 (define-key function-key-map "\e[5;9~" [M-prior])
2653 (define-key function-key-map "\e[6;9~" [M-next])
2655 ;; The following ones are not standard
2657 (define-key function-key-map "\eO}" (kbd "C-}"))
2658 (define-key function-key-map "\eO{" (kbd "C-{"))
2659 (define-key function-key-map "\eO?" (kbd "C-?"))
2660 (define-key function-key-map "\eO/" (kbd "C-/"))
2661 (define-key function-key-map "\eO:" (kbd "C-:"))
2662 (define-key function-key-map "\eO;" (kbd "C-;"))
2663 (define-key function-key-map "\eO~" (kbd "C-~"))
2664 (define-key function-key-map "\eO`" (kbd "C-\`"))
2665 (define-key function-key-map "\eO\"" (kbd "C-\""))
2666 (define-key function-key-map "\eO|" (kbd "C-|"))
2667 (define-key function-key-map "\eO'" (kbd "C-'"))
2668 (define-key function-key-map "\eO>" (kbd "C->"))
2669 (define-key function-key-map "\eO." (kbd "C-."))
2670 (define-key function-key-map "\eO<" (kbd "C-<"))
2671 (define-key function-key-map "\eO," (kbd "C-,"))
2672 (define-key function-key-map "\eO-" (kbd "C--"))
2673 (define-key function-key-map "\eO=" (kbd "C-="))
2674 (define-key function-key-map "\eO+" (kbd "C-+"))
2676 (define-key function-key-map "\eOZ" [C-backspace])
2678 (define-key minibuffer-local-map "
\10" 'previous-history-element)
2679 (define-key minibuffer-local-map "
\ e" 'next-history-element)
2681 ;; (define-key global-map [(alt prior)] 'ff/prev-buffer)
2682 ;; (define-key global-map [(alt next)] 'ff/next-buffer)
2686 ;; I am fed up with Alt-Backspace in the minibuffer erasing the
2687 ;; content of the kill-ring
2689 (defun ff/backward-delete-word (arg)
2690 "Delete characters forward until encountering the end of a word, but do not put them in the kill ring.
2691 With argument ARG, do this that many times."
2693 (delete-region (point) (progn (forward-word (- arg)) (point))))
2695 (define-key minibuffer-local-map
2696 [remap backward-kill-word] 'ff/backward-delete-word)
2698 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2700 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2702 ;; Where to save the bookmarks and where is bbdb
2704 (setq bookmark-default-file "~/private/emacs/bmk"
2705 bbdb-file "~/private/bbdb"
2706 custom-file "~/private/emacs/custom")
2708 ;; enotes.el is one of my own scripts, check my web page
2710 (when (ff/load-or-alert "enotes" t)
2711 (setq enotes/file "~/private/enotes"
2712 enotes/show-help nil
2713 enotes/full-display nil
2714 enotes/default-time-fields "9:30")
2717 ;; (add-hook 'enotes/alarm-hook
2718 ;; (lambda () (ff/play-sound-async "~/local/sounds/three_notes2.wav")))
2721 ;; (when (ff/load-or-alert "goto-last-change.el")
2722 ;; (define-key global-map [(control x) (control a)] 'goto-last-change))
2724 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2725 ;; My private stuff (email adresses, mail filters, etc.)
2726 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2728 (ff/load-or-alert "~/private/emacs.perso.el" t)
2730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2732 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2734 ;; Runs in server mode, so that emacsclient works
2737 (defun ff/raise-frame-and-give-focus ()
2740 (x-focus-frame (selected-frame))
2741 (set-mouse-pixel-position (selected-frame) 4 4)
2744 ;; Raises the window when the server is invoked
2746 (add-hook 'server-switch-hook 'ff/raise-frame-and-give-focus)