Skip to content

Instantly share code, notes, and snippets.

@tastycode
Created September 30, 2015 17:58
Show Gist options
  • Save tastycode/535d9e414039afae43ec to your computer and use it in GitHub Desktop.
Save tastycode/535d9e414039afae43ec to your computer and use it in GitHub Desktop.
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
(when (>= emacs-major-version 24)
(require 'package)
(add-to-list
'package-archives
'("melpa" . "http://melpa.org/packages/")
t)
(package-initialize))
(evil-mode t)
(global-evil-tabs-mode t)
(elscreen-set-prefix-key "\C-z")
(setq helm-quick-update t)
(setq helm-bookmark-show-location t)
(setq helm-buffers-fuzzy-matching t)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "M-g") 'helm-git-grep)
(global-set-key (kbd "M-G") 'helm-git-grep-at-point)
(global-set-key (kbd "M-p") 'helm-projectile)
;;; C-c as general purpose escape key sequence.
;;;
(defun my-esc (prompt)
"Functionality for escaping generally. Includes exiting Evil insert state and C-g binding. "
(cond
;; If we're in one of the Evil states that defines [escape] key, return [escape] so as
;; Key Lookup will use it.
((or (evil-insert-state-p) (evil-normal-state-p) (evil-replace-state-p) (evil-visual-state-p)) [escape])
;; This is the best way I could infer for now to have C-c work during evil-read-key.
;; Note: As long as I return [escape] in normal-state, I don't need this.
;;((eq overriding-terminal-local-map evil-read-key-map) (keyboard-quit) (kbd ""))
(t (kbd "C-g"))))
(define-key key-translation-map (kbd "C-c") 'my-esc)
;; Works around the fact that Evil uses read-event directly when in operator state, which
;; doesn't use the key-translation-map.
(define-key evil-operator-state-map (kbd "C-c") 'keyboard-quit)
(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.
'(custom-safe-themes
(quote
("08851585c86abcf44bb1232bced2ae13bc9f6323aeda71adfa3791d6e7fea2b6" default))))
(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.
)
(setq ruby-indent-level 2)
(setq indent-tabs-mode nil)
(defun how-many-region (begin end regexp &optional interactive)
"Print number of non-trivial matches for REGEXP in region.
Non-interactive arguments are Begin End Regexp"
(interactive "r\nsHow many matches for (regexp): \np")
(let ((count 0) opoint)
(save-excursion
(setq end (or end (point-max)))
(goto-char (or begin (point)))
(while (and (< (setq opoint (point)) end)
(re-search-forward regexp end t))
(if (= opoint (point))
(forward-char 1)
(setq count (1+ count))))
(if interactive (message "%d occurrences" count))
count)))
(defun infer-indentation-style ()
;; if our source file uses tabs, we use tabs, if spaces spaces, and if
;; neither, we use the current indent-tabs-mode
(let ((space-count (how-many-region (point-min) (point-max) "^ "))
(tab-count (how-many-region (point-min) (point-max) "^\t")))
(if (> space-count tab-count) (setq indent-tabs-mode nil))
(if (> tab-count space-count) (setq indent-tabs-mode t))))
(infer-indentation-style)
(load-theme 'molokai)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment