;; ----------------------------------------------------------------------------- ;; ;; LMB's .emacs -- Emacs the way I like ;; ;; By Leandro Motta Barros. Well, actually I collected most of this from the ;; web, so I'm much more the editor than the author of this file. Some places ;; from which I took parts of this file: ;; ;; - http://www.dotemacs.de ;; - http://nafai.dyndns.org/files/casey-emacs-tmp.html ;; - http://www.darkridge.com/~jpr5/src/dot-emacs.txt ;; - http://www.teuton.org/~erik/configs/emacs.html ;; - http://patter.mine.nu/emacs ;; ;; ----------------------------------------------------------------------------- ;; - Personal stuff (change this if you are not me!) --------------------------- ; Email address (setq user-mail-address "xyz@foo.bar") ; Directory where I put extra elisp files. (add-to-list 'load-path "~/.emacs-stuff/elisp/") ;; - Key-mapping --------------------------------------------------------------- ; Make keys like 'end' and 'delete' work as expected (global-set-key [delete] 'delete-char) (global-set-key [kp-delete] 'delete-char) (global-set-key [end] 'end-of-line) (global-set-key [C-end] 'end-of-buffer) (global-set-key [home] 'beginning-of-line) (global-set-key [C-home] 'beginning-of-buffer) ; Open the man page of the work under the cursor (global-set-key [(f1)] (lambda () (interactive) (manual-entry (current-word)))) ; Change to next buffer (global-set-key [(C-f6)] (lambda () (interactive) (bury-buffer))) ; A few other useful things (global-set-key "\C-cl" 'goto-line) (global-set-key "\C-cc" 'compile) (global-set-key "\C-cu" 'uncoment-region) ;; - Assorted Emacs behavior --------------------------------------------------- ; Column numbers, please. (setq column-number-mode t) ; I like tabs with 3 spaces (setq default-tab-width 3) ; Don't let everybody in the room look at me if I hit C-g too many times (setq visible-bell t) ; GoboLinux users know that pressing Shift is bad (setq completion-ignore-case t) ; Enable syntax highlighting everywhere (global-font-lock-mode) (setq font-lock-maximum-decoration t) (setq font-lock-support-mode 'jit-lock-mode) ; those are expected to make syntax (setq jit-lock-stealth-time 0) ; highlighting faster (TODO: works?) ; What time is it? (display-time) ; Blinking cursors are soooo distracting (blink-cursor-mode 0) ; Show parentheses matching (I can't believe an editor written in LISP don't ; have this on by default!) (show-paren-mode) ; Don't break long lines, I like to scroll to see them (setq-default truncate-lines t) ; Tabs are evil (setq-default indent-tabs-mode nil) ; Lines with trailings spaces are evil, too. But, since they are not *that* ; evil, highlight them with a color more discrete than the default red (setq-default show-trailing-whitespace t) (set-face-background 'trailing-whitespace "gray25") ; Enable mouse wheel (mouse-wheel-mode) ; Scroll one line at a time ; TODO: this does not work all the time. Also tried to play with the variables ; 'scroll-step', 'scroll-up-aggressively' and 'scroll-down-aggressively', ; but they don't seem to make things better (setq scroll-conservatively 100) ; I really mean it! ; Make all backups in the same directory ; TODO: I really must understand the syntax here... (setq backup-directory-alist `(("." . ,(expand-file-name "~/.emacs-stuff/backups")))) ; Helps to identify empty lines at the end of the file (I'm not sure if I really ; like this) (setq default-indicate-empty-lines t) ;; - The look ------------------------------------------------------------------ ; This applies to all Emacs frames (setq default-frame-alist (list ; Hide that ridiculous tool bar '(tool-bar-lines . 0) ; But enable the menu (TODO: only if in X11) '(menu-bar-lines . 1) ; Position and dimensions '(width . 92) '(height . 38) '(left . 0) '(top . 0) ; Anything different than these colors is unusable '(background-color . "dark slate gray") '(foreground-color . "wheat") '(mouse-color . "tomato") '(cursor-color . "tomato") ; The font (TODO: check if I'm at home or at the lab) '(font . "-adobe-courier-medium-r-normal-*-*-180-*-100-*-*-*-*") ) ) ; Set the color of some "special" fonts that are used to build the interface (set-face-foreground 'modeline "black") (set-face-background 'modeline "grey") (set-face-foreground 'menu "wheat") (set-face-background 'menu "dark slate grey") ;; - Compilation-related stuff ------------------------------------------------- ; The two following variables make it simpler to work with projects organized in ; a directory tree. They work nicely if Emacs is executed from the same ; directory of the 'Makefile' (or 'Jamfile', or 'SConstruct', or whatever). ; TODO: - Be smarter when setting 'compilation-search-path'. ; - Issue the 'compile-command' depending whether a 'Makefile', 'Jamfile' ; or 'SConstruct' is found. (setq compilation-search-path (list (substring (pwd) 10)) compile-command (concat "cd " (car compilation-search-path) " ; make -k")) ; Use 'makefile-mode' for 'Jamfile's. Not the ideal solution, but at least ; comments are properly highlighted... (add-to-list 'auto-mode-alist '("Jamfile\\'" . makefile-mode)) ; Use 'python-mode' for SCons stuff (add-to-list 'auto-mode-alist '("SConstruct\\'" . python-mode)) (add-to-list 'auto-mode-alist '("SConscript\\'" . python-mode)) ;; - C Mode and friends -------------------------------------------------------- (defun hook-c-mode () "My hook for c-mode." (c-set-style "ellemtel") ; The nicest indentation style (flyspell-prog-mode) ; Spell check strings and comments (hs-minor-mode) ; Allow to hide and show blocks ) (add-hook 'c-mode-common-hook 'hook-c-mode) ; Use 'c++-mode' (instead of 'c-mode') for '*.h'. Perhaps I can disable this ; now that I use '.hpp' for C++ headers. (add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode)) ; TODO: make this work ;; (font-lock-add-keywords ;; 'c++-mode ;; '(("@param" 1 font-lock-doc-face t)) ;; '(("@return" 1 font-lock-doc-face t))) ; TODO: The following are nice, but flyspell mode hides them... ;(font-lock-add-keywords ; 'c-mode ; '(("\\<\\(TODO\\):" 1 font-lock-warning-face t)) ; '(("\\<\\(FIXME\\):" 1 font-lock-warning-face t))) ;(font-lock-add-keywords ; 'c++-mode ; '(("\\<\\(TODO\\):" 1 font-lock-warning-face t)) ; '(("\\<\\(FIXME\\):" 1 font-lock-warning-face t))) ;; - Text mode ----------------------------------------------------------------- (defun hook-text-mode () "My hook for text-mode. (Wow! What a descriptive string!)" (auto-fill-mode 1) ;(flyspell-mode) ; TODO: What's a good way to decide which dictionary to use? ) (add-hook 'text-mode-hook 'hook-text-mode) ;; - Prolog mode --------------------------------------------------------------- ; Use 'prolog-mode' (instead of 'perl-mode') for '*.pl'. Can't I remove this? ; I don't believe I'll be programming in Prolog again soon. (add-to-list 'auto-mode-alist '("\\.pl\\'" . prolog-mode)) ;; - Emacs-Lisp mode ----------------------------------------------------------- (add-hook 'emacs-lisp-mode-hook `flyspell-prog-mode) ;; - Python mode --------------------------------------------------------------- (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode)) (add-to-list 'interpreter-mode-alist '("python" . python-mode)) (autoload 'python-mode "python-mode" "Python editing mode." t) (add-hook 'python-mode-hook `flyspell-prog-mode) ;; - Lua mode ------------------------------------------------------------------ (add-to-list 'auto-mode-alist '("\\.lua\\'" . lua-mode)) (add-to-list 'interpreter-mode-alist '("lua" . lua-mode)) (autoload 'lua-mode "lua-mode" "Lua editing mode." t) (add-hook 'lua-mode-hook `flyspell-prog-mode) ;; - Erlang mode --------------------------------------------------------------- (add-to-list 'auto-mode-alist '("\\.erl\\'" . erlang-mode)) (autoload 'erlang-mode "erlang" "Erlang editing mode." t) (add-hook 'erlang-mode-hook `flyspell-prog-mode) ;; - Nuweb mode ---------------------------------------------------------------- (add-to-list 'auto-mode-alist '("\\.w\\'" . nuweb-mode)) (autoload 'nuweb-mode "nuweb" "Nuweb editing mode." t) ; - LaTeX mode ----------------------------------------------------------------- (require 'tex-site) (defun hook-auctex() ; Use C-c C-f C-o for "\foreign{}" (add-to-list 'TeX-font-list '(15 "\\foreign{" "}")) ; And C-c C-f C-k for "\kw{}" (add-to-list 'TeX-font-list '(11 "\\kw{" "}")) ; Make RefTeX and AUCTeX live together in perfect harmony (setq reftex-plug-into-AUCTeX t) ) ; Added those while trying to make "preview-latex" work. Not much success so far. (setenv "TEXINPUTS" (concat "~/.emacs-stuff/elisp/preview-latex/texmf/tex/latex/preview:" (getenv "TEXINPUTS"))) (setenv "TEXDOCS" (concat "~/.emacs-stuff/elisp/preview-latex/texmf/doc/latex/styles:" (getenv "TEXDOCS"))) (add-to-list 'load-path "~/.emacs-stuff/elisp/preview-latex/elisp") (defun lmb-LaTeX-hook() "My very own LaTeX hook." ; (load "preview-latex.el" nil t t) ; Load preview-latex ) (load "preview-latex.el" nil t t) ; Load preview-latex (add-hook 'LaTeX-mode-hook 'hook-auctex) (add-hook 'LaTeX-mode-hook 'turn-on-reftex) (add-hook 'LaTeX-mode-hook 'lmb-LaTeX-hook) ; - Emacs-Wiki mode ------------------------------------------------------------ ; This is great! (load "emacs-wiki") ;; - Auto-insert --------------------------------------------------------------- ; Skeletons used for auto insertion (define-skeleton c-beginning-comment-block-skeleton "A skeleton for the comment in the beginning of C and C++ source and header files." nil '(setq v1 (file-name-nondirectory buffer-file-name)) "/" (make-string 78 ?*) "\\" ?\n "* " v1 (lmb-fill-line-with 79 ? ) "*" ?\n "* " (make-string 77 ? ) "*" ?\n "* " (user-full-name) (lmb-fill-line-with 79 ? ) "*" ?\n "\\" (make-string 78 ?*) "/" ?\n ) (define-skeleton c-source-skeleton "A skeleton for C and C++ source files." nil '(setq v1 (file-name-nondirectory buffer-file-name)) (c-beginning-comment-block-skeleton) ?\n "#include \"" (lmb-deduce-header-name v1) "\"" ?\n ?\n ) (define-skeleton c-header-skeleton "A skeleton for C and C++ header files." nil '(setq v1 (file-name-nondirectory buffer-file-name)) (c-beginning-comment-block-skeleton) ?\n "#ifndef " (lmb-deduce-include-guard-name v1) ?\n "#define " (lmb-deduce-include-guard-name v1) ?\n ?\n _ ?\n ?\n "#endif // " (lmb-deduce-include-guard-name v1) ?\n ) (auto-insert-mode) (setq auto-insert-query nil) ; I want auto-insert to be really automatic! (setq auto-insert-directory "~/.emacs-stuff/auto-insert/" auto-insert-alist '( ("\\.\\([Hh]\\|hh\\|hpp\\)\\'" . c-header-skeleton) ("\\.\\([Cc]\\|cc\\|cpp\\)\\'" . c-source-skeleton) ("\\.\\(tex\\)\\'" . "template.tex") ) ) ;; - Emacs/W3 ------------------------------------------------------------------ (add-to-list 'load-path "~/.emacs-stuff/elisp/w3/elisp") (condition-case() (require 'w3-auto "w3-auto") (error nil)) ;; - Useful functions used somewhere else -------------------------------------- (defun flyspell-generic-progmode-verify() "Used for `flyspell-generic-check-word-p' in programming modes." (let ((f (get-text-property (point) `face))) (memq f `(font-lock-comment-face font-lock-string-face)))) (defun flyspell-prog-mode() "Turn on `flyspell-mode' for comments and strings." (interactive) (setq flyspell-generic-check-word-p 'flyspell-generic-progmode-verify) (flyspell-mode 1)) (defun lmb-fill-line-with (line-width character) "Returns a string that can be used to fill a line up to its `line-width'-th column with `character'." (make-string (- line-width (current-column)) character)) (defun lmb-deduce-header-name (filename) "Returns a string representing the header file corresponding to the given C or C++ source `filename'." (concat (file-name-sans-extension filename) (if (equal (file-name-extension filename) "c") ".h" ".hpp"))) (defun lmb-deduce-include-guard-name (filename) "Returns a string usable as the identifier for the include guard in a C or C++ program. `filename' can be either the source or the header file name (without path in any case)." (concat "_" (upcase (file-name-sans-extension filename)) "_" (if (or (equal (file-name-extension filename) "c") (equal (file-name-extension filename) "h")) "H_" "HPP_")))