;; where to look for loadable files (setq load-path (append (list "~/portable-homedir/lisp") load-path )) ;; encoding (modify-coding-system-alist 'file "\\.*\\'" 'utf-8) ;; tab settings (setq-default indent-tabs-mode nil) (setq default-tab-width 4) (setq c-basic-offset 4) (setq c-hungry-delete-key t) ;; "y or n" instead of "yes or no" (fset 'yes-or-no-p 'y-or-n-p) ;; do not show the startup message (setq inhibit-startup-message t) (setq inhibit-startup-echo-area-message t) ;; highlight matches from searches (setq isearch-highlight t) (setq search-highlight t) ;; Highlight regions and add special behaviors to regions. ;; "C-h d transient" for more info (setq transient-mark-mode t) ;; do not beep (setq visible-bell t) ;; include the newline when killing a line (setq kill-whole-line t) ;; do not confirm revert of file list buffers (setq revert-without-query '("file_list\.org$")) ;; make control and alt work normally under OS X (setq mac-option-modifier 'meta) (setq mac-command-modifier nil) ;; do not show the scroll bar (toggle-scroll-bar -1) ;; do not show the tool bar (tool-bar-mode -1) ;; display column number (setq column-number-mode t) ;; do not make backup (~) files (setq make-backup-files nil) ;; disable auto fill mode (turn-off-auto-fill) ;; minibuffer starts out in current buffer's directory (setq insert-default-directory t) ;; turn on font-lock mode (global-font-lock-mode t) (setq font-lock-maximum-decoration t) ;; use ido-mode during find-file and switch-to-buffer (ido-mode t) ;; matching parenthesis should be highlighted (show-paren-mode 1) ;; the frame title should be the name of the current buffer (setq frame-title-format "%b %Z") ;; start off in text mode (setq default-major-mode 'text-mode) ;; keep track of window configurations, and make it easy to dismiss ;; new windows. Activated via C-c (winner-mode 1) ;; don't automatically add new lines when scrolling down at ;; the bottom of a buffer (setq next-line-add-newlines nil) ;; shortcuts for moving around multi-window frames (global-set-key [M-left] 'windmove-left) (global-set-key [M-right] 'windmove-right) (global-set-key [M-up] 'windmove-up) (global-set-key [M-down] 'windmove-down) ;; msf-abbreviations (require 'msf-abbrev) (setq msf-abbrev-root "~/portable-homedir/lisp/msf-abbreviations") (global-set-key (kbd "C-c l") 'msf-abbrev-goto-root) (global-set-key (kbd "C-c a") 'msf-abbrev-define-new-abbrev-this-mode) (msf-abbrev-load) ;; buffer switching (require 'bs) ;; chmod u+x when saving a script (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p) ;; MODES ;;---------------------------------------------------------------------- ;; org mode (add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) (add-hook 'org-mode-hook (lambda () (auto-revert-mode t))) ;; abbrev mode (setq-default abbrev-mode t) (autoload 'expand-abbrev-hook "expand") (setq save-abbrevs t) ;; php (autoload 'php-mode "php-mode" "PHP mode" t) (add-to-list 'auto-mode-alist '("\\.php$" . php-mode)) (add-hook 'php-mode-hook (lambda () (imenu-add-menubar-index) (turn-off-auto-fill) (setq truncate-lines t))) ;; css (autoload 'css-mode "css-mode-simple" "CSS mode" t) (add-to-list 'auto-mode-alist '("\\.css$" . css-mode)) ;; perl (fset 'perl-mode 'cperl-mode) (add-hook 'cperl-mode-hook (lambda () (turn-off-auto-fill) (setq abbrev-mode nil))) ;; javascript (autoload 'ecmascript-mode "ecmascript-mode" "Ecmascript mode" t) (add-to-list 'auto-mode-alist '("\\.js$" . ecmascript-mode)) (add-hook 'ecmascript-mode-hook (lambda () (imenu-add-menubar-index) (turn-off-auto-fill) (setq truncate-lines t))) ;; html (add-to-list 'auto-mode-alist (cons (concat "\\." (regexp-opt '("html" "htm" "rhtml" "thtml" "aspx" "asp") t) "\\'") 'sgml-mode)) (add-hook 'sgml-mode-hook (lambda () (abbrev-mode t) (turn-off-auto-fill) (setq truncate-lines t))) ;; python ;; (autoload 'python-mode "python-mode" "Python Mode" t) ;; (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode)) ;; (add-to-list 'interpreter-mode-alist '("python" . python-mode)) ;; ruby ;; (autoload 'ruby-mode "ruby-mode" "Ruby mode" t) ;; (add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode)) ;; (add-to-list 'auto-mode-alist '("\\.rake$" . ruby-mode)) ;; text (add-hook 'text-mode-hook 'turn-on-auto-fill) ;; shell (add-hook 'comint-output-filter-functions 'comint-watch-for-password-prompt) ;; KEYBINDINGS ;;---------------------------------------------------------------------- ;; auto fill mode toggle (global-set-key [f3] 'auto-fill-mode) ;; truncate lines toggle (global-set-key [f4] 'toggle-truncate-lines) ;; php mode (global-set-key "\C-cp" 'php-mode) ;; ecmascript mode (global-set-key "\C-cj" 'ecmascript-mode) ;; sgml mode (global-set-key "\C-cs" 'sgml-mode) ;; dired on ~/Sites (global-set-key "\C-co" '(lambda () "Dired here" (interactive) (dired "~/Sites"))) ;; goto-line (global-set-key "\M-g" 'goto-line) ;; disable the display of the key binding help window, which tends to ;; annoyingly pop up from misfirings of \C-xh (global-set-key "\C-x\C-h" 'ignore) ;; disable default buffer menu command; use C-b instead (global-set-key "\C-x\C-b" 'ignore) ;; buffer menu (global-set-key "\C-cb" 'ibuffer) ;; next buffer (global-set-key "\C-cp" 'bs-cycle-previous) ;; previous buffer (global-set-key "\C-cn" 'bs-cycle-next) ;; copy-from-above-command is provided by misc.el (load "misc") (global-set-key [(control meta y)] 'copy-from-above-command) ;; revert buffer (global-set-key "\C-cr" '(lambda () "Revert without confirm" (interactive) (revert-buffer nil t))) ;; jump to bookmark (global-set-key "\C-cj" 'bookmark-jump) ;; FUNCTIONS ;;---------------------------------------------------------------------- ;; http://emacs.wordpress.com/2007/01/22/killing-yanking-and-copying-lines/ (defadvice yank (after indent-region activate) (let ((mark-even-if-inactive t))) (if (member major-mode '(emacs-lisp-mode php-mode lisp-mode ruby-mode ecmascript-mode objc-mode sgml-mode nxml-mode)) (indent-region (region-beginning) (region-end) nil))) ;; http://emacs.wordpress.com/2007/01/22/killing-yanking-and-copying-lines/ (defun lovett-copy-without-kill (arg) "Copy one or more lines without killing them." (interactive "p") (kill-ring-save (line-beginning-position) (line-beginning-position (+ 1 arg))) (message "%d line%s copied" arg (if (= 1 arg) "" "s"))) (global-set-key "\C-cc" 'lovett-copy-without-kill) ;; http://blog.zenspider.com/archives/2007/02/control_your_emacs_frames_programatically.html (defun arrange-frame (w h &optional nosplit) "Rearrange the current frame to a custom width and height and split unless prefix." (let ((frame (selected-frame))) (when (equal 'mac (framep frame)) (delete-other-windows) (set-frame-position frame 2 22) (set-frame-size frame w h) (if (not nosplit) (split-window-horizontally 24))))) ;; http://blog.zenspider.com/archives/2007/02/control_your_emacs_frames_programatically.html (defun my-set-mac-font (name size) (interactive (list (completing-read "font-name: " (mapcar (lambda (p) (list (car p) (car p))) (x-font-family-list)) nil t) (read-number "size: " 12))) (set-face-attribute 'default nil :family name :slant 'normal :weight 'normal :width 'normal :height (* 10 size)) (frame-parameter nil 'font)) ;; http://blog.zenspider.com/archives/2007/02/control_your_emacs_frames_programatically.html (defun medium (&optional nosplit) "Create a large window suitable for coding on a macbook." (interactive "P") (my-set-mac-font "Courier" 11) (arrange-frame 120 57 t)) (medium) (ibuffer) (defun lovett-arrange-for-file-list () (interactive) (delete-other-windows) (arrange-frame 140 47 nil)) (global-set-key "\C-cF" 'lovett-arrange-for-file-list) (global-set-key [f12] 'ansi-term) (defun lovett-reindent-buffer () "Reindent the contents of the entire buffer." (interactive) (mark-whole-buffer) (indent-region (region-beginning) (region-end))) (global-set-key "\C-ci" 'lovett-reindent-buffer) (defun tagwrap (tags) (interactive "sList of tags (outermost first, space separated): ") (save-excursion (insert tags) (insert "\n")) (save-excursion (shell-command-on-region (point) (mark) "~/Library/Scripts/tagwrap" nil t)) (let ((beg (point))) (search-forward "\n\n") (backward-delete-char 2) (indent-region beg (point))) ) (global-set-key "\C-cI" 'tagwrap) (defun todo-datestamp (prefix) "Insert the current date." (interactive "P") (insert (format-time-string "[%Y-%m-%d] "))) (global-set-key "\C-cd" `todo-datestamp) (defun insert-timestamp (prefix) "Insert the current timestamp." (interactive "P") (insert (format-time-string "%Y-%m-%d %I:%M %p "))) (global-set-key "\C-ct" `insert-timestamp) (defun whack-whitespace (arg) "Delete all white space from point to the next word." (interactive "P") (re-search-forward "[ \t\n]+" nil t) (replace-match "" nil nil)) (defun lovett-leading-whitespace (arg) "Delete all whitespace " (interactive "p") (move-beginning-of-line nil) (re-search-forward "[ \t]+" nil t) (replace-match "" nil nil)) (defun html-table-generator (numrows numcols) "Generate an HTML table with arbitrary rows and columns" (interactive "nHow many rows? \nnHow many columns? ") (save-excursion (newline-and-indent) (insert "") (loop repeat numrows do (newline-and-indent) (insert "") (loop repeat numcols do (newline-and-indent) (insert "")) (newline-and-indent) (insert "") (indent-according-to-mode)) (newline-and-indent) (insert "
~
") (indent-according-to-mode)) (search-forward "~") (delete-backward-char 1)) (defun lovett-revert-file-list () "" (interactive) (switch-to-buffer-other-window "file_list.org") (revert-buffer t t) (shell-command "~/portable-homedir/bin/file_list.codeigniter.pl" t) (revert-buffer t t) (beginning-of-buffer)) (global-set-key "\C-x\M-r" `lovett-revert-file-list) (defun tag-image () "Replace an image file name at point with an HTML img tag. eg: x.jpg became ." (interactive) (let ((imgName (thing-at-point 'filename)) (bounds (bounds-of-thing-at-point 'filename))) (delete-region (car bounds) (cdr bounds)) (let ((image-size (let ((ximg (create-image (concat default-directory imgName)))) (image-size ximg t)))) (let ((width (number-to-string (car image-size))) (height (number-to-string (cdr image-size)))) (insert ""))))) (defun sort-todolist () "" (interactive) (mark-whole-buffer) (sort-lines nil (region-beginning) (region-end))) ;; KEY BINDINGS ;;---------------------------------------------------------------------- ;; the rest of this file is managed by Custom (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. '(enable-local-variables :all) '(ibuffer-default-shrink-to-minimum-size t) '(ibuffer-movement-cycle t) '(ido-ignore-buffers (quote ("\\` " "^\*Mess" "^\*Back"))) '(org-file-apps (quote (("txt" . emacs) ("org" . emacs) ("el" . emacs) ("css" . emacs) ("php" . emacs) ("js" . emacs) ("html" . emacs) ("ini" . emacs)))) '(org-return-follows-link t) '(org-tab-follows-link nil) ) (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. ) (put 'narrow-to-region 'disabled nil) (put 'downcase-region 'disabled nil)