Bastien Guerry

Flattr this
Creative Commons License

bzg .emacs.el file

This is my .emacs.el file, as a HTMLized file.

You can browse the .el file here or clone the .org file from github.

Comments and suggestions are welcome! bzg AT gnu DOT org

Package initialization

;; I don't use package a lot but don't want to configure the list of
;; archives each time I use it.

(define-key global-map (kbd "<print>") (lambda()(interactive)(insert " ")))

(require 'package)
(setq package-archives
      '(;; ("org" . "")
        ;; ("marmalade" . "")
        ("gnu" . "")
        ("melpa" . "")
        ;; ("SC" . "")
        ;; ("ELPA" . "")


General defaults

;; Let's get a backtrace when errors are
(setq debug-on-error t)

;; Scrolling done right
(setq scroll-error-top-bottom t)

;; Display byte-compiler warnings on error
(setq byte-compile-debug t)

;; elp.el is the Emacs Lisp profiler, sort by average time
(setq elp-sort-by-function 'elp-sort-by-average-time)

;; Stop polluting the directory with auto-saved files and backup
(setq auto-save-default nil)
(setq make-backup-files nil)

;; Well, it's more so that you know this option
(setq kill-ring-max 120)
(setq kill-whole-line t)
(setq kill-read-only-ok t)

(tooltip-mode -1)
(setq tooltip-delay 3.0)

(setq sentence-end-double-space t)
(setq require-final-newline t)

;; Number of lines of continuity when scrolling by screenfuls.
(setq next-screen-context-lines 0)

;; (setq bidi-display-reordering nil)
(setq enable-local-variables t)
(setq enable-local-eval t)

;; Always use "y" for "yes"
(fset 'yes-or-no-p 'y-or-n-p)

(setenv "EDITOR" "emacsclient")
(setenv "CVS_RSH" "ssh")

;; I see my battery info in i3, I don't use this anymore
;; (setq battery-mode-line-format " [%b%p%%,%d°C]")

;; I used to deactivate this but find it useful now
;; (electric-indent-mode -1)
(electric-pair-mode -1)
(setq-default electric-indent-chars '(?\n))

(require 'whitespace)
(add-to-list 'whitespace-style 'lines-tail)
(setq whitespace-line-column 80)
(setq load-prefer-newer t)

Enable/Disable some minor modes

;; I love parentheses in *every* mode
(show-paren-mode 1)
(display-time-mode 1)
(auto-compression-mode t)

;; Don't clutter the emacs screen
;; (tool-bar-mode -1)
;; (menu-bar-mode -1)
(blink-cursor-mode -1)

Set my exec/load paths

(add-to-list 'exec-path "~/bin/")

(let ((default-directory "~/elisp/"))

(let ((default-directory "~/install/git/gnus/"))

(add-to-list 'load-path "~/install/cvs/emacs-w3m/")
(add-to-list 'load-path "~/install/git/org-trello/")
(add-to-list 'load-path "~/install/git/org-reveal/")
(add-to-list 'load-path "~/install/git/helm/")
(add-to-list 'load-path "~/install/git/geiser/elisp/")
;; (add-to-list 'load-path "~/install/git/ac-nrepl/")

(add-to-list 'load-path "~/install/git/clojure-mode/")
(add-to-list 'load-path "~/install/git/cider/")
(add-to-list 'load-path "~/install/git/smartparens/")
(add-to-list 'load-path "~/install/git/clojure-cheatsheet/")
(add-to-list 'load-path "~/install/git/magit/")
(add-to-list 'load-path "~/install/git/git-modes/")
;; (add-to-list 'load-path "~/install/src/bbdb/lisp/")
(add-to-list 'load-path "~/install/git/bbdb/lisp/")

(add-to-list 'load-path "~/install/git/notmuch/emacs/")

(add-to-list 'load-path "~/install/git/org-trello/")
(add-to-list 'load-path "~/install/git/org-mode/lisp/")
(add-to-list 'load-path "~/install/git/org-mode/contrib/lisp/")


;; M-x package-install RET register-list RET
(require 'register-list)

;; I'm using an old elscreen but there is more recent activity:
(require 'elscreen)
(setq elscreen-display-tab nil)
(setq elscreen-tab-display-control nil)

(require 'session)
(require 'ibuffer)
;; (require 'paredit)
;; (require 'smartparens-config)
;; (show-smartparens-global-mode)

(require 'dash)
;; (require 'auto-complete)
(require 'cider)

(setq nrepl-hide-special-buffers t)
(setq cider-repl-pop-to-buffer-on-connect nil)
(setq cider-popup-stacktraces nil)
(setq cider-repl-popup-stacktraces t)

(require 'company)
(require 'company-cider)
(eval-after-load 'company '(add-to-list 'company-backends 'company-cider))

;; (require 'ac-nrepl)
;; (add-hook 'cider-repl-mode-hook 'ac-nrepl-setup)
;; (add-hook 'cider-mode-hook 'ac-nrepl-setup)
;; (eval-after-load "auto-complete"
;;   '(progn (add-to-list 'ac-modes 'cider-repl-mode)
;;           (add-to-list 'ac-modes 'cider-mode)))
;; (eval-after-load "cider"
;;   '(define-key cider-mode-map (kbd "C-c C-d") 'ac-nrepl-popup-doc))

;; (remove-hook 'clojure-mode-hook 'auto-complete-mode)
;; (add-hook 'cider-repl-mode-hook 'paredit-mode)

Info initialization

(require 'info)

(setq Info-refill-paragraphs t)
(add-to-list 'Info-directory-list "~/install/git/org-mode/doc/")

Enable some functions

(put 'erase-buffer 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'scroll-left 'disabled nil)
(put 'scroll-right 'disabled nil)
(put 'set-goal-column 'disabled nil)


(setq custom-file "/home/guerry/elisp/config/emacs-custom.el")
(load custom-file)

(setq initial-frame-alist
      '((left-fringe . 10)
        (right-fringe . 10)
        (alpha . 85)
        ;; (cursor-type . (hbar . 1))
        (left-margin-width . 10)
        (menu-bar-lines . 0)
        (tool-bar-lines . 0)
        (horizontal-scroll-bars . nil)
        (vertical-scroll-bars . nil)
        ;; (background-color . "black")
        ;; (foreground-color . "#dddddd")

(setq default-frame-alist initial-frame-alist)


;; This is my favorite default font:
;; (set-frame-font "Monospace 10")

;; I use this sometimes for reading long blog posts:
;; (set-frame-font "Inconsolata 13")
;; (set-frame-font "Deja Vu Sans Mono 13")
;; (set-frame-font "Consolas 12")
;; (set-frame-font "Droid Sans Mono 11")
;; (set-frame-font "Source Code Pro 10")
(set-frame-font "Meslo LG M DZ 11")


(setq-default line-spacing nil) ; 0.1)
(setq fill-column 70)
(setq line-move-visual nil)
(setq show-trailing-whitespace t)
(setq initial-scratch-message "")
(setq initial-major-mode 'org-mode)
(setq inhibit-startup-message t)
(setq inhibit-startup-echo-area-message "guerry")
(setq visible-bell t)
(setq spell-command "aspell")
(setq speedbar-use-images nil)
(setq tab-always-indent 'always)
(setq display-time-mail-string "#")
(setq focus-follows-mouse t)
(setq text-mode-hook '(turn-on-auto-fill text-mode-hook-identify))

;; (mouse-avoidance-mode 'cat-and-mouse)


(add-to-list 'custom-theme-load-path "~/install/git/cyberpunk-theme.el/")
(load-theme 'cyberpunk)


(setq ps-paper-type 'a4
      ps-font-size 7.0
      ps-print-header nil
      ps-print-color-p nil
      ps-landscape-mode nil
      ps-number-of-columns 1
      ps-auto-font-detect nil
      ps-default-bg "white"
      ps-default-fg "black"
      ps-left-margin 56.69291338582677
      ps-print-color-p (quote black-white))


(require 'w3m)
(if window-system
    ;; (setq browse-url-browser-function 'w3m-browse-url)
    (setq browse-url-browser-function 'browse-url-firefox)
          ;; (setq browse-url-browser-function 'w3m-browse-url
          ;;      browse-url-generic-program "conkeror")
          ;; browse-url-generic-program "chromium")
          ;; browse-url-generic-program "firefox"
  (setq browse-url-browser-function 'w3m-browse-url)) ;
(setq browse-url-text-browser "w3m")

(setq browse-url-firefox-new-window-is-tab t)
(setq browse-url-firefox-program "firefox")
(setq browse-url-new-window-flag t)

Define global keys

(global-set-key (kbd "C-h /") 'find-function)
(global-set-key (kbd "C-x <C-backspace>") 'bzg-find-bzg)
(global-set-key (kbd "<home>") 'beginning-of-buffer)
(global-set-key (kbd "<end>") 'end-of-buffer)
(global-set-key (kbd "<insert>") (lambda() (interactive) (insert-char ?<)))
(global-set-key (kbd "<deletechar>") (lambda() (interactive) (insert-char ?>)))
(global-set-key (quote [f1]) 'gnus)
(global-set-key (quote [f2]) 'hidden-mode-line-mode)
(global-set-key (quote [f3]) 'bzg-big-fringe-mode)
(global-set-key (quote [f5]) 'edebug-defun)
(global-set-key (quote [f6]) 'w3m)
(global-set-key (quote [f7]) 'auto-fill-mode)
(global-set-key (quote [f8]) 'occur)
(global-set-key [(shift f8)] 'multi-occur)
(global-set-key (quote [f10]) 'calc)
(global-set-key (quote [f11]) 'eshell)
(global-set-key (kbd "C-&")
                (lambda (arg) (interactive "P")
                  (if arg (switch-to-buffer "#twitter_bzg2") (switch-to-buffer "&bitlbee"))))
(global-set-key (kbd "M-+") 'text-scale-increase)
(global-set-key (kbd "M--") 'text-scale-decrease)
(global-set-key (kbd "M-0") 'text-scale-adjust)
(global-set-key (kbd "C-M-]") (lambda () (interactive) (org-cycle t)))
(global-set-key (kbd "M-]")
                (lambda () (interactive)
                  (ignore-errors (end-of-defun) (beginning-of-defun)) (org-cycle)))
(global-set-key (kbd "C-x r L") 'register-list)

(define-key global-map "\M-n" 'next-word-at-point)
(define-key global-map "\M-n" 'current-word-search)
(define-key global-map "\M-p" 'previous-word-at-point)


(require 'dired)
(require 'dired-x)
(require 'dired-details)
(require 'wdired)

(global-set-key (kbd "C-x d") 'dired)
(define-key dired-mode-map "\C-cb" 'org-ibuffer)
(define-key dired-mode-map ")" 'dired-details-toggle)
(define-key dired-mode-map "\C-cg" 'grep-find)
(define-key dired-mode-map "\C-cd" 'dired-clean-tex)

(setq directory-free-space-args "-Pkh")
(setq list-directory-verbose-switches "-al")
(setq dired-listing-switches "-l")
(setq dired-dwim-target t)
(setq dired-omit-mode nil)
(setq dired-recursive-copies 'always)
(setq dired-recursive-deletes 'always)
(setq delete-old-versions t)

(setq dired-guess-shell-alist-user
;;       (list "\\.pdf$" "acroread")
       (list "\\.pdf$" "mupdf")
       (list "\\.docx?$" "libreoffice")
       (list "\\.aup?$" "audacity")
       (list "\\.pptx?$" "libreoffice")
       (list "\\.odf$" "libreoffice")
       (list "\\.odt$" "libreoffice")
       (list "\\.odt$" "libreoffice")
       (list "\\.kdenlive$" "kdenlive")
       (list "\\.svg$" "gimp")
       (list "\\.csv$" "libreoffice")
       (list "\\.sla$" "scribus")
       (list "\\.ods$" "libreoffice")
       (list "\\.odp$" "libreoffice")
       (list "\\.xls$" "libreoffice")
       (list "\\.xlsx$" "libreoffice")
       (list "\\.txt$" "gedit")
       (list "\\.sql$" "gedit")
       (list "\\.css$" "gedit")
       (list "\\.html$" "w3m")
       (list "\\.jpe?g$" "gqview")
       (list "\\.png$" "gqview")
       (list "\\.gif$" "gqview")
       (list "\\.psd$" "gimp")
       (list "\\.xcf" "gimp")
       (list "\\.odt$" "libreoffice")
       (list "\\.xo$" "unzip")
       (list "\\.3gp$" "vlc")
       (list "\\.mp3$" "vlc")
       (list "\\.flac$" "vlc")
       (list "\\.avi$" "mplayer -fs")
       ;; (list "\\.og[av]$" "vlc")
       (list "\\.wm[va]$" "vlc")
       (list "\\.flv$" "mplayer -fs")
       (list "\\.mov$" "mplayer -fs")
       (list "\\.divx$" "mplayer -fs")
       (list "\\.mp4$" "mplayer -fs")
       (list "\\.mkv$" "mplayer -fs")
       (list "\\.mpe?g$" "mplayer -fs")
       (list "\\.m4[av]$" "mplayer -fs")
       (list "\\.mp2$" "vlc")
       (list "\\.pp[st]$" "libreoffice")
       (list "\\.ogg$" "vlc")
       (list "\\.ogv$" "mplayer -fs")
       (list "\\.rtf$" "libreoffice")
       (list "\\.ps$" "gv")
       (list "\\.mp3$" "play")
       (list "\\.wav$" "vlc")
       (list "\\.rar$" "unrar x")

(setq dired-tex-unclean-extensions
  '(".toc" ".log" ".aux" ".dvi" ".out" ".nav" ".snm"))

(setq inferior-lisp-program "sbcl")


Org initialization and hooks

(require 'org)
;; (require 'org-trello)
(require 'ox-rss)
(require 'ox-reveal)
(require 'ox-beamer)
(require 'ox-latex)
(require 'ox-odt)
(require 'org-gnus)
(require 'ox-koma-letter)

(setq org-element-use-cache t)
(setq org-adapt-indentation t)

;; Hook to update all blocks before saving
(add-hook 'org-mode-hook
          (lambda() (add-hook 'before-save-hook
                              'org-update-all-dblocks t t)))

;; Hook to display dormant article in Gnus
(add-hook 'org-follow-link-hook
          (lambda ()
            (if (eq major-mode 'gnus-summary-mode)

(add-hook 'org-mode-hook (lambda () (imenu-add-to-menubar "Imenu")))

(add-hook 'org-follow-link-hook
          (lambda () (if (eq major-mode 'gnus-summary-mode)

Org keys

(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-cL" 'org-occur-link-in-agenda-files)
(define-key global-map "\C-ca" 'org-agenda)
(define-key global-map "\C-cc" 'org-capture)

Org babel

 '((emacs-lisp . t)
   (sh . t)
   (dot . t)
   (clojure . t)
   (org . t)
   (ditaa . t)
   (org . t)
   (ledger . t)
   (scheme . t)
   (plantuml . t)
   (R . t)
   (gnuplot . t)))


(add-hook 'org-clock-in-hook (lambda() (org-todo "STRT")))

(appt-activate t)

(setq display-time-24hr-format t)
(setq display-time-day-and-date t)

(setq appt-audible nil
      appt-display-interval 10
      appt-message-warning-time 120)

(setq org-babel-default-header-args
      '((:session . "none")
        (:results . "replace")
        (:exports . "code")
        (:cache . "no")
        (:noweb . "yes")
        (:hlines . "no")
        (:tangle . "no")
        (:padnewline . "yes")))

(setq org-edit-src-content-indentation 0)
(setq org-babel-clojure-backend 'cider)

Org agenda

(setq org-agenda-bulk-mark-char "*")
(setq org-agenda-diary-file "/home/guerry/org/")
(setq org-agenda-dim-blocked-tasks nil)
(setq org-agenda-entry-text-maxlines 10)
(setq org-agenda-file-regexp "\\.org\\'")
(setq org-agenda-files '("~/org/" "~/org/" "~/org/"))
(setq org-agenda-include-diary nil)
(setq org-agenda-prefix-format
      '((agenda . " %i %-12:c%?-14t%s")
        (timeline . "  % s")
        (todo . " %i %-14:c")
        (tags . " %i %-14:c")
        (search . " %i %-14:c")))
(setq org-agenda-remove-tags t)
(setq org-agenda-restore-windows-after-quit t)
(setq org-agenda-show-inherited-tags nil)
(setq org-agenda-skip-deadline-if-done t)
(setq org-agenda-skip-deadline-prewarning-if-scheduled t)
(setq org-agenda-skip-scheduled-if-done t)
(setq org-agenda-skip-timestamp-if-done t)
(setq org-agenda-sorting-strategy
      '((agenda time-up) (todo time-up) (tags time-up) (search time-up)))
(setq org-agenda-start-on-weekday 1)
(setq org-agenda-sticky nil)
(setq org-agenda-tags-todo-honor-ignore-options t)
(setq org-agenda-use-tag-inheritance nil)
(setq org-agenda-window-frame-fractions '(0.0 . 0.5))
(setq org-agenda-deadline-faces
      '((1.0001 . org-warning)              ; due yesterday or before
        (0.0    . org-upcoming-deadline)))  ; due today or later

Org agenda custom commands

(setq org-agenda-custom-commands
        ;; list of tasks for today
        (" " "Aujourd'hui" agenda "List of rendez-vous and tasks for today"
         ((org-agenda-span 1)
          (org-agenda-files '("~/org/" "~/org/"))
          (org-deadline-warning-days 3)
          (org-agenda-effort-filter '("+=30"))
           '(todo-state-up time-up priority-up))))

        ;; list of free tasks for today
        ("+" "Aujourd'hui" agenda "List of core+extra tasks for today"
         ((org-agenda-span 1)
          (org-agenda-files '("~/org/" "~/org/"))
          (org-deadline-warning-days 3)
           '(todo-state-up time-up priority-up))))

        ;; list of WP tasks for today
        ("%" "Rendez-vous" agenda* "Week RDV"
         ((org-agenda-span 'week)
          (org-agenda-files '("~/org/"))
          (org-deadline-warning-days 10)
           '(todo-state-up time-up priority-up))))

        ("n" "NEXT (core)"
         todo "NEXT" ((org-agenda-files '("~/org/"))
                      (org-agenda-sorting-strategy '(timestamp-up))))
        ("N" "NEXT (all)"
         todo "NEXT" ((org-agenda-sorting-strategy '(timestamp-up))))
        ("d" "TODO (core)"
         todo "TODO" ((org-agenda-files '("~/org/"))
                      (org-agenda-sorting-strategy '(timestamp-up))))
        ("D" "TODO (all)"
         todo "TODO" ((org-agenda-sorting-strategy '(timestamp-up))))
        ("s" "STRT (core)"
         todo "STRT" ((org-agenda-files '("~/org/"))
                      (org-agenda-sorting-strategy '(timestamp-up))))
        ("S" "STRT (all)"
         todo "STRT" ((org-agenda-sorting-strategy '(timestamp-up))))

        ("x" "All tasks scheduled today" agenda "List of scheduled tasks for today"
         ((org-agenda-span 1)
          (org-agenda-entry-types '(:timestamp :scheduled))
           '(time-up todo-state-up priority-up))))

        ;; list of WP tasks for today
        ("X" "Upcoming deadlines" agenda "List of past and upcoming deadlines"
         ((org-agenda-span 1)
          (org-deadline-warning-days 15)
          (org-agenda-entry-types '(:deadline))
           '(time-up todo-state-up priority-up))))

        ;; list of Old deadlines
        ("Y" tags-todo "+SCHEDULED<=\"<now>\"")
        ("Z" tags-todo "+DEADLINE<=\"<now>\"")

        ("R" tags-todo "+Read+TODO={NEXT}" nil)
        ;; Everything that has a "Read" tag
        ("r" . "Read")
        ("rn" tags-todo "+Read+TODO={NEXT}" nil)
        ("rt" tags-todo "+Read+TODO={TODO}" nil)
        ("rr" tags-todo "+Read+TODO={STRT}" nil)
        ("rF" tags "+Read+@Offline" nil)

        ("W" tags-todo "+Write+TODO={NEXT}" nil)

        ;; Everything that has a "Read" tag
        ("w" . "Write")
        ("wn" tags-todo "+Write+TODO={NEXT}" nil)
        ("wt" tags-todo "+Write+TODO={TODO}" nil)
        ("ww" tags-todo "+Write+TODO={STRT}" nil)
        ("wF" tags "+Write+@Offline" nil)


Org capture templates

(setq org-capture-templates
      ;; for org/

        ;; Mise, put it on top of my main .org file
        (" " "Misc" entry (file "~/org/")
         "* TODO %a\n  :PROPERTIES:\n  :CAPTURED: %U\n  :END:\n\n%i%?"
         :prepend t :immediate-finish t)

        ;; Mise, put it on top of my main .org file
        ("c" "Misc" entry (file "~/org/")
         "* TODO %a\n  :PROPERTIES:\n  :CAPTURED: %U\n  :END:\n\n%i%?"
         :prepend t)

        ;; for org/
        ("r" "Bzg RDV" entry (file+headline "~/org/" "RDV")
         "* %a\n  :PROPERTIES:\n  :CAPTURED: %U\n  :END:\n\n%i%?" :prepend t)

        ;; Basement et garden
        ("g" "Garden" entry (file+headline "~/org/" "Garden")
         "* TODO %?%a\n  :PROPERTIES:\n  :CAPTURED: %U\n  :END:\n\n%i" :prepend t)

        ;; Boite (lml) et cours
        ("b" "Boulot" entry (file+headline "~/org/" "Boulot")
         "* TODO %?%a\n  :PROPERTIES:\n  :CAPTURED: %U\n  :END:\n\n%i" :prepend t)

        ("e" "Emacs" entry (file+headline "~/org/" "Emacs")
         "* TODO %?%a\n  :PROPERTIES:\n  :CAPTURED: %U\n  :END:\n\n%i" :prepend t)

        ("o" "Org")
        ("of" "Org FR" entry (file+headline "~/org/" "Features")
         "* TODO %?%a :Code:\n  :PROPERTIES:\n  :CAPTURED: %U\n  :END:\n\n%^{OrgVersion}p%i" :prepend t)
        ("ob" "Org Bug" entry (file+headline "~/org/" "To fix")
         "* NEXT %?%a :Bug:\n  :PROPERTIES:\n  :CAPTURED: %U\n  :END:\n\n%^{OrgVersion}p%i" :prepend t)
        ("op" "Org Patch" entry (file+headline "~/org/" "Patches")
         "* NEXT [#A] %?%a :Patch:\n  :PROPERTIES:\n  :CAPTURED: %U\n  :END:\n\n%^{OrgVersion}p%i" :prepend t)
        ("ow" "Worg" entry (file+headline "~/org/" "Worg")
         "* TODO [#A] %?%a :Worg:\n  :PROPERTIES:\n  :CAPTURED: %U\n  :END:\n\n%i" :prepend t)


Org export

(setq org-export-default-language "fr")
(setq org-export-backends '(latex odt icalendar html ascii rss koma-letter))
(setq org-export-highlight-first-table-line t)
(setq org-export-html-extension "html")
(setq org-export-html-with-timestamp nil)
(setq org-export-skip-text-before-1st-heading nil)
(setq org-export-with-LaTeX-fragments t)
(setq org-export-with-archived-trees nil)
(setq org-export-with-drawers '("HIDE"))
(setq org-export-with-section-numbers nil)
(setq org-export-with-sub-superscripts '{})
(setq org-export-with-tags 'not-in-toc)
(setq org-export-with-timestamps t)
(setq org-html-head "")
(setq org-html-head-include-default-style nil)
(setq org-export-with-toc nil)
(setq org-export-with-priority t)
(setq org-export-dispatch-use-expert-ui nil)
(setq org-export-babel-evaluate t)
(setq org-taskjuggler-default-project-duration 2000)
(setq org-taskjuggler-target-version 3.0)

(setq org-latex-listings 'minted)
(add-to-list 'org-latex-packages-alist '("" "minted"))
;; (add-to-list 'org-latex-packages-alist '("" "listings"))
;; (add-to-list 'org-latex-packages-alist '("" "color"))

(setq org-latex-pdf-process
      '("pdflatex -interaction nonstopmode -shell-escape -output-directory %o %f" "pdflatex -interaction nonstopmode -shell-escape -output-directory %o %f" "pdflatex -interaction nonstopmode -shell-escape -output-directory %o %f"))

(setq org-export-allow-bind-keywords t)
(setq org-publish-list-skipped-files nil)

(setq org-html-table-row-tags
      (cons '(cond (top-row-p "<tr class=\"tr-top\">")
                   (bottom-row-p "<tr class=\"tr-bottom\">")
                   (t (if (= (mod row-number 2) 1)
                          "<tr class=\"tr-odd\">"
                        "<tr class=\"tr-even\">")))

(add-to-list 'org-latex-classes

(setq org-pretty-entities t)
(setq org-fast-tag-selection-single-key 'expert)
(setq org-fontify-done-headline t)
(setq org-fontify-emphasized-text t)
(setq org-footnote-auto-label 'confirm)
(setq org-footnote-auto-adjust t)
(setq org-footnote-define-inline nil)
(setq org-hide-emphasis-markers t)
(setq org-icalendar-include-todo 'all)
(setq org-list-indent-offset 0)
(setq org-link-frame-setup '((gnus . gnus) (file . find-file-other-window)))
(setq org-link-mailto-program '(browse-url-mail "mailto:%a?subject=%s"))
(setq org-log-note-headings
      '((done . "CLOSING NOTE %t") (state . "State %-12s %t") (clock-out . "")))
(setq org-priority-start-cycle-with-default nil)
(setq org-refile-targets '((org-agenda-files . (:maxlevel . 2))
                           (("~/org/") . (:maxlevel . 2))
                           (("~/org/") . (:maxlevel . 2))
                           (("~/org/") . (:maxlevel . 2))
(setq org-refile-use-outline-path t)
(setq org-refile-allow-creating-parent-nodes t)
(setq org-refile-use-cache t)
(setq org-return-follows-link t)
(setq org-reverse-note-order t)
(setq org-scheduled-past-days 100)
(setq org-show-following-heading '((default nil) (occur-tree t)))
(setq org-show-hierarchy-above '((default nil) (tags-tree . t)))
(setq org-special-ctrl-a/e 'reversed)
(setq org-special-ctrl-k t)
(setq org-stuck-projects '("+LEVEL=1" ("NEXT" "TODO" "DONE")))
(setq org-tag-persistent-alist '(("Write" . ?w) ("Read" . ?r)))
(setq org-tag-alist
      '((:startgroup . nil)
        ("Write" . ?w) ("Trad" . ?t) ("Read" . ?r) ("Proofread" . ?f)
        ("View" . ?v) ("Listen" . ?l)
        (:endgroup . nil)
        (:startgroup . nil) ("@Online" . ?O) ("@Offline" . ?F)
        (:endgroup . nil)
        ("Print" . ?P) ("Code" . ?c) ("Patch" . ?p) ("Bug" . ?b)
        ("Twit" . ?i) ("Tel" . ?T) ("Buy" . ?B) ("Doc" . ?d) ("Mail" . ?@)))
(setq org-tags-column -74)
(setq org-tags-match-list-sublevels t)
(setq org-todo-keywords '((type "STRT" "NEXT" "TODO" "WAIT" "|" "DONE" "DELEGATED" "CANCELED")))
(setq org-use-property-inheritance t)
(setq org-clock-persist t)
(setq org-clock-history-length 35)
(setq org-clock-in-resume t)
(setq org-clock-out-remove-zero-time-clocks t)
(setq org-clock-sound t)
(setq org-insert-heading-respect-content t)
(setq org-id-method 'uuidgen)
(setq org-combined-agenda-icalendar-file "~/org/bzg.ics")
(setq org-icalendar-combined-name "Bastien Guerry ORG")
(setq org-icalendar-use-scheduled '(todo-start event-if-todo event-if-not-todo))
(setq org-icalendar-use-deadline '(todo-due event-if-todo event-if-not-todo))
(setq org-icalendar-timezone "Europe/Paris")
(setq org-icalendar-store-UID t)
(setq org-timer-default-timer 20)
(setq org-confirm-babel-evaluate nil)
(setq org-archive-default-command 'org-archive-to-archive-sibling)
(setq org-clock-idle-time 15)
(setq org-id-uuid-program "uuidgen")
;;    (setq org-modules '(org-bbdb org-bibtex org-docview org-gnus org-id org-protocol org-info org-jsinfo org-irc org-w3m org-taskjuggler org-learn))
(setq org-modules '(org-bbdb org-bibtex org-docview org-gnus org-protocol org-info org-jsinfo org-irc org-w3m org-taskjuggler org-learn))
(setq org-use-speed-commands
      (lambda nil
        (and (looking-at org-outline-regexp-bol)
             (not (org-in-src-block-p t)))))
(setq org-src-tab-acts-natively t)
(setq org-hide-block-startup t)
(setq org-highlight-latex-and-related '(latex))
(setq org-log-into-drawer "LOGBOOK")
(setq org-goto-auto-isearch nil)
(setq org-beamer-outline-frame-title "Survol")
(setq org-image-actual-width 600)
(setq org-src-fontify-natively t)
(setq org-todo-keyword-faces '(("STRT" . "Purple")
                               ("WAIT" . "Gray")
                               ("CANCELED" . "Gray")))

(setq org-plantuml-jar-path "~/bin/plantuml.jar")
(setq org-link-abbrev-alist
      '(("bugzilla" . "")
        ("google"   . "")
        ("gnugol"   . "shell:gnugol -o org %s")
        ("gmap"     . "")
        ("omap"     . "")))

(setq org-attach-directory "~/org/data/")
(setq org-link-display-descriptive nil)
(setq org-loop-over-headlines-in-active-region t)
(setq org-create-formula-image-program 'dvipng) ;; imagemagick
(setq org-allow-promoting-top-level-subtree t)
(setq org-description-max-indent 5)
(setq org-gnus-prefer-web-links nil)
(setq org-html-head-include-default-style nil)
(setq org-html-head-include-scripts nil)
(setq org-blank-before-new-entry '((heading . t) (plain-list-item . auto)))
(setq org-contacts-files '("~/org/"))
(setq org-crypt-key "Bastien Guerry")
(setq org-enforce-todo-dependencies t)
(setq org-mobile-directory "~/Dropbox/org/")
(setq org-mobile-files '("~/Dropbox/org/" "~/org/"))
(setq org-fontify-whole-heading-line t)
(setq org-file-apps
      '((auto-mode . emacs)
        ("\\.mm\\'" . default)
        ("\\.x?html?\\'" . default)
        ("\\.pdf\\'" . "mupdf %s")))

Org publish project alist

(setq html-preamble "<div class=\"bg\">
  <a title=\"\" href=\"\"><img alt=\"Bastien Guerry\" src=\"u/bg.jpg\" /></a>

<div id=\"share\">
<!-- Place this tag where you want the share button to render. -->
<div class=\"g-plus\" data-action=\"share\" data-annotation=\"none\"></div>

<!-- Place this tag after the last share tag. -->
<script type=\"text/javascript\">
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = '';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);


<a href=\"\" class=\"twitter-share-button\" data-via=\"bzg2\">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);;js.src=p+'://';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>


<a href=\"\" class=\"twitter-follow-button\" data-show-count=\"false\">Follow @bzg2</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);;js.src=p+'://';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>

<div id=\"menu\">
  <a href=\"\"><button class=\"btn btn-success\" type=\"button\">Home</button></a>
  <a href=\"/blog.html\"><button class=\"btn btn-warning\" type=\"button\">Blog</button></a>
  <a href=\"/crowdsupport.html\"><button class=\"btn btn-danger\" type=\"button\">Donate</button></a>
  <a href=\"\"><button class=\"btn btn-success\" type=\"button\">Talks</button></a>

<script src=\"\" type=\"text/javascript\"></script>
<script type=\"text/javascript\">
 _uacct = \"UA-2658857-1\";

<div class=\"bottomrightbutton\">
<a href=\"\" target=\"_blank\"><img src=\"\" alt=\"Flattr this\" title=\"Flattr this\" border=\"0\" /></a>


<a rel=\"license\" href=\"\"><img class=\"flattr\" alt=\"Creative Commons License\" src=\"\" /></a>

(setq html-dll-preamble
    \(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

    ga('create', 'UA-42064173-1', '');
    ga('send', 'pageview');

    <div class=\"toprightbutton\">
    <a href=\"blog.xml\"><img alt=\"RSS\" width=\"70px\" src=\"u/rss.jpg\" /></a>

    <div class=\"topleftbutton\">

    <a href=\"/index.html\">Home</a><br/>

    <a href=\"\" target=\"new\"><img src=\"\" alt=\"Flattr this\" title=\"Flattr this\" border=\"0\" /></a><br/>

    <a href=\"\" class=\"twitter-share-button\"
    data-count=\"none\" data-via=\"bzg2\" data-lang=\"fr\">Tweeter</a><script
    type=\"text/javascript\" src=\"//\"></script>


    <div class=\"bottomrightbutton\">
    <a rel=\"license\" href=\"\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"\" /></a>

(setq html-postamble "
    <script src=\"u/bootstrap.min.js\"></script>")

(setq org-publish-project-alist
         :base-directory "~/install/git/homepage/"
         :html-extension "html"
         :base-extension "org"
         :publishing-directory "/home/guerry/public_html/org/homepage/"
         :publishing-function (org-html-publish-to-html)
         :auto-sitemap nil
         :recursive t
         :makeindex t
         :preserve-breaks nil
         :sitemap-sort-files chronologically
         :with-tasks nil
         :section-numbers nil
         :with-toc nil
         "<link rel=\"alternate\" type=\"application/rss+xml\" href=\"\" title=\"RSS feed for\">
<link rel=\"stylesheet\" href=\"u/bootstrap.min.css\" />
<link rel=\"stylesheet\" href=\"index.css\" type=\"text/css\" />
    <script src=\"\" type=\"text/javascript\"></script>
    <script type=\"text/javascript\">
      google.load(\"jquery\", \"1.3.1\");
         :html-preamble ,html-preamble
         :htmlized-source t
         :html-postamble ,html-postamble)
         :base-directory "~/install/git/homepage/"
         :base-extension "org"
         :publishing-directory "/home/guerry/public_html/org/homepage/"
         :publishing-function (org-org-publish-to-org)
         :recursive t
         :with-tasks nil
         :htmlized-source t)
         :base-directory "~/install/git/homepage/"
         :base-extension "org"
         :html-link-home ""
         :publishing-directory "/home/guerry/public_html/org/homepage/"
         :publishing-function (org-rss-publish-to-rss)
         :html-link-use-abs-url t
         :section-numbers nil
         :exclude ".*"
         :with-tasks nil
         :include ("")
         :with-toc nil)
         :base-directory "~/install/git/homepage/"
         :base-extension "org"
         :html-link-home ""
         :publishing-directory "/home/guerry/public_html/org/homepage/"
         :publishing-function (org-rss-publish-to-rss)
         :html-link-use-abs-url t
         :section-numbers nil
         :exclude ".*"
         :with-tasks nil
         :include ("")
         :with-toc nil)
         :base-directory "~/install/git/homepage"
         :base-extension "css"
         :publishing-directory "/home/guerry/public_html/org/homepage/"
         :publishing-function org-publish-attachment)
         :base-directory "~/install/git/homepage"
         :base-extension "png\\|jpg\\|gif\\|atom"
         :publishing-directory "/home/guerry/public_html/org/homepage/u/"
         :publishing-function org-publish-attachment)

         :base-directory "~/install/git/dotemacs/"
         :html-extension "html"
         :base-extension "org"
         :publishing-directory "/home/guerry/public_html/org/homepage/"
         :publishing-function (org-html-publish-to-html)
         :auto-sitemap nil
         :recursive t
         :makeindex nil
         :preserve-breaks nil
         :sitemap-sort-files chronologically
         :section-numbers nil
         :with-toc nil
         "<link rel=\"stylesheet\" href=\"u/bootstrap.min.css\" />
<link rel=\"stylesheet\" href=\"index.css\" type=\"text/css\" />"
         :html-preamble ,html-preamble
         :html-postamble ,html-postamble
         :htmlized-source nil
         :html-postamble nil)

         :base-directory "~/install/git/faqrel/"
         :html-extension "html"
         :base-extension "org"
         :publishing-directory "/home/guerry/public_html/org/homepage/"
         :publishing-function (org-html-publish-to-html)
         :auto-sitemap nil
         :recursive t
         :makeindex nil
         :preserve-breaks nil
         :sitemap-sort-files chronologically
         :section-numbers nil
         :with-toc nil
         "<link rel=\"stylesheet\" href=\"index.css\" type=\"text/css\" />"
         :html-preamble ,html-preamble
         :htmlized-source nil
         :html-postamble ,html-postamble)

         :base-directory "~/install/git/dunlivrelautre/"
         :html-extension "html"
         :base-extension "org"
         :publishing-directory "/home/guerry/public_html/org/dunlivrelautre/"
         :publishing-function (org-html-publish-to-html)
         :auto-sitemap nil
         :recursive t
         :with-tasks nil
         :makeindex t
         :preserve-breaks nil
         :sitemap-sort-files chronologically
         :section-numbers nil
         :with-toc nil
         :html-head-extra "<link rel=\"stylesheet\" href=\"index.css\" type=\"text/css\" />"
         :html-postamble nil
         :htmlized-source nil
         :html-preamble ,html-dll-preamble)
         :base-directory "~/install/git/dunlivrelautre/"
         :base-extension "org"
         :html-link-home ""
         :publishing-directory "/home/guerry/public_html/org/dunlivrelautre/"
         :publishing-function (org-rss-publish-to-rss)
         :html-link-use-abs-url t
         :section-numbers nil
         :exclude ".*"
         :include ("")
         :with-tasks nil
         :with-toc nil)
         :base-directory "~/install/git/dunlivrelautre"
         :base-extension "css"
         :publishing-directory "/home/guerry/public_html/org/dunlivrelautre/"
         :publishing-function org-publish-attachment)
         :base-directory "~/install/git/dunlivrelautre"
         :base-extension "png\\|jpg\\|gif\\|xml\\|atom"
         :publishing-directory "/home/guerry/public_html/org/dunlivrelautre/"
         :publishing-function org-publish-attachment)

        ;; Meta projects
        ("hp" :components
         ("homepage" "homepage-sources" "homepage-attachments" "homepage-rss" "clojure-rss" "homepage-css"))
        ("dll" :components ("dll" "dll-attachments" "dll-rss"))

(setq org-export-htmlize-output-type 'css)

(setq org-export-filter-planning-functions

(defun my-org-html-export-planning (planning-string backend info)
  (when (string-match "<p>.+><\\([0-9]+-[0-9]+-[0-9]+\\)[^>]+><.+</p>" planning-string)
    (concat "<span class=\"planning\">" (match-string 1 planning-string) "</span>")))

Org other variables

;; Generic / unsorted
(setq org-hide-leading-stars t)
(setq org-reveal-theme "night")
(setq org-global-properties
      '(("Effort_ALL" .
         "0 0:10 0:20 0:30 0:40 0:50 1:00 1:30 2:00 2:30 3:00 4:00 5:00 6:00 7:00 8:00")
        ("Progress_ALL" . "10% 20% 30% 40% 50% 60% 70% 80% 90%")
        ("Status_ALL" . "Work Leisure GTD WOT")))

(setq org-confirm-elisp-link-function nil)
(setq org-confirm-shell-link-function nil)
(setq org-context-in-file-links t)
(setq org-cycle-include-plain-lists nil)
(setq org-deadline-warning-days 7)
(setq org-default-notes-file "~/org/")
(setq org-directory "~/org/")
(setq org-ellipsis nil)
(setq org-email-link-description-format "%c: %.50s")
(setq org-support-shift-select t)

Org dynamic blocks

(defun org-dblock-write:fb_like (params)
  (let ((url (concat ""
                     (file-name-sans-extension (file-name-nondirectory
    (insert (format
             "#+HTML: <div class=\"fb-like\" data-href=\"%s\" data-send=\"true\" data-width=\"450\" data-show-faces=\"false\"></div>"


(require 'debbugs-org)
(setq debbugs-gnu-default-packages '("emacs" "org-mode"))


(require 'notmuch)

(setq notmuch-fcc-dirs nil)
(add-hook 'gnus-group-mode-hook 'bzg-notmuch-shortcut)

(defun bzg-notmuch-shortcut ()
  (define-key gnus-group-mode-map "GG" 'notmuch-search))

(defun bzg-notmuch-file-to-group (file)
  "Calculate the Gnus group name from the given file name."
  (let* ((g0 (directory-file-name (file-name-directory file)))
         (g1 (replace-regexp-in-string "/home/guerry/Mail/" "" g0)))
    (concat "nnml:" (replace-regexp-in-string "/" "." g1))))

(defun bzg-notmuch-goto-message-in-gnus ()
  "Open a summary buffer containing the current notmuch
  (let ((group (bzg-notmuch-file-to-group (notmuch-show-get-filename)))
        (message-id (replace-regexp-in-string
                     "^id:" "" (notmuch-show-get-message-id))))
    (setq message-id (replace-regexp-in-string "\"" "" message-id))
    (if (and group message-id)
          (switch-to-buffer "*Group*")
          (org-gnus-follow-link group message-id))
      (message "Couldn't get relevant infos for switching to Gnus."))))

(define-key notmuch-show-mode-map (kbd "C-c C-c") 'bzg-notmuch-goto-message-in-gnus)


Gnus general

(setq gnus-ignored-from-addresses
      (regexp-opt '(""

(require 'message)
(require 'gnus)
(require 'starttls)
(require 'epg)
(require 'epa)
(setq epa-popup-info-window nil)

(require 'smtpmail)
(require 'spam)

(setq spam-use-spamassassin t)
(setq spam-spamassassin-path "/usr/bin/vendor_perl/spamassassin")
(setq spam-use-spamassassin-headers t)
(setq smiley-style 'medium)

Set sendmail function and Gnus methods

(require 'boxquote)

(setq send-mail-function 'sendmail-send-it)
(setq message-send-mail-function 'message-send-mail-with-sendmail)

(setq use-dialog-box nil)
(setq user-full-name "Bastien Guerry")
;; (setq user-mail-address "")
(setq user-mail-address "")

(setq mail-header-separator "----")
(setq mail-use-rfc822 nil)

(setq message-cite-function (quote message-cite-original-without-signature))
(setq message-default-charset (quote utf-8))
(setq message-generate-headers-first t)

;; Attachments
(setq mm-content-transfer-encoding-defaults
       (("text/x-patch" 8bit)
        ("text/.*" 8bit)
        ("message/rfc822" 8bit)
        ("application/emacs-lisp" 8bit)
        ("application/x-emacs-lisp" 8bit)
        ("application/x-patch" 8bit)
        (".*" base64))))
(setq mm-default-directory "~/attachments/")
(setq mm-url-program (quote w3m))
(setq mm-url-use-external nil)

(setq nnmail-extra-headers
      '(X-Diary-Time-Zone X-Diary-Dow X-Diary-Year
        X-Diary-Month X-Diary-Dom X-Diary-Hour X-Diary-Minute To Newsgroups Cc))

;; Sources and methods
(setq mail-sources '((file :path "/var/mail/guerry")
                     (maildir :path "~/Maildir/" :subdirs ("cur" "new")))
      gnus-select-method '(nnmaildir "Bastien" (directory "~/Maildir/"))
      '((nnml "")
        (nntp "news" (nntp-address ""))
        (nntp "free" (nntp-address ""))
        ;; (nnimap "")
        (nnimap "")

(setq gnus-check-new-newsgroups nil)
(setq gnus-read-active-file 'some)
(setq gnus-agent t)
(setq gnus-agent-consider-all-articles t)
(setq gnus-agent-enable-expiration 'disable)

Set basics

(setq read-mail-command 'gnus
      message-mail-user-agent 'gnus-user-agent
      message-kill-buffer-on-exit t
      ;; user-mail-address ""
      ;; mail-envelope-from ""
      mail-user-agent 'gnus-user-agent
      mail-specify-envelope-from nil
      gnus-directory "~/News/"
      gnus-novice-user nil
      gnus-inhibit-startup-message t
      gnus-play-startup-jingle nil
      gnus-interactive-exit nil
      gnus-no-groups-message ""
      gnus-show-all-headers nil
      gnus-use-correct-string-widths nil
      gnus-use-cross-reference nil
      gnus-asynchronous t
      gnus-interactive-catchup nil
      gnus-inhibit-user-auto-expire t
      gnus-gcc-mark-as-read t
      gnus-verbose 6
      gnus-backup-startup-file t
      gnus-use-tree t
      gnus-use-header-prefetch t
      gnus-large-newsgroup 10000
      nnmail-expiry-wait 'never
      nnimap-expiry-wait 'never
      nnmail-crosspost nil
      nnmail-expiry-target "nnml:expired"
      nnmail-split-methods 'nnmail-split-fancy
      nnmail-treat-duplicates 'delete
      nnml-marks nil
      gnus-nov-is-evil nil
      nnml-marks-is-evil t
      nntp-marks-is-evil t)

(setq message-dont-reply-to-names gnus-ignored-from-addresses)

;; Start the topic view
(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)

;; Levels and subscription
(setq gnus-subscribe-newsgroup-method 'gnus-subscribe-interactively
      gnus-group-default-list-level 3
      gnus-level-default-subscribed 3
      gnus-level-default-unsubscribed 7
      gnus-level-subscribed 6
      gnus-level-unsubscribed 7
      gnus-activate-level 5)

;; Archives
(setq gnus-message-archive-group
      '((if (message-news-p)
            (concat "nnfolder+archive:" (format-time-string "%Y-%m")
          (concat "nnfolder+archive:" (format-time-string "%Y-%m")

;; Delete mail backups older than 1 days
(setq mail-source-delete-incoming 1)

;; Select the first mail when entering a group
(setq gnus-auto-select-first t)
(setq gnus-auto-select-subject 'unread)

;; Group sorting
(setq gnus-group-sort-function

;; Thread sorting (from Gnus master branch as of 2013-07-30)
;; (setq gnus-thread-sort-functions
;;       '(gnus-thread-sort-by-most-recent-date
;;         gnus-thread-sort-by-number
;;         gnus-thread-sort-by-total-score)
;;       gnus-subthread-sort-functions
;;       '(gnus-thread-sort-by-date
;;         gnus-thread-sort-by-number)
;;       gnus-sort-gathered-threads-function
;;       'gnus-thread-sort-by-date)

;; Display the thread by default
(setq gnus-thread-hide-subtree nil)

;; Headers we wanna see:
(setq gnus-visible-headers

;;; [En|de]coding
(setq mm-body-charset-encoding-alist
      '((utf-8 . 8bit)
        (iso-8859-1 . 8bit)
        (iso-8859-15 . 8bit)))

(setq mm-coding-system-priorities
      '(iso-8859-1 iso-8859-9 iso-8859-15 utf-8
                   iso-2022-jp iso-2022-jp-2 shift_jis))

;; bbdb
(setq gnus-use-generic-from t
      gnus-use-bbdb t)

;;; Trier les mails
(setq nnmail-split-abbrev-alist
      '((any . "From\\|To\\|Cc\\|Sender\\|Apparently-To\\|Delivered-To\\|X-Apparently-To\\|Resent-From\\|Resent-To\\|Resent-Cc")
        (mail . "Mailer-Daemon\\|Postmaster\\|Uucp")
        (to . "To\\|Cc\\|Apparently-To\\|Resent-To\\|Resent-Cc\\|Delivered-To\\|X-Apparently-To")
        (from . "From\\|Sender\\|Resent-From")
        (nato . "To\\|Cc\\|Resent-To\\|Resent-Cc\\|Delivered-To\\|X-Apparently-To")
        (naany . "From\\|To\\|Cc\\|Sender\\|Resent-From\\|Resent-To\\|Delivered-To\\|X-Apparently-To\\|Resent-Cc")))

;; Load nnmail-split-fancy (private)
(load "/home/guerry/elisp/config/gnus_.el")

;; Simplify the subject lines
(setq gnus-simplify-subject-functions

;; Display faces
(setq gnus-treat-display-face 'head)

;; Thread by Xref, not by subject
(setq gnus-thread-ignore-subject t)
(setq gnus-summary-thread-gathering-function

;; Dispkay a button for MIME parts
(setq gnus-buttonized-mime-types '("multipart/alternative"))

;; Use w3m to display HTML mails
(setq mm-text-html-renderer 'gnus-w3m
      mm-inline-text-html-with-images t
      mm-inline-large-images nil
      mm-attachment-file-modes 420)

;; Avoid spaces when saving attachments
(setq mm-file-name-rewrite-functions

(setq gnus-user-date-format-alist
      '(((gnus-seconds-today) . "     %k:%M")
        ((+ 86400 (gnus-seconds-today)) . "hier %k:%M")
        ((+ 604800 (gnus-seconds-today)) . "%a  %k:%M")
        ((gnus-seconds-month) . "%a  %d")
        ((gnus-seconds-year) . "%b %d")
        (t . "%b %d '%y")))

;; Add a time-stamp to a group when it is selected
(add-hook 'gnus-select-group-hook 'gnus-group-set-timestamp)

;; Format group line
(setq gnus-group-line-format
      ;;      "%M\%S\%p\%P\%5T>%5y: %(%-40,40g%) %ud\n")
      ;;      "%M\%S\%p\%P\%y: %(%-40,40g%) %T/%i\n")
      ;; "%M\%S\%p\%P %(%-30,30G%) %-3y %-3T %-3I\n"
      "%M\%S\%p\%P %(%-40,40G%)\n")

(setq gnus-topic-indent-level 3)

(defun bzg-gnus-toggle-group-line-format ()
  (if (equal gnus-group-line-format
             "%M\%S\%p\%P %(%-40,40G%) %-3y %-3T %-3I\n")
      (setq gnus-group-line-format
             "%M\%S\%p\%P %(%-40,40G%)\n")
    (setq gnus-group-line-format
          "%M\%S\%p\%P %(%-40,40G%) %-3y %-3T %-3I\n")))

(define-key gnus-group-mode-map "x"
  (lambda () (interactive) (bzg-gnus-toggle-group-line-format) (gnus)))

;; (define-key gnus-group-mode-map "X"
;;   (lambda ()
;;     (interactive)
;;     (setq gnus-secondary-select-methods
;;           '((nnml "")
;;             (nntp "news" (nntp-address ""))
;;             (nntp "free" (nntp-address ""))
;;             (nnimap "")
;;             (nnimap "")))
;;     (gnus-server-open-server "")
;;     (gnus-server-open-server "nntp:news")
;;     (gnus-server-open-server "nntp:free"))
;;     (gnus))

(define-key gnus-summary-mode-map "$" 'gnus-summary-mark-as-spam)

;; Scoring
(setq gnus-use-adaptive-scoring 'line
      ;; gnus-score-expiry-days 14
      '((gnus-dormant-mark (from 20) (subject 100))
        (gnus-ticked-mark (subject 30))
        (gnus-read-mark (subject 30))
        (gnus-del-mark (subject -150))
        (gnus-catchup-mark (subject -150))
        (gnus-killed-mark (subject -1000))
        (gnus-expirable-mark (from -1000) (subject -1000)))
      gnus-score-decay-constant 1    ;default = 3
      gnus-score-decay-scale 0.03    ;default = 0.05
      gnus-decay-scores t)           ;(gnus-decay-score 1000)

;; (setq gnus-face-0 '((t (:foreground "grey60"))))
;; (setq gnus-face-1 '((t (:foreground "grey30"))))
;; (setq gnus-face-2 '((t (:foreground "grey90"))))

;; Prompt for the right group
(setq gnus-group-jump-to-group-prompt
      '((0 . "nnml:mail.")
        (1 . "nnfolder+archive:2013-")
        (2 . "nnfolder+archive:2012-")
        (3 . "nntp+news:gmane.")))

(setq gnus-summary-line-format
      (concat "%*%0{%U%R%z%}"
              "%0{ %}(%2t)"
              "%2{ %}%-23,23n"
              "%1{ %}%1{%B%}%2{%-102,102s%}%-140="

(require 'ecomplete)
(setq message-mail-alias-type 'ecomplete)

(add-hook 'message-mode-hook 'turn-on-orgstruct++)
(add-hook 'message-mode-hook 'turn-on-orgtbl)

(require 'gnus-gravatar)

;; Hack to store Org links upon sending Gnus messages

(defun bzg-message-send-and-org-gnus-store-link (&optional arg)
  "Send message with `message-send-and-exit' and store org link to message copy.
If multiple groups appear in the Gcc header, the link refers to
the copy in the last group."
  (interactive "P")
        (let ((gcc (car (last
                           (mail-fetch-field "gcc" nil t) " ,")))))
              (buf (current-buffer))
              (message-kill-buffer-on-exit nil)
              id to from subject desc link newsgroup xarchive)
        (message-send-and-exit arg)
         ;; gcc group found ...
         (and gcc
                (progn (set-buffer buf)
                       (setq id (org-remove-angle-brackets
                                 (mail-fetch-field "Message-ID")))
                       (setq to (mail-fetch-field "To"))
                       (setq from (mail-fetch-field "From"))
                       (setq subject (mail-fetch-field "Subject"))))
              (org-store-link-props :type "gnus" :from from :subject subject
                                    :message-id id :group gcc :to to)
              (setq desc (org-email-link-description))
              (setq link (org-gnus-article-link
                          gcc newsgroup id xarchive))
              (setq org-stored-links
                    (cons (list link desc) org-stored-links)))
         ;; no gcc group found ...
         (message "Can not create Org link: No Gcc header found."))))))

(define-key message-mode-map [(control c) (control meta c)]

;; (defun gnus-thread-sort-by-length (h1 h2)
;;   "Sort threads by the sum of all articles in the thread."
;;   (> (gnus-thread-length h1)
;;      (gnus-thread-length h2)))

;; (defun gnus-thread-length (thread)
;;   "Find the total number of articles in THREAD."
;;   (cond
;;    ((null thread) 0)
;;    ((listp thread) (length thread))))

(setq message-fill-column 70)
(setq message-use-mail-followup-to nil)


(setq bbdb-file "~/elisp/config/bbdb")

(require 'bbdb)
(require 'bbdb-loaddefs)
;; (require 'bbdb-hooks)
(require 'bbdb-com)
(require 'bbdb-anniv)
(require 'bbdb-gnus)
;; (require 'moy-bbdb)

(setq bbdb-pop-up-window-size 5)

(setq bbdb-update-records-p 'create)
(bbdb-mua-auto-update-init 'gnus 'message)
(setq bbdb-mua-pop-up nil)

(bbdb-initialize 'message 'gnus)

(setq bbdb-allow-duplicates t)

;; (autoload 'bbdb/send-hook "moy-bbdb"
;;   "Function to be added to `message-send-hook' to notice records
;;   when sending messages" t)

;; (add-hook 'message-send-hook 'bbdb/send-hook)

(add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus)
;; (add-hook 'message-setup-hook 'bbdb-define-all-aliases) Not in bbdb3?
(add-hook 'bbdb-change-hook 'bbdb-timestamp)
(add-hook 'bbdb-create-hook 'bbdb-creation-date)
(add-hook 'bbdb-notice-mail-hook 'bbdb-auto-notes)
(autoload 'bbdb-insinuate-gnus "bbdb-insinuate-gnus" "BBDB Gnus" t)
;; (add-hook 'list-diary-entries-hook 'bbdb-include-anniversaries)

(setq bbdb-always-add-addresses t
      bbdb-complete-name-allow-cycling t
      bbdb-completion-display-record t
      bbdb-default-area-code nil
      bbdb-dwim-net-address-allow-redundancy t
      bbdb-electric-p nil
      bbdb-new-nets-always-primary 'never
      bbdb-north-american-phone-numbers-p nil
      bbdb-offer-save 'auto
      bbdb-pop-up-target-lines 3
      bbdb-print-net 'primary
      bbdb-print-require t
      bbdb-use-pop-up nil
      bbdb-user-mail-names gnus-ignored-from-addresses
      bbdb/gnus-split-crosspost-default nil
      bbdb/gnus-split-default-group nil
      bbdb/gnus-split-myaddr-regexp gnus-ignored-from-addresses
      bbdb/gnus-split-nomatch-function nil
      bbdb/gnus-summary-known-poster-mark "+"
      bbdb/gnus-summary-mark-known-posters t)

(defalias 'bbdb-y-or-n-p '(lambda (prompt) t))

;; only set this when bbdb-user-mail-names is set
;; (setq bbdb-ignore-most-messages-alist
;;       `(("To" . ,bbdb-user-mail-names)))

;; FIXME: ignore hook est cassé
;; (setq bbdb/mail-auto-create-p 'bbdb-ignore-most-messages-hook)
;; (setq bbdb/news-auto-create-p 'bbdb-ignore-most-messages-hook)

(setq bbdb-auto-notes-alist
      `(("Newsgroups" ("[^,]+" newsgroups 0))
        ("Subject" (".*" last-subj 0 t))
        ("User-Agent" (".*" mailer 0))
        ("X-Mailer" (".*" mailer 0))
        ("Organization" (".*" organization 0))
        ("X-Newsreader" (".*" mailer 0))
        ("X-Face" (".+" face 0 'replace))
        ("Face" (".+" face 0 'replace))))

(add-hook 'bbdb-list-hook 'my-bbdb-display-xface)

(defun my-bbdb-display-xface ()
  "Search for face properties and display the faces."
  (when (or (gnus-image-type-available-p 'xface)
            (gnus-image-type-available-p 'pbm))
      (goto-char (point-min))
      (let ((inhibit-read-only t)
            (default-enable-multibyte-characters nil)
            pbm faces)
        (while (re-search-forward "^           face: \\(.*\\)" nil t)
          (setq faces (match-string 1))
          (replace-match "" t t nil 1)
          (dolist (data (split-string faces ", "))
            (condition-case nil
                (insert-image (create-image (gnus-convert-face-to-png data) nil t))
               (insert-image (gnus-create-image (uncompface data) nil t :face 'tooltip))))
            (insert " ")))))))

;; (setq bbdb-quiet-about-name-mismatches 0)

;; (setq bbdb-message-caching-enabled nil)


ERC variables

(require 'erc)
(require 'erc-services)

    (1 todo-comment-face t))))

(setq erc-modules '(autoaway autojoin irccontrols log netsplit noncommands
                             notify pcomplete completion ring services stamp
                             track truncate)
      erc-keywords nil
      erc-prompt-for-nickserv-password nil
      erc-timestamp-format "%s "
      erc-hide-timestamps t
      erc-log-channels t
      erc-log-write-after-insert t
      erc-log-insert-log-on-open nil
      erc-save-buffer-on-part t
      erc-input-line-position 0
      erc-fill-function 'erc-fill-static
      erc-fill-static-center 0
      erc-fill-column 130
      erc-insert-timestamp-function 'erc-insert-timestamp-left
      erc-insert-away-timestamp-function 'erc-insert-timestamp-left
      erc-whowas-on-nosuchnick t
      erc-public-away-p nil
      erc-save-buffer-on-part t
      erc-echo-notice-always-hook '(erc-echo-notice-in-minibuffer)
      erc-auto-set-away nil
      erc-autoaway-message "%i seconds out..."
      erc-away-nickname "bz_g"
      erc-kill-queries-on-quit nil
      erc-kill-server-buffer-on-quit t
      erc-log-channels-directory "~/.erc_log"
      ;; erc-enable-logging 'erc-log-all-but-server-buffers
      erc-enable-logging t
      erc-query-on-unjoined-chan-privmsg t
      erc-auto-query 'window-noselect
      erc-server-coding-system '(utf-8 . utf-8)
      erc-encoding-coding-alist '(("#emacs" . utf-8)
                                  ("#frlab" . iso-8859-1)
                                  ("&bitlbee" . utf-8)))

(defun erc-notify-on-msg (msg)
  (if (string-match "bz_g:" msg)
      (shell-command (concat "notify-send \"" msg "\""))))
(add-hook 'erc-insert-pre-hook 'erc-notify-on-msg)

ERC connect to bitlbee

(defun bzg-erc-connect-bitlbee ()
  "Connect to &bitlbee channel with ERC."
  (erc-select :server ""
              :port 6667
              :nick "bz_g"
              :full-name "Bastien"))

(defun bzg-erc-connect-bitlbee-2 ()
  "Connect to &bitlbee channel with ERC."
  (erc-select :server ""
              :port 6667
              :nick "lml"
              :full-name "Le_ Musée_ Libre_"))

(defun bzg-erc-connect-freenode ()
  "Connect to Freenode server with ERC."
  (erc-select :server ""
              :port 6666
              :nick "bz_g"
              :full-name "Bastien"))

ERC hooks

(add-hook 'erc-mode-hook
          '(lambda ()
             (auto-fill-mode -1)
             (erc-completion-mode 1)
             (erc-ring-mode 1)
             (erc-log-mode 1)
             (erc-netsplit-mode 1)
             (erc-button-mode -1)
             (erc-match-mode 1)
             (erc-autojoin-mode 1)
             (erc-nickserv-mode 1)
             (erc-timestamp-mode 1)
             (erc-services-mode 1)))

ERC bot (disabled)

;; (add-hook 'erc-server-PRIVMSG-functions 'erc-bot-remote t)
;; (add-hook 'erc-send-completed-hook 'erc-bot-local t)
;; (add-hook 'erc-server-PRIVMSG-functions 'erc-warn-me-PRIVMSG t)

;; (defun erc-warn-me-PRIVMSG (proc parsed)
;;   (let* ((nick (car (erc-parse-user (erc-response.sender parsed))))
;;          (msg (erc-response.contents parsed)))
;;     ;; warn me if I'm in bitlbee or #org-mode
;;     (when (string-match "bitlbee\\|org-mode"
;;                      (buffer-name (window-buffer)))
;;       (let ((minibuffer-message-timeout 3))
;;      (minibuffer-message (format "%s: %s" nick msg))))))

ERC passwords

(load "/home/guerry/elisp/config/erc_.el")


(setq w3m-accept-languages '("fr;" "q=1.0" "en;"))
(setq w3m-antenna-sites '(("" "EUCD.INFO" time)))
(setq w3m-broken-proxy-cache t)
(setq w3m-confirm-leaving-secure-page nil)
(setq w3m-cookie-accept-bad-cookies nil)
(setq w3m-cookie-accept-domains nil)
(setq w3m-cookie-file "/home/guerry/.w3m/cookie")
(setq w3m-fill-column 70)
(setq w3m-form-textarea-edit-mode 'org-mode)
(setq w3m-icon-directory nil)
(setq w3m-key-binding 'info)
(setq w3m-use-cookies t)
(setq w3m-use-tab t)
(setq w3m-use-toolbar nil)

Buffer length goal

(defvar buffer-length-goal nil)
(defvar buffer-length-to-goal nil)
(make-variable-buffer-local 'buffer-length-goal)
(make-variable-buffer-local 'buffer-length-to-goal)

(defun bzg-set-buffer-length-goal ()
  (setq buffer-length-goal
        (string-to-number (read-from-minibuffer "Buffer length goal: ")))
  (setq buffer-length-to-goal (bzg-update-buffer-length-goal))
  (add-to-list 'global-mode-string 'buffer-length-to-goal t)
  (run-at-time nil 3 'bzg-update-buffer-length-goal))

(defun bzg-update-buffer-length-goal ()
  (setq buffer-length-to-goal
        (concat " Done: "
                  (- 100
                     (* 100
                        (/ (float (- buffer-length-goal (buffer-size)))
                           buffer-length-goal))))) "%"))

Calendar and diary

(global-set-key (quote [f12]) 'calendar)

(setq diary-file "~/.diary")

(setq french-holiday
      '((holiday-fixed 1 1 "Jour de l'an")
        (holiday-fixed 5 8 "Victoire 45")
        (holiday-fixed 7 14 "Fête nationale")
        (holiday-fixed 8 15 "Assomption")
        (holiday-fixed 11 1 "Toussaint")
        (holiday-fixed 11 11 "Armistice 18")
        (holiday-easter-etc 1 "Lundi de Pâques")
        (holiday-easter-etc 39 "Ascension")
        (holiday-easter-etc 50 "Lundi de Pentecôte")
        (holiday-fixed 1 6 "Épiphanie")
        (holiday-fixed 2 2 "Chandeleur")
        (holiday-fixed 2 14 "Saint Valentin")
        (holiday-fixed 5 1 "Fête du travail")
        (holiday-fixed 5 8 "Commémoration de la capitulation de l'Allemagne en 1945")
        (holiday-fixed 6 21 "Fête de la musique")
        (holiday-fixed 11 2 "Commémoration des fidèles défunts")
        (holiday-fixed 12 25 "Noël")
        ;; fêtes à date variable
        (holiday-easter-etc 0 "Pâques")
        (holiday-easter-etc 49 "Pentecôte")
        (holiday-easter-etc -47 "Mardi gras")
        (holiday-float 6 0 3 "Fête des pères") ;; troisième dimanche de juin
        ;; Fête des mères
         '(if (equal
               ;; Pentecôte
               (holiday-easter-etc 49)
               ;; Dernier dimanche de mai
               (holiday-float 5 0 -1 nil))
              ;; -> Premier dimanche de juin si coïncidence
              (car (car (holiday-float 6 0 1 nil)))
            ;; -> Dernier dimanche de mai sinon
            (car (car (holiday-float 5 0 -1 nil))))
         "Fête des mères")))

(setq calendar-date-style 'european
      calendar-holidays (append french-holiday)
      calendar-mark-holidays-flag t
      calendar-week-start-day 1
      calendar-mark-diary-entries-flag nil)

(setq TeX-master 'dwim)
(setq doc-view-scale-internally nil)

Various functions

(defun bzg-find-bzg nil
  "Find the file."
  (find-file "~/org/"))

(defun org-ibuffer ()
  "Open an `ibuffer' window showing only `org-mode' buffers."
  (ibuffer nil "*Org Buffers*" '((used-mode . org-mode))))

(defun kill-line-save (&optional arg)
  "Save the rest of the line as if killed, but don't kill it."
  (interactive "P")
  (let ((buffer-read-only t))
    (kill-line arg)
    (message "Line(s) copied to the kill ring")))

(defun copy-line (&optional arg)
  "Copy the current line."
  (interactive "P")
   (+ (if kill-whole-line 1 0) (point-at-eol arg))))

(defun racket-enter! ()
  (comint-send-string (scheme-proc)
        (format "(enter! (file \"%s\") #:verbose)\n" buffer-file-name))
  (switch-to-scheme t))

(defun unfill-paragraph ()
  "Takes a multi-line paragraph and makes it into a single line of text."
  (let ((fill-column (point-max)))
    (fill-paragraph nil)))
;; Handy key definition
(define-key global-map "\M-Q" 'unfill-paragraph)

(defun uniquify-all-lines-region (start end)
  "Find duplicate lines in region START to END keeping first occurrence."
  (interactive "*r")
    (let ((end (copy-marker end)))
            (goto-char start)
            (re-search-forward "^\\(.*\\)\n\\(\\(.*\n\\)*\\)\\1\n" end t))
        (replace-match "\\1\n\\2")))))

(defun uniquify-all-lines-buffer ()
  "Delete duplicate lines in buffer and keep first occurrence."
  (interactive "*")
  (uniquify-all-lines-region (point-min) (point-max)))

(defun my-copy-rectangle-to-primary ()
  (when (region-active-p)
    (let ((text (mapconcat 'identity
                            (region-end)) "\n")))
      (deactivate-mark) ;; lost 30mn because of this
      (x-set-selection 'PRIMARY text)
      (message "%s" text))))

(defun insert-xo () (interactive) (insert "⨰"))

(defun org-dblock-write:amazon (params)
  "Dynamic block for inserting the cover of a book."
  (let* ((asin (plist-get params :asin))
         (tpl "<a href=\"\"><img border=\"0\" src=\"\" ></a><img src=\"\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" />")
         (str (format tpl asin asin asin asin)))
    (insert "#+begin_html\n" str "\n#+end_html")))

(defun benchmark-two-defuns (defa defb)
   (list (intern (completing-read "First function: " obarray))
         (intern (completing-read "Second function: " obarray))))
  (message "%d"
           (/ (/ (car (benchmark-run 10 (funcall defa))) 10)
              (/ (car (benchmark-run 10 (funcall defb))) 10))))

(defun next-word-at-point (previous)
  "Jump to the next occurrence of the word at point."
  (interactive "P")
  (let* ((w (thing-at-point 'word))
         (w (mapconcat
             (lambda(c) (if (eq (char-syntax c) ?w)
                            (char-to-string c))) w ""))
         (wre (concat "\\<" w "\\>"))
         (s (if previous #'re-search-backward #'re-search-forward)))
    (unless previous (forward-word 1))
    (funcall s wre nil t)
    (unless previous (re-search-backward wre nil t))))

(defun previous-word-at-point ()
  "Jump to the previous occurrence of the word at point."
  (next-word-at-point t))

(defun current-word-search ()
  "Search forward for word under cursor"
  (word-search-forward (current-word)))

(defun org-hh:mm:ss-string-to-seconds (hhmmss-string)
  (when (string-match "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)"
    (let ((hours (string-to-number (match-string 1 hhmmss-string)))
          (mins (string-to-number (match-string 2 hhmmss-string)))
          (secs (string-to-number (match-string 3 hhmmss-string))))
      (+ (* 3600 hours) (* 60 mins) secs))))

(defun increase-srt (n)
  "Increase srt timestamp by N seconds."
  (interactive "p")
  (goto-char (point-min))
  (while (re-search-forward "\\([0-9]+:[0-9]+:[0-9]+\\)," nil t)
    (let ((s (save-match-data (org-hh:mm:ss-string-to-seconds (match-string 1)))))
      (replace-match (save-match-data (org-format-seconds "%.2h:%.2m:%.2s," (+ s n))) t t))))

;; No mode-line
;; (if (custom-theme-enabled-p "cyberpunk")
;;     (custom-set-faces
;;      '(fringe ((t (:background "black"))))
;;      '(mode-line-highlight ((t nil)))
;;      '(mode-line ((t (:foreground "white" :background "black"))))
;;      '(mode-line-inactive ((t (:background "white" :foreground "black")))))
;;   (custom-set-faces
;;    '(fringe ((t (:background "white"))))
;;    '(mode-line-highlight ((t nil)))
;;    '(mode-line ((t (:foreground "black" :background "white"))))
;;    '(mode-line-inactive ((t (:background "black" :foreground "white"))))))

;; Hide fringe indicators
(mapcar (lambda(fb) (set-fringe-bitmap-face fb 'org-hide))

;; Command to toggle the display of the mode-line as a header
(defun mode-line-in-header ()
  (if (not header-line-format)
      (rotatef header-line-format mode-line-format)
    (rotatef mode-line-format header-line-format))
(global-set-key (kbd "C-s-SPC") 'mode-line-in-header)

(defvar bzg-big-fringe-mode nil)
(define-minor-mode bzg-big-fringe-mode
  "Minor mode to hide the mode-line in the current buffer."
  :init-value nil
  :global t
  :variable bzg-big-fringe-mode
  :group 'editing-basics
  (if (not bzg-big-fringe-mode)
      (set-fringe-style nil)
     ;; (/ (- (frame-pixel-width)
     ;;       (* 120 (frame-char-width)))
     ;;    2)

(defun bzg-enable-big-fringe-conditionnally ()
  (if (delq nil
  (let ((fw (frame-width)))
    (mapcar (lambda(w) (< (window-width w) fw))
      (bzg-big-fringe-mode 0)
    (bzg-big-fringe-mode 1)))

(add-hook 'window-configuration-change-hook

;; (remove-hook 'window-configuration-change-hook
;;              'bzg-enable-big-fringe-conditionnally)

;; See
(defvar-local hidden-mode-line-mode nil)
(defvar-local hide-mode-line nil)

(define-minor-mode hidden-mode-line-mode
  "Minor mode to hide the mode-line in the current buffer."
  :init-value nil
  :global nil
  :variable hidden-mode-line-mode
  :group 'editing-basics
  (if hidden-mode-line-mode
      (setq hide-mode-line mode-line-format
            mode-line-format nil)
    (setq mode-line-format hide-mode-line
          hide-mode-line nil))
  ;; Apparently force-mode-line-update is not always enough to
  ;; redisplay the mode-line
  (when (and (called-interactively-p 'interactive)
     0 nil 'message
     (concat "Hidden Mode Line Mode enabled.  "
             "Use M-x hidden-mode-line-mode to make the mode-line appear."))))

(add-hook 'after-change-major-mode-hook 'hidden-mode-line-mode)

Start the server


Customize modes

Emacs lisp

(add-hook 'emacs-lisp-mode-hook 'turn-on-orgstruct)
(add-hook 'emacs-lisp-mode-hook 'fontify-todo)
(add-hook 'emacs-lisp-mode-hook 'fontify-headline)
(add-hook 'emacs-lisp-mode-hook 'company-mode)
(add-hook 'emacs-lisp-mode-hook 'electric-indent-mode 'append)

(add-hook 'clojure-mode-hook 'turn-on-orgstruct)
(add-hook 'clojure-mode-hook 'fontify-todo)
(add-hook 'clojure-mode-hook 'fontify-headline)
(add-hook 'emacs-lisp-mode-hook 'company-mode 'append)
(add-hook 'emacs-lisp-mode-hook 'electric-indent-mode 'append)

;; (require 'paredit)
;; (add-hook 'emacs-lisp-mode-hook 'paredit-mode)
;; (add-hook 'clojure-mode-hook 'paredit-mode)
;; (add-hook 'emacs-lisp-mode-hook 'electric-layout-mode)

(defvar todo-comment-face 'todo-comment-face)
(defvar headline-face 'headline-face)

;; Fontifying todo items outside of org-mode
(defface todo-comment-face
  '((t (:background "gray"
        :foreground "black"
        :weight bold
        :bold t)))
  "Face for TODO in code buffers."
  :group 'org-faces)

(defface headline-face
  '((t (:foreground "gray"
        :background "black"
        :weight bold
        :bold t)))
  "Face for headlines."
  :group 'org-faces)

(defun fontify-todo ()
   nil '((";;.*\\(TODO\\|FIXME\\)"
          (1 todo-comment-face t)))))

(defun fontify-headline ()
   nil '(("^;;;;* ?\\(.*\\)\\>"
          (1 headline-face t)))))


(setq geiser-active-implementations '(guile racket))
(setq geiser-scheme-implementation 'racket)
(setq geiser-repl-startup-time 20000)


(require 'git-commit-mode)
(require 'rebase-mode)
(require 'magit)

(global-set-key (quote [f9]) 'magit-status)

(setq magit-save-some-buffers 'dontask)
(setq magit-commit-all-when-nothing-staged 'ask)


(require 'helm-config)

(defun helm-clojure-headlines ()
  "Display headlines for the current Clojure file."
  (helm :sources '(((name . "Clojure Headlines")
                    (headline "^[;(]")))))

lein kibit

;; Teach compile the syntax of the kibit output
(require 'compile)
(add-to-list 'compilation-error-regexp-alist-alist
         '(kibit "At \\([^:]+\\):\\([[:digit:]]+\\):" 1 2 nil 0))
(add-to-list 'compilation-error-regexp-alist 'kibit)

;; A convenient command to run "lein kibit" in the project to which
;; the current emacs buffer belongs to.
(defun kibit ()
  "Run kibit on the current project.
Display the results in a hyperlinked *compilation* buffer."
  (compile "lein kibit"))

(defun kibit-current-file ()
  "Run kibit on the current file.
Display the results in a hyperlinked *compilation* buffer."
  (compile (concat "lein kibit " buffer-file-name)))


(require 'clojure-cheatsheet)
(require 'clj-refactor)
(cljr-add-keybindings-with-prefix "C-c C-x")


(setq doc-view-continuous t)
(set-frame-parameter nil 'fullscreen 'fullboth)


;; (put 'org-paragraph 'bounds-of-thing-at-point
;;      'thing-at-point-bounds-of-org-paragraph-at-point)

;; (defun thing-at-point-bounds-of-org-paragraph-at-point ()
;;   "Return the bounds of the org paragraph at point."
;;   (save-excursion
;;     (cons (progn (ignore-errors (org-backward-paragraph) (point)))
;;        (progn (ignore-errors (org-forward-paragraph))))))