emacskurs/emacs-init.el
2015-03-14 15:11:54 +01:00

143 lines
4.2 KiB
EmacsLisp

;; Requiring features is like loading libraries.
;; We need these two in the config:
(require 'cl)
(require 'package)
;; add mirrors for list-packages
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/"))
;; needed to use things downloaded with the package manager
(package-initialize)
;; install some packages if missing
(let* ((packages '(auto-complete
ido-vertical-mode
monokai-theme
multiple-cursors
undo-tree
;; if you want more packages, add them here
))
(packages (remove-if 'package-installed-p packages)))
(when packages
(package-refresh-contents)
(mapc 'package-install packages)))
;; no splash screen
(setq inhibit-splash-screen t)
;; show matching parenthesis
(show-paren-mode 1)
;; show column number in mode-line
(column-number-mode 1)
;; overwrite marked text
(delete-selection-mode 1)
;; changes selection in the minibuffer
(ido-mode 1)
;; use ido everywhere
(ido-everywhere 1)
;; show vertically
(ido-vertical-mode 1)
;; use undo-tree-mode globally
(global-undo-tree-mode 1)
;; stop blinking cursor
(blink-cursor-mode 0)
;; no menubar
(menu-bar-mode 0)
;; no toolbar either
(tool-bar-mode 0)
;; scrollbar? no
(scroll-bar-mode 0)
;; global-linum-mode shows line numbers in all buffers, exchange 0
;; with 1 to enable this feature
(global-linum-mode 0)
;; answer with y/n
(fset 'yes-or-no-p 'y-or-n-p)
;; choose a color-theme
(load-theme 'monokai t)
;; get the default config for auto-complete (downloaded with
;; package-manager)
(require 'auto-complete-config)
;; load the default config of auto-complete
(ac-config-default)
;; kills the active buffer, not asking what buffer to kill.
(global-set-key (kbd "C-x k") 'kill-this-buffer)
;; adds all autosave-files (i.e #test.txt#, test.txt~) in one
;; directory, avoid clutter in filesystem.
(defvar emacs-autosave-directory (concat user-emacs-directory "autosaves/"))
(setq backup-directory-alist
`((".*" . ,emacs-autosave-directory))
auto-save-file-name-transforms
`((".*" ,emacs-autosave-directory t)))
;; defining a function that sets more accessible keyboard-bindings to
;; hiding/showing code-blocs
(defun hideshow-on ()
(interactive)
(local-set-key (kbd "<backtab>") 'hs-toggle-hiding)
(local-set-key (kbd "C-c <right>") 'hs-show-block)
(local-set-key (kbd "C-c <left>") 'hs-hide-block)
(local-set-key (kbd "C-c <up>") 'hs-hide-all)
(local-set-key (kbd "C-c <down>") 'hs-show-all)
(hs-minor-mode t))
;; now we have to tell emacs where to load these functions. Showing
;; and hiding codeblocks could be useful for all c-like programming
;; (java is c-like) languages, so we add it to the c-mode-common-hook.
(add-hook 'c-mode-common-hook 'hideshow-on)
;; adding shortcuts to java-mode, writing the shortcut folowed by a
;; non-word character will cause an expansion.
(defun java-shortcuts ()
(define-abbrev-table 'java-mode-abbrev-table
'(("psv" "public static void main(String[] args) {" nil 0)
("sop" "System.out.printf" nil 0)
("sopl" "System.out.println" nil 0)))
(abbrev-mode t))
;; the shortcuts are only useful in java-mode so we'll load them to
;; java-mode-hook.
(add-hook 'java-mode-hook 'java-shortcuts)
;; defining a function that guesses a compile command and bindes the
;; compile-function to C-c C-c
(defun java-setup ()
(set (make-variable-buffer-local 'compile-command)
(concat "javac " (buffer-name)))
(local-set-key (kbd "C-c C-c") 'compile))
;; this is a java-spesific function, so we only load it when entering
;; java-mode
(add-hook 'java-mode-hook 'java-setup)
;; defining a function that sets the right indentation to the marked
;; text, or the entire buffer if no text is selected.
(defun tidy ()
"Ident, untabify and unwhitespacify current buffer, or region if active."
(interactive)
(let ((beg (if (region-active-p) (region-beginning) (point-min)))
(end (if (region-active-p) (region-end) (point-max))))
(whitespace-cleanup)
(indent-region beg end nil)
(untabify beg end)))
;; bindes the tidy-function to C-TAB
(global-set-key (kbd "<C-tab>") 'tidy)