12 KiB
Emacs Configuration
- Personal Information
- Update config in a running config
- Customize settings
- Theme
- Sane defaults
- List buffers
- Recentf
- Org Mode
- which-key
- ivy / counsel / swiper
- Programming
Personal Information
(setq user-full-name "Marc Pohling" user-mail-address "marc.pohling@googlemail.com")
Update config in a running config
Two options:
-
reload the open file: M-x load-file, then press twice to accept the default filename, which is the currently opened
-
Point at the end of any sexp and press C-x C-e
Customize settings
Move the customize settings to its own file, instead of saving customize settings in init.el.
(setq custom-file (expand-file-name "custom.el" user-emacs-directory)) (load custom-file)
Theme
Material Theme
The Material Theme comes in a dark and a light variant. Not too dark to be strenious though.
(use-package material-theme :if (window-system) :defer t :ensure t :init (load-theme 'material t) )
Sane defaults
Sources for this section include Magnars Sveen and Sacha Chua
These functions are useful. Activate them.
(put 'downcase-region 'disabled nil) (put 'upcase-region 'disabled nil) (put 'narrow-to-region 'disabled nil) (put 'dired-find-alternate-file 'disabled nil)
Answering just 'y' or 'n' should be enough.
(defalias 'yes-or-no-p 'y-or-n-p)
Keep all backup and auto-save files in one directory
(setq backup-directory-alist '(("." . "~/.emacs.d/backups"))) (setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))
UTF-8 please
(setq locale-coding-system 'utf-8) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) (set-selection-coding-system 'utf-8) (prefer-coding-system 'utf-8)
Avoid tabs in place of multiple spaces (they look bad in TeX) and show empty lines
(setq-default indent-tabs-mode nil) (setq-default indicate-empty-lines t)
Turn off blinking cursor
(blink-cursor-mode -1)
Don't count two spaces after a period as the end of a sentence. Just one space is needed
(setq sentence-end-double-space nil)
Delete the region when typing, just like as we expect nowadays.
(delete-selection-mode t)
Various stuff
(show-paren-mode t) (column-number-mode t) (global-visual-line-mode) (diminish 'visual-line-mode) (setq uniquify-buffer-name-style 'forward)
List buffers
Ibuffer is the improved version of list-buffers. Make ibuffer the default buffer lister. Source
(defalias 'list-buffers 'ibuffer)
Also auto refresh dired, but be quiet about it. Source
(add-hook 'dired-mode-hook 'auto-revert-mode) (setq global-auto-revert-non-file-buffers t) (setq auto-revert-verbose nil)
Recentf
(use-package recentf :bind ("C-x C-r" . helm-recentf) :config (recentf-mode t) (setq recentf-max-saved-items 200) )
Org Mode
Installation
Although org mode ships with Emacs, the latest version can be installed externally. The configuration here follows the Org mode ELPA Installation instructions.
(use-package org :ensure org-plus-contrib)
To avoid problems executing source blocks out of the box. Others have the same problem, too. The solution is to remove the .elc files form the package directory:
var ORG_DIR=(let* ((org-v (cadr (split-string (org-version nil t) "@"))) (len (length org-v))) (substring org-v 1 (- len 2))) rm ${ORG_DIR}/*.elc
Org activation bindings
Set up some global key bindings that integrate with Org mode features
(bind-key "C-c l" 'org-store-link) (bind-key "C-c c" 'org-capture) (bind-key "C-c a" 'org-agenda)
Org agenda
For a more detailed example see here.
(setq org-agenda-files (delq nil (mapcar (lambda (x) (and (file-exists-p x) x)) '("~/Archiv/Dokumente/Agenda")) ) )
Org capture
(bind-key "C-c c" 'org-capture) (setq org-default-notes-file "~/Archiv/Dokumente/Notizen/notes.org")
Org Setup
Speed commands are a nice and quick way to perform certain actions while at the beginning of a heading. It's not activated by default.
See the doc for speed keys by checking out the documentation for speed keys in Org mode.
(setq org-use-speed-commands t) (setq org-image-actual-width 550) (setq org-highlight-latex-and-related '(latex script entities))
Org tags
The default value is -77, which is weird for smaller width windows. I'd rather have the tags align horizontally with the header. 45 is a good column number to do that.
(setq org-tags-column 45)
Org babel languages
(org-babel-do-load-languages 'org-babel-load-languages '((python . t) (C . t) (calc . t) (latex . t) (java . t) (ruby . t) (lisp . t) (scheme . t) (shell . t) (sqlite . t) (js . t))) (defun my-org-confirm-babel-evaluate (lang body) "Do not confirm evaluation for these languages." (not (or (string= lang "C") (string= lang "java") (string= lang "python") (string= lang "emacs-lisp") (string= lang "sqlite")))) (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
Org babel/source blocks
I like to have source blocks properly syntax highlighted and with the editing popup window staying within the same window so all the windows don't jump around. Also, having the top and bottom trailing lines in the block is a waste of space, so we can remove them
I noticed that fontification doesn't work with markdown mode when the block is indented after editing it in the org src buffer - the leading #s for headers don't get fontified properly because they apppear as Org comments. Setting org-src-preserve-identation
makes things consistent as it doesn't pad source blocks with leading spaces
(setq org-src-fontify-natively t org-src-window-setup 'current-window org-src-strip-leading-and-trailing-blank-lines t org-src-preserve-indentation t org-src-tab-acts-natively t)
which-key
Greatly increases discovery of functions! Click here for source and more info. Info in Emacs: M-x customize-group which-key
(use-package which-key :ensure t :diminish which-key-mode :config (which-key-mode) (which-key-setup-side-window-right-bottom) (which-key-setup-minibuffer) (setq which-key-idle-delay 0.5) )
ivy / counsel / swiper
Ivy displays a window with suggestions for hotkeys and M-x
(use-package ivy :ensure t :diminish (ivy-mode . "") ;; does not display ivy in the mode line :init (ivy-mode 1) :bind ("C-c C-r" . ivy-resume) :config (setq ivy-use-virtual-buffers t) ;; recent files and bookmarks in ivy-switch-buffer (setq ivy-height 20) ;; height of ivy window (setq ivy-count-format "%d/%d") ;; current and total number )
Counsel replaces:
-
M-x
-
C-x C-f find-file
-
C-c h f describe-function
-
C-c h v describe-variable
-
M-i imenu
The find-file replacement is nicer to navigate
(use-package counsel :ensure t :bind* ;; load counsel when pressed (("M-x" . counsel-M-x) ("C-x C-f" . counsel-find-file) ("C-c h f" . counsel-describe-function) ("C-c h v" . counsel-describe-variable) ("M-i" . counsel-imenu) ) )
Swiper ivy-enhances isearch
(use-package swiper :ensure t :bind (("C-s" . swiper) ("C-c C-r" . ivy-resume) ) )
Programming
Common things
List of plugins and settings which are shared between the language plugins
Company Mode
Complete Anything!
Activate company and make it react nearly instantly
(use-package company :ensure t :config (add-to-list 'company-backends 'company-elisp) (setq company-minimum-prefix-length 2 company-tooltip-align-annotation t company-tooltop-flip-when-above t company-show-numbers t) (setq company-idle-delay 0.1) (add-hook 'after-init-hook 'global-company-mode) ;; (global-company-mode t) )
Addon to sort suggestions by usage
(use-package company-statistics :ensure t :config (company-statistics-mode 1) )
Get a popup with documentation of the completion candidate. I have to test if it even works.
(use-package company-quickhelp :ensure t :config (company-quickhelp-mode 1) )
Maybe add company-dict? It's a dictionary based on major modes, plus it has Yasnippet integration.
Python
Systemwide following packages need to be installed:
-
virtualenv
The virtual environments need to have following modules installed:
-
jedi
-
epc
-
flake8
Automatically start python-mode when opening a .py-file.
Not sure if python.el is better than python-mode.el.
See here for info about python-shell-completion-native-enable
.
The custom function is to run inferiour processes (do I really need that?), see here.
(use-package python :mode ("\\.py\\'" . python-mode) :interpreter ("python" . python-mode) :config (setq python-shell-completion-native-enable nil) ;; (defun my/run-python () ;; (save-selected-window ;; (switch-to-buffer-other-window (process-buffer (python-shell-get-or-create-process (python-shell-parse-command))))) ;; ) ;; (add-hook 'python-mode-hook 'my/run-python) )
TEST
ELPY
begin_src emacs-lisp (use-package elpy :ensure t ;; :pin elpy :config (elpy-enable) (add-hook 'python-mode-hook 'elpy-mode) (setq elpy-rpc-backend "jedi") (pyvenv-mode 1) ) end_src
Jedi is a backend for python autocompletion and needs to be installed on the server:
-
pip install jedi
Code checks need to be installed, too:
-
pip install flake8
(use-package company-jedi :defer t :ensure t :config (setq jedi:environment-virtualenv (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))) (add-hook 'python-mode-hook 'jedi:setup) (setq jedi:complete-on-dot t) (setq jedi:use-shortcuts t) (defun my/python-mode-hook() (add-to-list 'company-backends 'company-jedi)) (add-hook 'python-mode-hook 'my/python-mode-hook) )
A wrapper to handle virtual environments. I strongly recommend to install virtual environments on the terminal, not through this wrapper, but changing venvs is fine.
(use-package virtualenvwrapper :ensure t :init (venv-initialize-interactive-shells) (venv-initialize-eshell) (setq venv-location "~/Archiv/Programmierprojekte/Python/virtualenv") (setq python-environment-directory venv-location) (add-hook 'venv-postmkvirtualenv-hook (lambda () (shell-command "pip install epc jedi"))) (add-hook 'venv-postactivate-hook 'jedi:stop-server) (add-hook 'venv-postdeactivate-hook 'jedi:stop-server) )