Skip to content

Instantly share code, notes, and snippets.

@timjstewart
Last active December 28, 2015 00:39
Show Gist options
  • Save timjstewart/7415086 to your computer and use it in GitHub Desktop.
Save timjstewart/7415086 to your computer and use it in GitHub Desktop.
My Emacs dotfile
;;;; Tim Stewart's Emacs dotfile
;;;; focused on Java/Scala development
;;; All that cool Emacs chrome? Get rid of it...
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
;;; Theme Setup
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
;;; Initialize the Emacs Package System
(package-initialize)
(setq package-archives
'(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")))
;;;; Global Key Bindings
(global-set-key "\C-x\C-b" 'buffer-menu)
(global-set-key "\C-x\C-r" 'recentf-open-files)
(global-set-key (kbd "<f1>") 'find-dot-file)
;;;; exec-path setup
(add-to-list 'exec-path "/home/tim/scripts")
(add-to-list 'exec-path "/home/tim/bin")
(add-to-list 'exec-path "/home/tim/bin/scala/bin")
(add-to-list 'exec-path "/home/tim/bin/maven/bin")
;;;; load-path setup
(add-to-list 'load-path "~/.emacs.d")
(add-to-list 'load-path "~/.emacs.d/scala-mode")
;;;; Enable Disabled Features
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
;;;; Editing
(server-start)
(require 'iedit)
(defalias 'yes-or-no-p 'y-or-n-p)
(show-paren-mode t)
(recentf-mode 1)
(ido-mode t) ; interactively do things
(setq column-number-mode t) ; to help with error messages
(setq default-abbrev-mode t)
(setq-default indent-tabs-mode nil)
(setq-default truncate-lines t)
(menu-bar-enable-clipboard)
(global-font-lock-mode 1)
(setq tab-width 4)
(set-fill-column 80)
(icomplete-mode t)
(setq x-select-enable-clipboard t)
(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
(delete-selection-mode +1) ;; When I have some text selected and I type
;; something, the something replaces the selection.
;;; Move between windows with the Meta and arrow keys
(require 'windmove)
(windmove-default-keybindings 'meta)
;;; Snippets
(require 'yasnippet)
(setq yas-snippet-dirs '("~/.emacs.d/snippets"))
(yas-global-mode 1)
;;; For some nice string functions
(require 's)
(defun find-file-or-prompt-create (file-name)
(if (file-exists-p file-name)
(find-file-other-window file-name)
(when (y-or-n-p (format "Would you like to create %s?" file-name))
(make-directory (file-name-directory file-name) t)
(find-file file-name))))
(defun toggle-test-and-prod-file ()
"Toggles between test and production source files assuming the
Maven directory structure and Test file name suffix"
(interactive)
(let ((file-name (buffer-file-name)))
(cond
((s-index-of "/src/main/" file-name)
(find-file-or-prompt-create (s-replace "/src/main/" "/src/test/"
(s-replace "." "Test." file-name))))
((s-index-of "/src/test/" file-name)
(find-file-or-prompt-create (s-replace "/src/test/" "/src/main/"
(s-replace "Test." "." file-name))))
(t (error "can't find alternate file")))))
(defconst +PACKAGE-REGEXP+
"/src/\\(main\\|test\\)/\\(scala\\|java\\)/\\(.*\\)/")
(defun current-package-name ()
"Returns the name of the current package (based on its location
in the filesystem) suitable for use in a Java/Scala source file"
(interactive)
(let ((file-name (buffer-file-name)))
(if file-name
(let ((matches (s-match +PACKAGE-REGEXP+ file-name)))
(if matches
(let ((dirs (nth 3 matches)))
(s-replace "/" "." dirs))
nil))
(error "Buffer has no file name"))))
(defun insert-current-package-name ()
"Inserts the name of the current file's package (based on its
location in the filesystem)"
(interactive)
(let ((cpn (current-package-name)))
(if cpn
(insert cpn))))
(defun init-java-or-scala-mode ()
"Set up Java or Scala mode"
(toggle-truncate-lines t)
(local-set-key "\C-c\C-c" 'toggle-test-and-prod-file)
(local-set-key "\C-c\C-p" 'insert-current-package-name))
(defun find-dot-file ()
"find ~/.emacs"
(interactive)
(find-file "~/.emacs"))
;;; Scala Specific
(add-hook 'scala-mode-hook
(lambda ()
(init-java-or-scala-mode)))
;;; Java Specific
(add-hook 'java-mode-hook
(lambda ()
(init-java-or-scala-mode)))
(require 'mvn)
;;; Org-mode setup
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(define-key global-map "\C-cc" 'org-capture)
(setq org-log-done t)
(setq org-agenda-files (list "~/org/notebook.org"))
(setq org-default-notes-file "~/org/notes.org")
;;; Tramp
(require 'tramp)
(setq tramp-default-method "ssh")
(setq tramp-default-user "ubuntu")
(custom-set-variables
'(ag-highlight-search t)
'(ag-reuse-buffers t)
'(comint-move-point-for-output (quote all))
'(comint-scroll-show-maximum-output t)
'(comint-scroll-to-bottom-on-input (quote all))
'(compilation-scroll-output t)
'(custom-enabled-themes (quote (flatland)))
'(custom-safe-themes (quote ("fe243221e262fe5144e89bb5025e7848cd9fb857ff5b2d8447d115e58fede8f7" default)))
'(explicit-shell-file-name "/bin/zsh")
'(fringe-mode nil nil (fringe))
'(global-auto-revert-mode nil)
'(ido-auto-merge-work-directories-length -1)
'(ido-case-fold t)
'(indicate-buffer-boundaries nil)
'(indicate-empty-lines nil)
'(inferior-lisp-program "/home/tim/bin/clojure-1.3.0/clojure")
'(inhibit-startup-screen t)
'(initial-buffer-choice nil)
'(initial-scratch-message "")
'(linum-eager nil)
'(mvn-command "/home/tim/bin/maven/bin/mvn")
'(org-export-with-section-numbers nil)
'(org-export-with-toc nil)
'(overflow-newline-into-fringe t)
'(python-indent-offset 4)
'(save-place t nil (saveplace))
'(scala-interpreter "~/bin/scala/bin/scala")
'(show-paren-mode t)
'(tool-bar-mode nil)
'(uniquify-buffer-name-style (quote forward) nil (uniquify))
'(windmove-wrap-around t))
(custom-set-faces '(default ((t (:inherit nil :stipple
nil :inverse-video nil :box nil :strike-through nil :overline
nil :underline nil :slant normal :weight normal :height
120 :width normal :foundry "unknown" :family "DejaVu Sans
Mono")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment