Skip to content

Instantly share code, notes, and snippets.

@juanfgs
Created August 12, 2015 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanfgs/5aaca59ac24dd87b67f4 to your computer and use it in GitHub Desktop.
Save juanfgs/5aaca59ac24dd87b67f4 to your computer and use it in GitHub Desktop.
;; Global Include
(add-to-list 'load-path ".../git/contrib/emacs")
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp"))
;; Theme & Appearance
;;(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/emacs-deviant-theme")
;;(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/emacs-colors-solarized")
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/smyx-master")
(set-face-attribute 'default nil :height 108) ;; font size
(defun enable-custom-theme ()
(load-theme 'smyx t)
(enable-theme 'smyx))
(if (display-graphic-p)
(enable-custom-theme))
;; Remove toolbar and menubar
(tool-bar-mode -1)
;; Line number mode
(global-linum-mode 1)
;; Visible bell
(setq visible-bell t)
;; No startup screen
(setq inhibit-startup-screen t)
;; Highlight line on all modes
(global-hl-line-mode t)
(autoload 'ibuffer "ibuffer" "List buffers." t)
;; PACKAGE MANAGEMENT
;; Add melpa and Marmalade repos
(when (>= emacs-major-version 24)
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
)
;; Bindings
;; use IBuffers instead of regular buffers
(global-set-key (kbd "C-x C-b") 'ibuffer)
;; Window Movement Bindings
;; Requires
(require 'windata)
(global-set-key (kbd "C-x K") 'nuke-all-buffers)
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)
(global-set-key [f8] 'sr-speedbar-toggle)
;; Major Modes
(add-hook 'after-init-hook 'global-company-mode) ;; Enable company for all modes
;; Requires
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp")) ;; Misc
(require 'magit)
(require 'sr-speedbar)
;; PHP
(require 'multi-web-mode)
;;Go
(add-to-list 'load-path "~/Go/src/github.com/dougm/goflymake")
(require 'go-flymake)
;; PHP Multiple Major Modes
(setq php-manual-path "~/Documents/phpdocs/")
(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"))
(multi-web-global-mode 1)
(autoload 'php-mode "php-mode" "Major mode for editing php code." t)
(add-to-list 'auto-mode-alist '("\\.php$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.inc$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.erb$" . nxml-mode))
(add-to-list 'auto-mode-alist '("\\.tpl$" . nxml-mode))
;; Speedbar configuration
(make-face 'speedbar-face)
(set-face-font 'speedbar-face "Inconsolata-9")
(setq sr-speedbar-right-side nil)
(setq sr-speedbar-max-width 10)
(setq sr-speedbar-width-x 10 )
(setq sr-speedbar-skip-other-window-p t)
(setq speedbar-mode-hook '(lambda ()
(buffer-face-set 'speedbar-face)
(speedbar-add-supported-extension ".go")
(speedbar-add-supported-extension ".sql")
(speedbar-add-supported-extension ".php")
(speedbar-add-supported-extension ".css")
(speedbar-add-supported-extension ".html")
(speedbar-add-supported-extension ".rb")
(speedbar-add-supported-extension ".erb")
(speedbar-add-supported-extension ".tpl")
(add-hook 'php-mode-user-hook 'semantic-default-java-setup)
(add-hook 'php-mode-user-hook
(lambda ()
(setq imenu-create-index-function
'semantic-create-imenu-index)
))
))
;; Go Specific
(add-hook
'go-mode-hook
'(lambda ()
;; gocode
;; Imenu & Speedbar
(setq imenu-generic-expression
'(("type" "^type *\\([^ \t\n\r\f]*\\)" 1)
("func" "^func *\\(.*\\) {" 1)))
(imenu-add-to-menubar "Index")
;; Outline mode
(make-local-variable 'outline-regexp)
(setq outline-regexp "//\\.\\|//[^\r\n\f][^\r\n\f]\\|pack\\|func\\|impo\\|cons\\|var.\\|type\\|\t\t*....")
(outline-minor-mode 1)
(local-set-key "\M-a" 'outline-previous-visible-heading)
(local-set-key "\M-e" 'outline-next-visible-heading)
;; Menu bar
(require 'easymenu)
(defconst go-hooked-menu
'("Go tools"
["Go run buffer" go t]
["Go reformat buffer" go-fmt-buffer t]
["Go check buffer" go-fix-buffer t]))
(easy-menu-define
go-added-menu
(current-local-map)
"Go tools"
go-hooked-menu)
;; Other
(setq show-trailing-whitespace t)
))
;; Custom Functions
;; Nuke all other buffers
(defun nuke-all-buffers ()
(interactive)
(mapcar 'kill-buffer (buffer-list))
(delete-other-windows))
;; Custom set variables
(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.
'(c-basic-offset 4)
'(company-backends
(quote
(php-extras-company company-go company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-ropemacs company-cmake company-capf
(company-dabbrev-code company-gtags company-etags company-keywords)
company-oddmuse company-files company-dabbrev)))
'(frame-background-mode (quote dark))
'(package-archives
(quote
(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/"))))
'(php-manual-path "~/Documentos/phpdocs/")
'(sr-speedbar-auto-refresh nil))
;; Indentation
(require 'highlight-indentation)
;; PHP mode code styles
(add-hook 'php-mode-hook 'my-php-mode-hook)
(add-hook 'html-mode-hook 'my-xml-mode-hook)
(defun my-php-mode-hook ()
(setq indent-tabs-mode nil)
(setq show-paren-mode t)
(let ((my-tab-width 4))
(setq tab-width my-tab-width)
(setq c-basic-indent my-tab-width)
(set (make-local-variable 'tab-stop-list)
(number-sequence my-tab-width 200 my-tab-width))))
(defun my-xml-mode-hook ()
(setq indent-tabs-mode nil)
(let ((my-tab-width 4))
(setq tab-width my-tab-width)
(setq sgml-basic-offset my-tab-width)
(set (make-local-variable 'tab-stop-list)
(number-sequence my-tab-width 200 my-tab-width))))
;; XDebug
(autoload 'geben "geben" "DBGp protocol frontend, a script debugger" t)
;; Debug a simple PHP script.
;; Change the session key my-php-54 to any session key text you like
(defun my-php-debug ()
"Run current PHP script for debugging with geben"
(interactive)
(call-interactively 'geben)
(shell-command
(concat "XDEBUG_CONFIG='idekey=my-php-54' /usr/bin/env php "
(buffer-file-name) " &"))
)
(global-set-key [f5] 'my-php-debug)
;; Fix indentation for function arguments
(defun my-indent-setup ()
(c-set-offset 'arglist-intro '+))
(add-hook 'php-mode-hook 'my-indent-setup)
;; Ctags configuration
(setq path-to-ctags "/usr/bin/ctags")
(defun create-tags (dir-name)
"Create tags file."
(interactive "DDirectory: ")
(shell-command
(format "ctags -f %s -e -R %s" path-to-ctags (directory-file-name dir-name)))
)
(defadvice find-tag (around refresh-etags activate)
"Rerun etags and reload tags if tag not found and redo find-tag.
If buffer is modified, ask about save before running etags."
(let ((extension (file-name-extension (buffer-file-name))))
(condition-case err
ad-do-it
(error (and (buffer-modified-p)
(not (ding))
(y-or-n-p "Buffer is modified, save it? ")
(save-buffer))
(er-refresh-etags extension)
ad-do-it))))
(defun er-refresh-etags (&optional extension)
"Run etags on all peer files in current dir and reload them silently."
(interactive)
(shell-command (format "etags *.%s" (or extension "el")))
(let ((tags-revert-without-query t)) ; don't query, revert silently
(visit-tags-table default-directory 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.
'(font-lock-warning-face ((t (:background "gray3" :foreground "magenta")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment