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)))
53 ;; And I do not like scrollbar neither
54 (when (functionp 'scroll-bar-mode) (scroll-bar-mode -1))
56 ;; Make all "yes or no" prompts be "y or n" instead
57 (fset 'yes-or-no-p 'y-or-n-p)
59 ;; Show the matching parenthesis and do it immediately, we are in a
61 (setq show-paren-delay 0)
64 ;; use colorization for all modes
65 (global-font-lock-mode t)
67 (setq font-lock-maximum-decoration 2
68 ;;'((latex-mode . 2) (t . 2))
71 ;; Activate the dynamic completion of buffer names
74 ;; Save the minibuffer history
75 (setq savehist-file "~/private/emacs/savehist")
76 (when (functionp 'savehist-mode) (savehist-mode 1))
78 ;; I do not like tooltips
79 (when (functionp 'tooltip-mode) (tooltip-mode nil))
81 ;; Activate the dynamic completion in the mini-buffer
84 ;; (setq highlight-current-line-globally t
85 ;; highlight-current-line-ignore-regexp "Faces\\|Colors\\| \\*Mini\\|\\*media\\|INBOX")
87 ;; (highlight-current-line-minor-mode 1)
88 ;; (highlight-current-line-set-bg-color "gray75")
90 (defun ff/compile-when-needed (name)
91 "Compiles the given file only if needed. Adds .el if required, and
92 uses `load-path' to find it."
93 (if (not (string-match "\.el$" name))
94 (ff/compile-when-needed (concat name ".el"))
96 (let* ((src (concat dir "/" name)))
97 (when (file-newer-than-file-p src (concat src "c"))
98 (if (let ((byte-compile-verbose nil))
100 (byte-compile-file src)
102 (message (format "Compiled %s" src ))
103 (message (format "Failed compilation of %s" src))))))
106 ;; This is useful when using the same .emacs in many places
108 (defun ff/load-or-alert (name &optional compile-when-needed)
109 "Tries to load the specified file and insert a warning message in a
110 load-warning buffer in case of failure."
112 (when compile-when-needed (ff/compile-when-needed name))
114 (if (load name t nil) t
115 (let ((buf (get-buffer-create "*loading warnings*")))
118 (insert (propertize "Warning:" 'face 'font-lock-warning-face) " could not load '" name "'\n")
119 (fit-window-to-buffer (get-buffer-window buf))
120 (set-buffer-modified-p nil))
123 ;; This is the default in emacs 22.1 and later
124 ;; (auto-compression-mode 1)
126 ;; make emacs use the clipboard so that copy/paste works for other
127 ;; x-programs. I have no clue how all that clipboard thing works.
128 ;; (setq x-select-enable-clipboard t)
129 ;; (setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
135 ;; avoid GC as much as possible
136 gc-cons-threshold 2500000
138 ;; no startup message
139 inhibit-startup-screen t
141 ;; no message in the scratch buffer
142 initial-scratch-message nil
144 ;; do not fill my buffers, you fool
145 next-line-add-newlines nil
147 ;; keep the window focused on the messages during compilation
148 compilation-scroll-output t
150 ;; Keep the highlight on the compilation error
151 next-error-highlight t
153 ;; blink the screen instead of beeping
156 ;; take the CR when killing a line
159 ;; I prefer to move between lines as defined in the buffer, not
163 ;; I comment empty lines, too (does not seem to work, though)
164 comment-empty-lines t
166 ;; We want long lines to be truncated instead of displayed on several lines
168 ;; Show all lines, even if the window is not as large as the frame
169 ;; truncate-partial-width-windows nil
170 ;; truncate-partial-width-windows t
172 ;; Do not keep tracks of the autosaved files
173 auto-save-list-file-prefix nil
175 ;; Show me empty lines at the end of the buffer
176 default-indicate-empty-lines t
178 ;; Show me the region until I do something on it
179 transient-mark-mode t
181 ;; Do not color stuff which are clickable when hovering over it
184 ;; Don't bother me with questions even if "unsafe" local variables
186 enable-local-variables :all
188 ;; I have no problem with small windows
191 ;; I am not a fan of develock
192 develock-auto-enable nil
194 ;; I do not like women to open windows
195 woman-use-own-frame nil
197 ;; I am not that paranoid, contrary to what you think
198 epa-file-cache-passphrase-for-symmetric-encryption t
199 ;; And I like ascii files
202 tramp-default-method "ssh"
204 ;; I have no problem with files having their own local variables
207 mail-from-style 'angles
208 browse-url-mozilla-program "firefox"
210 mc-use-default-recipients t
212 ;; browse-url-new-window-flag t
218 temporary-file-directory "/tmp/"
219 vc-make-backup-files t
220 backup-directory-alist '((".*" . "~/misc/emacs.backups/"))
221 version-control t ;; Use backup files with numbers
224 delete-old-versions t
225 backup-by-copying-when-linked t
229 user-emacs-directory "~/misc/emacs.d/")
232 abbrev-file-name (concat user-emacs-directory "abbrev_defs")
233 server-auth-dir (concat user-emacs-directory "server/")
234 custom-theme-directory user-emacs-directory
237 ;; Stop this crazy blinking cursor
238 (blink-cursor-mode 0)
240 ;; (setq blink-cursor-delay 0.25
241 ;; blink-cursor-interval 0.25)
243 ;; (set-terminal-coding-system 'utf-8)
245 ;; (unless window-system
246 ;; (xterm-mouse-mode 1)
247 ;; (if (string= (getenv "TERM") "xterm-256color")
248 ;; (ff/load-or-alert "xterm-256color" t))
253 ;; Show white spaces at the end of lines
254 show-trailing-whitespace t
256 ;; Do not show the cursor in non-active window
257 cursor-in-non-selected-windows nil
262 ;; when on a TAB, the cursor has the TAB length
265 ;; This is the default coding system when toggle-input-method is
267 default-input-method "latin-1-prefix"
268 ;; do not put tabs when indenting
270 ;; And yes, we have a fast display / connection / whatever
274 ;; To keep the cursor always visible when it moves (thanks
276 redisplay-dont-pause t
278 ;; I want to see the keys I type instantaneously
282 ;; Show the column number
283 (column-number-mode 1)
285 ;; What modes for what file extentions
286 (add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
288 (add-to-list 'auto-mode-alist '("\\.txt\\'" . (lambda()
294 (add-hook 'c++-mode-hook 'flyspell-prog-mode)
295 (add-hook 'log-edit-mode-hook 'flyspell-mode)
299 (put 'narrow-to-region 'disabled nil)
300 (put 'upcase-region 'disabled nil)
301 (put 'downcase-region 'disabled nil)
302 ;; (put 'scroll-left 'disabled nil)
303 ;; (put 'scroll-right 'disabled nil)
305 ;; My selector is clearer than that
306 ;; (when (load "ido" t) (ido-mode t))
308 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
310 ;; Makes buffer names more explicit then <2>, <3> etc. when there are
311 ;; several identical filenames
313 (when (load "uniquify" t)
314 (setq uniquify-buffer-name-style 'post-forward-angle-brackets))
316 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
318 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
320 (when (boundp 'x-display-name)
324 ;; If the display is :0.0, we make the assumption that we are
325 ;; running the emacs locally, and we do not show the
326 ;; hostname. Otherwise, show @host.
328 frame-title-format (concat "emacs" ;;invocation-name
329 (unless (string= x-display-name ":0.0")
330 (concat "@" system-name))
333 ;; Use the same for the icone
335 icon-title-format frame-title-format
338 ;; "tool" bar? Are you kidding?
339 (when (boundp 'tool-bar-mode) (tool-bar-mode -1))
341 ;; ;; If my own letter icon is here, use it and change its color
342 ;; (when (file-exists-p "~/local/share/emacs/letter.xbm")
343 ;; (setq-default display-time-mail-icon
346 ;; :file "~/local/share/emacs/letter.xbm"
347 ;; :ascent center)))))
349 ;; My funky setting of face colors. Basically, we switch to a sober
350 ;; look and darken a bit the colors which need to (because of the
351 ;; darker background)
353 (defun ff/configure-faces (fl)
354 "Set face attributes and create faces when necessary"
356 (unless (boundp (car f)) (make-empty-face (car f)))
357 (eval `(set-face-attribute (car f) nil ,@(cdr f))))
360 ;; Not the same in xterm (which is gray in my case) and in
363 (unless window-system
364 ;; (xterm-mouse-mode 1)
366 '((italic :underline nil)
367 (info-title-2 :foreground "green")
368 (cperl-array-face :background "gray90" :foreground "blue" :weight 'bold)
369 (cperl-hash-face :background "gray90" :foreground "purple" :weight 'bold)
370 (diff-added-face :foreground "blue" :weight 'bold)
371 (diff-changed-face :foreground "green" :weight 'bold)
372 (diff-removed-face :foreground "red" :weight 'bold)
373 (diff-file-header-face :background "white" :foreground "black"
375 (diff-header-face :background "white" :foreground "black")
376 (diff-hunk-header-face :background "white" :foreground "black")
377 (diff-indicator-removed :foreground "red" :weight 'bold)
378 (diff-removed :foreground "red" :weight 'bold)
379 (diff-indicator-added :foreground "blue" :weight 'bold)
380 (diff-added :foreground "blue" :weight 'bold)
381 (font-lock-string-face :foreground "green")
382 (font-lock-variable-name-face :foreground "blue")
383 (font-lock-constant-face :foreground "blue")
384 (font-lock-function-name-face :foreground "blue")
385 (font-lock-preprocessor-face :foreground "green")
386 (font-lock-function-name-face :foreground "cyan")
387 (flyspell-incorrect-face :foreground "red2")
388 (flyspell-duplicate-face :foreground "OrangeRed2")
389 (hl-line :background "white")
390 (sh-heredoc :foreground "blue")
391 (sh-heredoc-face :foreground "blue")
392 (font-lock-keyword-face :foreground "blue")
393 (highlight :background "darkseagreen3")
394 (isearch :background "orange" :foreground "black")
395 (isearch-lazy-highlight-face' :background "yellow" :foreground "black")
396 ;; (display-time-mail-face :background "white")
397 (show-paren-match-face :background "gold" :foreground "black")
398 (show-paren-mismatch-face :background "red" :foreground "black")
399 (trailing-whitespace :background "white")
400 (mode-line :background "cornflowerblue" :foreground "black" :box nil
402 (header-line :background "cornflowerblue" :foreground "black" :box nil
404 (mode-line-inactive :background "gray60" :foreground "black" :box nil
406 (region :background "springgreen2")
407 (ff/date-info-face :foreground "white" :weight 'bold)
408 (ff/mail-alarm-face :foreground "red" :weight 'bold)
409 (gui-button-face :background "green" :foreground "white")
410 (enotes/information-face :foreground "cyan")
414 ;; (list-colors-display (mapcar 'car color-name-rgb-alist))
416 ;; (ff/configure-faces '((default :background "black" :foreground "gray80")))
417 ;; (ff/configure-faces '((default :background "gray80" :foreground "black")))
421 ;; display-time-use-mail-icon t)
425 (escape-glyph :foreground "#c0c0c0" :weight 'bold)
426 (default :background "gray90" :foreground "black")
427 (cperl-array-face :background "gray90" :foreground "blue" :weight 'bold)
428 (cperl-hash-face :background "gray90" :foreground "purple" :weight 'bold)
429 (message-cited-text :foreground "red4")
430 (diff-added :background "gray90" :foreground "green4" :weight 'bold)
431 (diff-removed :background "gray90" :foreground "red2" :weight 'bold)
432 (diff-changed :background "gray90" :foreground "blue")
433 (diff-file-header :background "white" :foreground "black"
435 (diff-header :background "white" :foreground "black")
436 (diff-hunk-header :background "white" :foreground "black")
437 (font-lock-builtin-face :foreground "deeppink3")
438 (font-lock-string-face :foreground "dark olive green")
439 (font-lock-variable-name-face :foreground "sienna")
440 (font-lock-function-name-face :foreground "blue4" :weight 'bold)
441 ;; (font-lock-comment-delimiter-face :foreground "dark violet")
442 ;; (font-lock-comment-face :foreground "dark violet")
443 (flyspell-incorrect-face :foreground "red2")
444 (flyspell-duplicate-face :foreground "OrangeRed2")
445 (hl-line :background "white")
446 (header-line :background "gray65")
447 (sh-heredoc :foreground "darkorange3")
448 (sh-heredoc-face :foreground "darkorange3")
449 (highlight :background "turquoise")
450 (message-cited-text-face :foreground "firebrick")
451 (isearch :background "yellow" :foreground "black")
452 (isearch-lazy-highlight-face' :background "yellow3" :foreground "black")
453 (region :background "#b8b8e0" :foreground "black")
454 ;; (region :background "plum" :foreground "black")
455 (show-paren-match-face :background "gold" :foreground "black")
456 (show-paren-mismatch-face :background "red" :foreground "black")
457 (trailing-whitespace :background "gray65")
458 (cursor :inverse-video t)
459 (enotes/list-title-face :foreground "blue" :weight 'bold)
460 (mode-line :background "#9090f0" :foreground "black" :box nil
462 (header-line :background "cornflowerblue" :foreground "black" :box nil
464 (mode-line-inactive :background "#606080" :foreground "black" :box nil
466 ;; (fringe :background "black" :foreground "gray90")
467 (fringe :background "gray65")
468 (tex-verbatim :family "courrier")
469 (ff/date-info-face :foreground "white" :weight 'bold)
470 (ff/mail-alarm-face :foreground "white" :background "red2")
471 ;; (alarm-vc-face :foreground "black" :background "yellow" :weight 'normal)
475 ;; When we are root, put the modeline in red
477 (when (string= (user-real-login-name) "root")
479 '((mode-line :background "red3" :foreground "black" :box nil
483 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
484 ;; Move the window on the buffer without moving the cursor
485 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
487 (defun ff/scroll-down ()
488 "Scroll the buffer down one line and keep the cursor at the same location."
494 (defun ff/scroll-up ()
495 "Scroll the buffer up one line and keep the cursor at the same location."
501 (defun ff/scroll-left ()
502 "Scroll the buffer left one column and keep the cursor at the same location."
508 (defun ff/scroll-right ()
509 "Scroll the buffer right one column and keep the cursor at the same location."
515 (define-key global-map [(meta up)] 'ff/scroll-down)
516 (define-key global-map [(meta down)] 'ff/scroll-up)
517 (define-key global-map [(meta p)] 'ff/scroll-down)
518 (define-key global-map [(meta n)] 'ff/scroll-up)
519 (define-key global-map [(meta right)] 'ff/scroll-left)
520 (define-key global-map [(meta left)] 'ff/scroll-right)
522 (defun ff/delete-trailing-whitespaces-and-indent ()
524 (delete-trailing-whitespace)
525 (indent-region (point-min) (point-max) nil))
527 (define-key global-map [(control c) (control q)] 'ff/delete-trailing-whitespaces-and-indent)
529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
531 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
533 ;; (defun ff/esd-sound (file)
534 ;; "Plays a sound with the Enlighted sound daemon."
536 ;; (process-kill-without-query (start-process-shell-command "esdplay"
540 (defun ff/alsa-sound (file)
541 "Plays a sound with ALSA."
543 (process-kill-without-query (start-process-shell-command "aplay"
547 (if (and (boundp 'x-display-name) (string= x-display-name ":0.0"))
548 (defalias 'ff/play-sound-async 'ff/alsa-sound)
549 (defalias 'ff/play-sound-async 'ding))
551 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
552 ;; I comment stuff often, let's be efficient. shift + down comments
553 ;; the current line and goes down, and shift + up uncomments the line
554 ;; and goes up (they are not the dual of each other, but moving and
555 ;; then uncommenting would be very counter-intuitive).
556 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
558 (defun ff/comment-and-go-down (arg)
559 "Comments and goes down ARG lines."
562 (comment-region (point-at-bol) (point-at-eol)) (error nil))
564 (if (> arg 1) (ff/comment-and-go-down (1- arg))))
566 (defun ff/uncomment-and-go-up (arg)
567 "Uncomments and goes up ARG lines."
570 (uncomment-region (point-at-bol) (point-at-eol)) (error nil))
572 (if (> arg 1) (ff/uncomment-and-go-up (1- arg))))
574 (define-key global-map [(shift down)] 'ff/comment-and-go-down)
575 (define-key global-map [(shift up)] 'ff/uncomment-and-go-up)
577 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
578 ;; Counting various entities in text
579 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
581 (defun ff/count-char ()
582 "Prints the number of characters between the first previous \"--\"
583 and the firt next \"--\"."
585 (let ((from (save-excursion (re-search-backward "^--$\\|BEGIN_COUNT" nil t)))
586 (to (save-excursion (re-search-forward "^--$\\|END_COUNT" nil t))))
587 (if (and to from) (message "%d character(s)" (- to from 6))
588 (error "Can not find the -- delimiters"))))
590 (defun ff/count-words ()
591 "Print number of words between the first previous \"--\" and the
594 (let ((from (save-excursion (re-search-backward "^--$" nil t)))
595 (to (save-excursion (re-search-forward "^--$" nil t))))
600 (while (< (point) to)
601 (re-search-forward "\\w+\\W+")
602 (setq count (1+ count)))
603 (message "%d word(s)" count)))
604 (error "Can not find the -- delimiters"))))
606 (defun ff/word-occurences ()
607 "Display in a new buffer the list of words sorted by number of
611 (let ((buf (get-buffer-create "*word counting*"))
612 (map (make-sparse-keymap))
613 (nb (make-hash-table))
614 (st (make-hash-table))
617 ;; Collects all words in a hash table
620 (goto-char (point-min))
621 (while (re-search-forward "\\([\\-a-zA-Z\\\\]+\\)" nil t)
622 (let* ((s (downcase (match-string-no-properties 1)))
625 (puthash k (1+ (gethash k nb 0)) nb))))
627 ;; Creates the result buffer
629 (define-key map "q" 'kill-this-buffer)
632 (setq show-trailing-whitespace nil)
635 ;; Builds a list from the hash table
639 (setq result (cons (cons value (gethash key st)) result)))
642 ;; Sort and display it
645 (if (and (> (car x) 3)
646 ;; No leading backslash and at least four characters
647 (string-match "^[^\\]\\{4,\\}" (cdr x))
649 (insert (number-to-string (car x)) " " (cdr x) "\n")))
650 (sort result (lambda (a b) (> (car a) (car b)))))
652 ;; Adjust the window size and stuff
654 (fit-window-to-buffer (get-buffer-window buf))
656 (set-buffer-modified-p nil))
659 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
661 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
665 (setq ps-print-color-p nil
666 ;; ps-paper-type 'letter
668 ;; ps-top-margin (* 1.75 56.692)
669 ;; ps-left-margin 56.692
670 ;; ps-bottom-margin 56.692
671 ;; ps-right-margin 56.692
673 ;; Simple header. Remove that silly frame shadow.
675 ps-print-header-frame nil
676 ps-header-line-pad 0.3
677 ps-header-font-family 'Courier
678 ps-header-title-font-size '(8.5 . 10)
679 ps-header-font-size '(6 . 7)
680 ps-font-size '(7 . 8)
683 (ps-put 'ps-header-frame-alist 'back-color 1.0)
684 (ps-put 'ps-header-frame-alist 'shadow-color 1.0)
685 (ps-put 'ps-header-frame-alist 'border-color 0.0)
686 (ps-put 'ps-header-frame-alist 'border-width 0.0)
688 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
690 ;; http://blog.tuxicity.se/elisp/emacs/2010/03/26/rename-file-and-buffer-in-emacs.htm
692 (defun rename-file-and-buffer ()
693 "Renames current buffer and file it is visiting."
695 (let ((name (buffer-name))
696 (filename (buffer-file-name)))
697 (if (not (and filename (file-exists-p filename)))
698 (message "Buffer '%s' is not visiting a file!" name)
699 (let ((new-name (read-file-name "New name: " filename)))
700 (cond ((get-buffer new-name)
701 (message "A buffer named '%s' already exists!" new-name))
703 (rename-file name new-name 1)
704 (rename-buffer new-name)
705 (set-visited-file-name new-name)
706 (set-buffer-modified-p nil)))))))
708 (global-set-key (kbd "C-c r") 'rename-file-and-buffer)
710 (defun ff/non-existing-filename (dir prefix suffix)
711 "Returns a filename of the form DIR/PREFIX[.n].SUFFIX whose file does
714 (f (concat prefix suffix)))
715 (while (file-exists-p (concat dir "/" f))
717 f (concat prefix "." (prin1-to-string n) suffix)))
720 (defun ff/print-buffer-or-region-with-faces (&optional file)
722 ;; I am fed up with spell checking highlights
723 (when (and flyspell-mode
724 ;; (or ispell-minor-mode flyspell-mode)
725 (not (y-or-n-p "The spell checking is on, still print ? ")))
726 (error "Printing cancelled, the spell-checking is on"))
730 (ps-print-region-with-faces (region-beginning) (region-end) file)
732 (ps-print-buffer-with-faces file)))
734 (defun ff/print-to-file (file)
735 "Prints the region if selected or the whole buffer in postscript
740 "PS file: " "/tmp/" nil nil
741 (ff/non-existing-filename
743 (replace-regexp-in-string "[^a-zA-Z0-9_.-]" "_" (file-name-nondirectory
747 (ff/print-buffer-or-region-with-faces file))
749 (defun ff/print-to-printer ()
750 "Prints the region if selected or the whole buffer to a postscript
753 (message "Printing to '%s'" (getenv "PRINTER"))
754 (ff/print-buffer-or-region-with-faces))
756 ;; Can you believe it? There is a "print" key on PC keyboards ...
758 (define-key global-map [(print)] 'ff/print-to-file)
759 (define-key global-map [(shift print)] 'ff/print-to-printer)
761 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
762 ;; Dealing with the laptop battery
763 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
765 (defcustom ff/battery-dir "/sys/class/power_supply/BAT0"
766 "*Where to gather the battery information")
768 (defcustom ff/temperature-file "/sys/class/thermal/thermal_zone0/temp"
769 "*Where to gather the thermal information")
771 (defun ff/file-first-line (file)
773 (insert-file-contents-literally file)
774 (buffer-substring (point-at-bol) (point-at-eol))))
776 (defun ff/battery-percent ()
777 (/ (* 100 (string-to-number (ff/file-first-line (concat ff/battery-dir "/charge_now"))))
778 (string-to-number (ff/file-first-line (concat ff/battery-dir "/charge_full")))))
780 (defun ff/laptop-info-string () (interactive)
785 (let ((temp (/ (string-to-number (ff/file-first-line ff/temperature-file)) 1000)))
788 (let ((s (format "%dC" temp)))
789 (if (> temp 65) (propertize s 'face
790 'font-lock-warning-face)
800 (let ((battery-status (ff/file-first-line (concat ff/battery-dir "/status"))))
803 ((string= battery-status "Full") "L")
804 ((string= battery-status "Charging") (format "L%d%%" (ff/battery-percent)))
805 ((string= battery-status "Discharging") (format "B%d%%" (ff/battery-percent)))
813 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
815 (defun ff/system-info () (interactive)
817 (let ((buf (get-buffer-create "*system info*"))
818 (map (make-sparse-keymap)))
820 (define-key map "q" 'kill-this-buffer)
823 (setq show-trailing-whitespace nil)
826 (let ((highlight nil))
830 (if (setq highlight (not highlight))
832 (with-temp-buffer (apply 'call-process x)
834 'face '(:background "#c0c0ff"))
835 (with-temp-buffer (apply 'call-process x)
841 ("hostname" nil t nil "-v")
843 ("df" nil t nil "-h")
846 ("ssh-add" nil t nil "-l")
849 (goto-char (point-min))
850 (while (re-search-forward "^$" nil t) (backward-delete-char 1))
852 (fit-window-to-buffer (get-buffer-window buf))
854 (set-buffer-modified-p nil)
857 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
858 ;; Make a sound when there is new mail
859 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
861 ;; I do not like sounds anymore
863 ;; (setq ff/already-boinged-for-mail nil)
865 ;; (defun ff/boing-if-new-mail ()
866 ;; (if mail (when (not ff/already-boinged-for-mail)
867 ;; ;; (ff/play-sound-async "~/local/sounds/boing1.wav")
868 ;; ;; (ff/show-unspooled-mails)
869 ;; (setq ff/already-boinged-for-mail t))
870 ;; (setq ff/already-boinged-for-mail nil))
873 ;; (add-hook 'display-time-hook 'ff/boing-if-new-mail)
875 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
877 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
881 display-time-interval 15 ;; Check every 15s
883 display-time-string-forms `(
887 ;; (propertize " mail "
888 ;; 'face 'ff/mail-alarm-face)
892 (propertize (concat 24-hours ":" minutes
897 'face 'ff/date-info-face)
901 ,(if (ff/laptop-info-string)
902 '(concat " /" (ff/laptop-info-string) "/"))
906 ;; display-time-format "%b %a %e %H:%M"
907 ;; display-time-mail-face nil
910 ;; Show the time, mail and stuff
913 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
914 ;; Moving through buffers
915 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
917 (defun ff/next-buffer ()
918 "Switches to the next buffer in cyclic order."
920 (let ((buffer (current-buffer)))
921 (switch-to-buffer (other-buffer buffer))
922 (bury-buffer buffer)))
924 (defun ff/prev-buffer ()
925 "Switches to the previous buffer in cyclic order."
927 (let ((list (nreverse (buffer-list)))
929 (while (and (not found) list)
930 (let ((buffer (car list)))
931 (if (and (not (get-buffer-window buffer))
932 (not (string-match "\\` " (buffer-name buffer))))
933 (setq found buffer)))
934 (setq list (cdr list)))
935 (switch-to-buffer found)))
937 (define-key global-map [?\C-x right] 'ff/next-buffer)
938 (define-key global-map [?\C-x left] 'ff/prev-buffer)
940 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
941 ;; There is actually a decent terminal emulator in emacs!
942 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
946 (defun ff/kill-associated-buffer (process str) (interactive)
947 (let ((buffer (process-buffer process)))
948 (kill-buffer buffer))
949 (message "Process finished (%s)" (replace-regexp-in-string "\n$" "" str)))
951 (defun ff/kill-associated-buffer-and-delete-windows (process str) (interactive)
952 (let ((buffer (process-buffer process)))
953 (delete-windows-on buffer)
954 (kill-buffer buffer))
955 (message "Process finished (%s)" (replace-regexp-in-string "\n$" "" str)))
957 (defun ff/shell-new-buffer (buffername program &rest param)
958 "Start a terminal-emulator in a new buffer with the shell PROGRAM,
959 optionally invoked with the parameters PARAM. The process associated
960 to the shell can be killed without query."
967 (while (get-buffer (concat "*" bn "*"))
969 bn (format "%s<%d>" buffername n)))
971 (set-buffer (apply 'make-term (append (list bn program nil) param)))
973 (setq show-trailing-whitespace nil)
975 (message "C-c C-k term-char-mode, C-c C-j term-line-mode. \
976 In line mode: M-p previous line, M-n next line.")
978 ;; A standard setup of the face above is not enough, I have to
979 ;; force them here. Since I have a gray90 background, I like
984 '((term-green :foreground "green3")
985 (term-cyan :foreground "cyan3")
986 (term-default-fg-inv :foreground "gray90" :background "black")
989 (term-set-escape-char ?\C-x)
991 ;; I like the shell buffer and windows to be deleted when the
992 ;; shell process terminates. It's a bit of a mess to acheive this.
994 (let ((process (get-buffer-process (current-buffer))))
995 (process-kill-without-query process)
996 (set-process-sentinel process
997 ;; 'ff/kill-associated-buffer-and-delete-windows
998 'ff/kill-associated-buffer
1001 ;; (switch-to-buffer-other-window (concat "*" bn "*"))
1002 (switch-to-buffer (concat "*" bn "*"))
1005 (defcustom ff/default-bash-commands '("ssh")
1006 "*List of commands to be used for completion when invoking a new
1007 bash shell with `ff/bash-new-buffer'.")
1009 (defun ff/bash-new-buffer (universal)
1010 "Starts a bash in a new buffer. When invoked with a universal
1011 argument, asks for a command to execute in that bash shell. The list
1012 of commands in `ff/default-bash-commands' is used for auto-completion"
1016 (let ((cmd (completing-read
1018 (mapcar (lambda (x) (cons x t)) ff/default-bash-commands))))
1019 (ff/shell-new-buffer cmd "/bin/bash" "-c" cmd))
1021 (ff/shell-new-buffer "bash" "/bin/bash")))
1023 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1027 (setq ;; Always follow links if the file is under version control
1028 vc-follow-symlinks t
1031 (when (require 'vc-git nil t)
1032 (add-to-list 'vc-handled-backends 'GIT))
1034 ;; alarm-vc.el is one of my own scripts, check my web page
1036 (when (ff/load-or-alert "alarm-vc" t)
1037 (setq alarm-vc-mode-exceptions "^VM"))
1039 (when (ff/load-or-alert "git")
1040 (setq git-show-unknown nil)
1043 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1044 ;; Makes .sh and others files executable automagically
1045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1047 ;; Please consider the security-related consequences of using it
1049 ;; (defun ff/make-shell-scripts-executable (&optional filename)
1050 ;; (setq filename (or filename (buffer-name)))
1051 ;; (when (and (string-match "\\.sh$\\|\\.pl$\\|\\.rb" filename)
1052 ;; (not (file-executable-p filename))
1054 ;; (set-file-modes filename 493)
1055 ;; (message "Made %s executable" filename)))
1057 ;; (add-hook 'after-save-hook 'ff/make-shell-scripts-executable)
1059 (add-hook 'after-save-hook
1060 'executable-make-buffer-file-executable-if-script-p)
1062 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1063 ;; Cool stuff to navigate in emacs-lisp sources
1064 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1066 (require 'find-func)
1068 (defun ff/goto-function-definition (&optional goback)
1069 "Go directly to the definition of the function at point. With
1070 goback argument, go back where we were."
1073 (if (not (and (boundp 'goto-function-history) goto-function-history))
1074 (error "We were nowhere, buddy")
1075 (message "Come back")
1076 (switch-to-buffer (car (car goto-function-history)))
1077 (goto-char (cdr (car goto-function-history)))
1078 (setq goto-function-history (cdr goto-function-history)))
1080 (let ((function (function-called-at-point)))
1082 (let ((location (find-function-search-for-symbol
1084 (symbol-file function))))
1085 (setq goto-function-history
1086 (cons (cons (current-buffer) (point))
1087 (and (boundp 'goto-function-history)
1088 goto-function-history)))
1089 (pop-to-buffer (car location))
1090 (goto-char (cdr location)))))))
1092 (define-key global-map [(meta g)] 'ff/goto-function-definition)
1093 (define-key global-map [(meta G)] (lambda () (interactive)
1094 (ff/goto-function-definition t)))
1096 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1097 ;; The big stuff (bbdb, mailcrypt, etc.)
1098 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1100 ;; Failsafe version if we can't load bbdb
1101 (defun ff/explicit-name (email) email)
1103 (when (ff/load-or-alert "bbdb")
1106 ;; Stop asking (if not t or nil, will not ask)
1107 bbdb-offer-save 'never
1108 ;; I hate when bbdb decides to mess up my windows
1110 ;; I have no problem with bbdb asking me if the sender email
1111 ;; does not match exactly the address we have in the database
1112 bbdb-quiet-about-name-mismatches 0
1113 ;; I have european friends, too
1114 bbdb-north-american-phone-numbers-p nil
1115 ;; To cycle through all possible addresses
1116 bbdb-complete-name-allow-cycling t
1117 ;; Cycle with full names only, not through all net-addresses alone too
1118 bbdb-dwim-net-address-allow-redundancy t
1119 ;; Do not add new addresses automatically
1120 bbdb-always-add-addresses nil
1123 (defface ff/known-address-face
1124 '((t (:foreground "blue2")))
1125 "The face to display known mail identities.")
1127 (defface ff/unknown-address-face
1128 '((t (:foreground "red4")))
1129 "The face to display unknown mail identities.")
1131 (defun ff/explicit-name (email)
1132 "Returns a string identity for the first address in EMAIL. The
1133 identity is taken from bbdb if possible or from the address itself
1134 with mail-extract-address-components. The suffix \"& al.\" is added if
1135 there are more than one address.
1137 If no bbdb record is found, the name is propertized with the face
1138 ff/unknown-address-face. If a record is found and contains a note
1139 'face, the associated face is used, otherwise
1140 ff/known-address-face is used."
1143 (let* ((data (mail-extract-address-components email))
1146 (record (bbdb-search-simple nil net)))
1151 (propertize (bbdb-record-name record)
1153 (or (cdr (assoc 'face
1154 (bbdb-record-raw-notes record)))
1155 'ff/known-address-face))
1157 (propertize (or (and data (concat "<" net ">"))
1159 'face 'ff/unknown-address-face)
1161 (if (string-match "," (mail-strip-quoted-names email)) " & al.")
1165 (ff/configure-faces '((ff/robot-address-face :foreground "green4")
1166 (ff/important-address-face :foreground "blue2"
1168 ;; :background "white"
1169 ;; :foreground "green4"
1177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1178 ;; An encrypted file to put secure stuff (passwords, ...)
1179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1181 (when (ff/load-or-alert "mailcrypt")
1182 (mc-setversion "gpg")
1183 ;; Keep the passphrase for 10min
1184 (setq mc-passwd-timeout 600
1185 ff/secure-note-file "~/private/secure-notes.gpg")
1188 (defface ff/secure-date
1189 '((t (:background "gold" :weight bold)))
1190 "The face to display the dates in the modeline.")
1192 (defun ff/secure-note-add () (interactive)
1193 (find-file "~/private/secure-notes.gpg")
1195 ;; Adds a new entry (i.e. date and a bunch of empty lines)
1197 (goto-char (point-min))
1199 (format-time-string "%Y %b %d %H:%M:%S" (current-time))
1200 " ------------------------------------------------\n\n")
1203 ;; Colorizes the dates
1206 (goto-char (point-min))
1207 (while (re-search-forward
1208 "^-+ [0-9]+ [a-z]+ [0-9]+ [0-9]+:[0-9]+:[0-9]+.+$"
1210 (add-text-properties
1211 (match-beginning 0) (match-end 0) '(face ff/secure-date))))
1213 (set-buffer-modified-p nil)
1214 (setq buffer-undo-list nil)
1217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1219 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1221 (setq ;; For french, aspell is far better than ispell
1222 ispell-program-name "aspell"
1223 ;; To avoid ispell errors in figure filenames, labels, references.
1224 ;; ispell-tex-skip-alists
1226 ;; (append (car ispell-tex-skip-alists)
1227 ;; '(("\\\\citep" ispell-tex-arg-end) ;; JMLR
1228 ;; ("\\\\cite" ispell-tex-arg-end)
1229 ;; ("\\\\nocite" ispell-tex-arg-end)
1230 ;; ("\\\\includegraphics" ispell-tex-arg-end)
1231 ;; ("\\\\author" ispell-tex-arg-end)
1232 ;; ("\\\\ref" ispell-tex-arg-end)
1233 ;; ("\\\\label" ispell-tex-arg-end)
1235 ;; (cadr ispell-tex-skip-alists))
1237 ;; So that reftex follows the text when moving in the summary
1238 reftex-toc-follow-mode nil
1239 ;; So that reftex visits files to follow
1240 reftex-revisit-to-follow t
1243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1244 ;; Used in a \includegraphics runs xfig with the corresponding .fig
1245 ;; file or gimp with the corresponding bitmap picture
1246 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1248 (defun ff/run-eps-edition (prefix rules &optional force)
1250 (let ((filename (concat prefix (car (car rules)))))
1251 (if (or force (file-exists-p filename))
1252 (start-process "latex-eps-editor" nil (cdr (car rules)) filename)
1253 (ff/run-eps-edition prefix (cdr rules) force)))
1254 (message "No original file found for %seps" prefix)))
1256 (defcustom ff/xdvi-for-latex-options nil
1257 "*Options to pass to xdvi when invoking `ff/run-viewer'")
1259 (defun ff/run-viewer (universal)
1261 "Starts an editor for the .eps at point (either xfig or gimp,
1262 depending with the original file it can find), or starts xdvi for
1263 the current .tex if no .eps is found at point. When run with a
1264 universal argument starts xfig even if the .fig does not exist"
1268 (if (and (save-excursion
1269 (and (re-search-backward "{" (point-at-bol) t)
1270 (or (re-search-forward "{\\([^{}]*.\\)eps}" (point-at-eol) t)
1271 (re-search-forward "{\\([^{}]*.\\)pdf}" (point-at-eol) t)
1272 (re-search-forward "{\\([^{}]*.\\)pdf_t}" (point-at-eol) t)
1273 (re-search-forward "{\\([^{}]*.\\)png}" (point-at-eol) t)
1274 (re-search-forward "{\\([^{}]*.\\)jpg}" (point-at-eol) t)
1276 (and (<= (match-beginning 1) (point))
1277 (>= (match-end 1) (- (point) 2))))
1279 (ff/run-eps-edition (match-string-no-properties 1)
1282 ("png" . "gimp") ("pgm" . "gimp") ("ppm" . "gimp")
1286 (if (not (and (buffer-file-name) (string-match "\\(.*\\)\.tex$"
1287 (buffer-file-name))))
1288 (message "Not a latex file!")
1289 (condition-case nil (kill-process xdvi-process) (error nil))
1290 (let ((dvi-name (concat (match-string 1 (buffer-file-name)) ".dvi")))
1291 (if (not (file-exists-p dvi-name)) (error "Can not find %s !" dvi-name)
1292 (message "Starting xdvi with %s" dvi-name)
1293 (setq xdvi-process (apply 'start-process
1294 (append '("xdvi-for-latex" nil "xdvi")
1295 ff/xdvi-for-latex-options
1297 (process-kill-without-query xdvi-process))))
1300 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1303 ;; When working on a tex file with other people, I can just change
1304 ;; ff/tex-command in the -*- part of the file so that I don't mess up
1305 ;; other's people configuration.
1307 (defadvice tex-file (around ff/set-my-own-tex-command () activate)
1309 (or (and (boundp 'ff/tex-command)
1314 ;; This is a bit hardcore, but really I can't bear the superscripts in
1315 ;; my emacs window and could not find another way to deactivate them.
1318 (defun tex-font-lock-suscript (pos) ())
1320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1321 ;; Prevents many errors from beeping and makes the others play a nifty
1323 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1325 (defun ff/ring-bell ()
1326 (unless (memq this-command
1328 abort-recursive-edit
1331 backward-delete-char-untabify
1332 delete-backward-char
1333 minibuffer-complete-and-exit
1334 previous-line next-line
1335 backward-char forward-char
1336 scroll-up scroll-down
1337 enlarge-window-horizontally shrink-window-horizontally
1338 enlarge-window shrink-window
1341 ;; (message "command [%s]" (prin1-to-string this-command))
1342 ;; (ff/play-sound-async "~/local/sounds/short_la.wav")
1345 (setq ring-bell-function 'ff/ring-bell)
1347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1348 ;; Past the content of the url currently in the kill-ring with
1350 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1352 (defun ff/insert-url (&optional url)
1353 "Downloads an URL with lynx and inserts it after the point."
1354 (interactive "MUrl: ")
1356 (message "Inserting %s" url)
1357 (insert (concat "from: " url "\n\n"))
1358 ;; (call-process "lynx" nil t nil "-nolist" "-dump" url))
1359 (call-process "w3m" nil t nil "-dump" url))
1362 (define-key global-map [(shift mouse-2)]
1363 (lambda () (interactive) (ff/insert-url (current-kill 0))))
1365 ;; lookup-dict is one of my own scripts, check my web page
1367 (when (ff/load-or-alert "lookup-dict" t)
1368 (define-key global-map [(control \?)] 'lookup-dict))
1370 ;; (defun ff/generate-password () (interactive)
1371 ;; (let ((c "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-"))
1372 ;; (nth (random (length c)) c))
1374 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1375 ;; Automatization of things I do often
1376 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1378 (defun ff/snip () (interactive)
1379 (let ((start (condition-case nil (region-beginning) (error (point))))
1380 (end (condition-case nil (region-end) (error (point)))))
1382 (insert "---------------------------- snip snip -------------------------------\n")
1384 (insert "---------------------------- snip snip -------------------------------\n")
1387 (defun ff/start-latex ()
1388 "Adds all that stuff to start a new LaTeX document."
1390 (goto-char (point-min))
1391 (insert "%% -*- mode: latex; mode: reftex; mode: flyspell; coding: utf-8; tex-command: \"pdflatex.sh\" -*-
1393 \\documentclass[12pt]{article}
1394 \\usepackage[a4paper,top=2.5cm,bottom=2cm,left=1.5cm,right=1.5cm]{geometry}
1395 \\usepackage[utf8]{inputenc}
1396 \\usepackage{amsmath}
1397 \\usepackage{amssymb}
1398 \\usepackage{hyperref}
1400 %% \\usepackage[pdftex]{graphicx}
1401 %% \\usepackage{eurosym}
1410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1412 %% \\usepackage[T1]{fontenc}
1413 %% \\usepackage[scaled]{helvet}
1414 %% \\usepackage[cm]{sfmath}
1415 %% \\renewcommand{\\ttdefault}{pcr}
1416 %% \\renewcommand*\\familydefault{\\sfdefault}
1417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1418 %% \\def\\argmax{\\operatornamewithlimits{argmax}}
1419 %% \\def\\argmin{\\operatornamewithlimits{argmin}}
1420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1421 %% \\setlength{\\parindent}{0cm}
1422 %% \\setlength{\\parskip}{12pt}
1423 %% \\renewcommand{\\baselinestretch}{1.3}
1424 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1430 (goto-char (point-max))
1437 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1439 (defun ff/add-copyrights ()
1440 "Adds two lines for the (C) at the beginning of current buffer."
1443 (let ((comment-style 'plain))
1445 (goto-char (point-min))
1447 ;; If this is a script, put the copyrights after the first line
1449 (when (re-search-forward "^#!" nil t)
1453 (let ((start (point))
1454 (comment-style 'box))
1458 "\nSTART_IP_HEADER\n"
1460 (when (boundp 'user-full-name)
1461 (concat "\nWritten by " user-full-name "\n"))
1463 (when (boundp 'user-mail-address)
1464 (concat "Contact <" user-mail-address "> for comments & bug reports\n"))
1469 (comment-region start (point)))
1473 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1475 (defun ff/remove-ip-header () (interactive)
1477 (goto-char (point-min))
1478 (when (and (re-search-forward "START_IP_HEADER" nil t)
1479 (re-search-forward "END_IP_HEADER" nil t))
1483 (defun ff/add-gpl ()
1484 "Adds the GPL statements at the beginning of current buffer."
1486 (let ((comment-style 'box)
1491 ;; This program is free software; you can redistribute it and/or
1492 ;; modify it under the terms of the GNU General Public License
1493 ;; version 2 as published by the Free Software Foundation.
1495 ;; This program is distributed in the hope that it will be useful, but
1496 ;; WITHOUT ANY WARRANTY\; without even the implied warranty of
1497 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1498 ;; General Public License for more details.
1504 This program is free software: you can redistribute it and/or modify
1505 it under the terms of the version 3 of the GNU General Public License
1506 as published by the Free Software Foundation.
1508 This program is distributed in the hope that it will be useful, but
1509 WITHOUT ANY WARRANTY; without even the implied warranty of
1510 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1511 General Public License for more details.
1513 You should have received a copy of the GNU General Public License
1514 along with this program. If not, see <http://www.gnu.org/licenses/>.
1517 (when (boundp 'user-full-name)
1518 (concat "Written by and Copyright (C) " user-full-name "\n"))
1520 (when (boundp 'user-mail-address)
1521 (concat "Contact <" user-mail-address "> for comments & bug reports\n"))
1529 (goto-char (point-min))
1531 ;; If this is a script, put the gpl after the first line
1532 (when (re-search-forward "^#!" nil t)
1536 (let ((start (point)))
1538 (comment-region start (point)))
1541 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1543 (defun ff/start-c ()
1544 "Adds the header to start a C program."
1546 ;; (beginning-of-buffer)
1552 int main(int argc, char **argv) {
1559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1561 (defun ff/start-c++ ()
1562 "Adds the header to start a C++ program."
1564 ;; (beginning-of-buffer)
1573 using namespace std;
1575 int main(int argc, char **argv) {
1582 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1584 (defun ff/headerize ()
1585 "Adds the #define HEADER_H, etc."
1587 (let ((flag-name (replace-regexp-in-string
1589 (upcase (file-name-nondirectory (buffer-file-name))))))
1590 (goto-char (point-max))
1591 (insert "\n#endif\n")
1592 (goto-char (point-min))
1593 (insert (concat "#ifndef " flag-name "\n"))
1594 (insert (concat "#define " flag-name "\n"))
1598 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1600 (defun ff/start-html ()
1601 "Adds all that stuff to start a new HTML file."
1603 (goto-char (point-min))
1604 (insert "<?xml version=\"1.0\" encoding=\"utf-8\"?>
1605 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1607 <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
1610 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
1616 (goto-char (point-max))
1624 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1626 ;; Insert a line showing all the variables written on the current line
1627 ;; and separated by commas
1629 (defun ff/cout-var (arg)
1630 "Invoked on a line with a list of variables names,
1631 it inserts a line which displays their values in cout, or cerr if
1632 the function is invoked with a universal arg"
1634 (let ((line (if arg "cerr" "cout")))
1635 (goto-char (point-at-bol))
1636 ;; Regexp syntax sucks moose balls, honnest. To match '[', just
1637 ;; put it as the first char in the [...] ... This leads to some
1638 ;; obvious things like the following
1639 (while (re-search-forward "\\([][a-zA-Z0-9_.:\(\)]+\\)" (point-at-eol) t)
1641 (concat line " << \" "
1642 (match-string 1) " = \" << " (match-string 1))))
1643 (goto-char (point-at-bol))
1645 (insert line " << endl\;\n")
1646 (indent-region (point-at-bol 0) (point-at-eol 0) nil)
1649 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1651 (defun ff/clean-article ()
1652 "Cleans up an article by removing the leading blanks on each line
1653 and refilling all the paragraphs."
1655 (let ((fill-column 92))
1656 (goto-char (point-min))
1657 (while (re-search-forward "^\\ +" nil t)
1658 (replace-match "" nil nil))
1659 (fill-individual-paragraphs (point-min) (point-max) t)))
1661 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1663 (defun ff/start-slide ()
1665 (insert "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1669 (save-excursion (insert "}{}
1679 (define-key latex-mode-map [(meta S)] 'ff/start-slide)
1680 (define-key latex-mode-map [(control c) (control a)] 'align-current)
1681 (define-key latex-mode-map [(control end)] 'tex-close-latex-block)
1682 (define-key latex-mode-map [(control tab)] 'ispell-complete-word)
1683 ;; Strange that I have to specify that
1684 ;; (setq paragraph-separate "[% \f]*$")
1685 ;; (setq paragraph-separate
1686 ;; (concat "[%]*\\|[\f%]\\|[ \t]*\\($\\|"
1688 ;; "\\\\" (regexp-opt (append
1689 ;; (mapcar 'car latex-section-alist)
1690 ;; '("begin" "label" "end" )) t)
1691 ;; "\\>\\|\\\\\\(" (regexp-opt '("item" "bibitem" "newline"
1692 ;; "noindent" "newpage" "footnote"
1693 ;; "marginpar" "parbox" "caption"))
1694 ;; "\\|\\$\\$\\|[a-z]*\\(space\\|skip\\|page[a-z]*\\)"
1695 ;; "\\>\\)[ \t]*\\($\\|%\\)\\)"))
1696 ;; (flyspell-mode 1)
1700 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1702 (defun ff/start-test-code ()
1704 (let ((start (point)))
1706 { // ******************************* START ***************************
1707 #warning Test code added on "
1708 (format-time-string "%04Y %b %02d %02H:%02M:%02S" (current-time))
1711 } // ******************************** END ****************************
1714 (indent-region start (point) nil))
1718 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1720 (defun ff/code-to-html () (interactive)
1722 (narrow-to-region (region-beginning) (region-end))
1723 (replace-string "\"" """ nil (point-min) (point-max))
1724 (replace-string " " " " nil (point-min) (point-max))
1725 (replace-string ">" ">" nil (point-min) (point-max))
1726 (replace-string "<" "<" nil (point-min) (point-max))
1727 (replace-string "\e" "^[" nil (point-min) (point-max))
1728 (replace-string "
\7f" "^?" nil (point-min) (point-max))
1729 (replace-string "
\1f" "^_" nil (point-min) (point-max))
1730 (replace-regexp "$" "<br />" nil (point-min) (point-max))
1734 (defun ff/downcase-html-tags () (interactive)
1736 (beginning-of-buffer)
1737 (while (re-search-forward "<\\([^>]+\\)>" nil t)
1738 (downcase-region (match-beginning 1) (match-end 1)))
1742 ;; If we enter html mode and there is no makefile around, create a
1743 ;; compilation command with tidy (this is cool stuff)
1745 (add-hook 'html-mode-hook
1747 (unless (or (not (buffer-file-name))
1748 (file-exists-p "makefile")
1749 (file-exists-p "Makefile"))
1750 (set (make-local-variable 'compile-command)
1751 (let ((fn (file-name-nondirectory buffer-file-name)))
1752 (format "tidy -utf8 %s > /tmp/%s" fn fn))))))
1754 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1756 (defun ff/count-words-region (beginning end)
1757 "Print number of words in the region.
1758 Words are defined as at least one word-constituent character
1759 followed by at least one character that is not a
1760 word-constituent. The buffer's syntax table determines which
1761 characters these are."
1764 (message "Counting words in region ... ")
1766 (goto-char beginning)
1768 (while (< (point) end)
1769 (re-search-forward "\\w+\\W+")
1770 (setq count (1+ count)))
1771 (cond ((zerop count) (message "The region does NOT have any word."))
1772 ((= 1 count) (message "The region has 1 word."))
1773 (t (message "The region has %d words." count))))))
1775 ;; (add-hook 'html-mode-hook 'flyspell-mode)
1777 (defun ff/tidy-html ()
1778 "Run tidy in on the content of the current buffer, put the result in
1781 (call-process-region (point-min) (point-max)
1784 (list nil (make-temp-file "/tmp/tidy-html."))))
1786 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1788 ;; Create the adequate embryo of a file if it does not exist
1790 (defun ff/start-file () (interactive)
1791 (let ((filename (buffer-file-name)))
1794 (when (string-match "\\.sh$" filename)
1796 (insert "#!/bin/bash\n\nset -e\n\n")
1798 (ff/add-copyrights))
1801 (when (string-match "\\.html$" filename)
1807 (when (string-match "\\.h$" filename)
1818 (when (string-match "\\.c$" filename)
1823 (when (string-match "\.\\(cc\\|cpp\\)$" filename)
1826 (let ((headername (replace-regexp-in-string "\\.\\(cc\\|cpp\\)$" ".h"
1828 (if (file-exists-p headername)
1829 (insert (concat "\n#include \"" (file-name-nondirectory headername) "\"\n"))
1833 (when (string-match "\\.tex$" filename)
1838 (set-buffer-modified-p nil)
1841 (if (>= emacs-major-version 22)
1842 (add-to-list 'find-file-not-found-functions 'ff/start-file)
1843 (add-to-list 'find-file-not-found-hooks 'ff/start-file))
1845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1847 (define-key global-map [f8] 'ff-find-other-file)
1848 (define-key global-map [(shift f8)] (lambda () (interactive) (ff-find-other-file t)))
1850 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1851 ;; Antiword, htmlize and boxquote
1852 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1854 (autoload 'no-word "no-word")
1855 (add-to-list 'auto-mode-alist '("\\.doc\\'" . no-word))
1856 ;; (add-to-list 'auto-mode-alist '("\\.DOC\\'" . no-word))
1858 (autoload 'htmlize-buffer "htmlize" nil t)
1860 (setq boxquote-top-and-tail "------------------")
1861 (autoload 'boxquote-region "boxquote" nil t)
1863 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1864 ;; The compilation hacks
1865 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1867 ;; If we enter c++ mode and there is no makefile around, we create a
1868 ;; make command on the fly for the specific object file
1870 (add-hook 'c++-mode-hook
1872 (unless (or (file-exists-p "makefile") (file-exists-p "Makefile"))
1873 (set (make-local-variable 'compile-command)
1876 (file-name-sans-extension
1877 (file-name-nondirectory buffer-file-name)))))))
1879 ;; <f1> runs the compilation according to the compile-command (and
1880 ;; thus does not ask any confirmation), shows the compilation buffer
1881 ;; during compilation and delete all windows showing the compilation
1882 ;; buffer if the compilation ends with no error
1884 ;; <shift-f1> asks for a compilation command and runs the compilation
1885 ;; but does not restore the window configuration (i.e. the compilation
1886 ;; buffer's window will still be visible, as usual)
1888 ;; <f2> goes to the next compilation error (as C-x ` does on the
1889 ;; standard configuration)
1891 (defun ff/restore-windows-if-no-error (buffer msg)
1892 "Delete the windows showing the compilation buffer if msg
1893 matches \"^finished\"."
1895 (when (string-match "^finished" msg)
1896 ;; (delete-windows-on buffer)
1897 (if (boundp 'ff/window-configuration-before-compilation)
1898 (set-window-configuration ff/window-configuration-before-compilation))
1902 (add-to-list 'compilation-finish-functions 'ff/restore-windows-if-no-error)
1904 (defun ff/fast-compile ()
1905 "Compiles without asking anything."
1907 (let ((compilation-read-command nil))
1908 (setq ff/window-configuration-before-compilation (current-window-configuration))
1909 (compile compile-command)))
1911 (setq compilation-read-command t
1912 compile-command "make -j -k"
1913 compile-history '("make clean" "make DEBUG=yes -j -k" "make -j -k")
1916 (defun ff/universal-compile () (interactive)
1917 (funcall (or (cdr (assoc major-mode
1919 (latex-mode . tex-file)
1920 (html-mode . browse-url-of-buffer)
1921 ;; Here you can add other mode -> compile command
1923 'ff/fast-compile ;; And this is the failsafe
1926 (define-key global-map [f1] 'ff/universal-compile)
1927 (define-key global-map [(shift f1)] 'compile)
1928 (define-key global-map [f2] 'next-error)
1930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1932 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1934 ;; (when (ff/load-or-alert "flyspell-timer" t)
1935 ;; (add-hook 'flyspell-mode-hook 'flyspell-timer-ensure-idle-timer))
1937 (defun ff/pick-dictionnary () (interactive)
1938 (when (and (boundp 'flyspell-mode) flyspell-mode)
1939 (if (and current-input-method (string-match "latin" current-input-method))
1940 (ispell-change-dictionary "francais")
1941 (ispell-change-dictionary "american"))
1942 ;; (flyspell-buffer)
1946 (defadvice toggle-input-method (after ff/switch-dictionnary nil activate)
1947 (ff/pick-dictionnary))
1949 ;; (add-hook 'message-mode-hook 'auto-fill-mode)
1950 ;; (add-hook 'message-mode-hook 'flyspell-mode)
1952 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1953 ;; Delete all windows which are in the same "column", which means
1954 ;; whose xmin and xmax are bounded by the xmin and xmax of the
1955 ;; currently selected column
1956 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1958 ;; This is from emacs23 ! better than my old ff/delete-other-windows-in-column
1960 (unless (fboundp 'delete-other-windows-vertically)
1962 (defun delete-other-windows-vertically (&optional window)
1963 "Delete the windows in the same column with WINDOW, but not WINDOW itself.
1964 This may be a useful alternative binding for \\[delete-other-windows]
1965 if you often split windows horizontally."
1967 (let* ((window (or window (selected-window)))
1968 (edges (window-edges window))
1970 (while (not (eq (setq w (next-window w 1)) window))
1971 (let ((e (window-edges w)))
1972 (when (and (= (car e) (car edges))
1973 (= (caddr e) (caddr edges)))
1975 (mapc 'delete-window delenda)))
1978 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1984 (defun ff/entropy (l)
1989 (* (- x) (/ (log x) (log 2)))))
1994 ;; Usefull to deal with results in latex files
1996 (defun ff/round-floats-in-region () (interactive)
1999 (narrow-to-region (region-beginning) (region-end))
2000 (error (thing-at-point 'word)))
2002 (goto-char (point-min))
2003 (while (re-search-forward "[0-9\.]+" nil t)
2004 (let ((value (string-to-number (buffer-substring (match-beginning 0) (match-end 0)))))
2005 (delete-region (match-beginning 0) (match-end 0))
2006 (insert (format "%0.2f" value)))))))
2008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2010 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2012 (require 'info nil t)
2014 (define-key global-map [(shift iso-lefttab)] 'ispell-complete-word)
2015 ;; shift-tab going backward is kind of standard
2016 (define-key Info-mode-map [(shift iso-lefttab)] 'Info-prev-reference)
2018 ;; (define-key global-map [(control x) (control a)] 'auto-fill-mode)
2020 ;; Put back my keys, you thief!
2021 (define-key global-map [(home)] 'beginning-of-buffer)
2022 (define-key global-map [(end)] 'end-of-buffer)
2023 ;; (define-key global-map [(insertchar)] 'overwrite-mode)
2024 (define-key global-map [(delete)] 'delete-char)
2026 ;; Cool shortcuts to move to the end / beginning of block keen
2027 (define-key global-map [(control right)] 'forward-sexp)
2028 (define-key global-map [(control left)] 'backward-sexp)
2030 ;; Wheel mouse moves up and down 2 lines (and DO NOT BEEP when we are
2031 ;; out of the buffer)
2033 (define-key global-map [mouse-4]
2034 (lambda () (interactive) (condition-case nil (scroll-down 2) (error nil))))
2035 (define-key global-map [mouse-5]
2036 (lambda () (interactive) (condition-case nil (scroll-up 2) (error nil))))
2038 ;; with shift it goes faster
2039 (define-key global-map [(shift mouse-4)]
2040 (lambda () (interactive) (condition-case nil (scroll-down 50) (error nil))))
2041 (define-key global-map [(shift mouse-5)]
2042 (lambda () (interactive) (condition-case nil (scroll-up 50) (error nil))))
2044 ;; Meta-? shows the properties of the character at point
2045 (define-key global-map [(meta ??)]
2046 (lambda () (interactive)
2047 (message (prin1-to-string (text-properties-at (point))))))
2049 ;; Compiles the latex file in the current buffer
2051 (setq tex-start-commands "\\input")
2052 (define-key global-map [f3] 'tex-file)
2053 (define-key global-map [(shift f3)] 'tex-bibtex-file)
2055 ;; To run xdvi on the dvi associated to the .tex in the current
2056 ;; buffer, and to edit the .fig or bitmap image used to generate the
2059 (define-key global-map [f4] 'ff/run-viewer)
2061 ;; Closes the current \begin{}
2063 (when (ff/load-or-alert "longlines")
2065 (setq longlines-show-hard-newlines t
2066 longlines-auto-wrap t
2067 ;; longlines-show-effect #("|\n" 0 2 (face escape-glyph))
2070 ;; (defun ff/auto-longlines ()
2071 ;; (when (save-excursion
2072 ;; (goto-char (point-min))
2073 ;; (re-search-forward "^.\\{81,\\}$" nil t))
2075 ;; (message "Switched on the lonlines mode automatically")
2078 ;; (add-hook 'latex-mode-hook 'ff/auto-longlines)
2082 ;; Meta-/ remaped (completion)
2084 (define-key global-map [(shift right)] 'dabbrev-expand)
2085 (define-key global-map [(meta =)] 'dabbrev-expand)
2087 ;; Change the current window.
2089 (defun ff/next-same-frame-window () (interactive)
2090 (select-window (next-window (selected-window)
2091 (> (minibuffer-depth) 0)
2094 (defun ff/previous-same-frame-window () (interactive)
2095 (select-window (previous-window (selected-window)
2096 (> (minibuffer-depth) 0)
2099 (define-key global-map [(shift prior)] 'ff/next-same-frame-window)
2100 (define-key global-map [(shift next)] 'ff/previous-same-frame-window)
2102 (define-key global-map [(control })] 'enlarge-window-horizontally)
2103 (define-key global-map [(control {)] 'shrink-window-horizontally)
2104 (define-key global-map [(control \")] 'enlarge-window)
2105 (define-key global-map [(control :)] 'shrink-window)
2107 ;; (define-key global-map [(control shift prior)] 'next-multiframe-window)
2108 ;; (define-key global-map [(control shift next)] 'previous-multiframe-window)
2110 ;; I have two screens sometime!
2112 (define-key global-map [(meta next)] 'other-frame)
2113 (define-key global-map [(meta prior)] (lambda () (interactive) (other-frame -1)))
2115 (define-key global-map [(shift home)] 'delete-other-windows-vertically)
2117 ;; (define-key global-map [(control +)] 'enlarge-window)
2118 ;; (define-key global-map [(control -)] 'shrink-window)
2120 ;; Goes to next/previous buffer
2122 (define-key global-map [(control prior)] 'ff/next-buffer)
2123 (define-key global-map [(control next)] 'ff/prev-buffer)
2125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2126 ;; If M-. on a symbol, show where it is defined in another window
2127 ;; without giving focus, cycle if repeated.
2128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2130 (when (ff/load-or-alert "etags")
2132 (defun ff/find-tag-nofocus () (interactive)
2133 "Show in another window the definition of the current tag"
2134 (let ((tag (find-tag-default)))
2135 (display-buffer (find-tag-noselect tag (string= tag last-tag)))
2136 (message "Tag %s" tag)
2140 (define-key global-map [(meta .)] 'ff/find-tag-nofocus)
2143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2144 ;; Destroys the current buffer and its window if it's not the only one
2145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2147 (defcustom ff/kill-this-buffer-and-delete-window-exceptions ""
2148 "*Regexp matching the buffer names which have to be kept when using
2149 `ff/kill-this-buffer-and-delete-window'.")
2151 (defun ff/kill-this-buffer-and-delete-window (universal)
2152 "Unless its name matches
2153 `ff/kill-this-buffer-and-delete-window-exceptions', kills the
2154 current buffer and deletes the current window if it's not the
2155 only one in the frame. If the buffer has to be kept, go to the
2156 next one. With universal argument, kill all killable buffers."
2159 (let ((nb-killed 0))
2161 (unless (string-match ff/kill-this-buffer-and-delete-window-exceptions
2164 (setq nb-killed (1+ nb-killed))
2167 (message "Killed %d buffer%s" nb-killed (if (> nb-killed 1) "s" "")))
2168 (if (string-match ff/kill-this-buffer-and-delete-window-exceptions (buffer-name))
2170 (kill-this-buffer)))
2171 ;; (unless (one-window-p t) (delete-window))
2174 (define-key global-map [(control backspace)] 'ff/kill-this-buffer-and-delete-window)
2175 ;; (define-key calc-mode-map [(control backspace)] 'calc-quit)
2178 (setq ff/kill-this-buffer-and-delete-window-exceptions
2179 "^ \\|\\*Messages\\*\\|\\*scratch\\*\\|\\*Group\\*\\|\\*-jabber-\\*\\|\\*-jabber-process-\\*\\|\\*media\\*")
2181 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2185 (defun ff/elisp-debug-on ()
2186 "Switches `debug-on-error' and `debug-on-quit'."
2189 (setq debug-on-error nil
2191 (setq debug-on-error t
2194 (message "elisp debug on")
2195 (message "elisp debug off")))
2197 (defun ff/create-dummy-buffer (&optional universal) (interactive "P")
2198 (find-file (concat "/tmp/" (ff/non-existing-filename "/tmp/" "dummy" "")))
2200 (if universal (ff/insert-url (current-kill 0)))
2201 (message "New dummy text-mode buffer"))
2203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2204 ;; Recentf to keep a list of recently visited files. I use it
2205 ;; exclusively with my selector.el
2206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2210 (setq recentf-exclude
2211 (append recentf-exclude
2212 '("enotes$" "secure-notes$" "media-playlists$"
2214 "svn-commit.tmp$" ".git/COMMIT_EDITMSG$"
2215 "\.bbl$" "\.aux$" "\.toc$"))
2216 recentf-max-saved-items 1000
2217 recentf-save-file "~/private/emacs/recentf"
2220 (when (boundp 'recentf-keep) (add-to-list 'recentf-keep 'file-remote-p))
2222 ;; Removes the link if we add the file itself (I am fed up with
2223 ;; duplicates because of vc-follow-symlinks)
2225 (defadvice recentf-add-file (before ff/remove-links (filename) activate)
2226 ;; If we are adding a filename corresponding to the last link we
2227 ;; have added, remove the latter
2228 (when (and recentf-list
2229 (file-symlink-p (car recentf-list))
2230 (string= filename (file-chase-links filename)))
2231 (setq recentf-list (cdr recentf-list))
2236 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2237 ;; My front-end to mplayer
2238 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2240 ;; (ff/compile-when-needed "media/mplayer")
2241 ;; (ff/compile-when-needed "media")
2243 (when (ff/load-or-alert "media")
2245 (unless window-system
2248 (media/mode-string-face
2249 :foreground "blue4" :weight 'bold)
2251 (media/current-tune-face
2252 :foreground "black" :background "yellow" :weight 'normal)
2254 (media/instant-highlight-face
2255 :foreground "black" :background "orange" :weight 'normal)
2259 (define-key global-map [(meta \\)] 'media)
2261 (setq media/expert t
2262 media/add-current-song-to-interrupted-when-killing t
2263 media/duration-to-history 30
2264 media/history-size 1000
2265 media/playlist-file "~/private/emacs/media-playlists"
2266 media/mplayer/args '(
2269 "-subfont-osd-scale" "3"
2270 ;; "-stop-xscreensaver"
2273 media/mplayer/timing-request-period 5.0
2277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2281 ;; selector.el is one of my own scripts, check my web page
2283 (when (ff/load-or-alert "selector" t)
2284 (define-key global-map [(shift return)] 'selector/quick-move-in-buffer)
2285 (define-key global-map [(control x) (control b)] 'selector/switch-buffer)
2287 (defun ff/visit-debpkg-file (&optional regexp)
2288 "This function lists all the files found with dpkg -S and
2289 proposes to visit them."
2290 (interactive "sPattern: ")
2296 (cons (selector/filename-to-string s) s))
2298 (shell-command-to-string (concat "dpkg -S " regexp " | awk '{print $2}'"))))
2301 "*selector find-file*"
2305 (add-hook 'selector/mode-hook (lambda () (setq truncate-lines t)))
2307 (defun ff/selector-insert-record-callback (r)
2308 (bbdb-display-records (list r))
2309 ;; Weird things will happen if you kill the buffer from which you
2310 ;; invoked ff/selector-mail-from-bbdb
2311 (insert (car (elt r 6)))
2314 (defun ff/selector-compose-mail-callback (r)
2315 (vm-compose-mail (car (elt r 6)))
2318 (defun ff/selector-mail-from-bbdb () (interactive)
2321 (lambda (r) (cons (concat (elt r 0)
2329 (if (string= mode-name "Mail")
2330 'ff/selector-insert-record-callback
2331 'ff/selector-compose-mail-callback)
2336 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2337 ;; A function to remove temporary alarm windows
2338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2340 (defcustom ff/annoying-windows-regexp
2341 "\\*Messages\\*\\|\\*compilation\\*\\|\\*tex-shell\\*\\|\\*Help\\*\\|\\*info\\*\\|\\*Apropos\\*\\|\\*BBDB\\*\\|\\*.*-diff\\*"
2342 "The regexp matching the windows to be deleted by `ff/delete-annoying-windows'"
2345 (defun ff/delete-annoying-windows ()
2346 "Close all the windows showing buffers whose names match
2347 `ff/annoying-windows-regexp'."
2349 (when ff/annoying-windows-regexp
2351 (when (and (not (one-window-p w))
2352 (string-match ff/annoying-windows-regexp
2353 (buffer-name (window-buffer w))))
2357 (message "Removed annoying windows")
2361 (setq ff/annoying-windows-regexp
2362 (concat ff/annoying-windows-regexp
2363 "\\|\\*unspooled mails\\*\\|\\*enotes alarms\\*\\|\\*system info\\*"))
2365 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2366 ;; Some handy functions
2367 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2369 (defun ff/twin-horizontal-current-buffer () (interactive)
2370 (delete-other-windows)
2371 (split-window-horizontally)
2375 (defun ff/twin-vertical-current-buffer () (interactive)
2376 (delete-other-windows)
2377 (split-window-vertically)
2381 (defun ff/flyspell-mode (arg) (interactive "p")
2383 (when flyspell-mode (flyspell-buffer)))
2385 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2387 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2389 (defun ff/move-region-to-fridge () (interactive)
2390 "Cut the current region, paste it in a file called ./fridge
2391 with a time tag, and save this file"
2392 (unless (use-region-p) (error "No region selected"))
2393 (let ((bn (file-name-nondirectory (buffer-file-name))))
2394 (kill-region (region-beginning) (region-end))
2395 (with-current-buffer (find-file-noselect "fridge")
2396 (goto-char (point-max))
2398 (insert "######################################################################\n")
2400 (format-time-string "%Y %b %d %H:%M:%S" (current-time))
2406 (message "Region moved to fridge")
2411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2415 (setq ff/map (make-sparse-keymap))
2416 (define-key global-map [(control \`)] ff/map)
2417 (define-key esc-map "`" ff/map)
2419 (defun ff/git-status (&optional dir) (interactive)
2420 (if (buffer-file-name)
2421 (git-status (file-name-directory (buffer-file-name)))
2422 (error "No file attached to this buffer")))
2424 (defun ff/insert-date () (interactive)
2425 (insert (format-time-string "\n * %Y %b %d %H:%M:%S\n\n" (current-time)))
2428 (define-key ff/map [(control g)] 'ff/git-status)
2429 (define-key ff/map [(control w)] 'server-edit)
2430 (define-key ff/map [(control d)] 'ff/elisp-debug-on)
2431 ;; (define-key ff/map "d" 'diary)
2432 (define-key ff/map "d" 'ff/insert-date)
2433 (define-key ff/map [(control \`)] 'ff/bash-new-buffer)
2434 (define-key ff/map [(control n)] 'enotes/show-all-notes)
2435 (define-key ff/map [(control s)] 'ff/secure-note-add)
2436 (define-key ff/map [(control t)] 'ff/start-test-code)
2437 (define-key ff/map [(control q)] 'ff/create-dummy-buffer)
2438 (define-key ff/map [(control a)] 'auto-fill-mode)
2439 (define-key ff/map [(control i)] 'ff/system-info)
2440 (define-key ff/map "w" 'ff/word-occurences)
2441 (define-key ff/map [(control c)] 'calendar)
2442 ;; (define-key ff/map [(control c)] (lambda () (interactive) (save-excursion (calendar))))
2443 (define-key ff/map [(control l)] 'goto-line)
2444 (define-key ff/map "l" 'longlines-mode)
2445 (define-key ff/map [(control o)] 'selector/quick-pick-recent)
2446 (define-key ff/map "s" 'selector/quick-move-in-buffer)
2447 (define-key ff/map "S" 'selector/search-sentence)
2448 (define-key ff/map "h" 'ff/tidy-html)
2449 (define-key ff/map "c" 'ff/count-char)
2450 (define-key ff/map [(control p)] 'ff/print-to-file)
2451 (define-key ff/map "P" 'ff/print-to-printer)
2452 (define-key ff/map [(control b)] 'bbdb)
2453 (define-key ff/map "m" 'ff/selector-mail-from-bbdb)
2454 (define-key ff/map [(control m)] 'woman)
2455 (define-key ff/map "b" 'bookmark-jump)
2456 (define-key ff/map [(control =)] 'calc)
2457 (define-key ff/map [(control shift b)]
2458 (lambda () (interactive)
2461 (define-key ff/map "f" 'ff/move-region-to-fridge)
2462 (define-key ff/map [(control f)] 'ff/flyspell-mode)
2464 (define-key ff/map [?\C-0] 'ff/delete-annoying-windows)
2465 (define-key ff/map "1" 'delete-other-windows)
2466 (define-key ff/map [?\C-1] 'delete-other-windows)
2467 (define-key ff/map "2" 'ff/twin-vertical-current-buffer)
2468 (define-key ff/map [?\C-2] 'ff/twin-vertical-current-buffer)
2469 (define-key ff/map "3" 'ff/twin-horizontal-current-buffer)
2470 (define-key ff/map [?\C-3] 'ff/twin-horizontal-current-buffer)
2472 (define-key ff/map " " 'delete-trailing-whitespace)
2474 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2475 ;; Hacks so that all keys are functionnal in xterm and through ssh.
2476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2478 (unless window-system
2480 ;; One day I will understand these clipboard business. Until then,
2481 ;; so that it works in xterm (yes), let's use xclip. This is a bit
2484 ;; (defun ff/yank-with-xclip (&optional arg)
2485 ;; "Paste the content of the X clipboard with the xclip
2486 ;; command. Without ARG converts some of the '\\uxxxx' characters."
2487 ;; (interactive "P")
2488 ;; (with-temp-buffer
2489 ;; (shell-command "xclip -o" t)
2491 ;; (mapc (lambda (x) (replace-string (concat "\\u" (car x)) (cdr x) nil (point-min) (point-max)))
2492 ;; '(("fffd" . "??")
2503 ;; (kill-ring-save (point-min) (point-max)))
2507 ;; (define-key global-map [(meta y)] 'ff/yank-with-xclip)
2509 ;; (set-terminal-coding-system 'iso-latin-1)
2510 ;; (set-terminal-coding-system 'utf-8)
2512 ;; I have in my .Xressource
2514 ;; XTerm.VT100.translations: #override\n\
2515 ;; <Btn4Down>,<Btn4Up>:scroll-back(2,line)\n\
2516 ;; <Btn5Down>,<Btn5Up>:scroll-forw(2,line)\n\
2517 ;; Ctrl<Btn4Down>,Ctrl<Btn4Up>:scroll-back(1,page)\n\
2518 ;; Ctrl<Btn5Down>,Ctrl<Btn5Up>:scroll-forw(1,page)\n\
2519 ;; Shift<Btn4Down>,Shift<Btn4Up>:scroll-back(1,halfpage)\n\
2520 ;; Shift<Btn5Down>,Shift<Btn5Up>:scroll-forw(1,halfpage)\n\
2521 ;; Alt<KeyPress>:insert-eight-bit()\n\
2522 ;; !Shift<Key>BackSpace: string("
\7f")\n\
2523 ;; Ctrl<Key>BackSpace: string("\eOZ")\n\
2524 ;; Shift<Key>Prior: string("\e[5;2~")\n\
2525 ;; Shift<Key>Next: string("\e[6;2~")\n\
2526 ;; Shift Ctrl<Key>]: string("\eO}")\n\
2527 ;; Shift Ctrl<Key>[: string("\eO{")\n\
2528 ;; Shift Ctrl<Key>/: string("\eO?")\n\
2529 ;; Ctrl<Key>/: string("\eO/")\n\
2530 ;; Shift Ctrl<Key>=: string("\eO+")\n\
2531 ;; Ctrl<Key>=: string("\eO=")\n\
2532 ;; Shift Ctrl<Key>;: string("\eO:")\n\
2533 ;; Ctrl<Key>;: string("\eO;")\n\
2534 ;; Shift Ctrl<Key>`: string("\eO~")\n\
2535 ;; Ctrl<Key>`: string("\eO`")\n\
2536 ;; Shift Ctrl<Key>': string("\eO\\\"")\n\
2537 ;; Ctrl<Key>': string("\eO'")\n\
2538 ;; Shift Ctrl<Key>.: string("\eO>")\n\
2539 ;; Ctrl<Key>.: string("\eO.")\n\
2540 ;; Shift Ctrl<Key>\\,: string("\eO<")\n\
2541 ;; Ctrl<Key>\\,: string("\eO,")
2543 (define-key function-key-map "\e[2~" [insert])
2545 (define-key function-key-map "\e[Z" [S-iso-lefttab])
2547 (define-key function-key-map "\e[1;2A" [S-up])
2548 (define-key function-key-map "\e[1;2B" [S-down])
2549 (define-key function-key-map "\e[1;2C" [S-right])
2550 (define-key function-key-map "\e[1;2D" [S-left])
2551 (define-key function-key-map "\e[1;2F" [S-end])
2552 (define-key function-key-map "\e[1;2H" [S-home])
2554 (define-key function-key-map "\e[2;2~" [S-insert])
2555 (define-key function-key-map "\e[5;2~" [S-prior])
2556 (define-key function-key-map "\e[6;2~" [S-next])
2558 (define-key function-key-map "\e[1;2P" [S-f1])
2559 (define-key function-key-map "\e[1;2Q" [S-f2])
2560 (define-key function-key-map "\e[1;2R" [S-f3])
2561 (define-key function-key-map "\e[1;2S" [S-f4])
2562 (define-key function-key-map "\e[15;2~" [S-f5])
2563 (define-key function-key-map "\e[17;2~" [S-f6])
2564 (define-key function-key-map "\e[18;2~" [S-f7])
2565 (define-key function-key-map "\e[19;2~" [S-f8])
2566 (define-key function-key-map "\e[20;2~" [S-f9])
2567 (define-key function-key-map "\e[21;2~" [S-f10])
2569 (define-key function-key-map "\e[1;5A" [C-up])
2570 (define-key function-key-map "\e[1;5B" [C-down])
2571 (define-key function-key-map "\e[1;5C" [C-right])
2572 (define-key function-key-map "\e[1;5D" [C-left])
2573 (define-key function-key-map "\e[1;5F" [C-end])
2574 (define-key function-key-map "\e[1;5H" [C-home])
2576 (define-key function-key-map "\e[2;5~" [C-insert])
2577 (define-key function-key-map "\e[5;5~" [C-prior])
2578 (define-key function-key-map "\e[6;5~" [C-next])
2580 (define-key function-key-map "\e[1;9A" [M-up])
2581 (define-key function-key-map "\e[1;9B" [M-down])
2582 (define-key function-key-map "\e[1;9C" [M-right])
2583 (define-key function-key-map "\e[1;9D" [M-left])
2584 (define-key function-key-map "\e[1;9F" [M-end])
2585 (define-key function-key-map "\e[1;9H" [M-home])
2587 (define-key function-key-map "\e[2;9~" [M-insert])
2588 (define-key function-key-map "\e[5;9~" [M-prior])
2589 (define-key function-key-map "\e[6;9~" [M-next])
2591 ;; The following ones are not standard
2593 (define-key function-key-map "\eO}" (kbd "C-}"))
2594 (define-key function-key-map "\eO{" (kbd "C-{"))
2595 (define-key function-key-map "\eO?" (kbd "C-?"))
2596 (define-key function-key-map "\eO/" (kbd "C-/"))
2597 (define-key function-key-map "\eO:" (kbd "C-:"))
2598 (define-key function-key-map "\eO;" (kbd "C-;"))
2599 (define-key function-key-map "\eO~" (kbd "C-~"))
2600 (define-key function-key-map "\eO`" (kbd "C-\`"))
2601 (define-key function-key-map "\eO\"" (kbd "C-\""))
2602 (define-key function-key-map "\eO|" (kbd "C-|"))
2603 (define-key function-key-map "\eO'" (kbd "C-'"))
2604 (define-key function-key-map "\eO>" (kbd "C->"))
2605 (define-key function-key-map "\eO." (kbd "C-."))
2606 (define-key function-key-map "\eO<" (kbd "C-<"))
2607 (define-key function-key-map "\eO," (kbd "C-,"))
2608 (define-key function-key-map "\eO-" (kbd "C--"))
2609 (define-key function-key-map "\eO=" (kbd "C-="))
2610 (define-key function-key-map "\eO+" (kbd "C-+"))
2612 (define-key function-key-map "\eOZ" [C-backspace])
2614 (define-key minibuffer-local-map "
\10" 'previous-history-element)
2615 (define-key minibuffer-local-map "
\ e" 'next-history-element)
2617 ;; (define-key global-map [(alt prior)] 'ff/prev-buffer)
2618 ;; (define-key global-map [(alt next)] 'ff/next-buffer)
2622 ;; I am fed up with Alt-Backspace in the minibuffer erasing the
2623 ;; content of the kill-ring
2625 (defun ff/backward-delete-word (arg)
2626 "Delete characters forward until encountering the end of a word, but do not put them in the kill ring.
2627 With argument ARG, do this that many times."
2629 (delete-region (point) (progn (forward-word (- arg)) (point))))
2631 (define-key minibuffer-local-map
2632 [remap backward-kill-word] 'ff/backward-delete-word)
2634 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2636 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2638 ;; Where to save the bookmarks and where is bbdb
2640 (setq bookmark-default-file "~/private/emacs/bmk"
2641 bbdb-file "~/private/bbdb"
2642 custom-file "~/private/emacs/custom")
2644 ;; enotes.el is one of my own scripts, check my web page
2646 (when (ff/load-or-alert "enotes" t)
2647 (setq enotes/file "~/private/enotes"
2648 enotes/show-help nil
2649 enotes/full-display nil
2650 enotes/default-time-fields "9:30")
2653 ;; (add-hook 'enotes/alarm-hook
2654 ;; (lambda () (ff/play-sound-async "~/local/sounds/three_notes2.wav")))
2657 ;; (when (ff/load-or-alert "goto-last-change.el")
2658 ;; (define-key global-map [(control x) (control a)] 'goto-last-change))
2660 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2661 ;; My private stuff (email adresses, mail filters, etc.)
2662 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2664 (ff/load-or-alert "~/private/emacs.perso.el" t)
2666 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2668 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2670 ;; Runs in server mode, so that emacsclient works
2673 (defun ff/raise-frame-and-give-focus ()
2676 (x-focus-frame (selected-frame))
2677 (set-mouse-pixel-position (selected-frame) 4 4)
2680 ;; Raises the window when the server is invoked
2682 (add-hook 'server-switch-hook 'ff/raise-frame-and-give-focus)