Skip to content

Instantly share code, notes, and snippets.

@bruinfish
Last active July 22, 2016 21:04
Show Gist options
  • Save bruinfish/931976e6066a2ea24fe2 to your computer and use it in GitHub Desktop.
Save bruinfish/931976e6066a2ea24fe2 to your computer and use it in GitHub Desktop.
.emacs
;; Make sure history of command and files is remembered
(savehist-mode t)
;; Disable backup files
(setq make-backup-files nil)
;; Add `~/.emacs.d' to search path
(add-to-list 'load-path "~/.emacs.d/lisp")
;; Configure ELPA package repositories
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")
("orgmode" . "http://orgmode.org/elpa/")))
(setq package-enable-at-startup nil)
(package-initialize)
;; Remove welcome window
(setq-default inhibit-startup-screen t)
;; Compiling tex documents to PDF by default
(setq TeX-PDF-mode t)
;; Turn off tool bar
(tool-bar-mode -1)
;; Symbol highlighting
;; For Aquamacs, download the highlight-symbol.el file into ~/Library/Application Support/Aquamacs Emacs/
(require 'highlight-symbol)
(defun move-and-highlight-symbol-at-point(event)
"Change cursor position and highlight symbol at point"
(interactive "e")
(mouse-set-point event)
(highlight-symbol-at-point))
(global-set-key [(mouse-4)] 'move-and-highlight-symbol-at-point)
;; Line numbers
(global-linum-mode 1)
;; Disable tabs
(setq-default indent-tabs-mode nil)
;; Highlilght whitespace
(require 'whitespace)
(setq whitespace-style '(face empty tabs lines-tail trailing))
(setq whitespace-line-column 100)
;; Line commenting
;; Original idea from
;; http://www.opensubscriber.com/message/emacs-devel@gnu.org/10971693.html
(defun comment-dwim-line (&optional arg)
"Replacement for the comment-dwim command.
If no region is selected and current line is not blank, then comment current line.
Replaces default behaviour of comment-dwim, when it inserts comment at the end of the line."
(interactive "*P")
(comment-normalize-vars)
(if (not (region-active-p))
(comment-or-uncomment-region (line-beginning-position) (line-end-position))
(comment-dwim arg))
(setq deactivate-mark nil))
(global-set-key "\M-;" 'comment-dwim-line) ;; compatible to terminal emacs
(global-set-key (kbd "A-/") 'comment-dwim-line) ;; for aquamacs
;; Hacking GNU c/c++ style
;; After trying my ass off, this is the only solution to add
;; "innamespace -" after local variables (style) is applied to a file
(c-add-style "gnu"
'(
(c-basic-offset . 2)
(c-comment-only-line-offset 0 . 0)
(c-hanging-braces-alist
(substatement-open before after)
(arglist-cont-nonempty))
(c-offsets-alist
(innamespace . -)
(statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . +)
(substatement-label . 0)
(label . 0)
(statement-case-open . +)
(statement-cont . +)
(arglist-intro . c-lineup-arglist-intro-after-paren)
(arglist-close . c-lineup-arglist)
(inline-open . 0)
(brace-list-open . +)
(topmost-intro-cont first c-lineup-topmost-intro-cont c-lineup-gnu-DEFUN-intro-cont))
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . "")
)
)
;; Spell checking
(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
(defun my-text-mode-hook()
(turn-on-flyspell)
(set-word-wrap)
(setq word-wrap t)
(auto-fill-mode -1)
)
(add-hook 'text-mode-hook 'my-text-mode-hook)
(add-hook 'TeX-mode-hook 'my-text-mode-hook)
(add-hook 'rst-mode-hook 'my-text-mode-hook)
(add-hook 'markdown-mode-hook 'my-text-mode-hook)
(add-hook 'change-log-mode-hook (lambda ()
(flyspell-mode -1)
))
(add-hook 'c-mode-common-hook (lambda ()
(flyspell-prog-mode)
(c-set-style "gnu")
(local-set-key (kbd "RET") 'newline-and-indent)
(setq comment-start "//" comment-end "")
(setq-default indent-tabs-mode nil)
(whitespace-mode)
;; (doxymacs-mode)
(add-to-list 'write-file-functions 'delete-trailing-whitespace)
))
;; Smex
(require 'smex) ; Not needed if you use package.el
(smex-initialize) ; Can be omitted. This might cause a (minimal) delay
; when Smex is auto-initialized on its first run.
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; This is your old M-x.
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
(require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t)
(require 'ido-vertical-mode)
(ido-vertical-mode t)
;; cedet
(semantic-mode 1)
(global-ede-mode 1)
;; load eassist
(require 'eassist)
;; to allow switching between source and headers
(add-hook 'c-mode-common-hook
(lambda()
(local-set-key (kbd "C-c o") 'eassist-switch-h-cpp)
(local-set-key (kbd "M-o") 'eassist-switch-h-cpp)
(local-set-key (kbd "M-m") 'eassist-list-methods)))
(defun my-cedet-hook ()
(local-set-key [(M return)] 'semantic-complete-analyze-inline)
;; (local-set-key [(M return)] 'semantic-ia-complete-symbol-menu)
;; (local-set-key "\C-c?" 'semantic-ia-complete-symbol-menu)
;; (local-set-key "\C-c>" 'semantic-complete-analyze-inline)
;; (local-set-key "\C-cp" 'semantic-analyze-proto-impl-toggle)
(local-set-key [(S-mouse-2)] 'semantic-ia-fast-jump))
(add-hook 'c-mode-common-hook 'my-cedet-hook)
(global-set-key "\C-c,s" 'semantic-speedbar-analysis)
(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.
'(ecb-options-version "2.40")
'(tool-bar-mode 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.
'(default ((t (:inherit nil :stipple nil :background "White" :foreground "Black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 140 :width normal :foundry "nil" :family "Menlo"))))
'(linum ((t (:inherit (shadow default) :background "gray85" :height 0.7)))))
;; (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.
;; '(gud-gdb-command-name "gdb --annotate=1")
;; '(large-file-warning-threshold nil)
;; '(safe-local-variable-values (quote ((py-indent-offset . 4)))))
;; (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.
;; )
;; Define goto-line short cut
(global-set-key "\M-g" 'goto-line)
;; set javascript indent
(setq js-indent-level 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment