; .emacs (-*-Emacs-Lisp-*-) ;; ;; Copyright (C) 2002-2008 Alejandro Espinoza Esparza ;; ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2 of the ;; License, or (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; ;; You should have received a copy of the GNU General Public License ;; along with this program; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ; (message "Loading .emacs") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Constants ;; Directories (defconst MAIN_DIR "C:/Users/aespinoza/emacs/" "Main Directory") (defconst SITELISP_DIR "site-lisp/" "Site-Lisp directory") (defconst COLORSCHEMES_DIR "color_schemes/" "Site-Lisp directory") ;; Settings (defconst COLOR_SCHEME "molokai" "Main Color Scheme to use.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Window Settings ;; Default Frame Parameters (setq default-frame-alist '((top . 80) (left . 80) (width . 120) (height . 50) (font . "-*-Consolas-normal-r-*-*-11-*-*-*-c-*-iso8859-1"))) ;; Show more info on the title. (setq-default frame-title-format (list invocation-name "@" system-name ": %b %+%+ %f")) ;; Speedbar parameters (require 'speedbar) (setq speedbar-frame-parameters (quote ((minibuffer) (width . 35) (border-width . 0) (menu-bar-lines . 0) (unsplittable . t) (font . "-*-Consolas-normal-r-*-*-11-*-*-*-c-*-iso8859-1")))) ;; Display clock (display-time) ;; No toolbar (it is actually very ugly and not very useful) (tool-bar-mode 0) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Buffer Settings ;; Default buffer type. (setq default-buffer-file-coding-system 'undecided-unix) ; Dont show GNU splash screen (setq inhibit-startup-message t) ;; Enable Narrow to region. (put 'narrow-to-region 'disabled nil) ;; Open unidentified files in text mode (setq default-major-mode 'text-mode) ; Make all "yes or no" prompts show "y or n" instead (fset 'yes-or-no-p 'y-or-n-p) ; Windows-like selection (pc-selection-mode t) ;; Disable tooltips (tooltip-mode 0) ; No bell, thank you. (setq visible-bell t) (setq ring-bell-function (lambda ())) ; Highlight current line. (global-hl-line-mode 1) ;; Highlight matching parenthesis (show-paren-mode t) ;; Paste at point NOT at cursor (setq mouse-yank-at-point 't) ;; Spaces, not tabs (setq-default indent-tabs-mode nil) ;; When you scroll down with the cursor, emacs will move down the buffer one ;; line at a time, instead of in larger amounts. (setq scroll-step 1) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Libraries Settings ; Define default path (add-to-list 'load-path (format "%s%s" MAIN_DIR "site-lisp/")) ;; Use ido (very cool script to navigate folders and files in the minibuffer.) (require 'ido) (ido-mode t) (setq ido-decorations '(" " "" " " " ..." " [" "]" " (No Match)" " (Matched)")) (setq ido-save-directory-list-file nil) (setq ido-max-window-height 1) ;; Add line number to the buffer (require 'linum) (global-linum-mode 1) ;; Snippet Support (require 'yasnippet-bundle) ;; Hide/Show Support. (require 'hideshow) ;; HTMLize support. (require 'htmlize) (setq htmlize-output-type 'inline-css) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Custom Faces (setq custom-file (format "%s%s%s%s" MAIN_DIR COLORSCHEMES_DIR COLOR_SCHEME ".el")) (load custom-file) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; External Commands Settings ;; The almighty grep. (setq-default grep-command "grep -i ") ;; Backup files in one spot (setq backup-directory-alist nil) (setq backup-directory-alist (cons (cons "\\.*$" (expand-file-name "c:/ebacks")) backup-directory-alist)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Global Keys Settings ;; Function Keys (define-key global-map [f1] 'hs-toggle-hiding) ;; F1 - Toggle block Hiding (define-key global-map [f2] 'create-scratch-buffer) ;; F2 - Create new Scratch buffer (define-key global-map [f3] 'kill-buffer-fast) ;; F3 - Close buffer (define-key global-map [f4] 'goto-line) ;; F4 - Go to line (define-key global-map [f5] 'other-window) ;; F5 - Other window (define-key global-map [f6] 'hs-show-block) ;; F6 - Show Block (define-key global-map [f7] 'hs-hide-block) ;; F7 - Hide Block (define-key global-map [f8] 'toggle-speedbar) ;; F8 - Toggle speedbar (define-key global-map [f9] 'w32-restore-frame) ;; F9 - Minimize window (define-key global-map [f10] 'w32-maximize-frame) ;; F10 - Maximize window (define-key global-map [f11] 'vs2emacs) ;; F11 - VS2005 2 Unix (define-key global-map [f12] 'add-change-log-entry-other-window) ;; F12 - Add Change log entry ;; Global Keys (global-set-key "\C-cu" 'uncomment-region) (global-set-key "\C-cf" 'speedbar-toggle-show-all-files) (global-set-key "\C-cf" 'sp) (global-unset-key "\C-t") (global-set-key "\C-t\C-s" '(lambda () (interactive) (insert-csharp-summary t))) (global-set-key "\C-t\C-p" '(lambda () (interactive) (insert-csharp-param t))) (global-set-key "\C-t\C-r" '(lambda () (interactive) (insert-csharp-returns t))) (global-set-key "\C-t\C-g" 'insert-file-header) (global-set-key "\C-t\C-k" 'insert-csharp-property) ; with point inside the block, use these keys to hide/show ;; (Ref: Dino's Emacs file. http://blogs.msdn.com/dotnetinterop/archive/2008/04/14/dino-s-emacs-file.aspx) (global-set-key "\C-c>" 'hs-hide-block) (global-set-key "\C-c<" 'hs-show-block) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; C Mode Custom Vars (custom-set-variables '(auto-revert-interval 2) '(auto-revert-stop-on-user-input nil) '(c-basic-offset 4) '(c-font-lock-extra-types (quote ("String" "BOOL" "using" "namespace" "this" "value" "void"))) '(c-progress-interval 8) '(c-tab-always-indent (quote other)) '(case-fold-search t) '(column-number-mode t) '(compilation-ask-about-save nil t) '(compilation-scroll-output t) '(compilation-window-height 6 t) '(current-language-environment "Latin-1") '(default-input-method "latin-1-prefix") '(delete-old-versions t) '(font-lock-global-modes t) '(font-lock-maximum-decoration t) '(font-lock-support-mode (quote jit-lock-mode)) '(global-auto-revert-mode t nil (autorevert)) '(global-auto-revert-mode-text " GRev") '(global-font-lock-mode t nil (font-lock)) '(indent-tabs-mode t) '(line-number-mode t) '(next-line-add-newlines nil) '(standard-indent 4) '(tab-width 4) '(comment-multi-line nil) '(transient-mark-mode t) '(uniquify-buffer-name-style (quote forward) nil (uniquify)) '(speedbar-show-unknown-files t) '(speedbar-use-images t) '(user-full-name "Alejandro Espinoza Esparza") '(user-mail-address "aespinoza@structum.com.mx")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Mode Mappings ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Scripting Languages ;; PHP mode ;;(autoload 'php-mode "php-mode" "PHP Mode" t) (require 'php-mode) (setq auto-mode-alist (append auto-mode-alist (list'("\\.php$" . php-mode)))) ;; HTML Helper Mode & scripting Langs. (require 'html-helper-mode) (setq auto-mode-alist (append auto-mode-alist (list'("\\.\\(html\\|htm\\|cst\\|asp\\|aspx\\)$" . html-helper-mode)))) ;; XML Modes (XML, RDF, RDFS, GLADE, etc.) (setq auto-mode-alist(append auto-mode-alist (list'("\\.\\(rdf\\|rdfs\\|glade\\|dtd\\|kon\\|xslt\\|xsd\\|config\\|xml\\|xaml\\)$" . sgml-mode)))) ;; CSS Mode (setq auto-mode-alist(cons '("\\.css\\'" . css-mode) auto-mode-alist)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; .Net Languages ;; C# Mode (require 'csharp-mode) (setq auto-mode-alist (append auto-mode-alist (list'("\\.cs$" . csharp-mode)))) ;; For Hide/Show ;; (Ref: Dino's Emacs file. http://blogs.msdn.com/dotnetinterop/archive/2008/04/14/dino-s-emacs-file.aspx) (defun csharp-hs-forward-sexp (&optional arg) "I set hs-forward-sexp-func to this function. I found this customization necessary to do the hide/show magic in C# code, when dealing with region/endregion. This routine goes forward one s-expression, whether it is defined by curly braces or region/endregion. It handles nesting, too. The forward-sexp method takes an arg which can be negative, which indicates the move should be backward. Therefore, to be fully correct this function should also handle a negative arg. However, the hideshow.el package never uses negative args to its hs-forward-sexp-func, so it doesn't matter that this function does not do negative numbers. The arg can also be greater than 1, which means go forward multiple times. This function doesn't handle that EITHER. But again, I haven't see that as a problem." (message "csharp-hs-forward-sexp, (arg %d) (point %d)..." (if (numberp arg) arg -1) (point)) (let ((nestlevel 0) (mark1 (point)) (done nil) ) (if (and arg (< arg 0)) (message "negative arg (%d) is not supported..." arg) ;; else, we have a positive argument, hence move forward. ;; simple case is just move forward one brace (if (looking-at "{") (forward-sexp arg) ; The more complex case is dealing with a "region/endregion" block. ; We have to deal with nested regions! (and (while (not done) (re-search-forward "^[ \\t]*#[ \\t]*\\(region\\|endregion\\)\\b" (point-max) 'move) (cond ((eobp)) ; do nothing if at end of buffer ((and (match-beginning 1) ;; if the match is longer than 6 chars, we know it is "endregion" (if (> (- (match-end 1) (match-beginning 1)) 6) (setq nestlevel (1- nestlevel)) (setq nestlevel (1+ nestlevel)) ) ))) (setq done (not (and (> nestlevel 0) (not (eobp))))) ) ; while (if (= nest 0) (goto-char (match-end 2))) ) ) ) ) ) ;; ;; more for hideshow.el ;; ; (Ref: Dino's Emacs file. http://blogs.msdn.com/dotnetinterop/archive/2008/04/14/dino-s-emacs-file.aspx) (unless (assoc 'csharp-mode hs-special-modes-alist) (push '(csharp-mode "\\(^[ \\t]*#[ \\t]*region\\b\\)\\|{" ; regexp for start block "\\(^[ \\t]*#[ \\t]*endregion\\b\\)\\|}" ; regexp for end block "/[*/]" ; regexp for comment start csharp-hs-forward-sexp ; hs-forward-sexp-func hs-c-like-adjust-block-beginning) ; c-like adjust (1 char) hs-special-modes-alist)) ;; Initialize C#-mode. (defun csharp-mode-init() (cond (window-system (yas/minor-mode-on) (hs-minor-mode 1) (setq hs-isearch-open t)))) (add-hook 'csharp-mode-hook 'csharp-mode-init) ;; VB mode (require 'vbnet-mode) (setq auto-mode-alist (append auto-mode-alist (list'("\\.\\(frm\\|bas\\|cls\\|ebf\\|vb\\|vbs\\)$" . vbnet-mode)))) ;; Powershell mode (require 'powershell-mode) (setq auto-mode-alist (append auto-mode-alist (list'("\\.ps1$" . powershell-mode)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Other Languages ;; HLA Mode (setq auto-mode-alist (append auto-mode-alist (list'("\\.hla$" . asm-mode)))) ;; RC (setq auto-mode-alist (append auto-mode-alist (list'("\\.rc$" . c++-mode)))) ;; Java, JScript, J# mode (setq auto-mode-alist (append auto-mode-alist (list'("\\.\\(java\\|js\\|jsl\\)$" . java-mode)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Common Language Settings ;; Use C++-Style comments. (defun rt-do-line-comments() (setq comment-start "// ") (setq comment-end "")) (add-hook 'c-mode-hook 'rt-do-line-comments) ;; FIXME and TODO highlight mode C, C++, C# and Java (mapcar (lambda (mode) (font-lock-add-keywords mode '(("\\<\\(FIXME\\|TODO\\):" 1 font-lock-warning-face t)))) '(c-mode c++-mode csharp-mode java-mode)) ;; OpenGL Keywords Highlight (mapcar (lambda (mode) (progn ;; gl.h (font-lock-add-keywords mode '(("\\" . 'font-lock-type-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-variable-name-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-constant-face))) ;; glu.h (font-lock-add-keywords mode '(("\\" . 'font-lock-type-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-variable-name-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-constant-face))) ;; glx.h (font-lock-add-keywords mode '(("\\" . 'font-lock-type-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-variable-name-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-constant-face))) ;; glut.h (font-lock-add-keywords mode '(("\\" . 'font-lock-type-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-variable-name-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-constant-face))))) '(c-mode c++-mode)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Custom Functions (defun update-snippets() "Updates, Byte Compiles and Loads the snippets bundle." (interactive) (yas/compile-bundle (format "%s%s%s" MAIN_DIR SITELISP_DIR "yasnippet.el") (format "%s%s%s" MAIN_DIR SITELISP_DIR "yasnippet-bundle.el") (format "%s%s%s" MAIN_DIR SITELISP_DIR "snippets")) (byte-compile-file (format "%s%s%s" MAIN_DIR SITELISP_DIR "yasnippet-bundle.el") 1)) (defun csharp-newline-and-indent() "Adds a new line and indents it." (interactive) (end-of-line) (insert "\n") (c-indent-line)) (defun csharp-indent-and-newline() "Indents the line and adds a new line." (interactive) (beginning-of-line) (c-indent-line) (end-of-line) (insert "\n")) (defun insert-csharp-summary(movePos) "Inserts chsarp comment 'summary' tag." (interactive) (beginning-of-line) (c-indent-line) (insert "/// ") (csharp-newline-and-indent) (insert "/// ") (csharp-newline-and-indent) (insert "/// ") (if movePos (previous-line 1) (end-of-line))) (defun insert-csharp-param(movePos) "Inserts chsarp comment 'param' tag." (interactive) (beginning-of-line) (c-indent-line) (insert "/// ") (if movePos (backward-char 10))) (defun insert-csharp-value(movePos) "Inserts chsarp comment 'value' tag." (interactive) (beginning-of-line) (c-indent-line) (insert "/// ") (if movePos (backward-char 9))) (defun insert-csharp-returns(movePos) "Inserts chsarp comment 'returns' tag." (interactive) (beginning-of-line) (c-indent-line) (insert "/// ") (if movePos (backward-char 10))) (defun insert-csharp-property() "Inserts chsarp property skeleton." (interactive) (insert-csharp-summary nil) (csharp-newline-and-indent) (insert-csharp-value nil) (csharp-indent-and-newline) (c-indent-line) (insert "public ") (csharp-newline-and-indent) (insert "{") (csharp-indent-and-newline) (insert "get {") (csharp-indent-and-newline) (insert "return this._;") (csharp-indent-and-newline) (insert "}") (csharp-indent-and-newline) (insert "set {") (csharp-indent-and-newline) (insert "this._ = value;") (csharp-indent-and-newline) (insert "}") (csharp-indent-and-newline) (insert "}") (c-indent-line) (previous-line 8) (end-of-line)) (defun insert-file-header() "Inserts the file header" (interactive) (insert "/*\n") (insert " * .cs\n") (insert (concat " * Copyright (C) " (format-time-string "%Y") ", " user-full-name ". All Rights Reserved.\n")) (insert " *\n") (insert " * Description :\n") (insert " * \n") (insert " *\n") (insert " * Author(s):\n") (insert (concat " * " user-full-name " <" user-mail-address ">\n")) (insert " *\n") (insert (concat " * This is UNPUBLISHED PROPRIETARY SOURCE CODE of " user-full-name ".\n")) (insert " * The contents of this file may not be disclosed to third parties, copied or\n") (insert " * duplicated in any form, in whole or in part, without the prior written\n") (insert (concat " * permission of " user-full-name ".\n")) (insert " */\n") (previous-line 13) (backward-char 4)) (defvar speedbar-frame nil) (defun toggle-speedbar () "Toggles the speedbar" (interactive) (if speedbar-frame (speedbar-frame-mode -1) (speedbar-get-focus))) (defun kill-buffer-fast () "Kills the current buffer" (interactive ) (kill-buffer nil)) (defun w32-restore-frame () "Restore a minimized frame" (interactive) (w32-send-sys-command 61728)) (defun w32-maximize-frame () "Maximize the current frame" (interactive) (w32-send-sys-command 61488)) (defun swap-tab-for-space() "Swaps tab for space" (interactive) (narrow-to-region (region-beginning) (region-end)) (goto-char(point-min)) (while (search-forward "\t" nil t) (replace-match " ")) (widen) nil) (defun create-scratch-buffer nil "Create a new scratch buffer to work in. (could be *scratch* - *scratchX*)" (interactive) (let ((n 0) bufname) (while (progn (setq bufname (concat "*scratch" (if (= n 0) "" (int-to-string n)) "*")) (setq n (1+ n)) (get-buffer bufname))) (switch-to-buffer (get-buffer-create bufname)) (if (= n 1) (lisp-interaction-mode)))) (defun vs2emacs() "Remove (^@) from a visual studio formated text." (interactive) (goto-char(point-min)) (while (search-forward "ÿþ" nil t) (replace-match "")) (goto-char(point-min)) (while (search-forward "\C-@" nil t) (replace-match "")) (dos2unix)) (defun dos2unix() "Convert dos (^M) end of line to unix end of line" (interactive) (goto-char(point-min)) (while (search-forward "\r" nil t) (replace-match ""))) (defun unix2dos() "Unix 2 Dos" (interactive) (goto-char(point-min)) (while (search-forward "\n" nil t) (replace-match "\r\n"))) (defun insert-date () "Insert date at point." (interactive) (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %z"))) (defun region-length () "Length of a region" (interactive) (message (format "%d" (- (region-end) (region-beginning))))) (message ".emacs loaded. Let's get coding..!!!")