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 ;; (defadvice display-warning (before ff/blah (type message &optional level buffer-name) activate)
22 ;; (message "--- BLAH %s ---" message)
26 ;; It's better to set the preferences in the .Xresources so that the
27 ;; window is not first displayed with the wrong options
30 ;; Emacs.verticalScrollBars: off
32 ;; Emacs.internalBorder: 1
33 ;; Emacs.FontBackend: xft
36 ;; Xft.antialias: true
39 (set-frame-font "Inconsolata 14")
41 ;; (package-initialize)
43 ;; (set-default-font "Bitstream vera sans mono 12")
44 ;; (set-default-font "Liberation Mono-13")
45 ;; (set-default-font "DejaVu sans mono 15")
46 ;; (set-default-font "Droid sans mono 13")
47 ;; (set-default-font "Opensans 10")
49 (when (fboundp 'horizontal-scroll-bar-mode)
50 (horizontal-scroll-bar-mode -1))
52 ;; This is where I put most of my emacs-related files
53 (setq ff/emacs-dir "~/private/emacs")
54 (unless (file-exists-p ff/emacs-dir)
55 (mkdir ff/emacs-dir t))
57 ;; Give the focus to the emacs window if we are under a windowing
61 ;; (x-focus-frame nil)
62 (set-mouse-pixel-position (selected-frame) 4 4))
64 ;; Where I keep my own scripts
66 (add-to-list 'load-path "~/sources/gpl/elisp")
67 (add-to-list 'load-path "~/sources/elisp")
68 (add-to-list 'load-path "~/local/elisp")
70 ;; No, I do not like menus
74 ;; (when (functionp 'fringe-mode) (fringe-mode '(0 . 0)))
75 ;; (when (functionp 'fringe-mode) (fringe-mode '(0 . 1)))
76 (when (functionp 'fringe-mode) (fringe-mode 10))
78 ;; And I do not like scrollbar neither
79 (when (functionp 'scroll-bar-mode) (scroll-bar-mode -1))
81 ;; Make all "yes or no" prompts be "y or n" instead
82 (fset 'yes-or-no-p 'y-or-n-p)
84 ;; The space bar acting as "yes" has been several times really
86 (define-key query-replace-map (kbd "SPC") nil)
88 ;; Show the matching parenthesis and do it immediately, we are in a
90 (setq show-paren-delay 0)
93 ;; use colorization for all modes
94 (global-font-lock-mode t)
98 (setq font-lock-maximum-decoration 3
99 ;;'((latex-mode . 2) (t . 2))
102 ;; Activate the dynamic completion of buffer names
104 ;; (load "lcomplete")
106 ;; Save the minibuffer history
107 (setq savehist-file (concat ff/emacs-dir "/savehist"))
108 (when (functionp 'savehist-mode) (savehist-mode 1))
110 ;; And allow minibuffer recursion
111 (setq enable-recursive-minibuffers t)
112 (minibuffer-depth-indicate-mode 1)
114 ;; I do not like tooltips
115 (when (functionp 'tooltip-mode) (tooltip-mode nil))
117 ;; Activate the dynamic completion in the mini-buffer
120 ;; (setq highlight-current-line-globally t
121 ;; highlight-current-line-ignore-regexp "Faces\\|Colors\\| \\*Mini\\|\\*media\\|INBOX")
123 ;; (highlight-current-line-minor-mode 1)
124 ;; (highlight-current-line-set-bg-color "gray75")
126 (defun ff/compile-when-needed (name)
127 "Compiles the given file only if needed. Adds .el if required, and
128 uses `load-path' to find it."
129 (if (not (string-match "\.el$" name))
130 (ff/compile-when-needed (concat name ".el"))
132 (let* ((src (concat dir "/" name)))
133 ;; (message "Compiling " scr) ;;***********
134 (when (file-newer-than-file-p src (concat src "c"))
136 ;; (let ((byte-compile-verbose nil))
137 ;; (condition-case nil
138 ;; (byte-compile-file src)
141 (byte-compile-file src)
143 (message (format "Compiled %s" src ))
144 (message (format "Failed compilation of %s" src))))))
147 ;; This is useful when using the same .emacs in many places
149 (defun ff/load-or-alert (name &optional compile-when-needed)
150 "Tries to load the specified file and insert a warning message in a
151 load-warning buffer in case of failure."
153 (when compile-when-needed (ff/compile-when-needed name))
155 (if (load name t nil) t
156 (let ((buf (get-buffer-create "*loading warnings*")))
159 (insert (propertize "Warning:" 'face 'font-lock-warning-face) " could not load '" name "'\n")
160 (fit-window-to-buffer (get-buffer-window buf))
161 (set-buffer-modified-p nil))
164 ;; This is the default in emacs 22.1 and later
165 ;; (auto-compression-mode 1)
167 ;; make emacs use the clipboard so that copy/paste works for other
168 ;; x-programs. I have no clue how all that clipboard thing works.
170 ;; (setq x-select-enable-clipboard t)
171 ;; (setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
172 ;; (setq x-select-enable-primary t)
173 ;; (setq x-select-enable-clipboard t)
174 ;; (global-set-key "\C-y" 'clipboard-yank)
180 ;; avoid GC as much as possible
181 gc-cons-threshold 2500000
183 ;; no startup message
184 inhibit-startup-screen t
186 ;; no message in the scratch buffer
187 initial-scratch-message nil
189 ;; do not fill my buffers, you fool
190 next-line-add-newlines nil
192 ;; keep the window focused on the messages during compilation
193 compilation-scroll-output t
195 ;; Keep the highlight on the compilation error
196 next-error-highlight t
198 ;; blink the screen instead of beeping
201 ;; take the CR when killing a line
204 ;; I prefer to move between lines as defined in the buffer, not
208 ;; I comment empty lines, too (does not seem to work, though)
209 comment-empty-lines t
211 ;; We want long lines to be truncated instead of displayed on several lines
213 ;; Show all lines, even if the window is not as large as the frame
214 ;; truncate-partial-width-windows nil
215 ;; truncate-partial-width-windows t
217 ;; Do not keep tracks of the autosaved files
218 auto-save-list-file-prefix nil
220 ;; Show me empty lines at the end of the buffer
221 default-indicate-empty-lines t
223 ;; Show me the region until I do something on it
224 transient-mark-mode t
226 ;; Do not color stuff which are clickable when hovering over it
229 ;; Don't bother me with questions even if "unsafe" local variables
231 enable-local-variables :all
233 ;; I have no problem with small windows
236 ;; I am not a fan of develock
237 develock-auto-enable nil
239 ;; I do not like women to open windows
240 woman-use-own-frame nil
242 ;; I am not that paranoid, contrary to what you think
243 epa-file-cache-passphrase-for-symmetric-encryption t
244 ;; And I like ascii files
246 ;; This goes with in your ~/.gnupg/gpg-agent.conf:
247 ;; allow-emacs-pinentry
248 ;; allow-loopback-pinentry
249 epa-pinentry-mode 'loopback
251 ;; tramp-default-method "ssh"
252 tramp-default-method "scp"
254 ;; I have no problem with files having their own local variables
257 mail-from-style 'angles
258 browse-url-mozilla-program "firefox"
260 mc-use-default-recipients t
262 ;; browse-url-new-window-flag t
264 ;; I do not like compilation to automatically split the active window
265 ;; vertically, even when the said window is very wide
266 split-height-threshold 0
267 split-width-threshold nil
270 (custom-set-variables
271 '(query-replace-from-to-separator nil))
276 temporary-file-directory "/tmp/"
277 vc-make-backup-files t
278 backup-directory-alist '((".*" . "~/misc/emacs.backups/"))
279 version-control t ;; Use backup files with numbers
282 delete-old-versions t
283 backup-by-copying-when-linked t
286 (setq tramp-backup-directory-alist backup-directory-alist)
288 (setq user-emacs-directory "~/misc/emacs.d/")
291 abbrev-file-name (concat user-emacs-directory "abbrev_defs")
292 server-auth-dir (concat user-emacs-directory "server/")
293 custom-theme-directory user-emacs-directory
296 ;; Stop this crazy blinking cursor
297 (blink-cursor-mode 0)
299 ;; (setq blink-cursor-delay 0.05
300 ;; blink-cursor-blinks 0
301 ;; blink-cursor-interval 0.25)
303 ;; (set-terminal-coding-system 'utf-8)
305 ;; (unless window-system
306 ;; (xterm-mouse-mode 1)
307 ;; (if (string= (getenv "TERM") "xterm-256color")
308 ;; (ff/load-or-alert "xterm-256color" t))
313 ;; Show white spaces at the end of lines
314 show-trailing-whitespace t
316 ;; Do not show the cursor in non-active window
317 cursor-in-non-selected-windows nil
322 ;; when on a TAB, the cursor has the TAB length
325 ;; This is the default coding system when toggle-input-method is
327 default-input-method "latin-1-prefix"
329 ;; do not put tabs when indenting
331 ;; Stop indenting automatically, that's annoying
332 electric-indent-chars nil
334 ;; And yes, we have a fast display / connection / whatever
338 ;; To keep the cursor always visible when it moves (thanks
340 redisplay-dont-pause t
342 ;; I want to see the keys I type instantaneously
346 ;; Show the column number
347 (column-number-mode 1)
349 ;; What modes for what file extentions
350 (add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
352 (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
356 (add-to-list 'auto-mode-alist '("\\.txt\\'" . (lambda()
362 (add-hook 'c++-mode-hook 'flyspell-prog-mode)
363 ;; (add-hook 'lua-mode-hook 'flyspell-prog-mode)
364 (add-hook 'log-edit-mode-hook 'flyspell-mode)
366 (add-hook 'markdown-mode-hook 'flyspell-mode)
367 (add-hook 'markdown-mode-hook 'auto-fill-mode)
371 (put 'narrow-to-region 'disabled nil)
372 (put 'upcase-region 'disabled nil)
373 (put 'downcase-region 'disabled nil)
374 ;; (put 'scroll-left 'disabled nil)
375 ;; (put 'scroll-right 'disabled nil)
377 ;; My selector is clearer than that
378 ;; (when (load "ido" t) (ido-mode t))
380 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
382 ;; Makes buffer names more explicit then <2>, <3> etc. when there are
383 ;; several identical filenames
385 (when (load "uniquify" t)
386 (setq uniquify-buffer-name-style 'post-forward-angle-brackets))
388 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
390 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
392 (when (boundp 'x-display-name)
396 ;; If the display is :0.0, we make the assumption that we are
397 ;; running the emacs locally, and we do not show the
398 ;; hostname. Otherwise, show @host.
400 frame-title-format (concat "emacs" ;;invocation-name
401 (unless (string= x-display-name ":0.0")
402 (concat "@" system-name))
405 ;; Use the same for the icone
407 icon-title-format frame-title-format
410 ;; "tool" bar? Are you kidding?
411 (when (fboundp 'tool-bar-mode) (tool-bar-mode -1))
413 ;; My funky setting of face colors. Basically, we switch to a sober
414 ;; look and darken a bit the colors which need to (because of the
415 ;; darker background)
417 (defun ff/configure-faces (fl)
418 "Set face attributes and create faces when necessary"
420 (unless (boundp (car f)) (make-empty-face (car f)))
421 (eval `(set-face-attribute (car f) nil ,@(cdr f))))
424 ;; Not the same in xterm (which is gray in my case) and in
431 ;; (escape-glyph :foreground "#c0c0c0" :weight 'bold)
432 (escape-glyph :foreground "green3" :weight 'bold)
433 (default :background "gray90" :foreground "black")
434 (cperl-array-face :background "gray90" :foreground "blue" :weight 'bold)
435 (cperl-hash-face :background "gray90" :foreground "purple" :weight 'bold)
436 (message-cited-text :foreground "red4")
437 (diff-mode :background "gray90" :weight 'bold)
438 (diff-added :background "gray90" :foreground "green4" :weight 'bold)
439 (diff-removed :background "gray90" :foreground "red2" :weight 'bold)
440 (diff-changed :background "gray90" :foreground "blue" :weight 'bold)
441 (diff-file-header :background "white" :foreground "black"
443 (diff-header :background "white" :foreground "black")
444 (diff-hunk-header :background "white" :foreground "black")
445 (font-lock-builtin-face :foreground "deeppink3")
446 (font-lock-string-face :foreground "dark olive green")
447 (font-lock-variable-name-face :foreground "sienna")
448 ;; (font-lock-function-name-face :foreground "blue" :weight 'bold)
449 (font-lock-function-name-face :foreground "blue")
450 ;; (font-lock-comment-delimiter-face :foreground "dark violet")
451 ;; (font-lock-comment-face :foreground "dark violet")
452 (flyspell-incorrect :background "#ff0000" :foreground "black")
453 (flyspell-duplicate :background "#ff9000" :foreground "black")
454 (hl-line :background "white")
455 (sh-heredoc :foreground "black" :background "#fff0f0")
456 (sh-heredoc-face :foreground "black" :background "#fff0f0")
457 (header-line :background "gray65")
458 (highlight :background "white")
459 (message-cited-text-face :foreground "firebrick")
460 (isearch :background "yellow" :foreground "black")
461 (isearch-lazy-highlight-face' :background "yellow3" :foreground "black")
462 (region :background "#b8b8e0" :foreground "black")
463 ;; (region :background "plum" :foreground "black")
464 (show-paren-match-face :background "gold" :foreground "black")
465 (show-paren-mismatch-face :background "red" :foreground "black")
466 (trailing-whitespace :background "gray65")
467 (cursor :inverse-video t)
468 (enotes/list-title-face :foreground "blue" :weight 'bold)
469 (mode-line :background "#b0b0ff" :foreground "black" :box nil
471 (header-line :background "cornflowerblue" :foreground "black" :box nil
473 (mode-line-inactive :background "gray80" :foreground "black" :box nil
475 ;; (fringe :background "black" :foreground "gray90")
476 (fringe :background "gray80")
477 (ff/date-info-face :foreground "white")
478 (ff/battery-info-face :foreground "black")
479 (ff/battery-info-alarm-face :foreground "red")
480 ;; (ff/mail-alarm-face :foreground "white" :background "red2")
481 ;; (alarm-vc-face :foreground "black" :background "yellow" :weight 'normal)
482 (gui-button-face :background "green" :foreground "black")
486 (unless window-system
487 ;; (xterm-mouse-mode 1)
489 '((italic :underline nil)
490 (info-title-2 :foreground "green")
491 (font-lock-comment-delimiter-face :foreground "green")
492 (font-lock-comment-face :foreground "green")
493 (cperl-array-face :background "gray90" :foreground "blue" :weight 'bold)
494 (cperl-hash-face :background "gray90" :foreground "purple" :weight 'bold)
495 (diff-added :background "gray90" :foreground "green4" :weight 'bold)
496 (diff-removed :background "gray90" :foreground "red2" :weight 'bold)
497 (diff-changed :background "gray90" :foreground "blue" :weight 'bold)
498 (diff-file-header-face :background "white" :foreground "black"
500 (diff-header-face :background "white" :foreground "black")
501 (diff-hunk-header-face :background "white" :foreground "black")
502 (diff-indicator-removed :foreground "red" :weight 'bold)
503 (diff-removed :foreground "red" :weight 'bold)
504 (diff-indicator-added :foreground "blue" :weight 'bold)
505 (diff-added :foreground "blue" :weight 'bold)
506 (font-lock-string-face :foreground "green")
507 (font-lock-variable-name-face :foreground "blue")
508 (font-lock-constant-face :foreground "blue")
509 (font-lock-preprocessor-face :foreground "green")
510 (font-lock-function-name-face :foreground "cyan")
511 (flyspell-incorrect :foreground "red2")
512 (flyspell-duplicate :foreground "OrangeRed2")
513 (hl-line :background "white")
514 (sh-heredoc :foreground "black" :background "#fff0f0")
515 (sh-heredoc-face :foreground "black" :background "#fff0f0")
516 (font-lock-keyword-face :foreground "blue")
517 (highlight :background "white")
518 (isearch :background "orange" :foreground "black")
519 (isearch-lazy-highlight-face' :background "yellow" :foreground "black")
520 ;; (display-time-mail-face :background "white")
521 (show-paren-match-face :background "gold" :foreground "black")
522 (show-paren-mismatch-face :background "red" :foreground "black")
523 (trailing-whitespace :background "white")
524 (mode-line :background "cornflowerblue" :foreground "black" :box nil
526 (header-line :background "cornflowerblue" :foreground "black" :box nil
528 (mode-line-inactive :background "gray60" :foreground "black" :box nil
530 (region :background "white" :foreground "black")
531 (ff/date-info-face :foreground "white" :weight 'bold)
532 (ff/battery-info-face :foreground "black")
533 (ff/battery-info-alarm-face :foreground "red")
534 ;; (ff/mail-alarm-face :foreground "red" :weight 'bold)
535 (selector/selection :background "yellow")
536 (gui-button-face :background "green" :foreground "white")
537 (enotes/information-face :foreground "cyan")
539 (file-name-shadow :foreground "black")
540 (shadow :foreground "black")
541 (warning :foreground "black" :background "red")
545 ;; When we are root, put the modeline in red
547 (when (string= (user-real-login-name) "root")
549 '((mode-line :background "red3" :foreground "black" :box nil
553 ;; Why should I have to do this?
554 (add-hook 'sh-mode-hook
556 (set-face-attribute 'sh-heredoc nil
557 :foreground "#604000"
560 (set-face-attribute 'sh-heredoc-face nil
561 :foreground "#604000"
566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
567 ;; Move the window on the buffer without moving the cursor
568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
570 (defun ff/scroll-down ()
571 "Scroll the buffer down one line and keep the cursor at the same location."
577 (defun ff/scroll-up ()
578 "Scroll the buffer up one line and keep the cursor at the same location."
584 (defun ff/scroll-left ()
585 "Scroll the buffer left one column and keep the cursor at the same location."
591 (defun ff/scroll-right ()
592 "Scroll the buffer right one column and keep the cursor at the same location."
598 (define-key global-map [(meta up)] 'ff/scroll-down)
599 (define-key global-map [(meta down)] 'ff/scroll-up)
601 (define-key global-map [(meta shift up)]
602 (lambda () (interactive) (condition-case nil (scroll-down 10) (error nil))))
604 (define-key global-map [(meta shift down)]
605 (lambda () (interactive) (condition-case nil (scroll-up 10) (error nil))))
607 ;; (define-key global-map [(meta shift up)] (lambda () (interactive) (ff/scroll-down 10)))
608 ;; (define-key global-map [(meta shift down)] 'ff/scroll-up)
610 (define-key global-map [(meta p)] 'ff/scroll-down)
611 (define-key global-map [(meta n)] 'ff/scroll-up)
612 (define-key global-map [(meta right)] 'ff/scroll-left)
613 (define-key global-map [(meta left)] 'ff/scroll-right)
615 (defun ff/delete-trailing-whitespaces-and-indent ()
617 (delete-trailing-whitespace)
618 (indent-region (point-min) (point-max) nil))
620 (define-key global-map [(control c) (control q)] 'ff/delete-trailing-whitespaces-and-indent)
622 (define-key global-map [(control x) (control o)] 'other-window)
624 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
626 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
628 (defun ff/alsa-sound (file)
629 "Plays a sound with ALSA."
631 (process-kill-without-query (start-process-shell-command "aplay"
635 (if (and (boundp 'x-display-name) (string= x-display-name ":0.0"))
636 (defalias 'ff/play-sound-async 'ff/alsa-sound)
637 (defalias 'ff/play-sound-async 'ding))
639 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
640 ;; I comment stuff often, let's be efficient. shift + down comments
641 ;; the current line and goes down, and shift + up uncomments the line
642 ;; and goes up (they are not the dual of each other, but moving and
643 ;; then uncommenting would be very counter-intuitive).
644 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
646 (defun ff/comment-and-go-down (arg)
647 "Comments and goes down ARG lines."
650 (comment-region (point-at-bol) (point-at-eol)) (error nil))
652 (if (> arg 1) (ff/comment-and-go-down (1- arg))))
654 (defun ff/uncomment-and-go-up (arg)
655 "Uncomments and goes up ARG lines."
658 (uncomment-region (point-at-bol) (point-at-eol)) (error nil))
660 (if (> arg 1) (ff/uncomment-and-go-up (1- arg))))
662 (define-key global-map [(shift down)] 'ff/comment-and-go-down)
663 (define-key global-map [(shift up)] 'ff/uncomment-and-go-up)
665 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
667 (defun ff/show-compilation-buffer-split-window ()
668 "Split the window vertically and show the compilation buffer in the newly created right one"
670 (show-buffer (split-window-right) "*compilation*")
673 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
674 ;; Counting various entities in text
675 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
677 (defun ff/word-occurences ()
678 "Display in a new buffer the list of words sorted by number of
682 (let ((buf (get-buffer-create "*word counting*"))
683 (map (make-sparse-keymap))
684 (nb (make-hash-table))
685 (st (make-hash-table))
688 ;; Collects all words in a hash table
691 (goto-char (point-min))
692 (while (re-search-forward "\\([\\-a-zA-Z\\\\]+\\)" nil t)
693 (let* ((s (downcase (match-string-no-properties 1)))
696 (puthash k (1+ (gethash k nb 0)) nb))))
698 ;; Creates the result buffer
700 (define-key map "q" 'kill-this-buffer)
703 (setq show-trailing-whitespace nil)
706 ;; Builds a list from the hash table
710 (setq result (cons (cons value (gethash key st)) result)))
713 ;; Sort and display it
716 (if (and (> (car x) 3)
717 ;; No leading backslash and at least four characters
718 (string-match "^[^\\]\\{4,\\}" (cdr x))
720 (insert (number-to-string (car x)) " " (cdr x) "\n")))
721 (sort result (lambda (a b) (> (car a) (car b)))))
723 ;; Adjust the window size and stuff
725 (fit-window-to-buffer (get-buffer-window buf))
727 (set-buffer-modified-p nil))
730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
732 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
736 (setq ps-print-color-p nil
737 ps-paper-type 'letter
739 ;; ps-top-margin (* 1.75 56.692)
740 ;; ps-left-margin 56.692
741 ;; ps-bottom-margin 56.692
742 ;; ps-right-margin 56.692
744 ;; Simple header. Remove that silly frame shadow.
746 ps-print-header-frame nil
747 ps-header-line-pad 0.3
748 ps-header-font-family 'Courier
749 ps-header-title-font-size '(8.5 . 10)
750 ;; ps-header-font-size '(6 . 7)
751 ps-header-font-size '(10 . 12)
752 ps-font-size '(7 . 8)
755 (ps-put 'ps-header-frame-alist 'back-color 1.0)
756 (ps-put 'ps-header-frame-alist 'shadow-color 1.0)
757 (ps-put 'ps-header-frame-alist 'border-color 0.0)
758 (ps-put 'ps-header-frame-alist 'border-width 0.0)
760 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
762 ;; http://blog.tuxicity.se/elisp/emacs/2010/03/26/rename-file-and-buffer-in-emacs.htm
764 (defun rename-file-and-buffer ()
765 "Renames current buffer and file it is visiting."
767 (let ((name (buffer-name))
768 (filename (buffer-file-name)))
769 (if (not (and filename (file-exists-p filename)))
770 (message "Buffer '%s' is not visiting a file!" name)
771 (let ((new-name (read-file-name "New name: " filename)))
772 (cond ((get-buffer new-name)
773 (message "A buffer named '%s' already exists!" new-name))
775 (rename-file name new-name 1)
776 (rename-buffer new-name)
777 (set-visited-file-name new-name)
778 (set-buffer-modified-p nil)))))))
780 (global-set-key (kbd "C-c r") 'rename-file-and-buffer)
782 (defun ff/non-existing-filename (dir prefix suffix)
783 "Returns a filename of the form DIR/PREFIX[.n].SUFFIX whose file does
786 (f (concat prefix suffix)))
787 (while (file-exists-p (concat dir "/" f))
789 f (concat prefix "." (prin1-to-string n) suffix)))
792 (defun ff/print-buffer-or-region-with-faces (&optional file)
794 ;; I am fed up with spell checking highlights
795 (when (and flyspell-mode
796 ;; (or ispell-minor-mode flyspell-mode)
797 (not (y-or-n-p "The spell checking is on, still print ? ")))
798 (error "Printing cancelled, the spell-checking is on"))
802 (ps-print-region-with-faces (region-beginning) (region-end) file)
804 (ps-print-buffer-with-faces file)))
806 (defun ff/print-to-file (file)
807 "Prints the region if selected or the whole buffer in postscript
812 "PS file: " "/tmp/" nil nil
813 (ff/non-existing-filename
815 (replace-regexp-in-string "[^a-zA-Z0-9_.-]" "_" (file-name-nondirectory
819 (ff/print-buffer-or-region-with-faces file))
821 (defun ff/print-to-printer ()
822 "Prints the region if selected or the whole buffer to a postscript
825 (message "Printing to '%s'" (getenv "PRINTER"))
826 (ff/print-buffer-or-region-with-faces))
828 ;; Can you believe it? There is a "print" key on PC keyboards ...
830 (define-key global-map [(print)] 'ff/print-to-file)
831 (define-key global-map [(shift print)] 'ff/print-to-printer)
833 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
834 ;; Dealing with the laptop battery
835 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
837 (defcustom ff/battery-dirs '("/sys/class/power_supply/BAT0")
838 "*Where to gather the battery information")
840 (defcustom ff/temperature-files '("/sys/class/thermal/thermal_zone0/temp"
841 "/sys/class/thermal/thermal_zone1/temp"
842 "/sys/class/thermal/thermal_zone2/temp"
843 "/sys/class/thermal/thermal_zone3/temp"
844 "/sys/class/thermal/thermal_zone4/temp"
845 "/sys/class/thermal/thermal_zone5/temp")
846 "*Where to gather the thermal information")
848 (defun ff/file-first-line (file)
850 (insert-file-contents-literally file)
851 (buffer-substring (point-at-bol) (point-at-eol))))
853 (defun ff/battery-discharging (l)
854 (and l (or (string= (ff/file-first-line (concat (car l) "/status")) "Discharging")
855 (ff/battery-discharging (cdr l)))))
857 ;; If there is one "Discharging" among the states of all the
858 ;; batteries, the global state is 'discharging. Otherwise, if there is
859 ;; a "Charging", the state is 'charging. If none is true, it is
861 (defun ff/battery-state (l)
863 (let ((u (ff/file-first-line (concat (car l) "/status"))))
864 (if (string= u "Discharging") 'discharging
865 (let ((s (ff/battery-state (cdr l))))
866 (if (eq s 'discharging) 'discharging
867 (if (or (eq s 'charging) (string= u "Charging"))
875 (defun ff/sum-values-from-files (list-files prefix)
880 (string-to-number (ff/file-first-line (format "%s/%s" f prefix)))
885 (defun ff/battery-percent ()
887 (/ (* 100 (ff/sum-values-from-files ff/battery-dirs "energy_now"))
888 (ff/sum-values-from-files ff/battery-dirs "energy_full"))
892 (defun ff/temp-info-string () (interactive)
898 (lambda (f) (string-to-number (ff/file-first-line f)))
899 ff/temperature-files))
903 (let ((s (format "%dC " temp)))
905 (propertize s 'face 'font-lock-warning-face)
914 (defun ff/battery-info-string () (interactive)
916 (pcase (ff/battery-state ff/battery-dirs)
917 ;; (`charging (format "c%d%%" (ff/battery-percent)))
918 ;; (`discharging (format "d%d%%" (ff/battery-percent)))
922 (let ((p (ff/battery-percent)))
924 (propertize (format "↑%d%%" p) 'face 'ff/battery-info-face)
925 (propertize (format "↑%d%%" p) 'face 'ff/battery-info-alarm-face))
930 (let ((p (ff/battery-percent)))
932 (propertize (format "↓%d%%" p) 'face 'ff/battery-info-face)
933 (propertize (format "↓%d%%" p) 'face 'ff/battery-info-alarm-face))
943 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
945 (defun ff/system-info () (interactive)
947 (let* ((buf (get-buffer-create "*system info*"))
948 (win (get-buffer-window buf))
949 (map (make-sparse-keymap)))
956 (define-key map "q" 'kill-this-buffer)
959 (setq show-trailing-whitespace nil)
962 (let ((highlight nil))
966 (if (setq highlight (not highlight))
968 (with-temp-buffer (apply 'call-process x)
970 'face '(:background "#d0d0ff"))
971 (with-temp-buffer (apply 'call-process x)
977 ("hostname" nil t nil "-f")
979 ("df" nil t nil "-h")
982 ("ssh-add" nil t nil "-l")
985 (goto-char (point-min))
986 (while (re-search-forward "^$" nil t) (backward-delete-char 1))
988 (fit-window-to-buffer (get-buffer-window buf))
990 (set-buffer-modified-p nil)
995 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
997 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1001 display-time-interval 10 ;; Check every 10s
1003 display-time-string-forms `(
1009 ,@(when (ff/temp-info-string)
1010 '((ff/temp-info-string)))
1012 ,@(when (ff/battery-info-string)
1013 '((ff/battery-info-string)))
1016 ;; (ff/battery-info-string)
1017 ;; 'face 'ff/battery-info-face)))
1023 24-hours ":" minutes
1029 'face 'ff/date-info-face)
1033 ;; display-time-format "%b %a %e %H:%M"
1034 ;; display-time-mail-face nil
1037 ;; Show the time, mail and stuff
1040 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1041 ;; Moving through buffers
1042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1044 (defun ff/next-buffer ()
1045 "Switches to the next buffer in cyclic order."
1047 (let ((buffer (current-buffer)))
1048 (switch-to-buffer (other-buffer buffer))
1049 (bury-buffer buffer)))
1051 (defun ff/prev-buffer ()
1052 "Switches to the previous buffer in cyclic order."
1054 (let ((list (nreverse (buffer-list)))
1056 (while (and (not found) list)
1057 (let ((buffer (car list)))
1058 (if (and (not (get-buffer-window buffer))
1059 (not (string-match "\\` " (buffer-name buffer))))
1060 (setq found buffer)))
1061 (setq list (cdr list)))
1062 (switch-to-buffer found)))
1064 ;; (define-key global-map [?\C-x right] 'ff/next-buffer)
1065 ;; (define-key global-map [?\C-x left] 'ff/prev-buffer)
1066 ;; (define-key global-map [?\M-\]] 'ff/next-buffer)
1067 ;; (define-key global-map [?\M-\[] 'ff/prev-buffer)
1069 (define-key global-map [(meta right)] 'ff/next-buffer)
1070 (define-key global-map [(meta left)] 'ff/prev-buffer)
1072 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1073 ;; There is actually a decent terminal emulator in emacs!
1074 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1078 (defun ff/kill-associated-buffer (process str) (interactive)
1079 (let ((buffer (process-buffer process)))
1080 (kill-buffer buffer))
1081 (message "Process finished (%s)" (replace-regexp-in-string "\n$" "" str)))
1083 (defun ff/kill-associated-buffer-and-delete-windows (process str) (interactive)
1084 (let ((buffer (process-buffer process)))
1085 (delete-windows-on buffer)
1086 (kill-buffer buffer))
1087 (message "Process finished (%s)" (replace-regexp-in-string "\n$" "" str)))
1089 (defun ff/shell-new-buffer (buffername program &rest param)
1090 "Start a terminal-emulator in a new buffer with the shell PROGRAM,
1091 optionally invoked with the parameters PARAM. The process associated
1092 to the shell can be killed without query."
1099 (while (get-buffer (concat "*" bn "*"))
1101 bn (format "%s<%d>" buffername n)))
1103 (set-buffer (apply 'make-term (append (list bn program nil) param)))
1105 (setq show-trailing-whitespace nil)
1107 (message "C-c C-k term-char-mode, C-c C-j term-line-mode. \
1108 In line mode: M-p previous line, M-n next line.")
1110 ;; A standard setup of the face above is not enough, I have to
1111 ;; force them here. Since I have a gray90 background, I like
1116 '((term-green :foreground "green3")
1117 (term-cyan :foreground "cyan3")
1118 (term-default-fg-inv :foreground "gray90" :background "black")
1121 (term-set-escape-char ?\C-x)
1123 ;; I like the shell buffer and windows to be deleted when the
1124 ;; shell process terminates. It's a bit of a mess to acheive this.
1126 (let ((process (get-buffer-process (current-buffer))))
1127 (process-kill-without-query process)
1128 (set-process-sentinel process
1129 ;; 'ff/kill-associated-buffer-and-delete-windows
1130 'ff/kill-associated-buffer
1133 ;; (switch-to-buffer-other-window (concat "*" bn "*"))
1134 (switch-to-buffer (concat "*" bn "*"))
1137 (defcustom ff/default-bash-commands '("ssh")
1138 "*List of commands to be used for completion when invoking a new
1139 bash shell with `ff/bash-new-buffer'.")
1141 (defun ff/bash-new-buffer (universal)
1142 "Starts a bash in a new buffer. When invoked with a universal
1143 argument, asks for a command to execute in that bash shell. The list
1144 of commands in `ff/default-bash-commands' is used for auto-completion"
1148 (let ((cmd (completing-read
1150 (mapcar (lambda (x) (cons x t)) ff/default-bash-commands))))
1151 (ff/shell-new-buffer cmd "/bin/bash" "-c" cmd))
1153 (ff/shell-new-buffer "bash" "/bin/bash")))
1155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1159 (setq ;; Always follow links if the file is under version control
1160 vc-follow-symlinks t
1163 (when (load "vc-git" nil t)
1164 (add-to-list 'vc-handled-backends 'GIT))
1166 ;; alarm-vc.el is one of my own scripts, check my web page
1168 (when (ff/load-or-alert "alarm-vc" t)
1169 (setq alarm-vc-mode-exceptions "^VM"))
1171 (when (ff/load-or-alert "git")
1172 (setq git-show-unknown nil)
1175 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1176 ;; Makes .sh and others files executable automagically
1177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1179 ;; Please consider the security-related consequences of using it
1181 ;; (defun ff/make-shell-scripts-executable (&optional filename)
1182 ;; (setq filename (or filename (buffer-name)))
1183 ;; (when (and (string-match "\\.sh$\\|\\.pl$\\|\\.rb" filename)
1184 ;; (not (file-executable-p filename))
1186 ;; (set-file-modes filename 493)
1187 ;; (message "Made %s executable" filename)))
1189 ;; (add-hook 'after-save-hook 'ff/make-shell-scripts-executable)
1191 (add-hook 'after-save-hook
1192 'executable-make-buffer-file-executable-if-script-p)
1194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1195 ;; Cool stuff to navigate in emacs-lisp sources
1196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1200 (defun ff/goto-function-definition (&optional goback)
1201 "Go directly to the definition of the function at point. With
1202 goback argument, go back where we were."
1205 (if (not (and (boundp 'goto-function-history) goto-function-history))
1206 (error "We were nowhere, buddy")
1207 (message "Come back")
1208 (switch-to-buffer (car (car goto-function-history)))
1209 (goto-char (cdr (car goto-function-history)))
1210 (setq goto-function-history (cdr goto-function-history)))
1212 (let ((function (function-called-at-point)))
1214 (let ((location (find-function-search-for-symbol
1216 (symbol-file function))))
1217 (setq goto-function-history
1218 (cons (cons (current-buffer) (point))
1219 (and (boundp 'goto-function-history)
1220 goto-function-history)))
1221 (pop-to-buffer (car location))
1222 (goto-char (cdr location)))))))
1224 (define-key global-map [(meta g)] 'ff/goto-function-definition)
1225 (define-key global-map [(meta G)] (lambda () (interactive)
1226 (ff/goto-function-definition t)))
1228 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1230 ;; (setq python-indent-offset 4)
1232 ;; (define-key python-mode-map [(shift right)] 'python-indent-shift-right)
1233 ;; (define-key python-mode-map [(shift left)] 'python-indent-shift-left)
1234 ;; (define-key python-mode-map [(shift right)] 'indent-rigidly-right-to-tab-stop)
1235 ;; (define-key python-mode-map [(shift left)] 'indent-rigidly-left-to-tab-stop)
1239 (defun ff/git-pull-push (universal) (interactive "P")
1240 (when universal (shell-command "git commit -a -m \"Update.\"" nil))
1241 (message "git pull / push ...")
1242 (async-shell-command "git remote get-url origin && git pull && git push" nil)
1245 (defun ff/git-pull () (interactive)
1246 (message "git pull ...")
1247 (shell-command "git pull" nil)
1250 (define-key global-map [(control x) (v) (p)] 'ff/git-pull-push)
1251 (define-key global-map [(control x) (v) (P)] 'ff/git-pull)
1253 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1254 ;; The big stuff (bbdb, mailcrypt, etc.)
1255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1257 (setq bbdb-file "~/private/bbdb")
1259 (when (file-exists-p bbdb-file)
1261 ;; Failsafe version if we can't load bbdb
1262 (defun ff/explicit-name (email) email)
1264 (when (with-no-warnings (ff/load-or-alert "bbdb"))
1267 ;; Stop asking (if not t or nil, will not ask)
1268 bbdb-offer-save 'never
1269 ;; I hate when bbdb decides to mess up my windows
1271 ;; I have no problem with bbdb asking me if the sender email
1272 ;; does not match exactly the address we have in the database
1273 bbdb-quiet-about-name-mismatches 0
1274 ;; I have european friends, too
1275 bbdb-north-american-phone-numbers-p nil
1276 ;; To cycle through all possible addresses
1277 bbdb-complete-name-allow-cycling t
1278 ;; Cycle with full names only, not through all net-addresses alone too
1279 bbdb-dwim-net-address-allow-redundancy t
1280 ;; Do not add new addresses automatically
1281 bbdb-always-add-addresses nil
1284 (defface ff/known-address-face
1285 '((t (:foreground "blue2")))
1286 "The face to display known mail identities.")
1288 (defface ff/unknown-address-face
1289 '((t (:foreground "gray50")))
1290 "The face to display unknown mail identities.")
1292 (defun ff/explicit-name (email)
1293 "Returns a string identity for the first address in EMAIL. The
1294 identity is taken from bbdb if possible or from the address itself
1295 with mail-extract-address-components. The suffix \"& al.\" is added if
1296 there are more than one address.
1298 If no bbdb record is found, the name is propertized with the face
1299 ff/unknown-address-face. If a record is found and contains a note
1300 'face, the associated face is used, otherwise
1301 ff/known-address-face is used."
1304 (let* ((data (mail-extract-address-components email))
1307 (record (bbdb-search-simple nil net)))
1312 (propertize (bbdb-record-name record)
1314 (or (cdr (assoc 'face
1315 (bbdb-record-raw-notes record)))
1316 'ff/known-address-face))
1318 (propertize (or (and data (concat "<" net ">"))
1320 'face 'ff/unknown-address-face)
1322 (if (string-match "," (mail-strip-quoted-names email)) " & al.")
1326 (ff/configure-faces '((ff/robot-address-face :foreground "green4")
1327 (ff/personal-address-face :foreground "dark magenta" :weight 'bold)
1328 (ff/important-address-face :foreground "red3"
1335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1336 ;; An encrypted file to put secure stuff (passwords, ...)
1337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1339 (setq ff/secure-note-file "~/private/secure-notes.gpg")
1341 ;; (when (ff/load-or-alert "mailcrypt")
1342 ;; (mc-setversion "gpg")
1343 ;; ;; Keep the passphrase for 10min
1344 ;; (setq mc-passwd-timeout 600
1345 ;; ff/secure-note-file "~/private/secure-notes.gpg")
1348 (defface ff/secure-date
1349 '((t (:background "white" :weight bold)))
1350 "The face to display the dates in the modeline.")
1352 (defun ff/secure-note-add () (interactive)
1355 (let ((b (find-buffer-visiting ff/secure-note-file)))
1356 (and b (switch-to-buffer b)))
1357 (find-file ff/secure-note-file)
1358 ;; Adds a new entry (i.e. date and a bunch of empty lines)
1359 (goto-char (point-min))
1361 (format-time-string "%Y %b %d %H:%M:%S" (current-time))
1366 ;; Colorizes the dates
1369 (goto-char (point-min))
1370 (while (re-search-forward
1371 "^-- [0-9]+ [a-z]+ [0-9]+ [0-9]+:[0-9]+:[0-9]+ -+$"
1373 (add-text-properties
1374 (match-beginning 0) (1+ (match-end 0))
1375 '(face ff/secure-date rear-nonsticky t))))
1377 (set-buffer-modified-p nil)
1378 (setq buffer-undo-list nil)
1381 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1383 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1385 (setq ;; For french, aspell is far better than ispell
1386 ispell-program-name "aspell"
1387 ;; To avoid ispell errors in figure filenames, labels, references.
1388 ;; ispell-tex-skip-alists
1390 ;; (append (car ispell-tex-skip-alists)
1391 ;; '(("\\\\citep" ispell-tex-arg-end) ;; JMLR
1392 ;; ("\\\\cite" ispell-tex-arg-end)
1393 ;; ("\\\\nocite" ispell-tex-arg-end)
1394 ;; ("\\\\includegraphics" ispell-tex-arg-end)
1395 ;; ("\\\\author" ispell-tex-arg-end)
1396 ;; ("\\\\ref" ispell-tex-arg-end)
1397 ;; ("\\\\label" ispell-tex-arg-end)
1399 ;; (cadr ispell-tex-skip-alists))
1401 ;; So that reftex follows the text when moving in the summary
1402 reftex-toc-follow-mode nil
1403 ;; So that reftex visits files to follow
1404 reftex-revisit-to-follow t
1407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1408 ;; Used in a \includegraphics runs xfig with the corresponding .fig
1409 ;; file or gimp with the corresponding bitmap picture
1410 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1412 (defun ff/run-eps-edition (prefix rules &optional force)
1414 (let ((filename (concat prefix (car (car rules)))))
1415 (if (or force (file-exists-p filename))
1416 (start-process "latex-eps-editor" nil (cdr (car rules)) filename)
1417 (ff/run-eps-edition prefix (cdr rules) force)))
1418 (message "No original file found for %seps" prefix)))
1420 (defcustom ff/xdvi-for-latex-options nil
1421 "*Options to pass to xdvi when invoking `ff/run-viewer'")
1423 (defun ff/run-viewer (universal)
1425 "Starts an editor for the .eps at point (either xfig or gimp,
1426 depending with the original file it can find), or starts xdvi for
1427 the current .tex if no .eps is found at point. When run with a
1428 universal argument starts xfig even if the .fig does not exist"
1432 (if (and (save-excursion
1433 (and (re-search-backward "{" (point-at-bol) t)
1434 (or (re-search-forward "{\\([^{}]*.\\)eps}" (point-at-eol) t)
1435 (re-search-forward "{\\([^{}]*.\\)pdf}" (point-at-eol) t)
1436 (re-search-forward "{\\([^{}]*.\\)pdf_t}" (point-at-eol) t)
1437 (re-search-forward "{\\([^{}]*.\\)png}" (point-at-eol) t)
1438 (re-search-forward "{\\([^{}]*.\\)jpg}" (point-at-eol) t)
1440 (and (<= (match-beginning 1) (point))
1441 (>= (match-end 1) (- (point) 2))))
1443 (ff/run-eps-edition (match-string-no-properties 1)
1446 ("png" . "gimp") ("pgm" . "gimp") ("ppm" . "gimp")
1447 ("svg" . "inkscape"))
1450 (if (not (and (buffer-file-name) (string-match "\\(.*\\)\.tex$"
1451 (buffer-file-name))))
1452 (message "Not a latex file!")
1453 (condition-case nil (kill-process xdvi-process) (error nil))
1454 (let ((dvi-name (concat (match-string 1 (buffer-file-name)) ".dvi")))
1455 (if (not (file-exists-p dvi-name)) (error "Can not find %s !" dvi-name)
1456 (message "Starting xdvi with %s" dvi-name)
1457 (setq xdvi-process (apply 'start-process
1458 (append '("xdvi-for-latex" nil "xdvi")
1459 ff/xdvi-for-latex-options
1461 (process-kill-without-query xdvi-process))))
1464 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1467 ;; (defadvice tex-file (around ff/set-my-own-tex-command () activate)
1468 ;; (let ((ff/window-configuration-before-compilation (current-window-configuration)))
1470 ;; (set-window-configuration ff/window-configuration-before-compilation)
1474 ;; This is a bit hardcore, but really I can't bear the superscripts in
1475 ;; my emacs window and could not find another way to deactivate them.
1478 (defun tex-font-lock-suscript (pos) ())
1480 ;; Automagically add the frame numbers in comments in a beamer file
1482 (defun ff/number-beamer-frames ()
1483 "Add the frame numbers as comments after each \begin{frame}"
1490 ;; First, clean-up existing numbering
1491 (goto-char (point-min))
1492 (while (re-search-forward "^ *\\\\begin{frame}.*\\( %% frame [0-9]* / [0-9]*\\)$" nil t)
1493 (kill-region (match-beginning 1) (match-end 1))
1496 ;; Then count the total number of frames
1497 (goto-char (point-min))
1498 (while (re-search-forward "^ *\\\\begin{frame}" nil t)
1499 (setq total (+ total 1))
1502 ;; Then, add the updated numbers
1503 (goto-char (point-min))
1504 (while (re-search-forward "^ *\\\\begin{frame}" nil t)
1505 (move-end-of-line 1)
1506 (insert " %% frame " (prin1-to-string n) " / " (prin1-to-string total))
1512 (message "Added frame numbers in comments.")
1515 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1516 ;; Prevents many errors from beeping and makes the others play a nifty
1518 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1520 (defun ff/ring-bell ()
1521 (unless (memq this-command
1523 abort-recursive-edit
1526 backward-delete-char-untabify
1527 delete-backward-char
1528 minibuffer-complete-and-exit
1529 previous-line next-line
1530 backward-char forward-char
1531 scroll-up scroll-down
1532 enlarge-window-horizontally shrink-window-horizontally
1533 enlarge-window shrink-window
1536 ;; (message "command [%s]" (prin1-to-string this-command))
1537 ;; (ff/play-sound-async "~/local/sounds/short_la.wav")
1540 ;; (setq ring-bell-function 'ff/ring-bell)
1542 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1543 ;; Past the content of the url currently in the kill-ring with
1545 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1547 (defun ff/insert-url (&optional url)
1548 "Downloads an URL with lynx and inserts it after the point."
1549 (interactive "MUrl: ")
1551 (message "Inserting %s" url)
1552 (insert (concat "from: " url "\n\n"))
1553 ;; (call-process "lynx" nil t nil "-nolist" "-dump" url))
1554 (call-process "w3m" nil t nil "-dump" url))
1557 ;; (define-key global-map [(shift mouse-2)]
1558 ;; (lambda () (interactive) (ff/insert-url (current-kill 0))))
1560 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1561 ;; Trying to deal with cut-paste
1563 (setq x-select-enable-clipboard t)
1564 (setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
1565 (define-key global-map [(shift mouse-2)] 'clipboard-yank)
1567 ;; lookup-dict is one of my own scripts, check my web page
1569 (when (ff/load-or-alert "lookup-dict" t)
1570 (define-key global-map [(control \?)] 'lookup-dict))
1572 ;; (defun ff/generate-password () (interactive)
1573 ;; (let ((c "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-"))
1574 ;; (nth (random (length c)) c))
1576 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1577 ;; Automatization of things I do often
1578 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1580 (defun ff/snip () (interactive)
1581 (let ((start (condition-case nil (region-beginning) (error (point))))
1582 (end (condition-case nil (region-end) (error (point)))))
1584 (insert "----------------------------- snip snip -----------------------------\n")
1586 (insert "----------------------------- snip snip -----------------------------\n")
1589 (defun ff/start-latex ()
1590 "Adds all that stuff to start a new LaTeX document."
1592 (goto-char (point-min))
1593 (insert "%% -*- mode: latex; mode: reftex; mode: flyspell; coding: utf-8; tex-command: \"pdflatex.sh\" -*-
1595 \\documentclass[12pt,a4paper,twoside]{article}
1596 \\usepackage[a4paper,top=2.5cm,bottom=2cm,left=2.5cm,right=2.5cm]{geometry}
1597 \\usepackage[utf8]{inputenc}
1598 \\usepackage{amsmath}
1599 \\usepackage{amssymb}
1600 \\usepackage[pdftex]{graphicx}
1601 \\usepackage{microtype}
1602 \\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue,citecolor=blue]{hyperref}
1605 \\setlength{\\parindent}{0cm}
1606 \\setlength{\\parskip}{12pt}
1607 \\renewcommand{\\baselinestretch}{1.3}
1608 %\\setlength{\\tabcolsep}{0pt}
1609 %\\renewcommand{\\arraystretch}{1.0}
1611 \\def\\argmax{\\operatornamewithlimits{argmax}}
1612 \\def\\argmin{\\operatornamewithlimits{argmin}}
1614 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1616 %%\\usepackage[default]{opensans}
1617 %%\\usepackage{cmbright}
1618 %%\\renewcommand{\\familydefault}{fos}
1619 %%\\renewcommand{\\seriesdefault}{l}
1620 %%\\renewcommand{\\bfdefault}{sb}
1621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1622 %% The \\todo command
1623 \\newcounter{nbdrafts}
1624 \\setcounter{nbdrafts}{0}
1626 \\newcommand{\\checknbdrafts}{
1627 \\ifnum \\thenbdrafts > 0
1628 \\@latex@warning@no@line{*WARNING* The document contains \\thenbdrafts \\space draft note(s)}
1630 \\newcommand{\\todo}[1]{\\addtocounter{nbdrafts}{1}{\\color{red} #1}}
1632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1638 (goto-char (point-max))
1645 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1647 (defun ff/add-copyrights ()
1648 "Adds two lines for the (C) at the beginning of current buffer."
1651 (let ((comment-style 'plain))
1653 (goto-char (point-min))
1655 ;; If this is a script, put the copyrights after the first line
1657 (when (re-search-forward "^#!" nil t)
1661 (let ((start (point))
1662 (comment-style 'box))
1666 "\nSTART_IP_HEADER\n"
1668 (when (boundp 'user-full-name)
1669 (concat "\nWritten by " user-full-name "\n"))
1671 (when (boundp 'user-mail-address)
1672 (concat "Contact <" user-mail-address "> for comments & bug reports\n"))
1677 (comment-region start (point)))
1681 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1683 (defun ff/remove-ip-header () (interactive)
1685 (goto-char (point-min))
1686 (when (and (re-search-forward "START_IP_HEADER" nil t)
1687 (re-search-forward "END_IP_HEADER" nil t))
1691 (defun ff/add-gpl ()
1692 "Adds the GPL statements at the beginning of current buffer."
1694 (let ((comment-style 'box)
1699 ;; This program is free software; you can redistribute it and/or
1700 ;; modify it under the terms of the GNU General Public License
1701 ;; version 2 as published by the Free Software Foundation.
1703 ;; This program is distributed in the hope that it will be useful, but
1704 ;; WITHOUT ANY WARRANTY\; without even the implied warranty of
1705 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1706 ;; General Public License for more details.
1712 This program is free software: you can redistribute it and/or modify
1713 it under the terms of the version 3 of the GNU General Public License
1714 as published by the Free Software Foundation.
1716 This program is distributed in the hope that it will be useful, but
1717 WITHOUT ANY WARRANTY; without even the implied warranty of
1718 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1719 General Public License for more details.
1721 You should have received a copy of the GNU General Public License
1722 along with this program. If not, see <http://www.gnu.org/licenses/>.
1725 (when (boundp 'user-full-name)
1726 (concat "Written by and Copyright (C) " user-full-name "\n"))
1728 (when (boundp 'user-mail-address)
1729 (concat "Contact <" user-mail-address "> for comments & bug reports\n"))
1737 (goto-char (point-min))
1739 ;; If this is a script, put the gpl after the first line
1740 (when (re-search-forward "^#!" nil t)
1744 (let ((start (point)))
1746 (comment-region start (point)))
1749 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1751 (defun ff/start-c ()
1752 "Adds the header to start a C program."
1754 ;; (beginning-of-buffer)
1760 int main(int argc, char **argv) {
1767 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1769 (defun ff/start-c++ ()
1770 "Adds the header to start a C++ program."
1772 ;; (beginning-of-buffer)
1781 using namespace std;
1783 int main(int argc, char **argv) {
1790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1792 (defun ff/headerize ()
1793 "Adds the #define HEADER_H, etc."
1795 (let ((flag-name (replace-regexp-in-string
1797 (upcase (file-name-nondirectory (buffer-file-name))))))
1798 (goto-char (point-max))
1799 (insert "\n#endif\n")
1800 (goto-char (point-min))
1801 (insert (concat "#ifndef " flag-name "\n"))
1802 (insert (concat "#define " flag-name "\n"))
1806 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1808 (defun ff/start-lua ()
1809 "Adds all the stuff to start a new lua file"
1811 (goto-char (point-min))
1812 (insert "#!/usr/bin/env luajit
1823 (defun ff/start-python ()
1824 "Adds all the stuff to start a new python file"
1826 (goto-char (point-min))
1827 (insert "#!/usr/bin/env python
1831 import torch, torchvision
1833 from torch import nn
1834 from torch.nn import functional as F
1841 (defun ff/start-html ()
1842 "Adds all that stuff to start a new HTML file."
1844 (goto-char (point-min))
1845 (insert "<?xml version=\"1.0\" encoding=\"utf-8\"?>
1846 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1848 <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
1851 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
1853 <style type=\"text/css\">
1862 (goto-char (point-max))
1870 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1872 ;; Insert a line showing all the variables written on the current line
1873 ;; and separated by commas
1875 (defun ff/cout-var (arg)
1876 "Invoked on a line with a list of variables names,
1877 it inserts a line which displays their values in cout, or cerr if
1878 the function is invoked with a universal arg"
1880 (let ((line (if arg "cerr" "cout")))
1881 (goto-char (point-at-bol))
1882 ;; To match '[', put it as the first char in the [...]
1883 (while (re-search-forward "\\([][a-zA-Z0-9_.:\(\)]+\\)" (point-at-eol) t)
1885 (concat line " << \" "
1886 (match-string 1) " = \" << " (match-string 1))))
1887 (goto-char (point-at-bol))
1889 (insert line " << endl\;\n")
1890 (indent-region (point-at-bol 0) (point-at-eol 0) nil)
1893 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1895 (defun ff/clean-article ()
1896 "Cleans up an article by removing the leading blanks on each line
1897 and refilling all the paragraphs."
1899 (let ((fill-column 92))
1900 (goto-char (point-min))
1901 (while (re-search-forward "^\\ +" nil t)
1902 (replace-match "" nil nil))
1903 (fill-individual-paragraphs (point-min) (point-max) t)))
1905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1907 (defun ff/start-slide (universal)
1912 (insert "\\end{frame}
1914 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1917 (save-excursion (insert "}{}
1922 (insert "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1926 (save-excursion (insert "}{}
1937 (define-key latex-mode-map [(meta S)] 'ff/start-slide)
1938 (define-key latex-mode-map [(control c) (control a)] 'align-current)
1939 (define-key latex-mode-map [(control end)] 'tex-close-latex-block)
1940 (define-key latex-mode-map [(control tab)] 'ispell-complete-word)
1941 (copy-face 'default 'tex-verbatim)
1942 ;; (ff/configure-faces '((tex-verbatim :background "gray95")))
1945 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1947 (defun ff/start-test-code ()
1949 (let ((start (point)))
1951 { // ******************************* START ***************************
1952 #warning Test code added on "
1953 (format-time-string "%04Y %b %02d %02H:%02M:%02S" (current-time))
1956 } // ******************************** END ****************************
1959 (indent-region start (point) nil))
1963 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1965 (defun ff/code-to-html () (interactive)
1967 (narrow-to-region (region-beginning) (region-end))
1968 (replace-string "\"" """ nil (point-min) (point-max))
1969 (replace-string " " " " nil (point-min) (point-max))
1970 (replace-string ">" ">" nil (point-min) (point-max))
1971 (replace-string "<" "<" nil (point-min) (point-max))
1972 (replace-string "\e" "^[" nil (point-min) (point-max))
1973 (replace-string "
\7f" "^?" nil (point-min) (point-max))
1974 (replace-string "
\1f" "^_" nil (point-min) (point-max))
1975 (replace-regexp "$" "<br />" nil (point-min) (point-max))
1979 (defun ff/downcase-html-tags () (interactive)
1981 (beginning-of-buffer)
1982 (while (re-search-forward "<\\([^>]+\\)>" nil t)
1983 (downcase-region (match-beginning 1) (match-end 1)))
1987 ;; If we enter html mode and there is no makefile around, create a
1988 ;; compilation command with tidy (this is cool stuff)
1990 (add-hook 'html-mode-hook
1992 (unless (or (not (buffer-file-name))
1993 (file-exists-p "makefile")
1994 (file-exists-p "Makefile"))
1995 (set (make-local-variable 'compile-command)
1996 (let ((fn (file-name-nondirectory buffer-file-name)))
1997 (format "tidy -utf8 %s > /tmp/%s" fn fn))))))
1999 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2001 (defun ff/count-words-region (beginning end)
2002 "Print number of words in the region.
2003 Words are defined as at least one word-constituent character
2004 followed by at least one character that is not a
2005 word-constituent. The buffer's syntax table determines which
2006 characters these are."
2009 (message "Counting words in region ... ")
2011 (goto-char beginning)
2013 (while (< (point) end)
2014 (re-search-forward "\\w+\\W+")
2015 (setq count (1+ count)))
2016 (cond ((zerop count) (message "The region does NOT have any word."))
2017 ((= 1 count) (message "The region has 1 word."))
2018 (t (message "The region has %d words." count))))))
2020 ;; (add-hook 'html-mode-hook 'flyspell-mode)
2022 (defun ff/tidy-html ()
2023 "Run tidy in on the content of the current buffer, put the result in
2026 (call-process-region (point-min) (point-max)
2029 (list nil (make-temp-file "/tmp/tidy-html."))))
2031 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2033 ;; Create the adequate embryo of a file if it does not exist
2035 (defun ff/start-file () (interactive)
2036 (let ((filename (buffer-file-name)))
2039 (when (string-match "\\.sh$" filename)
2041 (insert "#!/bin/bash\n\nset -e\nset -o pipefail\n\n")
2043 (ff/add-copyrights))
2046 (when (string-match "\\.lua$" filename)
2051 (when (string-match "\\.py$" filename)
2056 (when (string-match "\\.html$" filename)
2062 (when (string-match "\\.h$" filename)
2073 (when (string-match "\\.c$" filename)
2078 (when (string-match "\.\\(cc\\|cpp\\)$" filename)
2081 (let ((headername (replace-regexp-in-string "\\.\\(cc\\|cpp\\)$" ".h"
2083 (if (file-exists-p headername)
2084 (insert (concat "\n#include \"" (file-name-nondirectory headername) "\"\n"))
2088 (when (string-match "\\.tex$" filename)
2093 (set-buffer-modified-p nil)
2096 (if (>= emacs-major-version 22)
2097 (add-to-list 'find-file-not-found-functions 'ff/start-file)
2098 (add-to-list 'find-file-not-found-hooks 'ff/start-file))
2100 (when (>= emacs-major-version 24)
2101 (define-obsolete-function-alias 'make-local-hook 'ignore "21.1")
2102 (setq send-mail-function 'sendmail-send-it) ;; emacs 24.x stuff
2105 '(diff-added ((default (:background "gray90" :foreground "green4" :weight bold))))
2106 '(diff-removed ((default (:background "gray90" :foreground "red2" :weight bold))))
2107 '(diff-changed ((default (:background "gray90" :foreground "blue" :weight bold))))
2111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2113 (define-key global-map [f8] 'ff-find-other-file)
2114 (define-key global-map [(shift f8)] (lambda () (interactive) (ff-find-other-file t)))
2116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2117 ;; The compilation hacks
2118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2120 ;; If we enter c++ mode and there is no makefile around, we create a
2121 ;; make command on the fly for the specific object file
2123 (add-hook 'c++-mode-hook
2125 (unless (or (file-exists-p "makefile") (file-exists-p "Makefile"))
2126 (set (make-local-variable 'compile-command)
2129 (file-name-sans-extension
2130 (file-name-nondirectory buffer-file-name)))))))
2132 ;; <f1> runs the compilation according to the compile-command (and
2133 ;; thus does not ask any confirmation), shows the compilation buffer
2134 ;; during compilation and delete all windows showing the compilation
2135 ;; buffer if the compilation ends with no error
2137 ;; <shift-f1> asks for a compilation command and runs the compilation
2138 ;; but does not restore the window configuration (i.e. the compilation
2139 ;; buffer's window will still be visible, as usual)
2141 ;; <f2> goes to the next compilation error (as C-x ` does on the
2142 ;; standard configuration)
2144 (defun ff/restore-windows-if-no-error (buffer msg)
2145 "Delete the windows showing the compilation buffer if msg
2146 matches \"^finished\"."
2148 (when (string-match "^finished" msg)
2149 ;; (delete-windows-on buffer)
2150 (if (boundp 'ff/window-configuration-before-compilation)
2151 (set-window-configuration ff/window-configuration-before-compilation))
2155 (add-to-list 'compilation-finish-functions 'ff/restore-windows-if-no-error)
2157 (defun ff/fast-compile ()
2158 "Compiles without asking anything."
2160 (let ((compilation-read-command nil))
2161 (setq ff/window-configuration-before-compilation (current-window-configuration))
2162 (compile compile-command)))
2164 (setq compilation-read-command t
2165 compile-command "make -j -k"
2166 ;; compile-history '("make clean" "make DEBUG=yes -j -k" "make -j -k")
2169 (defun ff/universal-compile (universal) (interactive "P")
2170 (funcall (or (cdr (assoc major-mode
2172 (latex-mode . tex-file)
2173 (html-mode . browse-url-of-buffer)
2174 ;; Here you can add other mode -> compile command
2176 'ff/fast-compile ;; And this is the failsafe
2179 (define-key global-map [f1] 'ff/universal-compile)
2180 (define-key global-map [(shift f1)] 'compile)
2181 (define-key global-map [f2] 'next-error)
2183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2187 ;; (when (ff/load-or-alert "flyspell-timer" t)
2188 ;; (add-hook 'flyspell-mode-hook 'flyspell-timer-ensure-idle-timer))
2190 (defun ff/start-flyspell () (interactive)
2193 ;; (flyspell-incorrect :background "#ff0000" :foreground "black")
2194 ;; (flyspell-duplicate :background "#ff9000" :foreground "black")
2195 (flyspell-incorrect :foreground "#ff0000" :weight 'bold)
2196 (flyspell-duplicate :foreground "#ff9000" :weight 'bold)
2198 ;; (flyspell-buffer)
2201 (add-hook 'flyspell-mode-hook 'ff/start-flyspell)
2203 (defun ff/pick-dictionnary () (interactive)
2204 (when (and (boundp 'flyspell-mode) flyspell-mode)
2205 (if (and current-input-method (string-match "latin" current-input-method))
2206 (ispell-change-dictionary "francais")
2207 (ispell-change-dictionary "american"))
2208 ;; (flyspell-buffer)
2212 (defadvice toggle-input-method (after ff/switch-dictionnary nil activate)
2213 (ff/pick-dictionnary))
2215 ;; (add-hook 'message-mode-hook 'auto-fill-mode)
2216 ;; (add-hook 'message-mode-hook 'flyspell-mode)
2218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2219 ;; Delete all windows which are in the same "column", which means
2220 ;; whose xmin and xmax are bounded by the xmin and xmax of the
2221 ;; currently selected column
2222 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2224 ;; This is from emacs23 ! better than my old ff/delete-other-windows-in-column
2226 (unless (fboundp 'delete-other-windows-vertically)
2228 (defun delete-other-windows-vertically (&optional window)
2229 "Delete the windows in the same column with WINDOW, but not WINDOW itself.
2230 This may be a useful alternative binding for \\[delete-other-windows]
2231 if you often split windows horizontally."
2233 (let* ((window (or window (selected-window)))
2234 (edges (window-edges window))
2236 (while (not (eq (setq w (next-window w 1)) window))
2237 (let ((e (window-edges w)))
2238 (when (and (= (car e) (car edges))
2239 (= (caddr e) (caddr edges)))
2241 (mapc 'delete-window delenda)))
2244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2246 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2250 (defun ff/entropy (l)
2255 (* (- x) (/ (log x) (log 2)))))
2260 ;; Usefull to deal with results in latex files
2262 (defun ff/round-floats-in-region () (interactive)
2265 (narrow-to-region (region-beginning) (region-end))
2266 (error (thing-at-point 'word)))
2268 (goto-char (point-min))
2269 (while (re-search-forward "[0-9\.]+" nil t)
2270 (let ((value (string-to-number (buffer-substring (match-beginning 0) (match-end 0)))))
2271 (delete-region (match-beginning 0) (match-end 0))
2272 (insert (format "%0.1e" value)))))))
2274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2280 (define-key global-map [(shift iso-lefttab)] 'ispell-complete-word)
2281 ;; shift-tab going backward is kind of standard
2282 (define-key Info-mode-map [(shift iso-lefttab)] 'Info-prev-reference)
2284 ;; (define-key global-map [(control x) (control a)] 'auto-fill-mode)
2286 ;; Put back my keys, you thief!
2287 (define-key global-map [(home)] 'beginning-of-buffer)
2288 (define-key global-map [(end)] 'end-of-buffer)
2289 ;; (define-key global-map [(insertchar)] 'overwrite-mode)
2290 (define-key global-map [(delete)] 'delete-char)
2292 ;; Cool shortcuts to move to the end / beginning of block keen
2293 (define-key global-map [(control right)] 'forward-sexp)
2294 (define-key global-map [(control left)] 'backward-sexp)
2296 ;; Wheel mouse moves up and down 2 lines (and DO NOT BEEP when we are
2297 ;; out of the buffer)
2299 (define-key global-map [mouse-4]
2300 (lambda () (interactive) (condition-case nil (scroll-down 2) (error nil))))
2301 (define-key global-map [mouse-5]
2302 (lambda () (interactive) (condition-case nil (scroll-up 2) (error nil))))
2304 ;; with shift it goes faster
2305 (define-key global-map [(shift mouse-4)]
2306 (lambda () (interactive) (condition-case nil (scroll-down 50) (error nil))))
2307 (define-key global-map [(shift mouse-5)]
2308 (lambda () (interactive) (condition-case nil (scroll-up 50) (error nil))))
2310 ;; Meta-? shows the properties of the character at point
2311 (define-key global-map [(meta ??)]
2312 (lambda () (interactive)
2313 (message (prin1-to-string (text-properties-at (point))))))
2315 ;; Compiles the latex file in the current buffer
2319 (setq tex-start-commands "\\input")
2320 (define-key global-map [f3] 'tex-file)
2321 (define-key global-map [(shift f3)] 'tex-bibtex-file)
2323 ;; To run xdvi on the dvi associated to the .tex in the current
2324 ;; buffer, and to edit the .fig or bitmap image used to generate the
2327 (define-key global-map [f4] 'ff/run-viewer)
2329 ;; Closes the current \begin{}
2331 ;; Meta-/ remaped (completion)
2333 (define-key global-map [(shift right)] 'dabbrev-expand)
2334 (define-key global-map [(meta =)] 'dabbrev-expand)
2336 ;; Change the current window.
2338 (defun ff/next-same-frame-window () (interactive)
2339 (select-window (next-window (selected-window)
2340 (> (minibuffer-depth) 0)
2343 (defun ff/previous-same-frame-window () (interactive)
2344 (select-window (previous-window (selected-window)
2345 (> (minibuffer-depth) 0)
2348 (define-key global-map [(shift prior)] 'ff/next-same-frame-window)
2349 (define-key global-map [(shift next)] 'ff/previous-same-frame-window)
2351 (define-key global-map [(control })] 'enlarge-window-horizontally)
2352 (define-key global-map [(control {)] 'shrink-window-horizontally)
2353 (define-key global-map [(control \")] 'enlarge-window)
2354 (define-key global-map [(control :)] 'shrink-window)
2356 ;; (define-key global-map [(control shift prior)] 'next-multiframe-window)
2357 ;; (define-key global-map [(control shift next)] 'previous-multiframe-window)
2359 ;; I have two screens sometime!
2360 ;; (define-key global-map [(meta next)] 'other-frame)
2361 ;; (define-key global-map [(meta prior)] (lambda () (interactive) (other-frame -1)))
2365 ;; (define-key global-map [(shift backspace)] 'winner-undo)
2367 ;; (define-key global-map [(shift home)] 'delete-other-windows-vertically)
2368 ;; (define-key global-map [(control +)] 'enlarge-window)
2369 ;; (define-key global-map [(control -)] 'shrink-window)
2370 ;; Goes to next/previous buffer
2371 ;; (define-key global-map [(control prior)] 'ff/next-buffer)
2372 ;; (define-key global-map [(control next)] 'ff/prev-buffer)
2374 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2375 ;; If M-. on a symbol, show where it is defined in another window
2376 ;; without giving focus, cycle if repeated.
2377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2379 (when (ff/load-or-alert "etags")
2381 (defun ff/find-tag-nofocus () (interactive)
2382 "Show in another window the definition of the current tag"
2383 (let ((tag (find-tag-default)))
2384 (display-buffer (find-tag-noselect tag (string= tag last-tag)))
2385 (message "Tag %s" tag)
2389 (define-key global-map [(meta .)] 'ff/find-tag-nofocus)
2392 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2393 ;; Destroys the current buffer and its window if it's not the only one
2394 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2396 (defcustom ff/kill-this-buffer-and-delete-window-exceptions ""
2397 "*Regexp matching the buffer names which have to be kept when using
2398 `ff/kill-this-buffer-and-delete-window'.")
2400 (defun ff/kill-this-buffer-and-delete-window (universal)
2401 "Unless its name matches
2402 `ff/kill-this-buffer-and-delete-window-exceptions', kills the
2403 current buffer and deletes the current window if it's not the
2404 only one in the frame. If the buffer has to be kept, go to the
2405 next one. With universal argument, kill all killable buffers."
2408 (let ((nb-killed 0))
2410 (unless (string-match ff/kill-this-buffer-and-delete-window-exceptions
2413 (setq nb-killed (1+ nb-killed))
2416 (message "Killed %d buffer%s" nb-killed (if (> nb-killed 1) "s" "")))
2417 (if (string-match ff/kill-this-buffer-and-delete-window-exceptions (buffer-name))
2419 (kill-this-buffer)))
2420 (unless (one-window-p t) (delete-window))
2423 (define-key global-map [(control backspace)] 'ff/kill-this-buffer-and-delete-window)
2424 ;; (define-key calc-mode-map [(control backspace)] 'calc-quit)
2427 (setq ff/kill-this-buffer-and-delete-window-exceptions
2428 "^ \\|\\*Messages\\*\\|\\*scratch\\*\\|\\*Group\\*\\|\\*-jabber-\\*\\|\\*-jabber-process-\\*\\|\\*media\\*")
2430 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2432 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2434 (defun ff/elisp-debug-on ()
2435 "Switches `debug-on-error' and `debug-on-quit'."
2438 (setq debug-on-error nil
2440 (setq debug-on-error t
2443 (message "elisp debug on")
2444 (message "elisp debug off")))
2446 (defun ff/create-dummy-buffer (&optional universal) (interactive "P")
2447 (find-file (concat "/tmp/" (ff/non-existing-filename "/tmp/" "dummy" "")))
2449 (if universal (ff/insert-url (current-kill 0)))
2450 (message "New dummy text-mode buffer"))
2452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2453 ;; Recentf to keep a list of recently visited files. I use it
2454 ;; exclusively with my selector.el
2455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2459 ;; If we just check for file-symlink-p, everytime we start emacs it
2460 ;; will check all the remote files listed in recentf-list, so we check
2461 ;; that they are not remote first
2462 (defun ff/file-not-remote-but-symlink (filename)
2463 (and (not (file-remote-p filename)) (file-symlink-p filename)))
2465 (setq recentf-exclude (append recentf-exclude
2467 ff/file-not-remote-but-symlink
2468 "enotes$" "secure-notes$" "media-playlists$"
2470 "svn-commit.tmp$" ".git/COMMIT_EDITMSG$"
2471 "\.bbl$" "\.aux$" "\.toc$"
2473 recentf-max-saved-items 10000
2474 recentf-save-file (concat ff/emacs-dir "/recentf")
2477 (when (boundp 'recentf-keep) (add-to-list 'recentf-keep 'file-remote-p))
2481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2482 ;; My front-end to mplayer
2483 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2485 ;; (ff/compile-when-needed "media/mplayer")
2486 ;; (ff/compile-when-needed "media")
2488 (when (ff/load-or-alert "media")
2490 (unless window-system
2493 (media/mode-string-face
2494 :foreground "blue4" :weight 'bold)
2496 (media/current-tune-face
2497 :foreground "black" :background "yellow" :weight 'normal)
2499 (media/instant-highlight-face
2500 :foreground "black" :background "orange" :weight 'normal)
2504 (define-key global-map [(meta \\)] 'media)
2506 (setq media/expert t
2507 media/add-current-song-to-interrupted-when-killing t
2508 media/duration-to-history 30
2509 media/history-size 1000
2510 media/playlist-file (concat ff/emacs-dir "/media-playlists")
2511 media/continue-mode-hint (if window-system "⤸" "*")
2512 media/mplayer/args '(
2516 "-subfont-osd-scale" "3"
2517 ;; "-stop-xscreensaver"
2520 media/mplayer/timing-request-period 1.0
2525 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2527 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2529 ;; selector.el is one of my own scripts, check my web page
2531 (when (ff/load-or-alert "selector" t)
2532 ;; (define-key global-map [(shift return)] 'selector/quick-move-in-buffer)
2533 (define-key global-map [(control x) (control b)] 'selector/switch-buffer)
2535 (defun ff/visit-debpkg-file (&optional regexp)
2536 "This function lists all the files found with dpkg -S and
2537 proposes to visit them."
2538 (interactive "sPattern: ")
2544 (cons (selector/filename-to-string s) s))
2546 (shell-command-to-string (concat "dpkg -S " regexp " | awk '{print $2}'"))))
2549 "*selector find-file*"
2553 (add-hook 'selector/mode-hook (lambda () (setq truncate-lines t)))
2555 (defun ff/selector-insert-record-callback (r)
2556 (bbdb-display-records (list r))
2557 ;; Weird things will happen if you kill the buffer from which you
2558 ;; invoked ff/selector-mail-from-bbdb
2559 (insert (car (elt r 6)))
2562 (defun ff/selector-compose-mail-callback (r)
2563 (vm-compose-mail (car (elt r 6)))
2566 (defun ff/selector-mail-from-bbdb () (interactive)
2569 (lambda (r) (cons (concat (elt r 0)
2577 (if (string= mode-name "Mail")
2578 'ff/selector-insert-record-callback
2579 'ff/selector-compose-mail-callback)
2584 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2585 ;; My script to automatically count the number of words and characters
2586 ;; between two markers
2588 (ff/load-or-alert "text-counters.el")
2590 ;; Display them in the modeline when in text-mode
2592 (add-hook 'text-mode-hook 'tc/add-text-counters-in-modeline)
2594 ;; (add-hook 'text-mode-hook
2596 ;; (setq comment-start " > ")))
2598 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2599 ;; A function to remove temporary alarm windows
2600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2602 (defcustom ff/annoying-windows-regexp
2603 "\\*Messages\\*\\|\\*compilation\\*\\|\\*tex-shell\\*\\|\\*Help\\*\\|\\*info\\*\\|\\*Apropos\\*\\|\\*BBDB\\*\\|\\*.*-diff\\*"
2604 "The regexp matching the windows to be deleted by `ff/delete-annoying-windows'"
2607 (defun ff/delete-annoying-windows ()
2608 "Close all the windows showing buffers whose names match
2609 `ff/annoying-windows-regexp'."
2611 (when ff/annoying-windows-regexp
2613 (when (and (not (one-window-p w))
2614 (string-match ff/annoying-windows-regexp
2615 (buffer-name (window-buffer w))))
2619 (message "Removed annoying windows")
2623 (setq ff/annoying-windows-regexp
2624 (concat ff/annoying-windows-regexp
2625 "\\|\\*unspooled mails\\*\\|\\*enotes alarms\\*\\|\\*system info\\*"))
2627 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2628 ;; Some handy functions
2629 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2631 (defun ff/twin-horizontal-current-buffer () (interactive)
2632 (delete-other-windows)
2633 (split-window-horizontally)
2637 (defun ff/twin-vertical-current-buffer () (interactive)
2638 (delete-other-windows)
2639 (split-window-vertically)
2643 (defun ff/flyspell-mode (arg) (interactive "p")
2644 (if flyspell-mode (flyspell-mode -1)
2649 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2651 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2653 (defun ff/move-region-to-fridge (&optional universal) (interactive "P")
2654 "Cut the current region, paste it in a file called ./fridge
2655 with a time tag, and save this file"
2656 (unless (use-region-p) (error "No region selected"))
2657 (let ((bn (file-name-nondirectory (buffer-file-name))))
2659 (copy-region-as-kill (region-beginning) (region-end))
2660 (kill-region (region-beginning) (region-end))
2662 (with-current-buffer (find-file-noselect "fridge")
2663 (goto-char (point-max))
2665 (insert "######################################################################\n")
2667 (format-time-string "%Y %b %d %H:%M:%S" (current-time))
2673 (message "Region moved to fridge")
2678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2679 ;; My own keymap mapped to C-`
2680 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2682 (setq ff/map (make-sparse-keymap))
2683 (define-key global-map [(control \`)] ff/map)
2685 ;; (defun ff/start-stop-macro-recording () (interactive)
2686 ;; (if (or defining-kbd-macro executing-kbd-macro)
2687 ;; (kmacro-end-macro)
2688 ;; (kmacro-start-macro))
2691 ;; (define-key global-map [(shift return)] 'ff/start-stop-macro-recording)
2693 (unless window-system
2694 ;; (define-key global-map [(control @)] ff/map)
2695 (define-key global-map [(meta O) \`] ff/map)
2698 (define-key esc-map "`" ff/map)
2700 (defun ff/kill-downto-signature () (interactive)
2702 (when (re-search-forward "^-- $")
2703 (kill-region s (match-beginning 0))
2706 (defun ff/git-status (&optional dir) (interactive)
2707 (if (buffer-file-name)
2708 (git-status (file-name-directory (buffer-file-name)))
2709 (error "No file attached to this buffer")))
2711 (defun ff/insert-date (&optional universal) (interactive "P")
2712 (insert (format-time-string "\n * %H:%M:%S %A %B %d, %Y\n\n" (current-time)))
2713 ;; ;; (insert (format-time-string "%Y %b %d %H:%M:%S" (current-time)))
2714 ;; ;; (insert (format-time-string "%d.%m.%y" (current-time)))
2716 ;; (insert (format-time-string "%d.%m.%Y %H:%M:%S" (current-time)))
2717 ;; (insert (format-time-string "%d.%m.%Y" (current-time))))
2720 (define-key ff/map [(control g)] 'ff/git-status)
2721 ;; (define-key ff/map [(control w)] 'server-edit)
2722 (define-key ff/map [(control d)] 'ff/elisp-debug-on)
2723 ;; (define-key ff/map "d" 'diary)
2724 (define-key ff/map "d" 'ff/insert-date)
2725 (define-key ff/map [(control \`)] 'ff/bash-new-buffer)
2726 (define-key ff/map [(control n)] 'enotes/show-all-notes)
2727 (define-key ff/map [(control s)] 'ff/secure-note-add)
2728 (define-key ff/map [(control t)] 'ff/start-test-code)
2729 (define-key ff/map [(control q)] 'ff/create-dummy-buffer)
2730 (define-key ff/map [(control a)] 'auto-fill-mode)
2731 (define-key ff/map [(control i)] 'ff/system-info)
2732 (define-key ff/map "w" 'ff/word-occurences)
2733 ;; (define-key ff/map [(control c)] 'calendar)
2734 (define-key ff/map [(control c)] 'ff/show-compilation-buffer-split-window)
2735 ;; (define-key ff/map [(control c)] (lambda () (interactive) (save-excursion (calendar))))
2736 (define-key ff/map [(control l)] 'goto-line)
2737 (define-key ff/map "l" 'longlines-mode)
2738 (define-key ff/map [(control o)] 'selector/quick-pick-recent)
2739 (define-key ff/map "s" 'selector/quick-move-in-buffer)
2740 (define-key ff/map "S" 'selector/search-sentence)
2741 (define-key ff/map "t" (lambda () (interactive) (find-file "~/private/TODO.txt")))
2742 (define-key ff/map "h" 'ff/tidy-html)
2743 (define-key ff/map "c" 'ff/count-char)
2744 (define-key ff/map [(control p)] 'ff/print-to-file)
2745 (define-key ff/map "P" 'ff/print-to-printer)
2746 (define-key ff/map [(control b)] 'bbdb)
2747 (define-key ff/map "m" 'ff/selector-mail-from-bbdb)
2748 (define-key ff/map [(control m)] 'woman)
2749 (define-key ff/map "b" 'bookmark-jump)
2750 (define-key ff/map [(control =)] 'calc)
2751 (define-key ff/map "=" 'ff/number-beamer-frames)
2752 (define-key ff/map [(control shift b)]
2753 (lambda () (interactive)
2756 (define-key ff/map "f" 'ff/move-region-to-fridge)
2757 (define-key ff/map [(control f)] 'ff/flyspell-mode)
2758 (define-key ff/map [(control k)] 'ff/kill-downto-signature)
2760 (define-key ff/map [?\C-0] 'ff/delete-annoying-windows)
2761 (define-key ff/map "1" 'delete-other-windows)
2762 (define-key ff/map [?\C-1] 'delete-other-windows)
2763 (define-key ff/map "2" 'ff/twin-vertical-current-buffer)
2764 (define-key ff/map [?\C-2] 'ff/twin-vertical-current-buffer)
2765 (define-key ff/map "3" 'ff/twin-horizontal-current-buffer)
2766 (define-key ff/map [?\C-3] 'ff/twin-horizontal-current-buffer)
2768 (define-key ff/map " " 'delete-trailing-whitespace)
2770 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2771 ;; Hacks so that all keys are functionnal in xterm and through ssh.
2772 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2774 (unless window-system
2776 ;; One day I will understand these clipboard business. Until then,
2777 ;; so that it works in xterm (yes), let's use xclip. This is a bit
2780 ;; (defun ff/yank-with-xclip (&optional arg)
2781 ;; "Paste the content of the X clipboard with the xclip
2782 ;; command. Without ARG converts some of the '\\uxxxx' characters."
2783 ;; (interactive "P")
2784 ;; (with-temp-buffer
2785 ;; (shell-command "xclip -o" t)
2787 ;; (mapc (lambda (x) (replace-string (concat "\\u" (car x)) (cdr x) nil (point-min) (point-max)))
2788 ;; '(("fffd" . "??")
2799 ;; (kill-ring-save (point-min) (point-max)))
2803 ;; (define-key global-map [(meta y)] 'ff/yank-with-xclip)
2805 ;; (set-terminal-coding-system 'iso-latin-1)
2806 ;; (set-terminal-coding-system 'utf-8)
2808 ;; I have in my .Xressource
2810 ;; XTerm.VT100.translations: #override\n\
2811 ;; <Btn4Down>,<Btn4Up>:scroll-back(2,line)\n\
2812 ;; <Btn5Down>,<Btn5Up>:scroll-forw(2,line)\n\
2813 ;; Ctrl<Btn4Down>,Ctrl<Btn4Up>:scroll-back(1,page)\n\
2814 ;; Ctrl<Btn5Down>,Ctrl<Btn5Up>:scroll-forw(1,page)\n\
2815 ;; Shift<Btn4Down>,Shift<Btn4Up>:scroll-back(1,halfpage)\n\
2816 ;; Shift<Btn5Down>,Shift<Btn5Up>:scroll-forw(1,halfpage)\n\
2817 ;; Alt<KeyPress>:insert-eight-bit()\n\
2818 ;; !Shift<Key>BackSpace: string("
\7f")\n\
2819 ;; Ctrl<Key>BackSpace: string("\eOZ")\n\
2820 ;; Shift<Key>Prior: string("\e[5;2~")\n\
2821 ;; Shift<Key>Next: string("\e[6;2~")\n\
2822 ;; Shift Ctrl<Key>]: string("\eO}")\n\
2823 ;; Shift Ctrl<Key>[: string("\eO{")\n\
2824 ;; Shift Ctrl<Key>/: string("\eO?")\n\
2825 ;; Ctrl<Key>/: string("\eO/")\n\
2826 ;; Shift Ctrl<Key>=: string("\eO+")\n\
2827 ;; Ctrl<Key>=: string("\eO=")\n\
2828 ;; Shift Ctrl<Key>;: string("\eO:")\n\
2829 ;; Ctrl<Key>;: string("\eO;")\n\
2830 ;; Shift Ctrl<Key>`: string("\eO~")\n\
2831 ;; Ctrl<Key>`: string("\eO`")\n\
2832 ;; Shift Ctrl<Key>': string("\eO\\\"")\n\
2833 ;; Ctrl<Key>': string("\eO'")\n\
2834 ;; Shift Ctrl<Key>.: string("\eO>")\n\
2835 ;; Ctrl<Key>.: string("\eO.")\n\
2836 ;; Shift Ctrl<Key>\\,: string("\eO<")\n\
2837 ;; Ctrl<Key>\\,: string("\eO,")
2839 (define-key function-key-map "\e[2~" [insert])
2841 (define-key function-key-map "\e[Z" [S-iso-lefttab])
2843 (define-key function-key-map "\e[1;2A" [S-up])
2844 (define-key function-key-map "\e[1;2B" [S-down])
2845 (define-key function-key-map "\e[1;2C" [S-right])
2846 (define-key function-key-map "\e[1;2D" [S-left])
2847 (define-key function-key-map "\e[1;2F" [S-end])
2848 (define-key function-key-map "\e[1;2H" [S-home])
2850 (define-key function-key-map "\e[2;2~" [S-insert])
2851 (define-key function-key-map "\e[5;2~" [S-prior])
2852 (define-key function-key-map "\e[6;2~" [S-next])
2854 (define-key function-key-map "\e[1;2P" [S-f1])
2855 (define-key function-key-map "\e[1;2Q" [S-f2])
2856 (define-key function-key-map "\e[1;2R" [S-f3])
2857 (define-key function-key-map "\e[1;2S" [S-f4])
2858 (define-key function-key-map "\e[15;2~" [S-f5])
2859 (define-key function-key-map "\e[17;2~" [S-f6])
2860 (define-key function-key-map "\e[18;2~" [S-f7])
2861 (define-key function-key-map "\e[19;2~" [S-f8])
2862 (define-key function-key-map "\e[20;2~" [S-f9])
2863 (define-key function-key-map "\e[21;2~" [S-f10])
2865 (define-key function-key-map "\e[1;5A" [C-up])
2866 (define-key function-key-map "\e[1;5B" [C-down])
2867 (define-key function-key-map "\e[1;5C" [C-right])
2868 (define-key function-key-map "\e[1;5D" [C-left])
2869 (define-key function-key-map "\e[1;5F" [C-end])
2870 (define-key function-key-map "\e[1;5H" [C-home])
2872 (define-key function-key-map "\e[2;5~" [C-insert])
2873 (define-key function-key-map "\e[5;5~" [C-prior])
2874 (define-key function-key-map "\e[6;5~" [C-next])
2876 (define-key function-key-map "\e[1;9A" [M-up])
2877 (define-key function-key-map "\e[1;9B" [M-down])
2878 (define-key function-key-map "\e[1;9C" [M-right])
2879 (define-key function-key-map "\e[1;9D" [M-left])
2880 (define-key function-key-map "\e[1;9F" [M-end])
2881 (define-key function-key-map "\e[1;9H" [M-home])
2883 (define-key function-key-map "\e[2;9~" [M-insert])
2884 (define-key function-key-map "\e[5;9~" [M-prior])
2885 (define-key function-key-map "\e[6;9~" [M-next])
2887 ;; The following ones are not standard
2889 (define-key function-key-map "\eO}" (kbd "C-}"))
2890 (define-key function-key-map "\eO{" (kbd "C-{"))
2891 (define-key function-key-map "\eO?" (kbd "C-?"))
2892 (define-key function-key-map "\eO/" (kbd "C-/"))
2893 (define-key function-key-map "\eO:" (kbd "C-:"))
2894 (define-key function-key-map "\eO;" (kbd "C-;"))
2895 (define-key function-key-map "\eO~" (kbd "C-~"))
2896 (define-key function-key-map "\eO`" (kbd "C-\`"))
2897 (define-key function-key-map "\eO\"" (kbd "C-\""))
2898 (define-key function-key-map "\eO|" (kbd "C-|"))
2899 (define-key function-key-map "\eO'" (kbd "C-'"))
2900 (define-key function-key-map "\eO>" (kbd "C->"))
2901 (define-key function-key-map "\eO." (kbd "C-."))
2902 (define-key function-key-map "\eO<" (kbd "C-<"))
2903 (define-key function-key-map "\eO," (kbd "C-,"))
2904 (define-key function-key-map "\eO-" (kbd "C--"))
2905 (define-key function-key-map "\eO=" (kbd "C-="))
2906 (define-key function-key-map "\eO+" (kbd "C-+"))
2908 (define-key function-key-map "\eOZ" [C-backspace])
2910 (define-key minibuffer-local-map "
\10" 'previous-history-element)
2911 (define-key minibuffer-local-map "
\ e" 'next-history-element)
2913 ;; (define-key global-map [(alt prior)] 'ff/prev-buffer)
2914 ;; (define-key global-map [(alt next)] 'ff/next-buffer)
2918 ;; I am fed up with Alt-Backspace in the minibuffer erasing the
2919 ;; content of the kill-ring
2921 (defun ff/backward-delete-word (arg)
2922 "Delete characters forward until encountering the end of a word, but do not put them in the kill ring.
2923 With argument ARG, do this that many times."
2925 (delete-region (point) (progn (forward-word (- arg)) (point))))
2927 (define-key minibuffer-local-map
2928 [remap backward-kill-word] 'ff/backward-delete-word)
2930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2932 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2934 ;; Where to save the bookmarks
2936 (setq bookmark-default-file (concat ff/emacs-dir "/bmk")
2937 custom-file (concat ff/emacs-dir "/custom"))
2939 ;; enotes.el is one of my own scripts, check my web page
2941 ;; ** ;; (when (ff/load-or-alert "enotes" t)
2942 ;; ** ;; (setq enotes/file "~/private/enotes"
2943 ;; ** ;; enotes/show-help nil
2944 ;; ** ;; enotes/full-display nil
2945 ;; ** ;; enotes/default-time-fields "9:30")
2947 ;; ** ;; (enotes/init)
2950 (when (ff/load-or-alert "goto-last-change.el")
2951 (define-key global-map [(control -)] 'goto-last-change)
2954 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2955 ;; My private stuff (email adresses, mail filters, etc.)
2956 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2958 (ff/load-or-alert "~/private/emacs.perso.el" t)
2960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2962 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2964 ;; Runs in server mode, so that emacsclient works
2967 (defun ff/raise-frame-and-give-focus ()
2970 (x-focus-frame (selected-frame))
2971 (set-mouse-pixel-position (selected-frame) 4 4)
2974 ;; Raises the window when the server is invoked
2976 (add-hook 'server-switch-hook 'ff/raise-frame-and-give-focus)