(custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(show-paren-mode t) '(transient-mark-mode t)) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ) (setq load-path (cons "~/emacs-packages" load-path)) ;; Highlight current line (require 'highlight-current-line) ;; If you want to mark only to the end of line: (highlight-current-line-whole-line-on nil) ;; switch highlighting on (highlight-current-line-on t) (highlight-current-line-set-bg-color "#f0f0fa") (highlight-current-line-set-fg-color "none") ;; HTML helper mode (autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t) (setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist)) ;; Aspell (setq-default ispell-program-name "aspell") ;;For some reason version 3.0 of ispell.el (the lisp program that (x)emacs uses) wants to reverse the suggestion list. To fix this add this line: ;;(setq-default ispell-extra-args '("--reverse")) ;; CPerl mode (require 'cperl-mode) ;; Perl file extension associations (add-to-list 'auto-mode-alist '("\\.pl$" . cperl-mode)) (add-to-list 'auto-mode-alist '("\\.cgi$" . cperl-mode)) (add-to-list 'auto-mode-alist '("\\.pm$" . cperl-mode)) (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode)) ;; BSD/Allman indentation style using cperl-mode (cperl-set-style "bsd") ;; From .emacs-win-accenture ;;================================================================================ ;;; Let .pc files to be treated as C source code. (setq auto-mode-alist (append '(("\\.pc$" . c-mode) ) auto-mode-alist)) ;; BSD/Allman C/C++ Indent style ;; Set TABs to be the width of 4 spaces. ;; NOTE: Tab using spaces (general indent style; use "M-x untabify" to convert tabs to spaces in existing docs.) (setq-default indent-tabs-mode nil) (setq c-default-style "bsd") (setq-default c-basic-offset 4) (setq-default c-substatement-open-offset 0) (setq-default c-statement-cont-offset 0) ;;; http://textsnippets.com/posts/show/1401 ;;; Emacs: search for the selected text by Shift-clicking with the left mouse-button (defun mouse-search-forward (begin end) (interactive (list (point) (mark))) (let ((text (filter-buffer-substring begin end nil t))) (goto-char (max begin end)) (let ((found-pos (search-forward text nil t))) (if (not found-pos) (progn (goto-char begin) (error "not found")) (progn (goto-char found-pos) (set-mark (- found-pos (length text)))))))) ;; My Function (DOES NOT WORK) (defun mouse-search-backward (begin end) (interactive (list (point) (mark))) (let ((text (filter-buffer-substring begin end nil t))) (goto-char (max begin end)) (let ((found-pos (search-backward text nil t))) (if (not found-pos) (progn (goto-char begin) (error "not found")) (progn (goto-char found-pos) (set-mark (- found-pos (length text)))))))) (define-key global-map [(shift down-mouse-1)] nil) (define-key global-map [(shift mouse-1)] 'mouse-search-forward) (define-key global-map [(shift down-mouse-3)] nil) (define-key global-map [(shift mouse-3)] 'mouse-search-backward) ;;; http://www.coverfire.com/archives/2004/06/24/emacs-source-code-navigation/ ;;; The etags system also gives you the ability to do auto-completion on function names that are in the TAGS file. ;;; Here is the necessary .emacs LISP code to bind this functionality to CTRL-Tab. (add-hook 'c-mode-common-hook (lambda () (define-key c-mode-map [(ctrl tab)] 'complete-tag))) ;; The following does not work as expected. ;; Regions are indented pressing TAB, but TAB without region selected does nothing. ;; (add-hook 'c-mode-common-hook ;; (lambda () ;; (define-key c-mode-map [(tab)] 'indent-region)) ;; (if mark-active ;; (indent-region (region-beginning) ;; (region-end)) ;; (indent-for-tab-command))) ;;================================================================================ ;;========================================================== ;; C template 1 - use CTRL+c CTRL+m to insert main() ;;========================================================== (defvar c-main-function "#include int main(int argc, char *argv[]) { printf(\"Hello, world!\\n\"); return 0; } ") (defun c-main () "Insert C main() function at cursor point." (interactive) (insert c-main-function)) (add-hook 'c-mode-common-hook (lambda () (define-key c-mode-map "\C-c\C-m" 'c-main))) ;;========================================================== ;;========================================================== ;; C template 2 - use CTRL+c CTRL+s CTRL+c to insert switch/case block ;;========================================================== (defvar c-switch-case-function "switch (grade) { case 1: printf(\"Case 1\\n\"); break; case 2: printf(\"Case 2\\n\"); break; case 3: case 4: printf(\"Case 3 and 4\\n\"); break; default: printf(\"Default case\\n\"); } ") (defun c-switch-case () "Insert C switch() block at cursor point." (interactive) (insert c-switch-case-function)) (add-hook 'c-mode-common-hook (lambda () (define-key c-mode-map "\C-c\M-s" 'c-switch-case))) ;;========================================================== ;; ========== Place Backup Files in Specific Directory ========== ;; http://homepages.inf.ed.ac.uk/s0243221/emacs/ ;; Enable backup files. (setq make-backup-files t) ;; Enable versioning with default values (keep five last versions, I think!) (setq version-control t) ;; Enable versioning with default values (keep five last versions, I think!) (setq delete-old-versions t) ;; Enable versioning with default values (keep five last versions, I think!) (setq kept-new-versions 50) ;; Save all backup file in this directory. (setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/")))) ;;========================================================== ;; ========== Enable Line and Column Numbering ========== ;; Show line-number in the mode line (line-number-mode 1) ;; Show column-number in the mode line (column-number-mode 1) ;; ETAGS COMMANDS ;; M-. (find-tag) - find a tag, that is, use the Tags file to look up a definition ;; M-* (pop-tag-mark) - jump back ;; tags-search - regexp-search through the source files indexed by a tags file (a bit like grep) ;; tags-query-replace - query-replace through the source files indexed by a tags file ;; M-, (tags-loop-continue) - resume tags-search or tags-query-replace starting at point in a source file ;; tags-apropos - list all tags in a tags file that match a regexp ;; list-tags - list all tags defined in a source file ;; SVN commands (requires psvn.el in ~/emacs-packages/) (require 'psvn)