Skip to content

Instantly share code, notes, and snippets.

Created December 30, 2012 08:04
Show Gist options
  • Save anonymous/4411509 to your computer and use it in GitHub Desktop.
Save anonymous/4411509 to your computer and use it in GitHub Desktop.
;Add ~/.emacs.d/lisp to load-path
(add-to-list 'load-path "/usr/share/emacs/24.1.50/lisp")
(add-to-list 'load-path "~/.emacs.d/lisp")
;;====================================================================================
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
;;====================================================================================
;;Setup color theme
(require 'color-theme)
(color-theme-initialize)
;; test for each frame or console
(defun color-theme-for-win-sys (frame)
(let ((color-theme-is-global nil))
(select-frame frame)
(when (window-system frame)
(color-theme-sanityinc-solarized-dark))))
;; hook on after-make-frame-functions
(add-hook 'after-make-frame-functions 'color-theme-for-win-sys)
;; Start up the color theme in this initial frame.
(let ((color-theme-is-global nil))
(when (window-system)
(color-theme-sanityinc-solarized-dark)))
;;====================================================================================
;;Setup sr-speedbar binding
(load-library "sr-speedbar")
(global-set-key (kbd "<f11>") 'sr-speedbar-toggle)
(setq speedbar-show-unknown-files t)
(setq speedbar-use-images nil)
(setq sr-speedbar-right-side nil)
;;====================================================================================
;;Setup php-mode-autoload
(load-library "php-mode")
(load-library "php-mode-autoloads")
;;====================================================================================
;;Setup scala-mode-auto
(require 'scala-mode-auto)
;;====================================================================================
;;Setup gpicker
(require 'gpicker)
(global-set-key (kbd "C-x C-g p") 'gpicker-visit-project)
(global-set-key (kbd "M-g") 'gpicker-find-file)
(global-set-key (kbd "C-x g") 'gpicker-find-file-other-window)
;;====================================================================================
;;Setup geben
(autoload 'geben "geben" "PHP Debugger on Emacs" t)
;;====================================================================================
;;Setup buffer menu+
(require 'buff-menu+)
(global-set-key (kbd "<menu>") 'buffer-menu)
;;====================================================================================
;;Setup auto complete
(load-library "auto-complete-config")
(ac-config-default)
;;====================================================================================
;;Setup php-doc
(require 'php-doc nil t)
(setq php-doc-directory "~/.emacs.d/php-chunked-xhtml")
(add-hook 'php-mode-hook
(lambda ()
(local-set-key "\t" 'php-doc-complete-function)
(local-set-key (kbd "\C-c h") 'php-doc)
(set (make-local-variable 'eldoc-documentation-function)
'php-doc-eldoc-function)
(eldoc-mode 1)))
;;====================================================================================
;;Setup Moz minor mode, just for fun :D
(autoload 'moz-minor-mode "moz" "Mozilla Minor and Inferior Mozilla Modes" t)
;;====================================================================================
;;Setup Rainbow mode css (kinda liked it)
(require 'rainbow-mode)
;; CSS and Rainbow modes
(defun all-css-modes() (css-mode) (rainbow-mode))
;; Load both major and minor modes in one call based on file type
(add-to-list 'auto-mode-alist '("\\.css$" . all-css-modes))
;;====================================================================================
;;Setup mustache mode
(add-to-list 'auto-mode-alist '("\\.mustache$" . mustache-mode))
;;====================================================================================
;;Setup flymake-phpcs
(require 'flymake-phpcs)
(setq flymake-phpcs-command "~/.emacs.d/bin/flymake_phpcs")
;; Show the name of sniffs in warnings (eg show
;; "Generic.CodeAnalysis.VariableAnalysis.UnusedVariable" in an unused
;; variable warning)
(setq flymake-phpcs-show-rule t)
(setq flymake-phpcs-standard "Xamin")
;(add-hook 'php-mode-hook 'flymake-mode-on)
;;====================================================================================
;;Setup smarttab -I prefer this over smart-tab, not in marmalade
(add-to-list 'load-path "~/.emacs.d/lisp/smarttabs")
(require 'smarttabs)
(autoload 'smart-tabs-mode "smart-tabs-mode"
"Intelligently indent with tabs, align with spaces!")
(autoload 'smart-tabs-mode-enable "smart-tabs-mode")
(autoload 'smart-tabs-advice "smart-tabs-mode")
;; PHP
(add-hook 'php-mode-hook 'smart-tabs-mode-enable)
(smart-tabs-advice c-indent-line c-basic-offset)
(smart-tabs-advice c-indent-region c-basic-offset)
;; Fuck, just force tab with C-Tab
(global-set-key (kbd "<C-tab>") 'c-indent-line-or-region)
;;====================================================================================
(require 'js2-mode-autoloads)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
;;====================================================================================
;;Setup tab bar
;(setq tabbar-ruler-global-tabbar 't)
;(setq tabbar-ruler-global-ruler 't)
;(setq tabbar-ruler-popup-menu 't)
;(setq tabbar-ruler-popup-toolbar 't)
(require 'tabbar)
(tabbar-mode)
;;====================================================================================
;; Setup multi webmode
(add-to-list 'load-path "~/.emacs.d/lisp/multi-web-mode")
(require 'multi-web-mode)
(setq mweb-default-major-mode 'html-mode)
(setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
(js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
(css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
(setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
(add-hook 'php-mode-hook (lambda () (mweb-set-default-major-mode 'php-mode)))
(multi-web-global-mode 1)
;;====================================================================================
;; Browse kill ring
(require 'browse-kill-ring)
(browse-kill-ring-default-keybindings)
;;====================================================================================
;; ampc
(autoload 'ampc "ampc" nil t)
(global-set-key (kbd "<f9>") (lambda () (interactive) (ampc "localhost" "6600")))
;;====================================================================================
;; Yasnippet
(setq yas-snippet-dirs
'("~/.emacs.d/snippets" ;; personal snippets
"~/.emacs.d/yasnippet-php-mode" ;; the default collection
))
(yas-global-mode 1) ;; or M-x yas-reload-all if you've started YASnippet already.
;;====================================================================================
;;My clipboard hack for C-z C-v , C-z C-c for X clipboard
(load-file "~/.emacs.d/lisp/clipboard.el")
;;====================================================================================
;; no easy keys
;(require 'no-easy-keys) (no-easy-keys 1)
;;====================================================================================
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode 1)
;;====================================================================================
;;Setup flex-autopair
(require 'flex-autopair) (flex-autopair-mode 1)
;;====================================================================================
;; Expand region (increases selected region by semantic units)
(global-set-key (kbd "C-'") 'er/expand-region)
;;====================================================================================
;;I think C-backspace should delete, rather than kill. Here code for .emacs
(defun my-backward-delete-word (arg) (interactive "p") (let ((kill-ring)) (kill-word (- arg))))
(global-set-key (kbd "C-<backspace>") 'my-backward-delete-word)
;;====================================================================================
;; someday might want to rotate windows if more than 2 of them
(defun swap-windows ()
"If you have 2 windows, it swaps them." (interactive) (cond ((not (= (count-windows) 2)) (message "You need exactly 2 windows to do this."))
(t
(let* ((w1 (first (window-list)))
(w2 (second (window-list)))
(b1 (window-buffer w1))
(b2 (window-buffer w2))
(s1 (window-start w1))
(s2 (window-start w2)))
(set-window-buffer w1 b2)
(set-window-buffer w2 b1)
(set-window-start w1 s2)
(set-window-start w2 s1)))))
;;====================================================================================
;; Never understood why Emacs doesn't have this function, either.
;;
(defun move-buffer-file (dir)
"Moves both current buffer and file it's visiting to DIR." (interactive "DNew directory: ")
(let* ((name (buffer-name))
(filename (buffer-file-name))
(dir
(if (string-match dir "\\(?:/\\|\\\\)$")
(substring dir 0 -1) dir))
(newname (concat dir "/" name)))
(if (not filename)
(message "Buffer '%s' is not visiting a file!" name)
(progn (copy-file filename newname 1) (delete-file filename) (set-visited-file-name newname) (set-buffer-modified-p nil) t))))
;;====================================================================================
;; source: http://steve.yegge.googlepages.com/my-dot-emacs-file
(defun rename-file-and-buffer (new-name)
"Renames both current buffer and file it's visiting to NEW-NAME."
(interactive "sNew name: ")
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not filename)
(message "Buffer '%s' is not visiting a file!" name)
(if (get-buffer new-name)
(message "A buffer named '%s' already exists!" new-name)
(progn
(rename-file name new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil))))))
;;====================================================================================
;; Js hint
(defun jshint ()
(interactive)
(shell-command (concat "jshint " buffer-file-name))
)
;;====================================================================================
;; PHPCS
(defun phpcs ()
(interactive)
(shell-command (concat "phpcs --standard=xamin --report=emacs " buffer-file-name))
)
;;====================================================================================
(defun put-file-name-on-clipboard ()
"Put the current file name on the clipboard"
(interactive)
(let ((filename (if (equal major-mode 'dired-mode)
default-directory
(buffer-file-name))))
(when filename
(with-temp-buffer
(insert filename)
(clipboard-kill-region (point-min) (point-max)))
(message filename))))
;;====================================================================================
(defun kill-other-buffers ()
"Kill all other buffers."
(interactive)
(mapc 'kill-buffer
(delq (current-buffer)
(remove-if-not 'buffer-file-name (buffer-list)))))
;;====================================================================================
; Delete trailing whitespace on save
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; untabify some modes
(setq alexott/untabify-modes '(php-mode js2-mode python-mode))
(defun alexott/untabify-hook ()
(when (member major-mode alexott/untabify-modes)
(untabify (point-min) (point-max))))
(add-hook 'before-save-hook 'alexott/untabify-hook)
;;====================================================================================
;; Misc key bindings
;;
;; Key chord mode to allow some str
(key-chord-mode 1)
(key-chord-define-global ",." "<>\C-b")
(key-chord-define-global "hj" 'undo)
(key-chord-define-global "cv" 'reindent-then-newline-and-indent)
(key-chord-define-global "4r" "$")
(key-chord-define-global ",," 'indent-for-comment)
(key-chord-define-global ";;" "\C-e;")
(global-unset-key (kbd "M-t")) ;; which used to be transpose-words
(global-set-key (kbd "M-t l") 'transpose-lines)
(global-set-key (kbd "M-t w") 'transpose-words)
(global-set-key (kbd "M-t s") 'transpose-sexps)
(global-set-key (kbd "M-t p") 'transpose-params)
;; iy-go-to-char - like f in Vim
(global-set-key (kbd "M-m") 'iy-go-to-char)
;; Comment/uncomment block
(global-set-key (kbd "C-c c") 'comment-or-uncomment-region)
(global-set-key (kbd "C-c u") 'uncomment-region)
;; Remap old M-m to M-i (better mnemonic for back-to-indentation)
;; We lose tab-to-tab-stop, which is no big loss in my use cases.
(global-set-key (kbd "M-i") 'back-to-indentation)
;; Clever newlines
(global-set-key (kbd "<C-return>") 'new-line-below)
(global-set-key (kbd "<C-S-return>") 'new-line-above)
(global-set-key (kbd "<M-return>") 'new-line-in-between)
;; Duplicate region
(global-set-key (kbd "C-c d") 'duplicate-current-line-or-region)
(global-set-key (kbd "C-S-<next>") 'move-line-down)
(global-set-key (kbd "C-S-<prior>") 'move-line-up)
(global-set-key (kbd "<f3>") 'bury-buffer)
(global-set-key (kbd "C-c s") 'toggle-scroll-bar)
(defun yank-pop-forwards (arg)
(interactive "p")
(yank-pop (- arg)))
(global-set-key "\M-Y" 'yank-pop-forwards) ; M-Y (Meta-Shift-Y)
(global-set-key (kbd "C-`") 'delete-window)
(global-set-key (kbd "C-1") 'delete-other-windows)
(global-set-key (kbd "C-<escape>") 'kill-buffer)
(define-key global-map [f8] 'bookmark-jump)
(define-key global-map [f7] 'bookmark-set)
(define-key global-map [f6] 'comment-region)
;New key bindings, C n for new empty document
;(global-set-key (kbd "C-n") 'new-empty-buffer) ; Open New File
(defun new-empty-buffer ()
"Opens a new empty buffer."
(interactive)
(let ((buf (generate-new-buffer "untitled")))
(switch-to-buffer buf)
(funcall (and initial-major-mode))
(setq buffer-offer-save t)))
(global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally)
(global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally)
(global-set-key (kbd "S-C-<down>") 'shrink-window)
(global-set-key (kbd "S-C-<up>") 'enlarge-window)
(global-set-key [M-left] 'windmove-left) ; move to left windnow
(global-set-key [M-right] 'windmove-right) ; move to right window
(global-set-key [M-up] 'windmove-up) ; move to upper window
(global-set-key [M-down] 'windmove-down) ; move to downer window
(global-set-key "\C-l" 'goto-line)
(fset 'yes-or-no-p 'y-or-n-p)
;;====================================================================================
(set-face-attribute 'default nil :family "Inconsolata" :height 125)
(set-fontset-font
"fontset-default"
(cons (decode-char 'ucs #x0600) (decode-char 'ucs #x06ff)) ; arabic
"DejaVu Sans Mono")
;;Customize variable by emacs :D
;; note: emacs won't offer to save a buffer that's
;; not associated with a file,
;; even if buffer-modified-p is true.
;; One work around is to define your own my-kill-buffer function
;; that wraps around kill-buffer, and check on the buffer modification
;; status to offer save
;; This custome kill buffer is close-current-buffer.
(setq-default bidi-display-reordering t)
;EMACS SETTINGS
(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.
'(auto-save-default nil)
'(c-default-style "linux")
'(column-number-mode t)
'(custom-safe-themes (quote ("1e7e097ec8cb1f8c3a912d7e1e0331caeed49fef6cff220be63bd2a6ba4cc365" default)))
'(delete-selection-mode t)
'(global-linum-mode t)
'(inhibit-startup-screen t)
'(make-backup-files nil)
'(menu-bar-mode nil)
'(php-mode-force-pear t)
'(scroll-bar-mode (quote right))
'(tab-always-indent nil)
'(tab-width 4)
'(tool-bar-mode nil)
'(x-select-enable-clipboard 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.
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment