; Path to *.el files (add-to-list 'load-path "~/.emacs.d/") ;; General settings ; Emacs color theme (require 'zenburn) (color-theme-zenburn) ; Start emacs server (server-start) (setq user-full-name "Arnaud Fontaine") (setq user-email "arnau@debian.org") ; Some useful keys (global-set-key (kbd "C-x s") 'query-replace-regexp) (global-set-key (kbd "C-x c") 'comment-region) (global-set-key (kbd "C-x u") 'uncomment-region) (global-set-key (kbd "M-z") 'downcase-word) (global-set-key (kbd "M-g") 'goto-line) (global-set-key (kbd "C-x C-m") 'compile) ; Prevent *scratch* buffer from accidental killed (require 'protbuf) (protect-buffer-from-kill-mode 1 "*scratch*") ; Put autosave and backup files in one place (let ((backup-dir "~/tmp/emacs/")) (defvar autosave-dir backup-dir) (make-directory autosave-dir t) (defvar backup-dir backup-dir) (setq backup-directory-alist (list (cons "." backup-dir)))) ;; Fix dead keys (e.g ' is undefined') (load-library "iso-transl") ; Allow to use M-y even with emacs22 (require 'browse-kill-ring) (browse-kill-ring-default-keybindings) ; Disable useless toolbars (tool-bar-mode -1) (scroll-bar-mode -1) ; Get rid of bells (setq visible-bell nil) (setq ring-bell-function 'ignore) ; Display time (display-time) (setq display-time-24hr-format t display-time-day-and-date t) ; Display column and line numbers (column-number-mode t) (line-number-mode t) ; Better frame title (setq frame-title-format '(buffer-file-name "Emacs: %b (%f)" "Emacs: %b")) ; Misc settings (set-input-mode nil nil 1) (show-paren-mode t) (global-font-lock-mode t) (transient-mark-mode t) (mouse-avoidance-mode 'jump) (put 'narrow-to-region 'disabled nil) (setq inhibit-startup-message t font-lock-maximum-decoration t indent-tabs-mode nil) ; Pour guess-lang (setq guess-lang-languages-to-guess '("french" "american")) ;; OTHER SETTINGS ;; Tramp (setq tramp-default-method "ssh") ;; Shebang ;; http://www.emacswiki.org/emacs/MakingScriptsExecutableOnSave (defun hlu-make-script-executable () "If file starts with a shebang, make `buffer-file-name' executable" (save-excursion (save-restriction (widen) (goto-char (point-min)) (when (and (looking-at "^#!") (not (file-executable-p buffer-file-name))) (set-file-modes buffer-file-name (logior (file-modes buffer-file-name) #o100)) (message (concat "Made " buffer-file-name " executable")))))) (add-hook 'after-save-hook 'hlu-make-script-executable) ;; Allow dired to recursively deletes files (setq dired-recursive-deletes t) ;; Open compressed files (autoload 'jka-compr-installed-p "jka-compr") (if (not (jka-compr-installed-p)) (auto-compression-mode)) ;; W3M (require 'w3m-load) (setq w3m-default-display-inline-images t) (setq w3m-use-tab t) (setq w3m-use-toolbar t) (setq w3m-use-favicon t) (setq w3m-async-exec t) ;; Kill ring (require 'browse-kill-ring) (browse-kill-ring-default-keybindings) (global-set-key (kbd "C-c k") 'browse-kill-ring) ;; HTML (add-to-list 'auto-mode-alist '("\\.php[34]?\\'" . php-mode)) (add-to-list 'auto-mode-alist '("\\.[sj]?html?\\'" . html-mode)) (add-to-list 'auto-mode-alist '("\\.tpl\\'" . html-mode)) ;; Speedbar/Elscreen (require 'elscreen-speedbar) (setq elscreen-display-tab nil speedbar-use-images nil) ; start speedbar if we're using a window system (when window-system (speedbar t)) (global-set-key (kbd "C-c s") 'speedbar-get-focus) (global-set-key (kbd "C-c u") 'speedbar-up-directory) ;; Python (require 'pymacs) (pymacs-load "ropemacs" "rope-") ;; Org mode (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode)) (global-set-key "\C-cl" 'org-store-link) (global-set-key "\C-ca" 'org-agenda) (global-set-key "\C-cb" 'org-iswitchb) ; Add a timestamp when a TODO entry is marked as DONE (setq org-log-done 'time) ; Set an entry as DONE when all its children are marked as DONE (defun org-summary-todo (n-done n-not-done) "Switch entry to DONE when all subentries are done, to TODO otherwise." (let (org-log-done org-log-states) (org-todo (if (= n-not-done 0) "DONE" "TODO")))) (add-hook 'org-after-todo-statistics-hook 'org-summary-todo) ; TODO states (C-c t) (setq org-todo-keywords '((sequence "TODO" "WAITING" "PENDING" "|" "DONE" "ABANDONED" ))) ;; Eproject, Ibuffers and Ido settings ; Unique buffer name (require 'uniquify) (setq uniquify-buffer-name-style 'post-forward-angle-brackets uniquify-ignore-buffers-re "^\\*") ;; Ido makes competing buffers and finding files easier ;; http://www.emacswiki.org/cgi-bin/wiki/InteractivelyDoThings (require 'ido) (ido-mode 'both) ;; for buffers and files (setq ido-save-directory-list-file "~/.emacs.d/cache/ido.last" ido-ignore-buffers '("\\` " "^\*Mess" "^\*Back" ".*Completion" "^\*Ido" "^\*trace" "^\*compilation" "^\*TAGS" "^session\.*" "^\*") ido-work-directory-list '("/src/dev" "/src/work") ; Be case-insensitive ido-case-fold t ; Remember last used dirs ido-enable-last-directory-history t ; Should be enough ido-max-work-directory-list 30 ; Remember many ido-max-work-file-list 50 ; Don't use filename at point (annoying) ido-use-filename-at-point nil ; Don't use url at point (annoying) ido-use-url-at-point nil ; Don't try to be too smart ido-enable-flex-matching nil ; Don't spam my minibuffer ido-max-prospects 8 ; Wait for RET, even with unique completion ido-confirm-unique-completion t ; When using ido, the confirmation is rather annoying... confirm-nonexistent-file-or-buffer nil) ;; Switch easily between buffers ;; http://emacs-fu.blogspot.com/2009/02/switching-buffers.html (iswitchb-mode t) (require 'ibuffer) (setq ibuffer-display-summary nil) ;; Group buffers by project or language (setq ibuffer-saved-filter-groups (quote (("default" ("xcb-util" (filename . "xorg/xcb-util/")) ("unagi" (filename . "xorg/unagi/")) ("libxcb" (filename . "xorg/libxcb/")) ("lora" (filename . "src/edg/mt02/lora")) ("python" (mode . python-mode)) ("c" (mode . c-mode)))))) (add-hook 'ibuffer-mode-hook (lambda () (ibuffer-switch-to-saved-filter-groups "default"))) (global-set-key (kbd "C-x C-b") 'ibuffer) ;; Project (including TAGS file) handling (require 'etags) (setq tags-revert-without-query t) (add-to-list 'load-path "~/.emacs.d/eproject") (require 'eproject) (require 'eproject-extras) (define-project-type c (generic) (look-for "configure.ac") :relevant-files ("\\.c$" "\\.h$" "\\.cpp$" "\\.am$" "\\.ac$" "\\.pc\\.in$" "\\.conf$" "\\.cfg$" "INSTALL$" "README$") ;; Skip hidden files :irrelevant-files ("\\(/\\|^\\)\\.[^/]*$")) (defun my-etags-create-update (&optional force_update) "Create/Update TAGS file and set etags root directory" (let (root) (if (string-match-p "/src/dev/xorg/.*" eproject-root) (setq root "/src/dev/xorg/") (setq root eproject-root)) (let ((tags-filename (concat root "TAGS"))) (message (format "find %s -name '*.[ch]' | xargs etags -o %s --declarations" root tags-filename)) (when (or force_update (not (file-readable-p tags-filename))) (shell-command (format "find %s -name '*.[ch]' | xargs etags -o %s --declarations" root tags-filename))) ;; Load TAGS file (visit-tags-table tags-filename t)))) (add-hook 'c-project-file-visit-hook '(lambda () ;; Do not prompt for the compilation command (set (make-local-variable 'compilation-read-command) nil) ;; Run compilation at the top of the project (set (make-local-variable 'compile-command) (format "cd %s && make -k" eproject-root)))) (setq compilation-finish-functions '(lambda (buffer string) ;; Update the tags (with-current-buffer (other-buffer buffer t) (my-etags-create-update t)) ;; Close the Compilation window if successful (when (string-match "finished" string) (progn ;; C-x b should not go there (bury-buffer) ;; Delete the *compilation* window (replace-buffer-in-windows "*compilation*"))))) ;; Git (git package) (add-to-list 'load-path "/usr/share/doc/git/contrib/emacs/") (require 'git) (require 'git-blame) ; http://github.com/chneukirchen/gitsum (require 'gitsum) (global-set-key (kbd "C-x C-g") 'git-status)