Skip to content

Instantly share code, notes, and snippets.

@johnfredcee
Created July 13, 2014 14:35
Show Gist options
  • Select an option

  • Save johnfredcee/d8d6463585d802f9afd1 to your computer and use it in GitHub Desktop.

Select an option

Save johnfredcee/d8d6463585d802f9afd1 to your computer and use it in GitHub Desktop.
Dot emacs with el-get
;; Ensure unix binaries on path
(setenv "PATH" (concat "C:\\wsr\\apps\\Git\\bin" path-separator "C:\\wsr\\apps\\emacs-24.3\\bin" path-separator (getenv "PATH")))
;;; basic load-path setup
;;; ------------------------------------------------------------------
(defun add-subdirs-to-load-path (dir)
(let ((default-directory (concat dir "/")))
(normal-top-level-add-subdirs-to-load-path)))
(setq wsr-site-lisp-dir (convert-standard-filename (expand-file-name "/wsr/apps/site-lisp")))
(add-to-list 'load-path wsr-site-lisp-dir)
(add-subdirs-to-load-path wsr-site-lisp-dir)
(setq find-program "C:\\wsr\\apps\\Git\\bin\\find.exe")
(setq grep-program "C:\\wsr\\apps\\Git\\bin\\grep.exe")
;; el - get
(add-to-list 'load-path "~/.emacs.d/el-get/el-get")
(unless (require 'el-get nil 'noerror)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.github.com/dimitri/el-get/master/el-get-install.el")
(goto-char (point-max))
(eval-print-last-sexp)))
(add-to-list 'el-get-recipe-path "~/.emacs.d/el-get-user/recipes")
(el-get 'sync)
(require 'eieio)
(require 'ibuffer)
(require 'savehist)
(require 'imenu)
(require 'windmove)
(require 'etags-select)
(require 'w32shell)
(require 'ido)
(require 'yasnippet)
(setq ido-enable-flex-matching t) ; fuzzy matching is a must have
(ido-mode t)
;; This tab override shouldn't be necessary given ido's default
;; configuration, but minibuffer-complete otherwise dominates the
;; tab binding because of my custom tab-completion-everywhere
;; configuration.
(add-hook 'ido-setup-hook
(lambda ()
(define-key ido-completion-map [tab] 'ido-complete)))
(require 'auto-complete)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/dict")
(require 'auto-complete-config)
(require 'auto-complete-etags)
(require 'multiple-cursors)
(global-linum-mode 1)
(savehist-mode 1)
(setq savehist-additional-variables '(extended-command-history kill-ring search-ring regexp-search-ring file-name-history compile-history grep-history shell-command-history))
(setq savehist-file "~/.emacs.d/savehist")
;; want to use capslock as a modifier
(setq w32-pass-lwindow-to-system nil) ;; want to use this as windmove modifier
(setq w32-lwindow-modifier nil)
(setq w32-recognize-altgr nil) ;; make altgr = ctrl + meta
(global-set-key [(meta kp-8)] 'windmove-up)
(global-set-key [(meta kp-4)] 'windmove-left)
(global-set-key [(meta kp-6)] 'windmove-right)
(global-set-key [(meta kp-2)] 'windmove-down)
(global-set-key [(meta kp-add)] 'hs-show-block)
(global-set-key [(control meta kp-add)] 'hs-show-all)
(global-set-key [(meta kp-subtract)] 'hs-hide-block)
(global-set-key [(control meta kp-subtract)] 'hs-hide-all)
(global-set-key [f12] 'ibuffer)
(global-set-key [(meta f12)] 'bookmark-bmenu-list)
(global-set-key [(meta f7)] 'compile)
(global-set-key [f7] 'recompile)
(global-set-key [(control f7)] 'compilation-minor-mode)
;; overload search on k3 (shift=backward, meta=regexp)
(global-set-key [(f3)] 'search-forward)
(global-set-key [(shift f3)] 'search-backward)
(global-set-key [(meta f3)] 'search-forward-regexp)
(global-set-key [(shift meta f3)] 'search-backward-regexp)
;; overload replacement on k4 (meta == regexp, control = query)
(global-set-key [(f4)] 'replace-string)
(global-set-key [(control f4)] 'query-replace)
(global-set-key [(meta f4)] 'replace-regexp)
(global-set-key [(control meta f4)] 'query-replace-regexp)
(global-set-key [(control meta f)] 'forward-sexp)
(global-set-key [(control meta b)] 'backward-sexp)
(global-set-key [(f8)] 'mc/mark-next-like-this)
(global-set-key [(shift f8)] 'mc/mark-previous-like-this)
(global-set-key [(meta f8)] 'mc/mark-all-like-this)
(global-set-key [(control meta f8)] 'mc/mark-more-like-this-extended)
(global-set-key [(control f8)] 'mc/mark-pop)
(ido-mode t)
(setq ido-enable-flex-matching t)
(winner-mode 1)
(savehist-mode 1)
(global-set-key "\M-." 'etags-select-find-tag)
(global-set-key "\M-," 'pop-tag-mark)
;; make the minibuffer a bit more demandingly visible
(add-hook 'minibuffer-setup-hook
(lambda ()
(ding)
(make-local-variable 'face-remapping-alist)
(add-to-list 'face-remapping-alist '(default (:background "green")))))
;; zap shouldn't be greedy -------------------------------------
(defun zap-upto-char (arg char)
"Kill up to but not including ARG'th occurrence of CHAR.
Case is ignored if `case-fold-search' is non-nil in the current buffer.
Goes backward if ARG is negative; error if CHAR not found."
(interactive "p\ncZap upto char: ")
(if (char-table-p translation-table-for-input)
(setq char (or (aref translation-table-for-input char) char)))
(kill-region (point)
(progn
(search-forward (char-to-string char) nil nil arg)
(if (minusp arg)
(forward-char 1)
(backward-char 1))
; (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
(point))))
(global-set-key [(meta z)] 'zap-upto-char)
(setq frame-title-format (concat invocation-name "@" system-name ": %b %+%+ %f"))
;; protect against accidental modificiation
(defun make-some-files-read-only ()
"when file opened is of a certain mode, make it read only"
(when (memq major-mode '(c++-mode python-mode c-mode actionscript-mode unrealscript-mode lisp-mode))
(toggle-read-only 1)))
(add-hook 'find-file-hook 'make-some-files-read-only)
;; assume filename is same as classname
(defun get-class-name ()
(file-name-nondirectory (file-name-sans-extension buffer-file-name)))
;; -- tagging should use ectags and be available from withih emacs --------------------
(defun tag-c++ ()
(interactive)
(shell-command
(concat
"dir /b /s *.cpp *.h *.cxx *.hpp *.hh | ctags --verbose -e -o TAGS --language-force=c++ --c++-kinds=cfnstunedm --extra=+q -L -"))
(visit-tags-table "TAGS"))
;; -- C/C++/Java ----------------------------------------------------------------------
(defun h-file-create ()
"Create a new h file. Insert a infdef/define/endif block"
(interactive)
(if (or (equal (substring (buffer-name (current-buffer)) -2 ) ".h")
(equal (substring (buffer-name (current-buffer)) -4 ) ".hpp"))
(if (equal "" (buffer-string))
(insert "#ifndef "(upcase (substring (buffer-name (current-buffer)) 0 -2)) "_H\n#define "
(upcase (substring (buffer-name (current-buffer)) 0 -2)) "_H\n\n#endif"))))
(defun forward-c-token ()
(interactive)
(c-forward-token-2 1))
(defun backward-c-token ()
(interactive)
(c-backward-token-2 1))
;; assume filename is same as classname
(defun get-class-name ()
(file-name-nondirectory (file-name-sans-extension buffer-file-name)))
;; insert it interactively
(defun insert-buffer-name ()
(interactive)
(insert (get-class-name)))
(add-hook 'c-mode-common-hook
'(lambda ()
(setq case-fold-search nil)
(c-set-offset 'substatement-open 0)
;; Do not check for old-style (K&R) function declarations;
;; this speeds up indenting a lot.
(setq c-recognize-knr-p nil)
(setq c-basic-offset 4)
(setq c-indent-level 4)
(setq c-tab-always-indent t)
(setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60))
(setq tab-width 4)
(setq indent-tabs-mode t) ; use spaces only if nil
(c-set-style "stroustrup")
(setq dabbrev-case-fold-search nil)
(setq dabbrev-case-replace nil)
(setq dabbrev-case-distinction nil)
(hs-minor-mode 1)
(h-file-create)
(setq-default ac-sources '(ac-source-dictionary ac-source-etags ac-source-words-in-same-mode-buffers))
(auto-complete-mode 1)
(local-set-key [(meta f)] 'forward-c-token)
(local-set-key [(meta b)] 'backward-c-token)
(local-set-key [(meta ?#)] 'insert-buffer-name)))
;; LUA ----------------------------------------------------------------------------
(autoload 'lua-mode "lua-mode" "Lua editing mode." t)
(add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))
(add-to-list 'interpreter-mode-alist '("lua" . lua-mode))
;; SLIME -------------------------------------------------------------------------
(load "/Users/john.connors/quicklisp/slime-helper.el")
;; Replace "sbcl" with the path to your implementation
(setq slime-lisp-implementations
'((sbcl ("c:\\wsr\\lisp\\sbcl\\sbcl.exe" "--userinit" "c:\\wsr\\lisp\\sbcl\\.sbclrc") :coding-system utf-8-unix)
(clozure ("c:\\wsr\\lisp\\ccl\\wx86cl.exe"))
(clozure64 ("c:\\wsr\\lisp\\ccl\\wx86cl64.exe"))))
;; EPROJECT ------------------------------------------------------------------------
(define-project-type bz (generic)
(look-for "Beelzebub")
:relevant-files ("\\.h$" "\\.cpp$" "\\.lua$" "\\.inl$"))
(define-project-type vs (generic)
(look-for "*.sln" :glob)
:relevant-files ("\\.h$" "\\.cpp$" "\\.lua$" "\\.inl$"))
; eproject global bindings
(defmacro .emacs-curry (function &rest args)
`(lambda () (interactive)
(,function ,@args)))
(defmacro .emacs-eproject-key (key command)
(cons 'progn
(loop for (k . p) in (list (cons key 4) (cons (upcase key) 1))
collect
`(global-set-key
(kbd ,(format "C-x p %s" k))
(.emacs-curry ,command ,p)))))
(.emacs-eproject-key "k" eproject-kill-project-buffers)
(.emacs-eproject-key "v" eproject-revisit-project)
(.emacs-eproject-key "b" eproject-ibuffer)
(.emacs-eproject-key "o" eproject-open-all-project-files)
;; BACKUPS ------------------------------------------------------------------------
(setq
backup-by-copying t ; don't clobber symlinks
backup-directory-alist
'(("." . "~/.saves")) ; don't litter my fs tree
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t) ; use versioned backups
(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.
'(ac-auto-start 4)
'(ansi-color-names-vector
["#242424" "#E5786D" "#95E454" "#CAE682" "#8AC6F2" "#333366" "#CCAA8F" "#F6F3E8"])
'(custom-enabled-themes (quote (light-blue)))
'(desktop-modes-not-to-save nil)
'(desktop-path (quote ("~/.emacs.d/" "~" ".")))
'(global-auto-complete-mode nil)
'(python-shell-interpreter "\\\\Python27\\\\python.exe")
'(tab-stop-list
(quote
(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120)))
'(tab-width 4)
'(tool-bar-mode nil)
'(vc-handled-backends nil)
'(visible-bell t)
'(w32shell-emacsw32-gnuwin32-bindir "\\\\wsr\\\\apps\\\\Git\\\\bin")
'(w32shell-shell (quote cmd))
'(w32shell-wanted-progs (quote ("grep" "find" "xargs" "patch"))))
(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 (:family "Consolas" :foundry "outline" :slant normal :weight normal :height 83 :width normal)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment