Skip to content

Instantly share code, notes, and snippets.

@theory
Created August 6, 2010 21:59
Show Gist options
  • Save theory/512079 to your computer and use it in GitHub Desktop.
Save theory/512079 to your computer and use it in GitHub Desktop.
(add-to-list 'load-path "/usr/local/share/emacs/site-lisp")
;(defconst mEV (emacs-version)
; "Keep the Emacs version string,
; that is needed a few times.")
;; make backup files in ~/.emacs-backups/ rather than scattered around all
;; over the filesystem.
(defun make-backup-file-name (file-name)
"Create the non-numeric backup file name for `file-name'."
(require 'dired)
(if (file-exists-p "~/.emacs-backups")
(concat (expand-file-name "~/.emacs-backups/")
(dired-replace-in-string "/" "|" file-name))
(concat file-name "~")))
;; Where is ispell?
(setq-default ispell-program-name "/usr/local/bin/aspell")
;; Don't just quit when I accidentally hit C-xc!
(setq confirm-kill-emacs 'y-or-n-p)
;; Make SVN work like CVS.
(add-to-list 'vc-handled-backends 'SVN)
;; Use only spaces, no tabs.
(setq-default indent-tabs-mode nil)
;; Indent 4 spaces in C.
(setq c-default-style "bsd"
c-basic-offset 4)
;; I'm a tramp, are you?
(setq tramp-default-method "ssh")
;; direct customization.
(add-hook 'dired-load-hook (function (lambda () (load "dired-x"))))
(setq dired-omit-files-p 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.
'(default ((t (:stipple nil :background "DarkSlateGrey" :foreground "Wheat" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 120 :width normal :family "apple-consolas"))))
'(cursor ((t (:background "Wheat")))))
'(mmm-default-submode-face ((t nil)))
;; http://www.emacsblog.org/2007/04/09/highlight-the-current-line/
(global-hl-line-mode 1)
(set-face-background 'hl-line "#273f46")
(set-cursor-color "blue")
(set-face-background 'region "#330") ; Set region background color
(set-selection-coding-system 'mac-roman)
(set-keyboard-coding-system 'mac-roman)
;(create-fontset-from-fontset-spec
; "-apple-lucida sans typewriter-medium-r-normal--11-*-*-*-*-*-fontset-mac,
;ascii:-apple-lucida sans typewriter-medium-r-normal--11-*-*-*-m-*-mac-roman,
;latin-iso8859-1:-apple-lucida sans typewriter-medium-r-normal--11-*-*-*-m-*-mac-roman,
;mule-unicode-0100-24ff:-apple-lucida sans typewriter-medium-r-normal--11-*-*-*-m-*-mac-roman")
;(set-frame-font "-apple-lucida sans typewriter-medium-r-normal--11-*-*-*-*-*-fontset-mac" 'keep)
;(add-to-list 'default-frame-alist '(font . "-apple-lucida sans typewriter-medium-r-normal--11-*-*-*-*-*-fontset-mac"))
;; set utf as default save encoding for files
(set-coding-priority (list 'coding-category-utf-8))
(prefer-coding-system 'utf-8)
;; General custom settings.
(setq line-number-mode t)
(setq column-number-mode t)
(setq-default transient-mark-mode t)
; Mac options.
(global-set-key (quote [f1]) 'help-command) ; f1 = help.
(global-set-key [?\A-v] 'yank) ; command-v = paste
(global-set-key [?\A-x] 'kill-region) ; command-x = cut
(global-set-key [?\A-c] 'kill-ring-save) ; command-c = copy
;; This setting is mainly for using emacs in the shell. It makes the backspace
;; key work correctly.
(keyboard-translate ?\C-h ?\C-?)
;; In Emacs regexen, match a newline with '\s '!
;; pcl-cvs keybinding.
;; (global-set-key "\C-cv" cvs-update)
;; mode-compile
(autoload 'mode-compile "mode-compile"
"Command to compile current buffer file based on the major mode" t)
(global-set-key "\C-cc" 'mode-compile)
(autoload 'mode-compile-kill "mode-compile"
"Command to kill a compilation launched by `mode-compile'" t)
(global-set-key "\C-ck" 'mode-compile-kill)
;; Ruby stuff.
(setq ruby-program-name "/usr/bin/ruby")
(autoload 'ruby-mode "ruby-mode" "Mode for editing ruby source files")
(add-to-list 'auto-mode-alist '("Rakefile\\|\\.rb$" . ruby-mode))
(add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode))
(autoload 'run-ruby "inf-ruby" "Run an inferior Ruby process")
(autoload 'inf-ruby-keys "inf-ruby" "Set local key defs for inf-ruby in ruby-mode")
(add-hook 'ruby-mode-hook '(lambda () (inf-ruby-keys)))
;; CPerl custom variables.
(defalias 'perl-mode 'cperl-mode)
(setq auto-mode-alist
(append
'(("\\.\\([pP]\\([Llm]\\|erl\\)\\|al\\|t\\|obj\\)\\'" . cperl-mode))
auto-mode-alist))
(setq interpreter-mode-alist (append interpreter-mode-alist '(("miniperl" . cperl-mode))))
(setq cperl-hairy t)
(setq cperl-electric-keywords t)
(setq cperl-highlight-variables-indiscriminately t)
(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.
'(blink-cursor-mode nil)
'(case-fold-search t)
'(column-number-mode t)
'(cperl-close-paren-offset -4)
'(cperl-continued-statement-offset 4)
'(cperl-indent-level 4)
'(cperl-indent-parens-as-block t)
'(cperl-label-offset 0)
'(cperl-merge-trailing-else nil)
'(cperl-tab-always-indent t)
'(cua-mode nil nil (cua-base))
'(fancy-splash-max-time 0)
'(fill-column 78)
'(global-font-lock-mode t nil (font-core))
'(inhibit-startup-screen t)
'(mmm-submode-decoration-level 0)
'(ns-alternate-modifier (quote meta))
'(pod2man-program "perldoc -MPod::Simple::Man")
'(ruby-indent-level 2)
'(safe-local-variable-values (quote ((basic-offset . 2))))
'(sentence-end-double-space nil)
'(show-paren-mode t)
'(sql-sqlite-program "/usr/local/bin/sqlite3")
'(tab-width 4)
'(tool-bar-mode nil nil (tool-bar))
'(transient-mark-mode t))
'(cua-mode nil)
'(current-language-environment "English")
'(indent-tabs-mode nil)
'(sentence-end-double-space nil)
'(show-paren-mode nil)
'(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
'(transient-mark-mode t)
;; POD mode.
(require 'pod-mode)
(add-to-list 'auto-mode-alist
'("\\.pod" . pod-mode))
(add-hook 'pod-mode-hook 'font-lock-mode)
;; TAP mode.
;(require 'tap-mode)
;(add-to-list 'auto-mode-alist
; '("\\.tap" . tap-mode))
;(add-hook 'tap-mode-hook 'font-lock-mode)
;; MMM and mmm-mason loading settings.
;(require 'php-mode)
(autoload 'php-mode "php-mode" "Major mode for editing php code." t)
(require 'mmm-mode)
(require 'mmm-mason)
(setq mmm-global-mode 'maybe)
(add-to-list 'auto-mode-alist
'("autohandler\\|dhandler\\|\\.\\(html\\|mc\\)"
. sgml-mode))
(mmm-add-mode-ext-class
'sgml-mode "autohandler\\|dhandler\\|\\.\\(html\\|mc\\)" 'mason)
;; erb in mmm-mode.
;;; ruby-electric (omg this is going to spoil me)
;`
;;; mmm-mode
(require 'mmm-auto)
(setq mmm-global-mode 'maybe)
(setq mmm-submode-decoration-level 0)
;;; ruby-electric (omg this is going to spoil me)
(require 'ruby-electric)
(defun ruby-indent ()
(local-set-key "\C-m" 'ruby-reindent-then-newline-and-indent))
(add-hook 'ruby-mode-hook
'(lambda ()
(ruby-indent)
(ruby-electric-mode)
))
;;; eRuby (ruby/html mmm)
(mmm-add-classes
'((erb-code
:submode ruby-mode
:front "<%[#=]?"
:back "%>"
)))
(add-hook 'html-mode-hook
(lambda ()
(setq mmm-classes '(erb-code))
(mmm-mode-on)))
(add-to-list 'auto-mode-alist '("\\.rhtml$" . html-mode))
;; SQL mode settings.
(setq auto-mode-alist
(append '(("\\.\\(con\\|use\\|val\\|tst\\|s\\|pg\\|ddl\\)$" . sql-mode)) auto-mode-alist ))
(eval-after-load "tsql"
'(load-library "tsql-indent"))
;; Markdown mode settings.
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown text files" t)
(setq auto-mode-alist
(cons '("\\.\\(te\?xt\\|pgtap\\)$" . markdown-mode) auto-mode-alist))
;; PHP mode mappings.
(setq auto-mode-alist
(append '(("\\.\\(php\\|php\\)$" . php-mode)) auto-mode-alist ))
;; Check your perl code!
(defun perlutil-perl-check ()
"Run a perl check on the current buffer."
(interactive)
(save-buffer)
(setq compile-command (format "perl -wc \'%s\'" (buffer-file-name)))
(message "compile-command: %s" compile-command)
(compile compile-command))
(global-set-key "\C-cp" 'perlutil-perl-check)
; Outline-minor-mode key map
(define-prefix-command 'cm-map nil "Outline-")
; HIDE
(define-key cm-map "q" 'hide-sublevels) ; Hide everything but the top-level headings
(define-key cm-map "t" 'hide-body) ; Hide everything but headings (all body lines)
(define-key cm-map "o" 'hide-other) ; Hide other branches
(define-key cm-map "c" 'hide-entry) ; Hide this entry's body
(define-key cm-map "l" 'hide-leaves) ; Hide body lines in this entry and sub-entries
(define-key cm-map "d" 'hide-subtree) ; Hide everything in this entry and sub-entries
; SHOW
(define-key cm-map "a" 'show-all) ; Show (expand) everything
(define-key cm-map "e" 'show-entry) ; Show this heading's body
(define-key cm-map "i" 'show-children) ; Show this heading's immediate child sub-headings
(define-key cm-map "k" 'show-branches) ; Show all sub-headings under this heading
(define-key cm-map "s" 'show-subtree) ; Show (expand) everything in this heading & below
; MOVE
(define-key cm-map "u" 'outline-up-heading) ; Up
(define-key cm-map "n" 'outline-next-visible-heading) ; Next
(define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
(define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
(define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
(global-set-key "\M-o" cm-map)
(defun perltidy ()
"Run perltidy on the current region or buffer."
(interactive)
; Inexplicably, save-excursion doesn't work here.
(let ((orig-point (point)))
(unless mark-active (mark-defun))
(shell-command-on-region (point) (mark) "perltidy -q" nil t)
(goto-char orig-point)))
(global-set-key "\C-ct" 'perltidy)
(global-set-key "\C-cr" 'replace-string)
(global-set-key "\C-cx" 'replace-regexp)
(global-set-key "\C-cw" 'whitespace-cleanup)
(global-set-key "\C-cc" 'comment-or-uncomment-region)
(put 'narrow-to-region 'disabled nil)
(setq ps-print-header nil)
(defun print-to-pdf ()
(interactive)
(ps-spool-buffer-with-faces)
(switch-to-buffer "*PostScript*")
(write-file "/tmp/tmp.ps")
(kill-buffer "tmp.ps")
(setq cmd (concat "ps2pdf14 /tmp/tmp.ps " (buffer-name) ".pdf"))
(shell-command cmd)
(shell-command "rm /tmp/tmp.ps")
(message (concat "Saved to: " (buffer-name) ".pdf"))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment