;; rename this file to ".emacs" ;; Please note: This .emacs files contains code written by many authors ;; Turn off menu bars (menu-bar-mode nil) (scroll-bar-mode nil) (tool-bar-mode nil) (set-face-background 'mode-line "forest green") ;; Bind backward-kill-word to \ (global-set-key "\C-\\" 'backward-kill-word) ;; Bind mark-word to End key (global-set-key [end] 'mark-word) ;; Create a macro that copies next word after cursor (fset 'copy-next-word [C-delete ?\C-x ?u]) ;; Create a macro that copies word before cursor (fset 'copy-last-word [escape ?- ?1 end escape ?w]) ;; Bind copy-last-word to PF 11. With this you can type a word ;; and then hit PF11 to copy it for later pasting. (global-set-key [f11] 'copy-last-word) (defun my-other-window-or-other-buffer () "Select other window on this frame or, if none, switch to `other-buffer'." (interactive) (if (one-window-p) (switch-to-buffer (other-buffer)) (other-window +1))) (defun next-buffer() "switches to next buffer on buffer list." (interactive) (bury-buffer) (switch-to-buffer (car (buffer-list)))) (defun prev-buffer() "switches to previous buffer" (interactive) (switch-to-buffer (car (reverse (buffer-list))))) ;; Bind next-buffer PF 6. Switches between two most recent buffers ;; Use for blink compare (global-set-key [f6] 'my-other-window-or-other-buffer) ;; Bind prev-buffer PF 7. Switches between two most recent buffers (global-set-key [f7] 'prev-buffer) ;; Bind next-buffer PF 8. Switches between two most recent buffers (global-set-key [f8] 'next-buffer) ;; Bind copy-next-word to PF 12. With this you can move cusror to start of word ;; and then hit PF12 to copy it for later pasting. (global-set-key [f12] 'copy-next-word) ;; Indent with spaces not tabs (set-default 'indent-tabs-mode nil) ;; Bind delete-whitespace-rectangle to C-x rv (global-set-key "\C-xrv" 'delete-whitespace-rectangle) ;; Dont show auto-saved "~" backup files in the directory edit (setq dired-listing-switches "-alB") ;; Set the debug option to enable a backtrace when a ;; problem occurs. (setq debug-on-error t) (setq auto-save-default nil) (setq auto-save-interval 99999999) (setq auto-save-timeout 600000) ;; This .emacs file illustrates the minimul setup ;; required to run the JDE. ;; Update the Emacs load-path to include the path to ;; the JDE and its require packages. (add-to-list 'load-path "/home/jd/emacslibs/misc") (add-to-list 'load-path "/home/jd/emacslibs/common") (add-to-list 'load-path "/home/jd/emacslibs/eieio") (add-to-list 'load-path "/home/jd/emacslibs/elib") (add-to-list 'load-path "/home/jd/emacslibs/semantic") (add-to-list 'load-path "/home/jd/emacslibs/speedbar") (add-to-list 'load-path "/home/jd/emacslibs/jde-2.3.3/lisp") (add-to-list 'load-path "/home/jd/emacslibs/elib-1.0") (add-to-list 'load-path "/home/jd/emacslibs/ecb-2.32") ;; If you want Emacs to defer loading the JDE until you open a ;; Java file, edit the following line (setq defer-loading-jde nil) ;; to read: ;; ;; (setq defer-loading-jde t) ;; (if defer-loading-jde (progn (autoload 'jde-mode "jde" "JDE mode." t) (setq auto-mode-alist (append '(("\\.java\\'" . jde-mode)) auto-mode-alist))) (require 'jde)) ;; Include the following only if you want to run ;; bash as your shell. ;; Setup Emacs to run bash as its primary shell. (setq shell-file-name "bash") (setq shell-command-switch "-c") (setq explicit-shell-file-name shell-file-name) (setenv "SHELL" shell-file-name) (setq explicit-sh-args '("-login" "-i")) (if (boundp 'w32-quote-process-args) (setq w32-quote-process-args ?\")) ;; Include only for MS Windows. ; Set colors (set-background-color "black") (set-foreground-color "white") (set-cursor-color "white") (transient-mark-mode t) ;; Sets the basic indentation for Java source files ;; to two spaces. (defun my-jde-mode-hook () (setq c-basic-offset 2)) (add-hook 'jde-mode-hook 'my-jde-mode-hook) (custom-set-faces ;; custom-set-faces was added by Custom -- don't edit or cut/paste it! ;; Your init file should contain only one such instance. '(default ((t (:stipple nil :background "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 140 :width normal :family "adobe-courier")))) '(custom-rogue-face ((((class color)) (:foreground "white" :background "black")))) '(font-lock-builtin-face ((t (:foreground "white" :bold nil)))) '(font-lock-comment-face ((t (:foreground "yellow" :bold nil)))) '(font-lock-constant-face ((t (:foreground "LightGray" :bold nil)))) '(font-lock-function-name-face ((t (:foreground "wheat" :bold nil)))) '(font-lock-keyword-face ((t (:foreground "PaleGreen" :bold nil)))) '(font-lock-package-face ((t (:foreground "PaleGreen" :bold nil)))) '(font-lock-string-face ((t (:foreground "LightGray" :bold nil)))) '(font-lock-type-face ((t (:foreground "white" :bold nil)))) '(font-lock-variable-name-face ((t (:foreground "wheat" :bold nil)))) '(font-lock-warning-face ((((class color) (background dark)) (:foreground "gray")))) '(gnus-summary-high-ticked-face ((((class color) (background dark)) (:bold t :foreground "white")))) '(jde-java-font-lock-api-face ((t (:foreground "red" :bold nil)))) '(jde-java-font-lock-bold-face ((t (:foreground "blue" :bold nil)))) '(jde-java-font-lock-code-face ((t (:foreground "orange" :bold nil)))) '(jde-java-font-lock-modifier-face ((t (:foreground "white" :bold nil)))) '(jde-java-font-lock-number-face ((t (:foreground "white" :bold nil)))) '(jde-java-font-lock-package-face ((t (:foreground "PaleGreen" :bold nil)))) '(jde-java-font-lock-pre-face ((t (:foreground "purple" :bold nil)))) '(region ((t (:background "dark blue"))))) (require 'browse-kill-ring) (global-set-key (kbd "C-c k") 'browse-kill-ring) (add-to-list 'default-frame-alist '(top . 0)) (add-to-list 'default-frame-alist '(left . 0)) (add-to-list 'default-frame-alist '(width . 97)) (add-to-list 'default-frame-alist '(height . 33)) ;; ;; A example reg-exp replace function ;; (defun change-abc-xyz () "Function description here." (interactive) (goto-char (point-min)) (replace-regexp "abc" "xyz") ) ;; ;; This function will change the coding style ;; of Java code, taking the open curly brace that ;; is by itself on a new line, and pulling it back ;; up to be at the end of the line that declares the ;; block ;; ;; ;; Note: Any "\" should be prefixed with an escape \ ;; So: \( becomes \\( ;; \) becomes \\) ;; \w becomes \\w ;; \1 becomes \\1 ;; The newline is entered as C-Q C-J. Same as in ;; emacs buffer ;; (defun fix-curly-braces () "Put curly braces at end." (interactive) (goto-char (point-min)) (replace-regexp "^\\(.*\\)[ ]* [ ]*{[ ]* " "\\1 { ") ) ;; Set up the keyboard so the delete key on both the regular keyboard ;; and the keypad delete the character under the cursor and to the right ;; under X, instead of the default, backspace behavior. (global-set-key [delete] 'delete-char) (global-set-key [kp-delete] 'delete-char) ;; Always end a file with a newline (setq require-final-newline t) ;; Stop at the end of the file, not just add lines (setq next-line-add-newlines nil) ; Set colors (set-background-color "black") (set-foreground-color "white") (set-cursor-color "white") (transient-mark-mode t) (defun fix-curly-braces () "Put curly braces at end." (interactive) (goto-char (point-min)) (replace-regexp "^\\(.*\\)[ ]* [ ]*{[ ]* " "\\1 { ") ) (defun find-first-duplicate-line () "Find a line that is repeated any where else in file." (interactive) (goto-char (point-min)) (search-forward-regexp "^\\(.*\\) \\(^.* \\)*\\1") ) ;; simplified version of ken wilder's "match-parent" function (cool ;; stuff!!!) (defun match-paren (arg) "Go to the matching parenthesis" (interactive "p") (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1)) ((looking-at "\\s\)") (forward-char 1) (backward-list 1)))) (define-key global-map [(control right)] 'match-paren) ;(require 'font-lock) ;(require 'jde) (defun tail-mode (&optional arg) "Toggle reverting buffer when file on disk changes.This is almost the same as `auto-revert-mode'. In addition, this mode adds `tail-mode-update-buffer' to `after-revert-hook' in a buffer-local way to move point to end of buffer after reverting it. Points are moved only in buffers which have an unselected window open. (However, this mode has an effect only if `revert-buffer' actually uses `after-revert-hook', see the documentation of `revert-buffer' for more information.)" (interactive "P") (make-local-hook 'after-revert-hook) ;; we modify the hook *before* we call `auto-revert-mode' ;; because we want `auto-revert-mode-hook' to be run at the ;; very end (if (if (null arg) (not (and (boundp 'auto-revert-mode) auto-revert-mode)) (> (prefix-numeric-value arg) 0)) (add-hook 'after-revert-hook 'tail-mode-update-buffer nil t) (remove-hook 'after-revert-hook 'tail-mode-update-buffer t)) (auto-revert-mode arg)) (defun tail-mode-update-buffer () "Move point to end of buffer after reverting buffers. Moves point only in buffers which have an unselected window open." (mapcar (function (lambda (window) (goto-char (point-max)) (vertical-motion (- 2 (window-height window))) (set-window-start window (point)) (set-window-point window (point-max)))) (get-buffer-window-list (current-buffer) 'no-minibuf t))) (custom-set-variables ;; custom-set-variables was added by Custom -- don't edit or cut/paste it! ;; Your init file should contain only one such instance. ) ;; Kill all white space to the right of point (defun kill-to-non-blank () "kill to 1st non blank (after blank) to right" (interactive "*") (kill-region (point) (progn (forward-to-non-blank) (point)))) (defun forward-to-non-blank () "go to 1st non blank (after blank) to right" (interactive) (if (re-search-forward "[ \t\n][^ \t\n]" (point-max) t) (backward-char 1))) ;; Kill all white space to the right of point (global-set-key "\C-q" 'kill-to-non-blank) (defun align-cols (start end max-cols) "Align text between point and mark as columns. Columns are separated by whitespace characters. Prefix arg means align that many columns. (default is all)" (interactive "r\nP") (save-excursion (let ((p start) pos end-of-line word count (max-cols (if (numberp max-cols) (max 0 (1- max-cols)) nil)) (pos-list nil) (ref-list nil)) ;; find the positions (goto-char start) (while (< p end) (beginning-of-line) (setq count 0) (setq end-of-line (save-excursion (end-of-line) (point))) (re-search-forward "^\\s-*" end-of-line t) (setq pos (current-column)) ;start of first word (if (null (car ref-list)) (setq pos-list (list pos)) (setq pos-list (list (max pos (car ref-list)))) (setq ref-list (cdr ref-list))) (while (and (if max-cols (< count max-cols) t) (re-search-forward "\\s-+" end-of-line t)) (setq count (1+ count)) (setq word (- (current-column) pos)) ;; length of next word including following whitespaces (setq pos (current-column)) (if (null (car ref-list)) (setq pos-list (cons word pos-list)) (setq pos-list (cons (max word (car ref-list)) pos-list)) (setq ref-list (cdr ref-list)))) (while ref-list (setq pos-list (cons (car ref-list) pos-list)) (setq ref-list (cdr ref-list))) (setq ref-list (nreverse pos-list)) (forward-line) (setq p (point))) ;; aling the cols starting with last row (setq pos-list (copy-sequence ref-list)) (setq start (save-excursion (goto-char start) (beginning-of-line) (point))) (goto-char end) (beginning-of-line) (while (>= p start) (beginning-of-line) (setq count 0) (setq end-of-line (save-excursion (end-of-line) (point))) (re-search-forward "^\\s-*" end-of-line t) (goto-char (match-end 0)) (setq pos (nth count pos-list)) (while (< (current-column) pos) (insert-char ?\040 1)) (setq end-of-line (save-excursion (end-of-line) (point))) (while (and (if max-cols (< count max-cols) t) (re-search-forward "\\s-+" end-of-line t)) (setq count (1+ count)) (setq pos (+ pos (nth count pos-list))) (goto-char (match-end 0)) (while (< (current-column) pos) (insert-char ?\040 1)) (setq end-of-line (save-excursion (end-of-line) (point)))) (forward-line -1) (if (= p (point-min)) (setq p (1- p)) (setq p (point)))))))