(require 'package)
(add-to-list 'package-archives '("melpa" . "https://www.mirrorservice.org/sites/melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
;; Don't need to check every time.
;; (when (not package-archive-contents)
;; (package-refresh-contents))
(package-initialize)
The
use-package
macro allows you to isolate package configuration in your .emacs file in a way that is both performance-oriented and, well, tidy. I created it because I have over 80 packages that I use in Emacs, and things were getting difficult to manage. Yet with this utility my total load time is around 2 seconds, with no loss of functionality!
If running Emacs for the first time, you need to install use-packages
manually.
M-x package-install [RET] use-package [RET]
Start using use-package
(eval-when-compile (require 'use-package))
;; (require 'diminish) ;; if you use :diminish (??)
;; (require 'bin-key) ;; if you use any :bind variant (??)
Add custom packages directory to the load-path
.
(add-to-list 'load-path (concat user-emacs-directory "packages/"))
; Update packages using (auto-package-update-now)
(use-package auto-package-update :ensure t)
Some quick essentials
;; No alarms.
(setq ring-bell-function 'ignore)
;; Keep emacs Custom-settings in separate file.
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file)
;; Write backup files to own directory
(setq backup-directory-alist
`(("." . ,(expand-file-name
(concat user-emacs-directory "backups")))))
;; Make backups of files, even when they're in version control.
(setq vc-make-backup-files t)
;; Save point position between sessions.
(use-package saveplace)
(setq-default save-place t)
(setq save-place-file (expand-file-name "places" user-emacs-directory))
;; Fix empty pasteboard error. (??)
;; (setq save-interprogram-paste-before-kill nil)
;; Don't automatically copy selected text (not sure about this one) (??)
;; (setq select-enable-primary nil)
;; Add filepath to frame title
(setq-default frame-title-format
'(:eval (format "%s (%s)"
(buffer-name)
(when (buffer-file-name)
(abbreviate-file-name (buffer-file-name))))))
;; Disable toolbar
(tool-bar-mode -1)
;; Crux - A Collection of Ridiculously Useful eXtensions for Emacs
;; Using it for moving to the first non-whitespace character of a line, instead
;; of start of line
(use-package crux
:ensure t
:bind (("C-a" . crux-move-beginning-of-line)))
(setq create-lockfiles nil)
;; Smarter cut/copy https://emacs.stackexchange.com/a/2348
(defun slick-cut (beg end)
(interactive
(if mark-active
(list (region-beginning) (region-end))
(list (line-beginning-position) (line-beginning-position 2)))))
(advice-add 'kill-region :before #'slick-cut)
(defun slick-copy (beg end)
(interactive
(if mark-active
(list (region-beginning) (region-end))
(message "Copied line")
(list (line-beginning-position) (line-beginning-position 2)))))
(advice-add 'kill-ring-save :before #'slick-copy)
Better Emacs Default Settings. Heavily influenced from sane-defaults.el.
;;------[Begin Sanity]--------------------------------------------------
;; Full path in frame title
(when window-system
(setq frame-title-format '(buffer-file-name "%f" ("%b"))))
;; Auto refresh buffers when edits occur outside emacs
(global-auto-revert-mode 1)
;; Also auto refresh Dired, but be quiet about it
(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-verbose nil)
;; Quickly copy/move file in Dired
(setq dired-dwim-target t)
;; Show keystrokes in progress
(setq echo-keystrokes 0.1)
;; Move files to trash when deleting (KNS: don't think I want this)
;; (setq delete-by-moving-to-trash t)
;; Transparently open compressed files (??)
(auto-compression-mode t)
;; Enable syntax highlighting for older Emacsen that have it off
(global-font-lock-mode t)
;; Show matching parens
(setq show-paren-delay 0)
(show-paren-mode 1)
;; Auto-close brackets and double quotes
(electric-pair-mode 1)
;; Answering just 'y' or 'n' will do
(defalias 'yes-or-no-p 'y-or-n-p)
;; UTF-8 please
(setq locale-coding-system 'utf-8) ; pretty
(set-terminal-coding-system 'utf-8) ; pretty
(set-keyboard-coding-system 'utf-8) ; pretty
(set-selection-coding-system 'utf-8) ; please
(prefer-coding-system 'utf-8) ; with sugar on top
;; Remove text in active region if inserting text
(delete-selection-mode 1)
;; Always display line and column numbers
(setq line-number-mode t)
(setq column-number-mode t)
;; Lines should be 120 characters wide, not 72
(setq fill-column 120)
;; Smooth Scroll:
(setq mouse-wheel-scroll-amount '(1 ((shift) .1))) ;; one line at a time
;; Scrol one line when hitting bottom of window
(setq scroll-conservatively 10000)
;; Change Cursor
(setq-default cursor-type 'box)
(blink-cursor-mode -1)
;; Remove alarm (bell) on scroll
(setq ring-bell-function 'ignore)
;; Set default tab width
(setq default-tab-width 4)
;; Never insert tabs (KNS: Don't know about this, no..)
;; Should rather depend on .editorconfig
;; (set-default 'indent-tabs-mode nil)
;; Easily navigate sillycased words
(global-subword-mode 1)
;; Word Wrap (t is no wrap, nil is wrap)
(setq-default truncate-lines nil)
;; Sentences do not need double spaces to end. Period.
(set-default 'sentence-end-double-space nil)
;; Real emacs knights don't use shift to mark things
(setq shift-select-mode nil)
;; Add parts of each file's directory to the buffer name if not unique
(use-package uniquify
:config
(setq uniquify-buffer-name-style 'forward))
;; eval-expression-print-level needs to be set to nil (turned off) so
;; that you can always see what's happening.
(setq eval-expression-print-level nil)
;; from 'better-defaults.el'
;; Allow clipboard from outside emacs
(setq x-select-enable-clipboard t
save-interprogram-paste-before-kill t
apropos-do-all t
mouse-yank-at-point t)
;; Ido, Yes!
(use-package ido
:ensure t
:config
(ido-mode t)
(ido-everywhere t)
(setq ido-enable-flex-matching t))
(use-package ido-completing-read+
:ensure t
:config
(ido-ubiquitous-mode t))
;; Fuzzy search
(use-package flx-ido
:ensure t
:config
(flx-ido-mode t)
(setq ido-enable-flex-matching t)
(setq ido-use-faces nil))
;; Show results as grid
(use-package ido-grid-mode
:ensure t
:config
(ido-grid-mode t))
There are a number of ways to bind keys in Emacs, but I find
bind-key
, bundled withuse-package
, easier to work with and, more importantly, easier to read.bind-key
takes a key sequence, a command, and an optional keymap.bind-key*
overrides any minor mode which sets the keybinding.unbind-key
takes a key sequence and a keymap and removes that binding. Invokingdescribe-personal-keybindings
prints a summary of your keybindings throughbind-key
and any overrides or conflicts. This is really the killer convenience of usingbind-key
.
(use-package color-theme-sanityinc-tomorrow
:ensure t
:config (load-theme 'sanityinc-tomorrow-night t))
The emacs git client.
(use-package magit
:ensure t)
Smex is a M-x enhancement for Emacs. Built on top of Ido, it provides a convenient interface to your recently and most frequently used commands. And to all the other commands, too.
(use-package smex
:ensure t
:bind (("M-x" . smex))
:config (smex-initialize))
(use-package markdown-mode
:ensure t
:commands (markdown-mode gfm-mode)
:mode (("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode))
:init (setq markdown-command "multimarkdown"))
Which-key is a minor mode for Emacs that displays the key bindings following your currently entered incomplete command (a prefix) in a popup.
(use-package which-key
:ensure t
:config (which-key-mode))
(use-package projectile
:ensure t
:config
(projectile-mode +1)
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
(setq projectile-indexing-method 'alien)
(setq projectile-enable-caching t)
(projectile-global-mode))
See here for details: https://github.com/editorconfig/editorconfig-emacs
(use-package editorconfig
:ensure t
:config
(editorconfig-mode 1))
Bitbake integration with emacs. See https://github.com/canatella/bitbake-el for details.
(use-package bitbake :ensure t)
(use-package company
:ensure t
:config
(setq company-idle-delay 0.1)
(setq company-minimum-prefix-length 2)
(add-hook 'elisp-mode-hook 'company-mode))
(use-package company-irony
:ensure t
:config
(require 'company)
(add-to-list 'company-backends 'company-irony))
(use-package irony
:ensure t
:config
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode))