Skip to content

Instantly share code, notes, and snippets.

@ptrv
Last active December 2, 2016 00:06
Show Gist options
  • Save ptrv/80170814e6ed44655b0793fab118bf7d to your computer and use it in GitHub Desktop.
Save ptrv/80170814e6ed44655b0793fab118bf7d to your computer and use it in GitHub Desktop.
Starter Emacs init file
(require 'cl)
(unless (fboundp 'helm-mode)
(ido-mode t)
(setq ido-enable-flex-matching t))
(menu-bar-mode -1)
(when (fboundp 'tool-bar-mode)
(tool-bar-mode -1))
(when (fboundp 'scroll-bar-mode)
(scroll-bar-mode -1))
(when (fboundp 'horizontal-scroll-bar-mode)
(horizontal-scroll-bar-mode -1))
(autoload 'zap-up-to-char "misc"
"Kill up to, but not including ARGth occurrence of CHAR." t)
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
(require 'saveplace)
(if (fboundp 'save-place-mode)
(save-place-mode 1)
(setq-default save-place t))
(global-set-key (kbd "M-/") 'hippie-expand)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "M-z") 'zap-up-to-char)
;; (global-set-key (kbd "C-s") 'isearch-forward-regexp)
;; (global-set-key (kbd "C-r") 'isearch-backward-regexp)
;; (global-set-key (kbd "C-M-s") 'isearch-forward)
;; (global-set-key (kbd "C-M-r") 'isearch-backward)
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-saved-items 200
recentf-auto-cleanup 300
recentf-exclude (list "/\\.git/.*\\'" ; Git contents
"/elpa/.*\\'" ; Package files
"/itsalltext/" ; It's all text temp files
".*\\.gz\\'"
"TAGS"
".*-autoloads\\.el\\'"
"ido.last"))
(global-set-key (kbd "C-x f") 'recentf-ido-find-file)
(defun recentf-ido-find-file ()
"Find a recent file using Ido."
(interactive)
(let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
(when file
(find-file file))))
(show-paren-mode 1)
(setq-default indent-tabs-mode nil)
(setq x-select-enable-clipboard t
x-select-enable-primary t
save-interprogram-paste-before-kill t
apropos-do-all t
mouse-yank-at-point t
require-final-newline t
visible-bell t
load-prefer-newer t
ediff-window-setup-function 'ediff-setup-windows-plain
save-place-file (concat user-emacs-directory "places")
backup-directory-alist `(("." . ,(concat user-emacs-directory
"backups"))))
;; disabled commands
(setq disabled-command-function nil)
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(defvar my-packages '(paredit idle-highlight-mode ido-ubiquitous
projectile magit smex lua-mode ycmd
company company-ycmd flycheck
flycheck-ycmd undo-tree company
yasnippet zenburn-theme markdown-mode
multiple-cursors expand-region))
(package-initialize)
(defun my-packages-installed-p ()
(cl-loop for p in my-packages
when (not (package-installed-p p)) do (return nil)
finally (return t)))
(unless (my-packages-installed-p)
;; check for new packages (package versions)
(message "%s" "refreshing package database...")
(package-refresh-contents)
(message "%s" " done.")
;; install the missing packages
(dolist (p my-packages)
(when (not (package-installed-p p))
(package-install p))))
;; Always ask for y/n keypress instead of typing out 'yes' or 'no'
(defalias 'yes-or-no-p 'y-or-n-p)
;; Theme
(load-theme 'zenburn t)
;; Project management
(require 'projectile)
(add-hook 'after-init-hook #'projectile-mode)
;; Magit
(global-set-key (kbd "C-x g") 'magit-status)
;; Smex is a M-x enhancement for Emacs
(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)
;; Lua
(with-eval-after-load 'lua-mode
(setq lua-indent-level 4)) ;; default is 3!?!
;; undo-tree
(add-hook 'after-init-hook #'global-undo-tree-mode)
;; syntax checking
(add-hook 'after-init-hook #'global-flycheck-mode)
;; completion
(add-hook 'after-init-hook #'global-company-mode)
;; documentatoin in minibuffer
(add-hook 'after-init-hook #'global-eldoc-mode)
;; C++
;; ycmd
(require 'ycmd)
(add-hook 'c++-mode-hook 'ycmd-mode)
(set-variable 'ycmd-server-command '("python" "/path/to/ycmd"))
(set-variable 'ycmd-global-config "/path/to/global_config.py")
(set-variable 'ycmd-extra-conf-whitelist '("~/my_projects/*"))
;; completion
(require 'company-ycmd)
(company-ycmd-setup)
;; syntax checking
(require 'flycheck-ycmd)
(flycheck-ycmd-setup)
;; snipptets
(yas-global-mode)
(put 'scroll-left 'disabled nil)
;; multiple-cursors
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
;; expand-region
(global-set-key (kbd "C-=") 'er/expand-region)
;; hippie-expand
(setq hippie-expand-try-functions-list
'(try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name-partially
try-complete-file-name
try-expand-all-abbrevs
try-expand-list
try-expand-line
try-complete-lisp-symbol-partially
try-complete-lisp-symbol))
;; paredit for emacs-lisp mode
(autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t)
(add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode)
(add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
(add-hook 'ielm-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
(add-hook 'scheme-mode-hook #'enable-paredit-mode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment