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 3
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 ;; And allow minibuffer recursion
79 (setq enable-recursive-minibuffers t)
80 (minibuffer-depth-indicate-mode 1)
82 ;; I do not like tooltips
83 (when (functionp 'tooltip-mode) (tooltip-mode nil))
85 ;; Activate the dynamic completion in the mini-buffer
88 ;; (setq highlight-current-line-globally t
89 ;; highlight-current-line-ignore-regexp "Faces\\|Colors\\| \\*Mini\\|\\*media\\|INBOX")
91 ;; (highlight-current-line-minor-mode 1)
92 ;; (highlight-current-line-set-bg-color "gray75")
94 (defun ff/compile-when-needed (name)
95 "Compiles the given file only if needed. Adds .el if required, and
96 uses `load-path' to find it."
97 (if (not (string-match "\.el$" name))
98 (ff/compile-when-needed (concat name ".el"))
100 (let* ((src (concat dir "/" name)))
101 (when (file-newer-than-file-p src (concat src "c"))
102 (if (let ((byte-compile-verbose nil))
104 (byte-compile-file src)
106 (message (format "Compiled %s" src ))
107 (message (format "Failed compilation of %s" src))))))
110 ;; This is useful when using the same .emacs in many places
112 (defun ff/load-or-alert (name &optional compile-when-needed)
113 "Tries to load the specified file and insert a warning message in a
114 load-warning buffer in case of failure."
116 (when compile-when-needed (ff/compile-when-needed name))
118 (if (load name t nil) t
119 (let ((buf (get-buffer-create "*loading warnings*")))
122 (insert (propertize "Warning:" 'face 'font-lock-warning-face) " could not load '" name "'\n")
123 (fit-window-to-buffer (get-buffer-window buf))
124 (set-buffer-modified-p nil))
127 ;; This is the default in emacs 22.1 and later
128 ;; (auto-compression-mode 1)
130 ;; make emacs use the clipboard so that copy/paste works for other
131 ;; x-programs. I have no clue how all that clipboard thing works.
132 ;; (setq x-select-enable-clipboard t)
133 ;; (setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
139 ;; avoid GC as much as possible
140 gc-cons-threshold 2500000
142 ;; no startup message
143 inhibit-startup-screen t
145 ;; no message in the scratch buffer
146 initial-scratch-message nil
148 ;; do not fill my buffers, you fool
149 next-line-add-newlines nil
151 ;; keep the window focused on the messages during compilation
152 compilation-scroll-output t
154 ;; Keep the highlight on the compilation error
155 next-error-highlight t
157 ;; blink the screen instead of beeping
160 ;; take the CR when killing a line
163 ;; I prefer to move between lines as defined in the buffer, not
167 ;; I comment empty lines, too (does not seem to work, though)
168 comment-empty-lines t
170 ;; We want long lines to be truncated instead of displayed on several lines
172 ;; Show all lines, even if the window is not as large as the frame
173 ;; truncate-partial-width-windows nil
174 ;; truncate-partial-width-windows t
176 ;; Do not keep tracks of the autosaved files
177 auto-save-list-file-prefix nil
179 ;; Show me empty lines at the end of the buffer
180 default-indicate-empty-lines t
182 ;; Show me the region until I do something on it
183 transient-mark-mode t
185 ;; Do not color stuff which are clickable when hovering over it
188 ;; Don't bother me with questions even if "unsafe" local variables
190 enable-local-variables :all
192 ;; I have no problem with small windows
195 ;; I am not a fan of develock
196 develock-auto-enable nil
198 ;; I do not like women to open windows
199 woman-use-own-frame nil
201 ;; I am not that paranoid, contrary to what you think
202 epa-file-cache-passphrase-for-symmetric-encryption t
203 ;; And I like ascii files
206 tramp-default-method "ssh"
208 ;; I have no problem with files having their own local variables
211 mail-from-style 'angles
212 browse-url-mozilla-program "firefox"
214 mc-use-default-recipients t
216 ;; browse-url-new-window-flag t
222 temporary-file-directory "/tmp/"
223 vc-make-backup-files t
224 backup-directory-alist '((".*" . "~/misc/emacs.backups/"))
225 version-control t ;; Use backup files with numbers
228 delete-old-versions t
229 backup-by-copying-when-linked t
232 (setq tramp-backup-directory-alist backup-directory-alist)
234 (setq user-emacs-directory "~/misc/emacs.d/")
237 abbrev-file-name (concat user-emacs-directory "abbrev_defs")
238 server-auth-dir (concat user-emacs-directory "server/")
239 custom-theme-directory user-emacs-directory
242 ;; Stop this crazy blinking cursor
243 (blink-cursor-mode 0)
245 ;; (setq blink-cursor-delay 0.25
246 ;; blink-cursor-interval 0.25)
248 ;; (set-terminal-coding-system 'utf-8)
250 ;; (unless window-system
251 ;; (xterm-mouse-mode 1)
252 ;; (if (string= (getenv "TERM") "xterm-256color")
253 ;; (ff/load-or-alert "xterm-256color" t))
258 ;; Show white spaces at the end of lines
259 show-trailing-whitespace t
261 ;; Do not show the cursor in non-active window
262 cursor-in-non-selected-windows nil
267 ;; when on a TAB, the cursor has the TAB length
270 ;; This is the default coding system when toggle-input-method is
272 default-input-method "latin-1-prefix"
273 ;; do not put tabs when indenting
275 ;; And yes, we have a fast display / connection / whatever
279 ;; To keep the cursor always visible when it moves (thanks
281 redisplay-dont-pause t
283 ;; I want to see the keys I type instantaneously
287 ;; Show the column number
288 (column-number-mode 1)
290 ;; What modes for what file extentions
291 (add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
293 (add-to-list 'auto-mode-alist '("\\.txt\\'" . (lambda()
299 (add-hook 'c++-mode-hook 'flyspell-prog-mode)
300 (add-hook 'log-edit-mode-hook 'flyspell-mode)
304 (put 'narrow-to-region 'disabled nil)
305 (put 'upcase-region 'disabled nil)
306 (put 'downcase-region 'disabled nil)
307 ;; (put 'scroll-left 'disabled nil)
308 ;; (put 'scroll-right 'disabled nil)
310 ;; My selector is clearer than that
311 ;; (when (load "ido" t) (ido-mode t))
313 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
315 ;; Makes buffer names more explicit then <2>, <3> etc. when there are
316 ;; several identical filenames
318 (when (load "uniquify" t)
319 (setq uniquify-buffer-name-style 'post-forward-angle-brackets))
321 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
323 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
325 (when (boundp 'x-display-name)
329 ;; If the display is :0.0, we make the assumption that we are
330 ;; running the emacs locally, and we do not show the
331 ;; hostname. Otherwise, show @host.
333 frame-title-format (concat "emacs" ;;invocation-name
334 (unless (string= x-display-name ":0.0")
335 (concat "@" system-name))
338 ;; Use the same for the icone
340 icon-title-format frame-title-format
343 ;; "tool" bar? Are you kidding?
344 (when (boundp 'tool-bar-mode) (tool-bar-mode -1))
346 ;; ;; If my own letter icon is here, use it and change its color
347 ;; (when (file-exists-p "~/local/share/emacs/letter.xbm")
348 ;; (setq-default display-time-mail-icon
351 ;; :file "~/local/share/emacs/letter.xbm"
352 ;; :ascent center)))))
354 ;; My funky setting of face colors. Basically, we switch to a sober
355 ;; look and darken a bit the colors which need to (because of the
356 ;; darker background)
358 (defun ff/configure-faces (fl)
359 "Set face attributes and create faces when necessary"
361 (unless (boundp (car f)) (make-empty-face (car f)))
362 (eval `(set-face-attribute (car f) nil ,@(cdr f))))
365 ;; Not the same in xterm (which is gray in my case) and in
368 (unless window-system
369 ;; (xterm-mouse-mode 1)
371 '((italic :underline nil)
372 (info-title-2 :foreground "green")
373 (cperl-array-face :background "gray90" :foreground "blue" :weight 'bold)
374 (cperl-hash-face :background "gray90" :foreground "purple" :weight 'bold)
375 (diff-added :background "gray90" :foreground "green4" :weight 'bold)
376 (diff-removed :background "gray90" :foreground "red2" :weight 'bold)
377 (diff-changed :background "gray90" :foreground "blue" :weight 'bold)
378 (diff-file-header-face :background "white" :foreground "black"
380 (diff-header-face :background "white" :foreground "black")
381 (diff-hunk-header-face :background "white" :foreground "black")
382 (diff-indicator-removed :foreground "red" :weight 'bold)
383 (diff-removed :foreground "red" :weight 'bold)
384 (diff-indicator-added :foreground "blue" :weight 'bold)
385 (diff-added :foreground "blue" :weight 'bold)
386 (font-lock-string-face :foreground "green")
387 (font-lock-variable-name-face :foreground "blue")
388 (font-lock-constant-face :foreground "blue")
389 (font-lock-function-name-face :foreground "blue")
390 (font-lock-preprocessor-face :foreground "green")
391 (font-lock-function-name-face :foreground "cyan")
392 (flyspell-incorrect-face :foreground "red2")
393 (flyspell-duplicate-face :foreground "OrangeRed2")
394 (hl-line :background "white")
395 (sh-heredoc :foreground "blue")
396 (sh-heredoc-face :foreground "blue")
397 (font-lock-keyword-face :foreground "blue")
398 (highlight :background "darkseagreen3")
399 (isearch :background "orange" :foreground "black")
400 (isearch-lazy-highlight-face' :background "yellow" :foreground "black")
401 ;; (display-time-mail-face :background "white")
402 (show-paren-match-face :background "gold" :foreground "black")
403 (show-paren-mismatch-face :background "red" :foreground "black")
404 (trailing-whitespace :background "white")
405 (mode-line :background "cornflowerblue" :foreground "black" :box nil
407 (header-line :background "cornflowerblue" :foreground "black" :box nil
409 (mode-line-inactive :background "gray60" :foreground "black" :box nil
411 (region :background "springgreen2")
412 (ff/date-info-face :foreground "white" :weight 'bold)
413 (ff/mail-alarm-face :foreground "red" :weight 'bold)
414 (gui-button-face :background "green" :foreground "white")
415 (enotes/information-face :foreground "cyan")
419 ;; (list-colors-display (mapcar 'car color-name-rgb-alist))
421 ;; (ff/configure-faces '((default :background "black" :foreground "gray80")))
422 ;; (ff/configure-faces '((default :background "gray80" :foreground "black")))
426 ;; display-time-use-mail-icon t)
430 (escape-glyph :foreground "#c0c0c0" :weight 'bold)
431 (default :background "gray90" :foreground "black")
432 (cperl-array-face :background "gray90" :foreground "blue" :weight 'bold)
433 (cperl-hash-face :background "gray90" :foreground "purple" :weight 'bold)
434 (message-cited-text :foreground "red4")
435 (diff-mode :background "gray90" :weight 'bold)
436 (diff-added :background "gray90" :foreground "green4" :weight 'bold)
437 (diff-removed :background "gray90" :foreground "red2" :weight 'bold)
438 (diff-changed :background "gray90" :foreground "blue" :weight 'bold)
439 (diff-file-header :background "white" :foreground "black"
441 (diff-header :background "white" :foreground "black")
442 (diff-hunk-header :background "white" :foreground "black")
443 (font-lock-builtin-face :foreground "deeppink3")
444 (font-lock-string-face :foreground "dark olive green")
445 (font-lock-variable-name-face :foreground "sienna")
446 (font-lock-function-name-face :foreground "blue4" :weight 'bold)
447 ;; (font-lock-comment-delimiter-face :foreground "dark violet")
448 ;; (font-lock-comment-face :foreground "dark violet")
449 (flyspell-incorrect-face :foreground "red2")
450 (flyspell-duplicate-face :foreground "OrangeRed2")
451 (hl-line :background "white")
452 (header-line :background "gray65")
453 (sh-heredoc :foreground "darkorange3")
454 (sh-heredoc-face :foreground "darkorange3")
455 (highlight :background "turquoise")
456 (message-cited-text-face :foreground "firebrick")
457 (isearch :background "yellow" :foreground "black")
458 (isearch-lazy-highlight-face' :background "yellow3" :foreground "black")
459 (region :background "#b8b8e0" :foreground "black")
460 ;; (region :background "plum" :foreground "black")
461 (show-paren-match-face :background "gold" :foreground "black")
462 (show-paren-mismatch-face :background "red" :foreground "black")
463 (trailing-whitespace :background "gray65")
464 (cursor :inverse-video t)
465 (enotes/list-title-face :foreground "blue" :weight 'bold)
466 (mode-line :background "#9090f0" :foreground "black" :box nil
468 (header-line :background "cornflowerblue" :foreground "black" :box nil
470 (mode-line-inactive :background "#606080" :foreground "black" :box nil
472 ;; (fringe :background "black" :foreground "gray90")
473 (fringe :background "gray65")
474 (tex-verbatim :family "courrier")
475 (ff/date-info-face :foreground "white" :weight 'bold)
476 (ff/mail-alarm-face :foreground "white" :background "red2")
477 ;; (alarm-vc-face :foreground "black" :background "yellow" :weight 'normal)
481 ;; When we are root, put the modeline in red
483 (when (string= (user-real-login-name) "root")
485 '((mode-line :background "red3" :foreground "black" :box nil
489 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
490 ;; Move the window on the buffer without moving the cursor
491 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
493 (defun ff/scroll-down ()
494 "Scroll the buffer down one line and keep the cursor at the same location."
500 (defun ff/scroll-up ()
501 "Scroll the buffer up one line and keep the cursor at the same location."
507 (defun ff/scroll-left ()
508 "Scroll the buffer left one column and keep the cursor at the same location."
514 (defun ff/scroll-right ()
515 "Scroll the buffer right one column and keep the cursor at the same location."
521 (define-key global-map [(meta up)] 'ff/scroll-down)
522 (define-key global-map [(meta down)] 'ff/scroll-up)
523 (define-key global-map [(meta p)] 'ff/scroll-down)
524 (define-key global-map [(meta n)] 'ff/scroll-up)
525 (define-key global-map [(meta right)] 'ff/scroll-left)
526 (define-key global-map [(meta left)] 'ff/scroll-right)
528 (defun ff/delete-trailing-whitespaces-and-indent ()
530 (delete-trailing-whitespace)
531 (indent-region (point-min) (point-max) nil))
533 (define-key global-map [(control c) (control q)] 'ff/delete-trailing-whitespaces-and-indent)
535 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
537 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
539 ;; (defun ff/esd-sound (file)
540 ;; "Plays a sound with the Enlighted sound daemon."
542 ;; (process-kill-without-query (start-process-shell-command "esdplay"
546 (defun ff/alsa-sound (file)
547 "Plays a sound with ALSA."
549 (process-kill-without-query (start-process-shell-command "aplay"
553 (if (and (boundp 'x-display-name) (string= x-display-name ":0.0"))
554 (defalias 'ff/play-sound-async 'ff/alsa-sound)
555 (defalias 'ff/play-sound-async 'ding))
557 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
558 ;; I comment stuff often, let's be efficient. shift + down comments
559 ;; the current line and goes down, and shift + up uncomments the line
560 ;; and goes up (they are not the dual of each other, but moving and
561 ;; then uncommenting would be very counter-intuitive).
562 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
564 (defun ff/comment-and-go-down (arg)
565 "Comments and goes down ARG lines."
568 (comment-region (point-at-bol) (point-at-eol)) (error nil))
570 (if (> arg 1) (ff/comment-and-go-down (1- arg))))
572 (defun ff/uncomment-and-go-up (arg)
573 "Uncomments and goes up ARG lines."
576 (uncomment-region (point-at-bol) (point-at-eol)) (error nil))
578 (if (> arg 1) (ff/uncomment-and-go-up (1- arg))))
580 (define-key global-map [(shift down)] 'ff/comment-and-go-down)
581 (define-key global-map [(shift up)] 'ff/uncomment-and-go-up)
583 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
584 ;; Counting various entities in text
585 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
587 (defun ff/count-char ()
588 "Prints the number of characters between the first previous \"--\"
589 and the firt next \"--\"."
591 (let ((from (save-excursion (re-search-backward "^--$\\|BEGIN_COUNT" nil t)))
592 (to (save-excursion (re-search-forward "^--$\\|END_COUNT" nil t))))
593 (if (and to from) (message "%d character(s)" (- to from 6))
594 (error "Can not find the -- delimiters"))))
596 (defun ff/count-words ()
597 "Print number of words between the first previous \"--\" and the
600 (let ((from (save-excursion (re-search-backward "^--$" nil t)))
601 (to (save-excursion (re-search-forward "^--$" nil t))))
606 (while (< (point) to)
607 (re-search-forward "\\w+\\W+")
608 (setq count (1+ count)))
609 (message "%d word(s)" count)))
610 (error "Can not find the -- delimiters"))))
612 (defun ff/word-occurences ()
613 "Display in a new buffer the list of words sorted by number of
617 (let ((buf (get-buffer-create "*word counting*"))
618 (map (make-sparse-keymap))
619 (nb (make-hash-table))
620 (st (make-hash-table))
623 ;; Collects all words in a hash table
626 (goto-char (point-min))
627 (while (re-search-forward "\\([\\-a-zA-Z\\\\]+\\)" nil t)
628 (let* ((s (downcase (match-string-no-properties 1)))
631 (puthash k (1+ (gethash k nb 0)) nb))))
633 ;; Creates the result buffer
635 (define-key map "q" 'kill-this-buffer)
638 (setq show-trailing-whitespace nil)
641 ;; Builds a list from the hash table
645 (setq result (cons (cons value (gethash key st)) result)))
648 ;; Sort and display it
651 (if (and (> (car x) 3)
652 ;; No leading backslash and at least four characters
653 (string-match "^[^\\]\\{4,\\}" (cdr x))
655 (insert (number-to-string (car x)) " " (cdr x) "\n")))
656 (sort result (lambda (a b) (> (car a) (car b)))))
658 ;; Adjust the window size and stuff
660 (fit-window-to-buffer (get-buffer-window buf))
662 (set-buffer-modified-p nil))
665 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
667 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
671 (setq ps-print-color-p nil
672 ;; ps-paper-type 'letter
674 ;; ps-top-margin (* 1.75 56.692)
675 ;; ps-left-margin 56.692
676 ;; ps-bottom-margin 56.692
677 ;; ps-right-margin 56.692
679 ;; Simple header. Remove that silly frame shadow.
681 ps-print-header-frame nil
682 ps-header-line-pad 0.3
683 ps-header-font-family 'Courier
684 ps-header-title-font-size '(8.5 . 10)
685 ps-header-font-size '(6 . 7)
686 ps-font-size '(7 . 8)
689 (ps-put 'ps-header-frame-alist 'back-color 1.0)
690 (ps-put 'ps-header-frame-alist 'shadow-color 1.0)
691 (ps-put 'ps-header-frame-alist 'border-color 0.0)
692 (ps-put 'ps-header-frame-alist 'border-width 0.0)
694 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
696 ;; http://blog.tuxicity.se/elisp/emacs/2010/03/26/rename-file-and-buffer-in-emacs.htm
698 (defun rename-file-and-buffer ()
699 "Renames current buffer and file it is visiting."
701 (let ((name (buffer-name))
702 (filename (buffer-file-name)))
703 (if (not (and filename (file-exists-p filename)))
704 (message "Buffer '%s' is not visiting a file!" name)
705 (let ((new-name (read-file-name "New name: " filename)))
706 (cond ((get-buffer new-name)
707 (message "A buffer named '%s' already exists!" new-name))
709 (rename-file name new-name 1)
710 (rename-buffer new-name)
711 (set-visited-file-name new-name)
712 (set-buffer-modified-p nil)))))))
714 (global-set-key (kbd "C-c r") 'rename-file-and-buffer)
716 (defun ff/non-existing-filename (dir prefix suffix)
717 "Returns a filename of the form DIR/PREFIX[.n].SUFFIX whose file does
720 (f (concat prefix suffix)))
721 (while (file-exists-p (concat dir "/" f))
723 f (concat prefix "." (prin1-to-string n) suffix)))
726 (defun ff/print-buffer-or-region-with-faces (&optional file)
728 ;; I am fed up with spell checking highlights
729 (when (and flyspell-mode
730 ;; (or ispell-minor-mode flyspell-mode)
731 (not (y-or-n-p "The spell checking is on, still print ? ")))
732 (error "Printing cancelled, the spell-checking is on"))
736 (ps-print-region-with-faces (region-beginning) (region-end) file)
738 (ps-print-buffer-with-faces file)))
740 (defun ff/print-to-file (file)
741 "Prints the region if selected or the whole buffer in postscript
746 "PS file: " "/tmp/" nil nil
747 (ff/non-existing-filename
749 (replace-regexp-in-string "[^a-zA-Z0-9_.-]" "_" (file-name-nondirectory
753 (ff/print-buffer-or-region-with-faces file))
755 (defun ff/print-to-printer ()
756 "Prints the region if selected or the whole buffer to a postscript
759 (message "Printing to '%s'" (getenv "PRINTER"))
760 (ff/print-buffer-or-region-with-faces))
762 ;; Can you believe it? There is a "print" key on PC keyboards ...
764 (define-key global-map [(print)] 'ff/print-to-file)
765 (define-key global-map [(shift print)] 'ff/print-to-printer)
767 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
768 ;; Dealing with the laptop battery
769 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
771 (defcustom ff/battery-dir "/sys/class/power_supply/BAT0"
772 "*Where to gather the battery information")
774 (defcustom ff/temperature-file "/sys/class/thermal/thermal_zone0/temp"
775 "*Where to gather the thermal information")
777 (defun ff/file-first-line (file)
779 (insert-file-contents-literally file)
780 (buffer-substring (point-at-bol) (point-at-eol))))
782 (defun ff/battery-percent (prefix)
784 (/ (* 100 (string-to-number (ff/file-first-line (format "%s/%s_now" ff/battery-dir prefix))))
785 (string-to-number (ff/file-first-line (format "%s/%s_full" ff/battery-dir prefix))))
789 (defun ff/laptop-info-string () (interactive)
795 (let ((temp (/ (string-to-number (ff/file-first-line ff/temperature-file)) 1000)))
798 (let ((s (format "%dC " temp)))
799 (if (> temp 65) (propertize s 'face
800 'font-lock-warning-face)
808 (let ((battery-status (ff/file-first-line (concat ff/battery-dir "/status"))))
811 ((string= battery-status "Full") "L")
813 ((string= battery-status "Charging")
814 (format "L%d%%" (max (ff/battery-percent "charge")
815 (ff/battery-percent "energy"))))
817 ((string= battery-status "Discharging")
818 (format "B%d%%" (max (ff/battery-percent "charge")
819 (ff/battery-percent "energy"))))
830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
832 (defun ff/system-info () (interactive)
834 (let ((buf (get-buffer-create "*system info*"))
835 (map (make-sparse-keymap)))
837 (define-key map "q" 'kill-this-buffer)
840 (setq show-trailing-whitespace nil)
843 (let ((highlight nil))
847 (if (setq highlight (not highlight))
849 (with-temp-buffer (apply 'call-process x)
851 'face '(:background "#c0c0ff"))
852 (with-temp-buffer (apply 'call-process x)
858 ("hostname" nil t nil "-v")
860 ("df" nil t nil "-h")
863 ("ssh-add" nil t nil "-l")
866 (goto-char (point-min))
867 (while (re-search-forward "^$" nil t) (backward-delete-char 1))
869 (fit-window-to-buffer (get-buffer-window buf))
871 (set-buffer-modified-p nil)
874 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
875 ;; Make a sound when there is new mail
876 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
878 ;; I do not like sounds anymore
880 ;; (setq ff/already-boinged-for-mail nil)
882 ;; (defun ff/boing-if-new-mail ()
883 ;; (if mail (when (not ff/already-boinged-for-mail)
884 ;; ;; (ff/play-sound-async "~/local/sounds/boing1.wav")
885 ;; ;; (ff/show-unspooled-mails)
886 ;; (setq ff/already-boinged-for-mail t))
887 ;; (setq ff/already-boinged-for-mail nil))
890 ;; (add-hook 'display-time-hook 'ff/boing-if-new-mail)
892 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
894 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
898 display-time-interval 15 ;; Check every 15s
900 display-time-string-forms `(
904 ;; (propertize " mail "
905 ;; 'face 'ff/mail-alarm-face)
909 (propertize (concat 24-hours ":" minutes
914 'face 'ff/date-info-face)
918 ,(if (ff/laptop-info-string)
919 '(concat " " (ff/laptop-info-string)))
923 ;; display-time-format "%b %a %e %H:%M"
924 ;; display-time-mail-face nil
927 ;; Show the time, mail and stuff
930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
931 ;; Moving through buffers
932 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
934 (defun ff/next-buffer ()
935 "Switches to the next buffer in cyclic order."
937 (let ((buffer (current-buffer)))
938 (switch-to-buffer (other-buffer buffer))
939 (bury-buffer buffer)))
941 (defun ff/prev-buffer ()
942 "Switches to the previous buffer in cyclic order."
944 (let ((list (nreverse (buffer-list)))
946 (while (and (not found) list)
947 (let ((buffer (car list)))
948 (if (and (not (get-buffer-window buffer))
949 (not (string-match "\\` " (buffer-name buffer))))
950 (setq found buffer)))
951 (setq list (cdr list)))
952 (switch-to-buffer found)))
954 (define-key global-map [?\C-x right] 'ff/next-buffer)
955 (define-key global-map [?\C-x left] 'ff/prev-buffer)
957 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
958 ;; There is actually a decent terminal emulator in emacs!
959 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
963 (defun ff/kill-associated-buffer (process str) (interactive)
964 (let ((buffer (process-buffer process)))
965 (kill-buffer buffer))
966 (message "Process finished (%s)" (replace-regexp-in-string "\n$" "" str)))
968 (defun ff/kill-associated-buffer-and-delete-windows (process str) (interactive)
969 (let ((buffer (process-buffer process)))
970 (delete-windows-on buffer)
971 (kill-buffer buffer))
972 (message "Process finished (%s)" (replace-regexp-in-string "\n$" "" str)))
974 (defun ff/shell-new-buffer (buffername program &rest param)
975 "Start a terminal-emulator in a new buffer with the shell PROGRAM,
976 optionally invoked with the parameters PARAM. The process associated
977 to the shell can be killed without query."
984 (while (get-buffer (concat "*" bn "*"))
986 bn (format "%s<%d>" buffername n)))
988 (set-buffer (apply 'make-term (append (list bn program nil) param)))
990 (setq show-trailing-whitespace nil)
992 (message "C-c C-k term-char-mode, C-c C-j term-line-mode. \
993 In line mode: M-p previous line, M-n next line.")
995 ;; A standard setup of the face above is not enough, I have to
996 ;; force them here. Since I have a gray90 background, I like
1001 '((term-green :foreground "green3")
1002 (term-cyan :foreground "cyan3")
1003 (term-default-fg-inv :foreground "gray90" :background "black")
1006 (term-set-escape-char ?\C-x)
1008 ;; I like the shell buffer and windows to be deleted when the
1009 ;; shell process terminates. It's a bit of a mess to acheive this.
1011 (let ((process (get-buffer-process (current-buffer))))
1012 (process-kill-without-query process)
1013 (set-process-sentinel process
1014 ;; 'ff/kill-associated-buffer-and-delete-windows
1015 'ff/kill-associated-buffer
1018 ;; (switch-to-buffer-other-window (concat "*" bn "*"))
1019 (switch-to-buffer (concat "*" bn "*"))
1022 (defcustom ff/default-bash-commands '("ssh")
1023 "*List of commands to be used for completion when invoking a new
1024 bash shell with `ff/bash-new-buffer'.")
1026 (defun ff/bash-new-buffer (universal)
1027 "Starts a bash in a new buffer. When invoked with a universal
1028 argument, asks for a command to execute in that bash shell. The list
1029 of commands in `ff/default-bash-commands' is used for auto-completion"
1033 (let ((cmd (completing-read
1035 (mapcar (lambda (x) (cons x t)) ff/default-bash-commands))))
1036 (ff/shell-new-buffer cmd "/bin/bash" "-c" cmd))
1038 (ff/shell-new-buffer "bash" "/bin/bash")))
1040 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1044 (setq ;; Always follow links if the file is under version control
1045 vc-follow-symlinks t
1048 (when (load "vc-git" nil t)
1049 (add-to-list 'vc-handled-backends 'GIT))
1051 ;; alarm-vc.el is one of my own scripts, check my web page
1053 (when (ff/load-or-alert "alarm-vc" t)
1054 (setq alarm-vc-mode-exceptions "^VM"))
1056 (when (ff/load-or-alert "git")
1057 (setq git-show-unknown nil)
1060 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1061 ;; Makes .sh and others files executable automagically
1062 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1064 ;; Please consider the security-related consequences of using it
1066 ;; (defun ff/make-shell-scripts-executable (&optional filename)
1067 ;; (setq filename (or filename (buffer-name)))
1068 ;; (when (and (string-match "\\.sh$\\|\\.pl$\\|\\.rb" filename)
1069 ;; (not (file-executable-p filename))
1071 ;; (set-file-modes filename 493)
1072 ;; (message "Made %s executable" filename)))
1074 ;; (add-hook 'after-save-hook 'ff/make-shell-scripts-executable)
1076 (add-hook 'after-save-hook
1077 'executable-make-buffer-file-executable-if-script-p)
1079 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1080 ;; Cool stuff to navigate in emacs-lisp sources
1081 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1085 (defun ff/goto-function-definition (&optional goback)
1086 "Go directly to the definition of the function at point. With
1087 goback argument, go back where we were."
1090 (if (not (and (boundp 'goto-function-history) goto-function-history))
1091 (error "We were nowhere, buddy")
1092 (message "Come back")
1093 (switch-to-buffer (car (car goto-function-history)))
1094 (goto-char (cdr (car goto-function-history)))
1095 (setq goto-function-history (cdr goto-function-history)))
1097 (let ((function (function-called-at-point)))
1099 (let ((location (find-function-search-for-symbol
1101 (symbol-file function))))
1102 (setq goto-function-history
1103 (cons (cons (current-buffer) (point))
1104 (and (boundp 'goto-function-history)
1105 goto-function-history)))
1106 (pop-to-buffer (car location))
1107 (goto-char (cdr location)))))))
1109 (define-key global-map [(meta g)] 'ff/goto-function-definition)
1110 (define-key global-map [(meta G)] (lambda () (interactive)
1111 (ff/goto-function-definition t)))
1113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1114 ;; The big stuff (bbdb, mailcrypt, etc.)
1115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1117 ;; Failsafe version if we can't load bbdb
1118 (defun ff/explicit-name (email) email)
1120 (when (ff/load-or-alert "bbdb")
1123 ;; Stop asking (if not t or nil, will not ask)
1124 bbdb-offer-save 'never
1125 ;; I hate when bbdb decides to mess up my windows
1127 ;; I have no problem with bbdb asking me if the sender email
1128 ;; does not match exactly the address we have in the database
1129 bbdb-quiet-about-name-mismatches 0
1130 ;; I have european friends, too
1131 bbdb-north-american-phone-numbers-p nil
1132 ;; To cycle through all possible addresses
1133 bbdb-complete-name-allow-cycling t
1134 ;; Cycle with full names only, not through all net-addresses alone too
1135 bbdb-dwim-net-address-allow-redundancy t
1136 ;; Do not add new addresses automatically
1137 bbdb-always-add-addresses nil
1140 (defface ff/known-address-face
1141 '((t (:foreground "blue2")))
1142 "The face to display known mail identities.")
1144 (defface ff/unknown-address-face
1145 '((t (:foreground "gray50")))
1146 "The face to display unknown mail identities.")
1148 (defun ff/explicit-name (email)
1149 "Returns a string identity for the first address in EMAIL. The
1150 identity is taken from bbdb if possible or from the address itself
1151 with mail-extract-address-components. The suffix \"& al.\" is added if
1152 there are more than one address.
1154 If no bbdb record is found, the name is propertized with the face
1155 ff/unknown-address-face. If a record is found and contains a note
1156 'face, the associated face is used, otherwise
1157 ff/known-address-face is used."
1160 (let* ((data (mail-extract-address-components email))
1163 (record (bbdb-search-simple nil net)))
1168 (propertize (bbdb-record-name record)
1170 (or (cdr (assoc 'face
1171 (bbdb-record-raw-notes record)))
1172 'ff/known-address-face))
1174 (propertize (or (and data (concat "<" net ">"))
1176 'face 'ff/unknown-address-face)
1178 (if (string-match "," (mail-strip-quoted-names email)) " & al.")
1182 (ff/configure-faces '((ff/robot-address-face :foreground "green4")
1183 (ff/important-address-face :foreground "blue2"
1185 ;; :background "white"
1186 ;; :foreground "green4"
1194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1195 ;; An encrypted file to put secure stuff (passwords, ...)
1196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1198 (when (ff/load-or-alert "mailcrypt")
1199 (mc-setversion "gpg")
1200 ;; Keep the passphrase for 10min
1201 (setq mc-passwd-timeout 600
1202 ff/secure-note-file "~/private/secure-notes.gpg")
1205 (defface ff/secure-date
1206 '((t (:background "gold" :weight bold)))
1207 "The face to display the dates in the modeline.")
1209 (defun ff/secure-note-add () (interactive)
1210 (find-file "~/private/secure-notes.gpg")
1212 ;; Adds a new entry (i.e. date and a bunch of empty lines)
1214 (goto-char (point-min))
1216 (format-time-string "%Y %b %d %H:%M:%S" (current-time))
1217 " ------------------------------------------------\n\n")
1220 ;; Colorizes the dates
1223 (goto-char (point-min))
1224 (while (re-search-forward
1225 "^-+ [0-9]+ [a-z]+ [0-9]+ [0-9]+:[0-9]+:[0-9]+.+$"
1227 (add-text-properties
1228 (match-beginning 0) (match-end 0) '(face ff/secure-date))))
1230 (set-buffer-modified-p nil)
1231 (setq buffer-undo-list nil)
1234 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1236 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1238 (setq ;; For french, aspell is far better than ispell
1239 ispell-program-name "aspell"
1240 ;; To avoid ispell errors in figure filenames, labels, references.
1241 ;; ispell-tex-skip-alists
1243 ;; (append (car ispell-tex-skip-alists)
1244 ;; '(("\\\\citep" ispell-tex-arg-end) ;; JMLR
1245 ;; ("\\\\cite" ispell-tex-arg-end)
1246 ;; ("\\\\nocite" ispell-tex-arg-end)
1247 ;; ("\\\\includegraphics" ispell-tex-arg-end)
1248 ;; ("\\\\author" ispell-tex-arg-end)
1249 ;; ("\\\\ref" ispell-tex-arg-end)
1250 ;; ("\\\\label" ispell-tex-arg-end)
1252 ;; (cadr ispell-tex-skip-alists))
1254 ;; So that reftex follows the text when moving in the summary
1255 reftex-toc-follow-mode nil
1256 ;; So that reftex visits files to follow
1257 reftex-revisit-to-follow t
1260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1261 ;; Used in a \includegraphics runs xfig with the corresponding .fig
1262 ;; file or gimp with the corresponding bitmap picture
1263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1265 (defun ff/run-eps-edition (prefix rules &optional force)
1267 (let ((filename (concat prefix (car (car rules)))))
1268 (if (or force (file-exists-p filename))
1269 (start-process "latex-eps-editor" nil (cdr (car rules)) filename)
1270 (ff/run-eps-edition prefix (cdr rules) force)))
1271 (message "No original file found for %seps" prefix)))
1273 (defcustom ff/xdvi-for-latex-options nil
1274 "*Options to pass to xdvi when invoking `ff/run-viewer'")
1276 (defun ff/run-viewer (universal)
1278 "Starts an editor for the .eps at point (either xfig or gimp,
1279 depending with the original file it can find), or starts xdvi for
1280 the current .tex if no .eps is found at point. When run with a
1281 universal argument starts xfig even if the .fig does not exist"
1285 (if (and (save-excursion
1286 (and (re-search-backward "{" (point-at-bol) t)
1287 (or (re-search-forward "{\\([^{}]*.\\)eps}" (point-at-eol) t)
1288 (re-search-forward "{\\([^{}]*.\\)pdf}" (point-at-eol) t)
1289 (re-search-forward "{\\([^{}]*.\\)pdf_t}" (point-at-eol) t)
1290 (re-search-forward "{\\([^{}]*.\\)png}" (point-at-eol) t)
1291 (re-search-forward "{\\([^{}]*.\\)jpg}" (point-at-eol) t)
1293 (and (<= (match-beginning 1) (point))
1294 (>= (match-end 1) (- (point) 2))))
1296 (ff/run-eps-edition (match-string-no-properties 1)
1299 ("png" . "gimp") ("pgm" . "gimp") ("ppm" . "gimp")
1303 (if (not (and (buffer-file-name) (string-match "\\(.*\\)\.tex$"
1304 (buffer-file-name))))
1305 (message "Not a latex file!")
1306 (condition-case nil (kill-process xdvi-process) (error nil))
1307 (let ((dvi-name (concat (match-string 1 (buffer-file-name)) ".dvi")))
1308 (if (not (file-exists-p dvi-name)) (error "Can not find %s !" dvi-name)
1309 (message "Starting xdvi with %s" dvi-name)
1310 (setq xdvi-process (apply 'start-process
1311 (append '("xdvi-for-latex" nil "xdvi")
1312 ff/xdvi-for-latex-options
1314 (process-kill-without-query xdvi-process))))
1317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1320 ;; When working on a tex file with other people, I can just change
1321 ;; ff/tex-command in the -*- part of the file so that I don't mess up
1322 ;; other's people configuration.
1324 (defadvice tex-file (around ff/set-my-own-tex-command () activate)
1326 (or (and (boundp 'ff/tex-command)
1331 ;; This is a bit hardcore, but really I can't bear the superscripts in
1332 ;; my emacs window and could not find another way to deactivate them.
1335 (defun tex-font-lock-suscript (pos) ())
1337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1338 ;; Prevents many errors from beeping and makes the others play a nifty
1340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1342 (defun ff/ring-bell ()
1343 (unless (memq this-command
1345 abort-recursive-edit
1348 backward-delete-char-untabify
1349 delete-backward-char
1350 minibuffer-complete-and-exit
1351 previous-line next-line
1352 backward-char forward-char
1353 scroll-up scroll-down
1354 enlarge-window-horizontally shrink-window-horizontally
1355 enlarge-window shrink-window
1358 ;; (message "command [%s]" (prin1-to-string this-command))
1359 ;; (ff/play-sound-async "~/local/sounds/short_la.wav")
1362 (setq ring-bell-function 'ff/ring-bell)
1364 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1365 ;; Past the content of the url currently in the kill-ring with
1367 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1369 (defun ff/insert-url (&optional url)
1370 "Downloads an URL with lynx and inserts it after the point."
1371 (interactive "MUrl: ")
1373 (message "Inserting %s" url)
1374 (insert (concat "from: " url "\n\n"))
1375 ;; (call-process "lynx" nil t nil "-nolist" "-dump" url))
1376 (call-process "w3m" nil t nil "-dump" url))
1379 (define-key global-map [(shift mouse-2)]
1380 (lambda () (interactive) (ff/insert-url (current-kill 0))))
1382 ;; lookup-dict is one of my own scripts, check my web page
1384 (when (ff/load-or-alert "lookup-dict" t)
1385 (define-key global-map [(control \?)] 'lookup-dict))
1387 ;; (defun ff/generate-password () (interactive)
1388 ;; (let ((c "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-"))
1389 ;; (nth (random (length c)) c))
1391 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1392 ;; Automatization of things I do often
1393 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1395 (defun ff/snip () (interactive)
1396 (let ((start (condition-case nil (region-beginning) (error (point))))
1397 (end (condition-case nil (region-end) (error (point)))))
1399 (insert "---------------------------- snip snip -------------------------------\n")
1401 (insert "---------------------------- snip snip -------------------------------\n")
1404 (defun ff/start-latex ()
1405 "Adds all that stuff to start a new LaTeX document."
1407 (goto-char (point-min))
1408 (insert "%% -*- mode: latex; mode: reftex; mode: flyspell; coding: utf-8; tex-command: \"pdflatex.sh\" -*-
1410 \\documentclass[12pt]{article}
1411 \\usepackage[a4paper,top=2.5cm,bottom=2cm,left=1.5cm,right=1.5cm]{geometry}
1412 \\usepackage[utf8]{inputenc}
1413 \\usepackage{amsmath}
1414 \\usepackage{amssymb}
1415 \\usepackage{hyperref}
1417 %% \\usepackage[pdftex]{graphicx}
1418 %% \\usepackage{eurosym}
1427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1429 %% \\usepackage[T1]{fontenc}
1430 %% \\usepackage[scaled]{helvet}
1431 %% \\usepackage[cm]{sfmath}
1432 %% \\renewcommand{\\ttdefault}{pcr}
1433 %% \\renewcommand*\\familydefault{\\sfdefault}
1434 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1435 %% \\def\\argmax{\\operatornamewithlimits{argmax}}
1436 %% \\def\\argmin{\\operatornamewithlimits{argmin}}
1437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1438 %% \\setlength{\\parindent}{0cm}
1439 %% \\setlength{\\parskip}{12pt}
1440 %% \\renewcommand{\\baselinestretch}{1.3}
1441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1447 (goto-char (point-max))
1454 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1456 (defun ff/add-copyrights ()
1457 "Adds two lines for the (C) at the beginning of current buffer."
1460 (let ((comment-style 'plain))
1462 (goto-char (point-min))
1464 ;; If this is a script, put the copyrights after the first line
1466 (when (re-search-forward "^#!" nil t)
1470 (let ((start (point))
1471 (comment-style 'box))
1475 "\nSTART_IP_HEADER\n"
1477 (when (boundp 'user-full-name)
1478 (concat "\nWritten by " user-full-name "\n"))
1480 (when (boundp 'user-mail-address)
1481 (concat "Contact <" user-mail-address "> for comments & bug reports\n"))
1486 (comment-region start (point)))
1490 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1492 (defun ff/remove-ip-header () (interactive)
1494 (goto-char (point-min))
1495 (when (and (re-search-forward "START_IP_HEADER" nil t)
1496 (re-search-forward "END_IP_HEADER" nil t))
1500 (defun ff/add-gpl ()
1501 "Adds the GPL statements at the beginning of current buffer."
1503 (let ((comment-style 'box)
1508 ;; This program is free software; you can redistribute it and/or
1509 ;; modify it under the terms of the GNU General Public License
1510 ;; version 2 as published by the Free Software Foundation.
1512 ;; This program is distributed in the hope that it will be useful, but
1513 ;; WITHOUT ANY WARRANTY\; without even the implied warranty of
1514 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1515 ;; General Public License for more details.
1521 This program is free software: you can redistribute it and/or modify
1522 it under the terms of the version 3 of the GNU General Public License
1523 as published by the Free Software Foundation.
1525 This program is distributed in the hope that it will be useful, but
1526 WITHOUT ANY WARRANTY; without even the implied warranty of
1527 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1528 General Public License for more details.
1530 You should have received a copy of the GNU General Public License
1531 along with this program. If not, see <http://www.gnu.org/licenses/>.
1534 (when (boundp 'user-full-name)
1535 (concat "Written by and Copyright (C) " user-full-name "\n"))
1537 (when (boundp 'user-mail-address)
1538 (concat "Contact <" user-mail-address "> for comments & bug reports\n"))
1546 (goto-char (point-min))
1548 ;; If this is a script, put the gpl after the first line
1549 (when (re-search-forward "^#!" nil t)
1553 (let ((start (point)))
1555 (comment-region start (point)))
1558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1560 (defun ff/start-c ()
1561 "Adds the header to start a C program."
1563 ;; (beginning-of-buffer)
1569 int main(int argc, char **argv) {
1576 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1578 (defun ff/start-c++ ()
1579 "Adds the header to start a C++ program."
1581 ;; (beginning-of-buffer)
1590 using namespace std;
1592 int main(int argc, char **argv) {
1599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1601 (defun ff/headerize ()
1602 "Adds the #define HEADER_H, etc."
1604 (let ((flag-name (replace-regexp-in-string
1606 (upcase (file-name-nondirectory (buffer-file-name))))))
1607 (goto-char (point-max))
1608 (insert "\n#endif\n")
1609 (goto-char (point-min))
1610 (insert (concat "#ifndef " flag-name "\n"))
1611 (insert (concat "#define " flag-name "\n"))
1615 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1617 (defun ff/start-html ()
1618 "Adds all that stuff to start a new HTML file."
1620 (goto-char (point-min))
1621 (insert "<?xml version=\"1.0\" encoding=\"utf-8\"?>
1622 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1624 <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
1627 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
1633 (goto-char (point-max))
1641 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1643 ;; Insert a line showing all the variables written on the current line
1644 ;; and separated by commas
1646 (defun ff/cout-var (arg)
1647 "Invoked on a line with a list of variables names,
1648 it inserts a line which displays their values in cout, or cerr if
1649 the function is invoked with a universal arg"
1651 (let ((line (if arg "cerr" "cout")))
1652 (goto-char (point-at-bol))
1653 ;; Regexp syntax sucks moose balls, honnest. To match '[', just
1654 ;; put it as the first char in the [...] ... This leads to some
1655 ;; obvious things like the following
1656 (while (re-search-forward "\\([][a-zA-Z0-9_.:\(\)]+\\)" (point-at-eol) t)
1658 (concat line " << \" "
1659 (match-string 1) " = \" << " (match-string 1))))
1660 (goto-char (point-at-bol))
1662 (insert line " << endl\;\n")
1663 (indent-region (point-at-bol 0) (point-at-eol 0) nil)
1666 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1668 (defun ff/clean-article ()
1669 "Cleans up an article by removing the leading blanks on each line
1670 and refilling all the paragraphs."
1672 (let ((fill-column 92))
1673 (goto-char (point-min))
1674 (while (re-search-forward "^\\ +" nil t)
1675 (replace-match "" nil nil))
1676 (fill-individual-paragraphs (point-min) (point-max) t)))
1678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1680 (defun ff/start-slide ()
1682 (insert "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1686 (save-excursion (insert "}{}
1696 (define-key latex-mode-map [(meta S)] 'ff/start-slide)
1697 (define-key latex-mode-map [(control c) (control a)] 'align-current)
1698 (define-key latex-mode-map [(control end)] 'tex-close-latex-block)
1699 (define-key latex-mode-map [(control tab)] 'ispell-complete-word)
1700 ;; Strange that I have to specify that
1701 ;; (setq paragraph-separate "[% \f]*$")
1702 ;; (setq paragraph-separate
1703 ;; (concat "[%]*\\|[\f%]\\|[ \t]*\\($\\|"
1705 ;; "\\\\" (regexp-opt (append
1706 ;; (mapcar 'car latex-section-alist)
1707 ;; '("begin" "label" "end" )) t)
1708 ;; "\\>\\|\\\\\\(" (regexp-opt '("item" "bibitem" "newline"
1709 ;; "noindent" "newpage" "footnote"
1710 ;; "marginpar" "parbox" "caption"))
1711 ;; "\\|\\$\\$\\|[a-z]*\\(space\\|skip\\|page[a-z]*\\)"
1712 ;; "\\>\\)[ \t]*\\($\\|%\\)\\)"))
1713 ;; (flyspell-mode 1)
1717 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1719 (defun ff/start-test-code ()
1721 (let ((start (point)))
1723 { // ******************************* START ***************************
1724 #warning Test code added on "
1725 (format-time-string "%04Y %b %02d %02H:%02M:%02S" (current-time))
1728 } // ******************************** END ****************************
1731 (indent-region start (point) nil))
1735 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1737 (defun ff/code-to-html () (interactive)
1739 (narrow-to-region (region-beginning) (region-end))
1740 (replace-string "\"" """ nil (point-min) (point-max))
1741 (replace-string " " " " nil (point-min) (point-max))
1742 (replace-string ">" ">" nil (point-min) (point-max))
1743 (replace-string "<" "<" nil (point-min) (point-max))
1744 (replace-string "\e" "^[" nil (point-min) (point-max))
1745 (replace-string "
\7f" "^?" nil (point-min) (point-max))
1746 (replace-string "
\1f" "^_" nil (point-min) (point-max))
1747 (replace-regexp "$" "<br />" nil (point-min) (point-max))
1751 (defun ff/downcase-html-tags () (interactive)
1753 (beginning-of-buffer)
1754 (while (re-search-forward "<\\([^>]+\\)>" nil t)
1755 (downcase-region (match-beginning 1) (match-end 1)))
1759 ;; If we enter html mode and there is no makefile around, create a
1760 ;; compilation command with tidy (this is cool stuff)
1762 (add-hook 'html-mode-hook
1764 (unless (or (not (buffer-file-name))
1765 (file-exists-p "makefile")
1766 (file-exists-p "Makefile"))
1767 (set (make-local-variable 'compile-command)
1768 (let ((fn (file-name-nondirectory buffer-file-name)))
1769 (format "tidy -utf8 %s > /tmp/%s" fn fn))))))
1771 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1773 (defun ff/count-words-region (beginning end)
1774 "Print number of words in the region.
1775 Words are defined as at least one word-constituent character
1776 followed by at least one character that is not a
1777 word-constituent. The buffer's syntax table determines which
1778 characters these are."
1781 (message "Counting words in region ... ")
1783 (goto-char beginning)
1785 (while (< (point) end)
1786 (re-search-forward "\\w+\\W+")
1787 (setq count (1+ count)))
1788 (cond ((zerop count) (message "The region does NOT have any word."))
1789 ((= 1 count) (message "The region has 1 word."))
1790 (t (message "The region has %d words." count))))))
1792 ;; (add-hook 'html-mode-hook 'flyspell-mode)
1794 (defun ff/tidy-html ()
1795 "Run tidy in on the content of the current buffer, put the result in
1798 (call-process-region (point-min) (point-max)
1801 (list nil (make-temp-file "/tmp/tidy-html."))))
1803 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1805 ;; Create the adequate embryo of a file if it does not exist
1807 (defun ff/start-file () (interactive)
1808 (let ((filename (buffer-file-name)))
1811 (when (string-match "\\.sh$" filename)
1813 (insert "#!/bin/bash\n\nset -e\n\n")
1815 (ff/add-copyrights))
1818 (when (string-match "\\.html$" filename)
1824 (when (string-match "\\.h$" filename)
1835 (when (string-match "\\.c$" filename)
1840 (when (string-match "\.\\(cc\\|cpp\\)$" filename)
1843 (let ((headername (replace-regexp-in-string "\\.\\(cc\\|cpp\\)$" ".h"
1845 (if (file-exists-p headername)
1846 (insert (concat "\n#include \"" (file-name-nondirectory headername) "\"\n"))
1850 (when (string-match "\\.tex$" filename)
1855 (set-buffer-modified-p nil)
1858 (if (>= emacs-major-version 22)
1859 (add-to-list 'find-file-not-found-functions 'ff/start-file)
1860 (add-to-list 'find-file-not-found-hooks 'ff/start-file))
1862 (when (>= emacs-major-version 24)
1863 (define-obsolete-function-alias 'make-local-hook 'ignore "21.1")
1864 (setq send-mail-function 'sendmail-send-it) ;; emacs 24.x stuff
1867 '(diff-added ((default (:background "gray90" :foreground "green4" :weight bold))))
1868 '(diff-removed ((default (:background "gray90" :foreground "red2" :weight bold))))
1869 '(diff-changed ((default (:background "gray90" :foreground "blue" :weight bold))))
1873 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1875 (define-key global-map [f8] 'ff-find-other-file)
1876 (define-key global-map [(shift f8)] (lambda () (interactive) (ff-find-other-file t)))
1878 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1879 ;; Antiword, htmlize and boxquote
1880 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1882 (autoload 'no-word "no-word")
1883 (add-to-list 'auto-mode-alist '("\\.doc\\'" . no-word))
1884 ;; (add-to-list 'auto-mode-alist '("\\.DOC\\'" . no-word))
1886 (autoload 'htmlize-buffer "htmlize" nil t)
1888 (setq boxquote-top-and-tail "------------------")
1889 (autoload 'boxquote-region "boxquote" nil t)
1891 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1892 ;; The compilation hacks
1893 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1895 ;; If we enter c++ mode and there is no makefile around, we create a
1896 ;; make command on the fly for the specific object file
1898 (add-hook 'c++-mode-hook
1900 (unless (or (file-exists-p "makefile") (file-exists-p "Makefile"))
1901 (set (make-local-variable 'compile-command)
1904 (file-name-sans-extension
1905 (file-name-nondirectory buffer-file-name)))))))
1907 ;; <f1> runs the compilation according to the compile-command (and
1908 ;; thus does not ask any confirmation), shows the compilation buffer
1909 ;; during compilation and delete all windows showing the compilation
1910 ;; buffer if the compilation ends with no error
1912 ;; <shift-f1> asks for a compilation command and runs the compilation
1913 ;; but does not restore the window configuration (i.e. the compilation
1914 ;; buffer's window will still be visible, as usual)
1916 ;; <f2> goes to the next compilation error (as C-x ` does on the
1917 ;; standard configuration)
1919 (defun ff/restore-windows-if-no-error (buffer msg)
1920 "Delete the windows showing the compilation buffer if msg
1921 matches \"^finished\"."
1923 (when (string-match "^finished" msg)
1924 ;; (delete-windows-on buffer)
1925 (if (boundp 'ff/window-configuration-before-compilation)
1926 (set-window-configuration ff/window-configuration-before-compilation))
1930 (add-to-list 'compilation-finish-functions 'ff/restore-windows-if-no-error)
1932 (defun ff/fast-compile ()
1933 "Compiles without asking anything."
1935 (let ((compilation-read-command nil))
1936 (setq ff/window-configuration-before-compilation (current-window-configuration))
1937 (compile compile-command)))
1939 (setq compilation-read-command t
1940 compile-command "make -j -k"
1941 compile-history '("make clean" "make DEBUG=yes -j -k" "make -j -k")
1944 (defun ff/universal-compile () (interactive)
1945 (funcall (or (cdr (assoc major-mode
1947 (latex-mode . tex-file)
1948 (html-mode . browse-url-of-buffer)
1949 ;; Here you can add other mode -> compile command
1951 'ff/fast-compile ;; And this is the failsafe
1954 (define-key global-map [f1] 'ff/universal-compile)
1955 (define-key global-map [(shift f1)] 'compile)
1956 (define-key global-map [f2] 'next-error)
1958 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1962 ;; (when (ff/load-or-alert "flyspell-timer" t)
1963 ;; (add-hook 'flyspell-mode-hook 'flyspell-timer-ensure-idle-timer))
1965 (defun ff/pick-dictionnary () (interactive)
1966 (when (and (boundp 'flyspell-mode) flyspell-mode)
1967 (if (and current-input-method (string-match "latin" current-input-method))
1968 (ispell-change-dictionary "francais")
1969 (ispell-change-dictionary "american"))
1970 ;; (flyspell-buffer)
1974 (defadvice toggle-input-method (after ff/switch-dictionnary nil activate)
1975 (ff/pick-dictionnary))
1977 ;; (add-hook 'message-mode-hook 'auto-fill-mode)
1978 ;; (add-hook 'message-mode-hook 'flyspell-mode)
1980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1981 ;; Delete all windows which are in the same "column", which means
1982 ;; whose xmin and xmax are bounded by the xmin and xmax of the
1983 ;; currently selected column
1984 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1986 ;; This is from emacs23 ! better than my old ff/delete-other-windows-in-column
1988 (unless (fboundp 'delete-other-windows-vertically)
1990 (defun delete-other-windows-vertically (&optional window)
1991 "Delete the windows in the same column with WINDOW, but not WINDOW itself.
1992 This may be a useful alternative binding for \\[delete-other-windows]
1993 if you often split windows horizontally."
1995 (let* ((window (or window (selected-window)))
1996 (edges (window-edges window))
1998 (while (not (eq (setq w (next-window w 1)) window))
1999 (let ((e (window-edges w)))
2000 (when (and (= (car e) (car edges))
2001 (= (caddr e) (caddr edges)))
2003 (mapc 'delete-window delenda)))
2006 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2012 (defun ff/entropy (l)
2017 (* (- x) (/ (log x) (log 2)))))
2022 ;; Usefull to deal with results in latex files
2024 (defun ff/round-floats-in-region () (interactive)
2027 (narrow-to-region (region-beginning) (region-end))
2028 (error (thing-at-point 'word)))
2030 (goto-char (point-min))
2031 (while (re-search-forward "[0-9\.]+" nil t)
2032 (let ((value (string-to-number (buffer-substring (match-beginning 0) (match-end 0)))))
2033 (delete-region (match-beginning 0) (match-end 0))
2034 (insert (format "%0.2f" value)))))))
2036 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2038 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2042 (define-key global-map [(shift iso-lefttab)] 'ispell-complete-word)
2043 ;; shift-tab going backward is kind of standard
2044 (define-key Info-mode-map [(shift iso-lefttab)] 'Info-prev-reference)
2046 ;; (define-key global-map [(control x) (control a)] 'auto-fill-mode)
2048 ;; Put back my keys, you thief!
2049 (define-key global-map [(home)] 'beginning-of-buffer)
2050 (define-key global-map [(end)] 'end-of-buffer)
2051 ;; (define-key global-map [(insertchar)] 'overwrite-mode)
2052 (define-key global-map [(delete)] 'delete-char)
2054 ;; Cool shortcuts to move to the end / beginning of block keen
2055 (define-key global-map [(control right)] 'forward-sexp)
2056 (define-key global-map [(control left)] 'backward-sexp)
2058 ;; Wheel mouse moves up and down 2 lines (and DO NOT BEEP when we are
2059 ;; out of the buffer)
2061 (define-key global-map [mouse-4]
2062 (lambda () (interactive) (condition-case nil (scroll-down 2) (error nil))))
2063 (define-key global-map [mouse-5]
2064 (lambda () (interactive) (condition-case nil (scroll-up 2) (error nil))))
2066 ;; with shift it goes faster
2067 (define-key global-map [(shift mouse-4)]
2068 (lambda () (interactive) (condition-case nil (scroll-down 50) (error nil))))
2069 (define-key global-map [(shift mouse-5)]
2070 (lambda () (interactive) (condition-case nil (scroll-up 50) (error nil))))
2072 ;; Meta-? shows the properties of the character at point
2073 (define-key global-map [(meta ??)]
2074 (lambda () (interactive)
2075 (message (prin1-to-string (text-properties-at (point))))))
2077 ;; Compiles the latex file in the current buffer
2079 (setq tex-start-commands "\\input")
2080 (define-key global-map [f3] 'tex-file)
2081 (define-key global-map [(shift f3)] 'tex-bibtex-file)
2083 ;; To run xdvi on the dvi associated to the .tex in the current
2084 ;; buffer, and to edit the .fig or bitmap image used to generate the
2087 (define-key global-map [f4] 'ff/run-viewer)
2089 ;; Closes the current \begin{}
2091 (when (ff/load-or-alert "longlines")
2093 (setq longlines-show-hard-newlines t
2094 longlines-auto-wrap t
2095 ;; longlines-show-effect #("|\n" 0 2 (face escape-glyph))
2098 ;; (defun ff/auto-longlines ()
2099 ;; (when (save-excursion
2100 ;; (goto-char (point-min))
2101 ;; (re-search-forward "^.\\{81,\\}$" nil t))
2103 ;; (message "Switched on the lonlines mode automatically")
2106 ;; (add-hook 'latex-mode-hook 'ff/auto-longlines)
2110 ;; Meta-/ remaped (completion)
2112 (define-key global-map [(shift right)] 'dabbrev-expand)
2113 (define-key global-map [(meta =)] 'dabbrev-expand)
2115 ;; Change the current window.
2117 (defun ff/next-same-frame-window () (interactive)
2118 (select-window (next-window (selected-window)
2119 (> (minibuffer-depth) 0)
2122 (defun ff/previous-same-frame-window () (interactive)
2123 (select-window (previous-window (selected-window)
2124 (> (minibuffer-depth) 0)
2127 (define-key global-map [(shift prior)] 'ff/next-same-frame-window)
2128 (define-key global-map [(shift next)] 'ff/previous-same-frame-window)
2130 (define-key global-map [(control })] 'enlarge-window-horizontally)
2131 (define-key global-map [(control {)] 'shrink-window-horizontally)
2132 (define-key global-map [(control \")] 'enlarge-window)
2133 (define-key global-map [(control :)] 'shrink-window)
2135 ;; (define-key global-map [(control shift prior)] 'next-multiframe-window)
2136 ;; (define-key global-map [(control shift next)] 'previous-multiframe-window)
2138 ;; I have two screens sometime!
2140 (define-key global-map [(meta next)] 'other-frame)
2141 (define-key global-map [(meta prior)] (lambda () (interactive) (other-frame -1)))
2143 (define-key global-map [(shift home)] 'delete-other-windows-vertically)
2145 ;; (define-key global-map [(control +)] 'enlarge-window)
2146 ;; (define-key global-map [(control -)] 'shrink-window)
2148 ;; Goes to next/previous buffer
2150 (define-key global-map [(control prior)] 'ff/next-buffer)
2151 (define-key global-map [(control next)] 'ff/prev-buffer)
2153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2154 ;; If M-. on a symbol, show where it is defined in another window
2155 ;; without giving focus, cycle if repeated.
2156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2158 (when (ff/load-or-alert "etags")
2160 (defun ff/find-tag-nofocus () (interactive)
2161 "Show in another window the definition of the current tag"
2162 (let ((tag (find-tag-default)))
2163 (display-buffer (find-tag-noselect tag (string= tag last-tag)))
2164 (message "Tag %s" tag)
2168 (define-key global-map [(meta .)] 'ff/find-tag-nofocus)
2171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2172 ;; Destroys the current buffer and its window if it's not the only one
2173 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2175 (defcustom ff/kill-this-buffer-and-delete-window-exceptions ""
2176 "*Regexp matching the buffer names which have to be kept when using
2177 `ff/kill-this-buffer-and-delete-window'.")
2179 (defun ff/kill-this-buffer-and-delete-window (universal)
2180 "Unless its name matches
2181 `ff/kill-this-buffer-and-delete-window-exceptions', kills the
2182 current buffer and deletes the current window if it's not the
2183 only one in the frame. If the buffer has to be kept, go to the
2184 next one. With universal argument, kill all killable buffers."
2187 (let ((nb-killed 0))
2189 (unless (string-match ff/kill-this-buffer-and-delete-window-exceptions
2192 (setq nb-killed (1+ nb-killed))
2195 (message "Killed %d buffer%s" nb-killed (if (> nb-killed 1) "s" "")))
2196 (if (string-match ff/kill-this-buffer-and-delete-window-exceptions (buffer-name))
2198 (kill-this-buffer)))
2199 ;; (unless (one-window-p t) (delete-window))
2202 (define-key global-map [(control backspace)] 'ff/kill-this-buffer-and-delete-window)
2203 ;; (define-key calc-mode-map [(control backspace)] 'calc-quit)
2206 (setq ff/kill-this-buffer-and-delete-window-exceptions
2207 "^ \\|\\*Messages\\*\\|\\*scratch\\*\\|\\*Group\\*\\|\\*-jabber-\\*\\|\\*-jabber-process-\\*\\|\\*media\\*")
2209 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2211 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2213 (defun ff/elisp-debug-on ()
2214 "Switches `debug-on-error' and `debug-on-quit'."
2217 (setq debug-on-error nil
2219 (setq debug-on-error t
2222 (message "elisp debug on")
2223 (message "elisp debug off")))
2225 (defun ff/create-dummy-buffer (&optional universal) (interactive "P")
2226 (find-file (concat "/tmp/" (ff/non-existing-filename "/tmp/" "dummy" "")))
2228 (if universal (ff/insert-url (current-kill 0)))
2229 (message "New dummy text-mode buffer"))
2231 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2232 ;; Recentf to keep a list of recently visited files. I use it
2233 ;; exclusively with my selector.el
2234 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2238 (setq recentf-exclude
2239 (append recentf-exclude
2240 '("enotes$" "secure-notes$" "media-playlists$"
2242 "svn-commit.tmp$" ".git/COMMIT_EDITMSG$"
2243 "\.bbl$" "\.aux$" "\.toc$"))
2244 recentf-max-saved-items 1000
2245 recentf-save-file "~/private/emacs/recentf"
2248 (when (boundp 'recentf-keep) (add-to-list 'recentf-keep 'file-remote-p))
2250 ;; Removes the link if we add the file itself (I am fed up with
2251 ;; duplicates because of vc-follow-symlinks)
2253 (defadvice recentf-add-file (before ff/remove-links (filename) activate)
2254 ;; If we are adding a filename corresponding to the last link we
2255 ;; have added, remove the latter
2256 (when (and recentf-list
2257 (file-symlink-p (car recentf-list))
2258 (string= filename (file-chase-links filename)))
2259 (setq recentf-list (cdr recentf-list))
2264 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2265 ;; My front-end to mplayer
2266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2268 ;; (ff/compile-when-needed "media/mplayer")
2269 ;; (ff/compile-when-needed "media")
2271 (when (ff/load-or-alert "media")
2273 (unless window-system
2276 (media/mode-string-face
2277 :foreground "blue4" :weight 'bold)
2279 (media/current-tune-face
2280 :foreground "black" :background "yellow" :weight 'normal)
2282 (media/instant-highlight-face
2283 :foreground "black" :background "orange" :weight 'normal)
2287 (define-key global-map [(meta \\)] 'media)
2289 (setq media/expert t
2290 media/add-current-song-to-interrupted-when-killing t
2291 media/duration-to-history 30
2292 media/history-size 1000
2293 media/playlist-file "~/private/emacs/media-playlists"
2294 media/mplayer/args '(
2297 "-subfont-osd-scale" "3"
2298 ;; "-stop-xscreensaver"
2301 media/mplayer/timing-request-period 5.0
2305 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2309 ;; selector.el is one of my own scripts, check my web page
2311 (when (ff/load-or-alert "selector" t)
2312 ;; (define-key global-map [(shift return)] 'selector/quick-move-in-buffer)
2313 (define-key global-map [(control x) (control b)] 'selector/switch-buffer)
2315 (defun ff/visit-debpkg-file (&optional regexp)
2316 "This function lists all the files found with dpkg -S and
2317 proposes to visit them."
2318 (interactive "sPattern: ")
2324 (cons (selector/filename-to-string s) s))
2326 (shell-command-to-string (concat "dpkg -S " regexp " | awk '{print $2}'"))))
2329 "*selector find-file*"
2333 (add-hook 'selector/mode-hook (lambda () (setq truncate-lines t)))
2335 (defun ff/selector-insert-record-callback (r)
2336 (bbdb-display-records (list r))
2337 ;; Weird things will happen if you kill the buffer from which you
2338 ;; invoked ff/selector-mail-from-bbdb
2339 (insert (car (elt r 6)))
2342 (defun ff/selector-compose-mail-callback (r)
2343 (vm-compose-mail (car (elt r 6)))
2346 (defun ff/selector-mail-from-bbdb () (interactive)
2349 (lambda (r) (cons (concat (elt r 0)
2357 (if (string= mode-name "Mail")
2358 'ff/selector-insert-record-callback
2359 'ff/selector-compose-mail-callback)
2364 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2365 ;; A function to remove temporary alarm windows
2366 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2368 (defcustom ff/annoying-windows-regexp
2369 "\\*Messages\\*\\|\\*compilation\\*\\|\\*tex-shell\\*\\|\\*Help\\*\\|\\*info\\*\\|\\*Apropos\\*\\|\\*BBDB\\*\\|\\*.*-diff\\*"
2370 "The regexp matching the windows to be deleted by `ff/delete-annoying-windows'"
2373 (defun ff/delete-annoying-windows ()
2374 "Close all the windows showing buffers whose names match
2375 `ff/annoying-windows-regexp'."
2377 (when ff/annoying-windows-regexp
2379 (when (and (not (one-window-p w))
2380 (string-match ff/annoying-windows-regexp
2381 (buffer-name (window-buffer w))))
2385 (message "Removed annoying windows")
2389 (setq ff/annoying-windows-regexp
2390 (concat ff/annoying-windows-regexp
2391 "\\|\\*unspooled mails\\*\\|\\*enotes alarms\\*\\|\\*system info\\*"))
2393 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2394 ;; Some handy functions
2395 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2397 (defun ff/twin-horizontal-current-buffer () (interactive)
2398 (delete-other-windows)
2399 (split-window-horizontally)
2403 (defun ff/twin-vertical-current-buffer () (interactive)
2404 (delete-other-windows)
2405 (split-window-vertically)
2409 (defun ff/flyspell-mode (arg) (interactive "p")
2410 (if flyspell-mode (flyspell-mode -1)
2415 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2417 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2419 (defun ff/move-region-to-fridge () (interactive)
2420 "Cut the current region, paste it in a file called ./fridge
2421 with a time tag, and save this file"
2422 (unless (use-region-p) (error "No region selected"))
2423 (let ((bn (file-name-nondirectory (buffer-file-name))))
2424 (kill-region (region-beginning) (region-end))
2425 (with-current-buffer (find-file-noselect "fridge")
2426 (goto-char (point-max))
2428 (insert "######################################################################\n")
2430 (format-time-string "%Y %b %d %H:%M:%S" (current-time))
2436 (message "Region moved to fridge")
2441 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2443 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2445 (setq ff/map (make-sparse-keymap))
2446 (define-key global-map [(control \`)] ff/map)
2447 (define-key esc-map "`" ff/map)
2449 (defun ff/git-status (&optional dir) (interactive)
2450 (if (buffer-file-name)
2451 (git-status (file-name-directory (buffer-file-name)))
2452 (error "No file attached to this buffer")))
2454 (defun ff/insert-date () (interactive)
2455 (insert (format-time-string "\n * %Y %b %d %H:%M:%S\n\n" (current-time)))
2458 (define-key ff/map [(control g)] 'ff/git-status)
2459 (define-key ff/map [(control w)] 'server-edit)
2460 (define-key ff/map [(control d)] 'ff/elisp-debug-on)
2461 ;; (define-key ff/map "d" 'diary)
2462 (define-key ff/map "d" 'ff/insert-date)
2463 (define-key ff/map [(control \`)] 'ff/bash-new-buffer)
2464 (define-key ff/map [(control n)] 'enotes/show-all-notes)
2465 (define-key ff/map [(control s)] 'ff/secure-note-add)
2466 (define-key ff/map [(control t)] 'ff/start-test-code)
2467 (define-key ff/map [(control q)] 'ff/create-dummy-buffer)
2468 (define-key ff/map [(control a)] 'auto-fill-mode)
2469 (define-key ff/map [(control i)] 'ff/system-info)
2470 (define-key ff/map "w" 'ff/word-occurences)
2471 (define-key ff/map [(control c)] 'calendar)
2472 ;; (define-key ff/map [(control c)] (lambda () (interactive) (save-excursion (calendar))))
2473 (define-key ff/map [(control l)] 'goto-line)
2474 (define-key ff/map "l" 'longlines-mode)
2475 (define-key ff/map [(control o)] 'selector/quick-pick-recent)
2476 (define-key ff/map "s" 'selector/quick-move-in-buffer)
2477 (define-key ff/map "S" 'selector/search-sentence)
2478 (define-key ff/map "h" 'ff/tidy-html)
2479 (define-key ff/map "c" 'ff/count-char)
2480 (define-key ff/map [(control p)] 'ff/print-to-file)
2481 (define-key ff/map "P" 'ff/print-to-printer)
2482 (define-key ff/map [(control b)] 'bbdb)
2483 (define-key ff/map "m" 'ff/selector-mail-from-bbdb)
2484 (define-key ff/map [(control m)] 'woman)
2485 (define-key ff/map "b" 'bookmark-jump)
2486 (define-key ff/map [(control =)] 'calc)
2487 (define-key ff/map [(control shift b)]
2488 (lambda () (interactive)
2491 (define-key ff/map "f" 'ff/move-region-to-fridge)
2492 (define-key ff/map [(control f)] 'ff/flyspell-mode)
2494 (define-key ff/map [?\C-0] 'ff/delete-annoying-windows)
2495 (define-key ff/map "1" 'delete-other-windows)
2496 (define-key ff/map [?\C-1] 'delete-other-windows)
2497 (define-key ff/map "2" 'ff/twin-vertical-current-buffer)
2498 (define-key ff/map [?\C-2] 'ff/twin-vertical-current-buffer)
2499 (define-key ff/map "3" 'ff/twin-horizontal-current-buffer)
2500 (define-key ff/map [?\C-3] 'ff/twin-horizontal-current-buffer)
2502 (define-key ff/map " " 'delete-trailing-whitespace)
2504 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2505 ;; Hacks so that all keys are functionnal in xterm and through ssh.
2506 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2508 (unless window-system
2510 ;; One day I will understand these clipboard business. Until then,
2511 ;; so that it works in xterm (yes), let's use xclip. This is a bit
2514 ;; (defun ff/yank-with-xclip (&optional arg)
2515 ;; "Paste the content of the X clipboard with the xclip
2516 ;; command. Without ARG converts some of the '\\uxxxx' characters."
2517 ;; (interactive "P")
2518 ;; (with-temp-buffer
2519 ;; (shell-command "xclip -o" t)
2521 ;; (mapc (lambda (x) (replace-string (concat "\\u" (car x)) (cdr x) nil (point-min) (point-max)))
2522 ;; '(("fffd" . "??")
2533 ;; (kill-ring-save (point-min) (point-max)))
2537 ;; (define-key global-map [(meta y)] 'ff/yank-with-xclip)
2539 ;; (set-terminal-coding-system 'iso-latin-1)
2540 ;; (set-terminal-coding-system 'utf-8)
2542 ;; I have in my .Xressource
2544 ;; XTerm.VT100.translations: #override\n\
2545 ;; <Btn4Down>,<Btn4Up>:scroll-back(2,line)\n\
2546 ;; <Btn5Down>,<Btn5Up>:scroll-forw(2,line)\n\
2547 ;; Ctrl<Btn4Down>,Ctrl<Btn4Up>:scroll-back(1,page)\n\
2548 ;; Ctrl<Btn5Down>,Ctrl<Btn5Up>:scroll-forw(1,page)\n\
2549 ;; Shift<Btn4Down>,Shift<Btn4Up>:scroll-back(1,halfpage)\n\
2550 ;; Shift<Btn5Down>,Shift<Btn5Up>:scroll-forw(1,halfpage)\n\
2551 ;; Alt<KeyPress>:insert-eight-bit()\n\
2552 ;; !Shift<Key>BackSpace: string("
\7f")\n\
2553 ;; Ctrl<Key>BackSpace: string("\eOZ")\n\
2554 ;; Shift<Key>Prior: string("\e[5;2~")\n\
2555 ;; Shift<Key>Next: string("\e[6;2~")\n\
2556 ;; Shift Ctrl<Key>]: string("\eO}")\n\
2557 ;; Shift Ctrl<Key>[: string("\eO{")\n\
2558 ;; Shift Ctrl<Key>/: string("\eO?")\n\
2559 ;; Ctrl<Key>/: string("\eO/")\n\
2560 ;; Shift Ctrl<Key>=: string("\eO+")\n\
2561 ;; Ctrl<Key>=: string("\eO=")\n\
2562 ;; Shift Ctrl<Key>;: string("\eO:")\n\
2563 ;; Ctrl<Key>;: string("\eO;")\n\
2564 ;; Shift Ctrl<Key>`: string("\eO~")\n\
2565 ;; Ctrl<Key>`: string("\eO`")\n\
2566 ;; Shift Ctrl<Key>': string("\eO\\\"")\n\
2567 ;; Ctrl<Key>': string("\eO'")\n\
2568 ;; Shift Ctrl<Key>.: string("\eO>")\n\
2569 ;; Ctrl<Key>.: string("\eO.")\n\
2570 ;; Shift Ctrl<Key>\\,: string("\eO<")\n\
2571 ;; Ctrl<Key>\\,: string("\eO,")
2573 (define-key function-key-map "\e[2~" [insert])
2575 (define-key function-key-map "\e[Z" [S-iso-lefttab])
2577 (define-key function-key-map "\e[1;2A" [S-up])
2578 (define-key function-key-map "\e[1;2B" [S-down])
2579 (define-key function-key-map "\e[1;2C" [S-right])
2580 (define-key function-key-map "\e[1;2D" [S-left])
2581 (define-key function-key-map "\e[1;2F" [S-end])
2582 (define-key function-key-map "\e[1;2H" [S-home])
2584 (define-key function-key-map "\e[2;2~" [S-insert])
2585 (define-key function-key-map "\e[5;2~" [S-prior])
2586 (define-key function-key-map "\e[6;2~" [S-next])
2588 (define-key function-key-map "\e[1;2P" [S-f1])
2589 (define-key function-key-map "\e[1;2Q" [S-f2])
2590 (define-key function-key-map "\e[1;2R" [S-f3])
2591 (define-key function-key-map "\e[1;2S" [S-f4])
2592 (define-key function-key-map "\e[15;2~" [S-f5])
2593 (define-key function-key-map "\e[17;2~" [S-f6])
2594 (define-key function-key-map "\e[18;2~" [S-f7])
2595 (define-key function-key-map "\e[19;2~" [S-f8])
2596 (define-key function-key-map "\e[20;2~" [S-f9])
2597 (define-key function-key-map "\e[21;2~" [S-f10])
2599 (define-key function-key-map "\e[1;5A" [C-up])
2600 (define-key function-key-map "\e[1;5B" [C-down])
2601 (define-key function-key-map "\e[1;5C" [C-right])
2602 (define-key function-key-map "\e[1;5D" [C-left])
2603 (define-key function-key-map "\e[1;5F" [C-end])
2604 (define-key function-key-map "\e[1;5H" [C-home])
2606 (define-key function-key-map "\e[2;5~" [C-insert])
2607 (define-key function-key-map "\e[5;5~" [C-prior])
2608 (define-key function-key-map "\e[6;5~" [C-next])
2610 (define-key function-key-map "\e[1;9A" [M-up])
2611 (define-key function-key-map "\e[1;9B" [M-down])
2612 (define-key function-key-map "\e[1;9C" [M-right])
2613 (define-key function-key-map "\e[1;9D" [M-left])
2614 (define-key function-key-map "\e[1;9F" [M-end])
2615 (define-key function-key-map "\e[1;9H" [M-home])
2617 (define-key function-key-map "\e[2;9~" [M-insert])
2618 (define-key function-key-map "\e[5;9~" [M-prior])
2619 (define-key function-key-map "\e[6;9~" [M-next])
2621 ;; The following ones are not standard
2623 (define-key function-key-map "\eO}" (kbd "C-}"))
2624 (define-key function-key-map "\eO{" (kbd "C-{"))
2625 (define-key function-key-map "\eO?" (kbd "C-?"))
2626 (define-key function-key-map "\eO/" (kbd "C-/"))
2627 (define-key function-key-map "\eO:" (kbd "C-:"))
2628 (define-key function-key-map "\eO;" (kbd "C-;"))
2629 (define-key function-key-map "\eO~" (kbd "C-~"))
2630 (define-key function-key-map "\eO`" (kbd "C-\`"))
2631 (define-key function-key-map "\eO\"" (kbd "C-\""))
2632 (define-key function-key-map "\eO|" (kbd "C-|"))
2633 (define-key function-key-map "\eO'" (kbd "C-'"))
2634 (define-key function-key-map "\eO>" (kbd "C->"))
2635 (define-key function-key-map "\eO." (kbd "C-."))
2636 (define-key function-key-map "\eO<" (kbd "C-<"))
2637 (define-key function-key-map "\eO," (kbd "C-,"))
2638 (define-key function-key-map "\eO-" (kbd "C--"))
2639 (define-key function-key-map "\eO=" (kbd "C-="))
2640 (define-key function-key-map "\eO+" (kbd "C-+"))
2642 (define-key function-key-map "\eOZ" [C-backspace])
2644 (define-key minibuffer-local-map "
\10" 'previous-history-element)
2645 (define-key minibuffer-local-map "
\ e" 'next-history-element)
2647 ;; (define-key global-map [(alt prior)] 'ff/prev-buffer)
2648 ;; (define-key global-map [(alt next)] 'ff/next-buffer)
2652 ;; I am fed up with Alt-Backspace in the minibuffer erasing the
2653 ;; content of the kill-ring
2655 (defun ff/backward-delete-word (arg)
2656 "Delete characters forward until encountering the end of a word, but do not put them in the kill ring.
2657 With argument ARG, do this that many times."
2659 (delete-region (point) (progn (forward-word (- arg)) (point))))
2661 (define-key minibuffer-local-map
2662 [remap backward-kill-word] 'ff/backward-delete-word)
2664 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2666 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2668 ;; Where to save the bookmarks and where is bbdb
2670 (setq bookmark-default-file "~/private/emacs/bmk"
2671 bbdb-file "~/private/bbdb"
2672 custom-file "~/private/emacs/custom")
2674 ;; enotes.el is one of my own scripts, check my web page
2676 (when (ff/load-or-alert "enotes" t)
2677 (setq enotes/file "~/private/enotes"
2678 enotes/show-help nil
2679 enotes/full-display nil
2680 enotes/default-time-fields "9:30")
2683 ;; (add-hook 'enotes/alarm-hook
2684 ;; (lambda () (ff/play-sound-async "~/local/sounds/three_notes2.wav")))
2687 ;; (when (ff/load-or-alert "goto-last-change.el")
2688 ;; (define-key global-map [(control x) (control a)] 'goto-last-change))
2690 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2691 ;; My private stuff (email adresses, mail filters, etc.)
2692 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2694 (ff/load-or-alert "~/private/emacs.perso.el" t)
2696 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2698 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2700 ;; Runs in server mode, so that emacsclient works
2703 (defun ff/raise-frame-and-give-focus ()
2706 (x-focus-frame (selected-frame))
2707 (set-mouse-pixel-position (selected-frame) 4 4)
2710 ;; Raises the window when the server is invoked
2712 (add-hook 'server-switch-hook 'ff/raise-frame-and-give-focus)