Skip to content

Instantly share code, notes, and snippets.

@nicolamontecchio
Created January 17, 2014 18:15
Show Gist options
  • Save nicolamontecchio/8478608 to your computer and use it in GitHub Desktop.
Save nicolamontecchio/8478608 to your computer and use it in GitHub Desktop.
emacs config as of 2014-01-17
;; ;; config using mac-port of emacs,
;; ;; see https://github.com/railwaycat/emacs-mac-port
;; ;; mac switch meta key
(setq mac-option-modifier 'meta)
(setq mac-command-modifier 'hyper)
(setq package-archives '(;;("gnu" . "http://elpa.gnu.org/packages/")
;;("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")))
;; check if the packages is installed; if not, install it.
(package-initialize)
(mapc
(lambda (package)
(or (package-installed-p package)
(progn
(message "installing %s" package)
(package-install package))))
'(auto-complete
auto-complete-clang-async
clojure-mode
jedi
json
cider
rainbow-delimiters
multiple-cursors
sublime-themes
idomenu
yasnippet
flycheck
ag
ein
haskell-mode
flatland-theme
magit
wrap-region
geiser
ghc
paredit
direx
projectile
flx-ido
exec-path-from-shell))
;; use PATH and other things from the shell even when starting from GUI in mac os x
(when (memq window-system '(mac ns))
(set-face-attribute 'default nil :font "monofur-12")
(exec-path-from-shell-initialize))
(load-theme 'dorsey t)
;; (load-theme 'flatland t)
(defadvice load-theme
(before theme-dont-propagate activate)
(mapcar #'disable-theme custom-enabled-themes))
;; KEY BINDINGS
(global-set-key (kbd "H-c") 'kill-ring-save) ;; copy
(global-set-key (kbd "H-x") 'kill-region) ;; cut
(global-set-key (kbd "H-v") 'yank) ;; paste
(global-set-key (kbd "H-s") 'save-buffer) ;; save
(global-set-key (kbd "H-z") 'undo) ;; undo
(global-set-key (kbd "H-k") 'kill-buffer) ;; kill buffer
(global-set-key (kbd "H-a") 'mark-whole-buffer) ;; select all
(global-set-key (kbd "H-m") 'idomenu) ;; ido menu (for python functions/globals)
(global-set-key (kbd "H-M-t") 'hs-toggle-hiding) ;; toggle show/hide block
(global-set-key (kbd "H-t") 'toggle-truncate-lines) ;; switch on-off word wrap
(global-set-key (kbd "H-M-f") 'toggle-fullscreen) ;; toggle full screen
(global-set-key (kbd "H-/") 'toggle-comment-region) ;; comment code - custom function below
(global-set-key (kbd "H-b") 'recompile) ;; recompile
(define-key global-map (kbd "RET") 'newline-and-indent) ;; auto indentation
(global-set-key [H-left] 'windmove-left) ;; move to left windnow
(global-set-key [H-right] 'windmove-right) ;; move to right window
(global-set-key [H-up] 'windmove-up) ;; move to upper window
(global-set-key [H-down] 'windmove-down) ;; move to downer window
(global-set-key (kbd "H-M-<left>") 'shrink-window-horizontally) ;; shrink window horizontally
(global-set-key (kbd "H-M-<right>") 'enlarge-window-horizontally) ;; enlarge window horizontally
(global-set-key (kbd "H-M-<down>") 'shrink-window) ;; shrink window vertically
(global-set-key (kbd "H-M-<up>") 'enlarge-window) ;; enlarge window vertically
(global-set-key (kbd "C->") 'mc/mark-next-like-this) ;; multiple cursors stuff
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
(global-set-key (kbd "C-M-<mouse-1>") 'mc/add-cursor-on-click)
(require 'direx) ;; for some reason it doesn't do this automaticallty
(global-set-key (kbd "H-j") 'direx:jump-to-directory) ;; tree view of directory
(global-set-key (kbd "H-M-s") 'magit-status) ;; git status
(global-set-key (kbd "H-M-b") 'browse-url-at-point) ;; open url under cursor in chrome
(global-set-key (kbd "H-M-<tab>") 'org-global-cycle)
(defun nop ()
"A do-nothing function"
nil)
(global-set-key (kbd "C-z") 'nop)
;; (setq next-screen-context-lines 40) ;; amount of scrolling
;; VISUAL ASPECT
(add-to-list 'default-frame-alist '(height . 58)) ;; default win size
(add-to-list 'default-frame-alist '(width . 120))
(setq inhibit-splash-screen t) ;; no splash screen
(tool-bar-mode -1) ;; no toolbar
(scroll-bar-mode -1) ;; no scroll bar
(setq mouse-wheel-progressive-speed nil)
(setq ring-bell-function 'ignore) ;; disable bell
;; (setq-default truncate-lines t) ;; line truncation (no wrapping)
(global-linum-mode t) ;; line numbering on
(setq linum-format "%4d ") ;; fix weird mac bug on fringe
(set-fringe-mode 0) ;; (also heere)
(show-paren-mode 1) ;; show matching parents
(defalias 'yes-or-no-p 'y-or-n-p)
(add-hook 'before-save-hook 'delete-trailing-whitespace) ;; delete trailing whitespaces on save
(column-number-mode) ;; display column number in command buf.
(add-hook 'prog-mode-hook 'subword-mode) ;; camel-case kill-word
(display-time-mode 1)
(projectile-global-mode)
(wrap-region-global-mode)
;; (global-hl-line-mode)
(defun toggle-comment-region () ;; custom comment toggle function
"Comments or uncomments the region or the current line if there's no active region."
(interactive)
(let (beg end)
(if (region-active-p)
(setq beg (region-beginning) end (region-end))
(setq beg (line-beginning-position) end (line-end-position)))
(comment-or-uncomment-region beg end)))
(autoload 'octave-mode "octave-mod" nil t) ;; octave mode for .m files
(setq auto-mode-alist (cons '("\\.m$" . octave-mode) auto-mode-alist))
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) ;; org mode for .org files
(setq c-default-style "linux" c-basic-offset 2) ;; c++ indentation
(add-hook 'c-mode-common-hook 'hs-minor-mode)
(setq js-indent-level 2) ;; javascript indentation
(put 'erase-buffer 'disabled nil)
(setq scheme-program-name "/usr/local/bin/guile") ;; scheme interpreter
;; jedi, flycheck
(setq jedi:setup-keys t)
(add-hook 'python-mode-hook 'jedi:setup)
(add-hook 'python-mode-hook 'auto-complete-mode)
(add-hook 'python-mode-hook 'hs-minor-mode)
(add-hook 'python-mode-hook (lambda () (local-set-key "\M-'" 'jedi:complete)))
;; (add-hook 'python-mode-hook 'flycheck-mode)
;; clang-complete
(require 'auto-complete-clang-async)
;; (setq ac-clang-async-do-autocompletion-automatically nil)
(defun my-ac-cc-mode-setup ()
(setq ac-clang-complete-executable "~/.emacs.d/clang-complete")
(setq ac-sources (append '(ac-source-clang-async) ac-sources))
(ac-clang-launch-completion-process)
(local-set-key "\M-'" 'ac-complete-clang-async)
(setq ac-auto-start nil)
(auto-complete-mode))
(add-hook 'c-mode-common-hook 'my-ac-cc-mode-setup)
;; code formatting functions
(defun beautify-xml (begin end)
(interactive "r")
(save-excursion
(nxml-mode)
(goto-char begin)
(while (search-forward-regexp "\>[ \\t]*\<" nil t)
(backward-char) (insert "\n"))
(indent-region begin end))
(message "Ah, much better!"))
(defun beautify-json () ;; json pretty print
(interactive)
(let ((b (if mark-active (min (point) (mark)) (point-min)))
(e (if mark-active (max (point) (mark)) (point-max))))
(shell-command-on-region b e "python -mjson.tool" (current-buffer) t)))
;; full screen mode
(defun toggle-fullscreen ()
"Toggle full screen"
(interactive)
(set-frame-parameter
nil 'fullscreen
(when (not (frame-parameter nil 'fullscreen)) 'fullboth)))
;; emacs server
(defvar server-buffer-clients)
(when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
(server-start)
(defun fp-kill-server-with-buffer-routine ()
(and server-buffer-clients (server-done)))
(add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
(server-start)
(remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)
;; haskell-mode indent
(custom-set-variables
'(haskell-mode-hook (lambda nil (turn-on-haskell-indentation) (ghc-init) (require (quote auto-complete-config)) (auto-complete-mode t) (add-to-list (quote ac-sources) (quote ac-source-ghc-mod)))))
;; various lisps
(add-hook 'emacs-lisp-mode-hook 'paredit-mode)
(add-hook 'eval-expression-minibuffer-setup-hook 'paredit-mode)
(add-hook 'scheme-mode-hook 'paredit-mode)
(add-hook 'clojure-mode-hook 'paredit-mode)
(add-hook 'scheme-mode-hook 'hs-minor-mode)
(yas-global-mode 1) ;; use snippets by default
(ido-mode 1) ;; IDO
(global-auto-revert-mode 1) ;; automatically reload files when changed
(custom-set-faces)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment