Tabs over Spaces!!!
(local-set-key (kbd "TAB") 'tab-to-tab-stop)
(setq indent-tabs-mode t)
(setq tab-width 4)
(setq backward-delete-char-untabify-method 'hungry)
I use use-package
to install and configure my packages. My init.el
includes
the initial setup for package.el
and ensures that use-package
is installed,
since I wanna do that right away.
This makes sure that use-package
will install the package if it’s not already
available. It also means that I should be able to open Emacs for the first time
on a fresh Debian box and have my whole environment automatically installed. I’m
not totally sure about that, but we’re gettin’ close.
(require 'use-package-ensure)
(setq use-package-always-ensure t)
Always compile packages, and use the newest version available.
(use-package auto-compile
:config (auto-compile-on-load-mode))
(setq load-prefer-newer t)
Auto-update packages
(use-package auto-package-update
:config
(setq auto-package-update-delete-old-versions t)
(setq auto-package-update-hide-results t)
(auto-package-update-maybe))
Use sensible-defaults.el for some basic settings.
(load-file "~/.emacs.d/sensible-defaults.el/sensible-defaults.el")
(sensible-defaults/use-all-settings)
(setq user-full-name "Florian Feldmann"
user-mail-address "[email protected]"
)
(add-to-list 'load-path "~/.emacs.d/resources/")
Define a big ol’ bunch of handy utility functions.
(defun hrs/rename-file (new-name)
(interactive "FNew name: ")
(let ((filename (buffer-file-name)))
(if filename
(progn
(when (buffer-modified-p)
(save-buffer))
(rename-file filename new-name t)
(kill-buffer (current-buffer))
(find-file new-name)
(message "Renamed '%s' -> '%s'" filename new-name))
(message "Buffer '%s' isn't backed by a file!" (buffer-name)))))
(defun hrs/generate-scratch-buffer ()
"Create and switch to a temporary scratch buffer with a random
name."
(interactive)
(switch-to-buffer (make-temp-name "scratch-")))
(defun hrs/kill-current-buffer ()
"Kill the current buffer without prompting."
(interactive)
(kill-buffer (current-buffer)))
(defun hrs/visit-last-migration ()
"Open the most recent Rails migration. Relies on projectile."
(interactive)
(let ((migrations
(directory-files
(expand-file-name "db/migrate" (projectile-project-root)) t)))
(find-file (car (last migrations)))))
(defun hrs/add-auto-mode (mode &rest patterns)
"Add entries to `auto-mode-alist' to use `MODE' for all given file `PATTERNS'."
(dolist (pattern patterns)
(add-to-list 'auto-mode-alist (cons pattern mode))))
(defun hrs/find-file-as-sudo ()
(interactive)
(let ((file-name (buffer-file-name)))
(when file-name
(find-alternate-file (concat "/sudo::" file-name)))))
(defun hrs/region-or-word ()
(if mark-active
(buffer-substring-no-properties (region-beginning)
(region-end))
(thing-at-point 'word)))
(defun hrs/append-to-path (path)
"Add a path both to the $PATH variable and to Emacs' exec-path."
(setenv "PATH" (concat (getenv "PATH") ":" path))
(add-to-list 'exec-path path))
There’s a tiny scroll bar that appears in the minibuffer window. This disables that:
(set-window-scroll-bars (minibuffer-window) nil nil)
The default frame title isn’t useful. This binds it to the name of the current project:
(setq frame-title-format '((:eval (projectile-project-name))))
Why not?
(global-prettify-symbols-mode t)
I’m currently using the “solarized-dark” theme. I’ve got a scenic wallpaper, so just a hint of transparency looks lovely and isn’t distracting or hard to read.
(use-package solarized-theme
:config
(load-theme 'solarized-dark t)
(setq solarized-use-variable-pitch nil
solarized-height-plus-1 1.0
solarized-height-plus-2 1.0
solarized-height-plus-3 1.0
solarized-height-plus-4 1.0)
(let ((line (face-attribute 'mode-line :underline)))
(set-face-attribute 'mode-line nil :overline line)
(set-face-attribute 'mode-line-inactive nil :overline line)
(set-face-attribute 'mode-line-inactive nil :underline line)
(set-face-attribute 'mode-line nil :box nil)
(set-face-attribute 'mode-line-inactive nil :box nil)
(set-face-attribute 'mode-line-inactive nil :background "#f9f2d9")))
(defun hrs/apply-theme ()
"Apply the `solarized-dark' theme and make frames just slightly transparent."
(interactive)
(load-theme 'solarized-dark t))
If this code is being evaluated by emacs --daemon
, ensure that each subsequent
frame is themed appropriately.
(if (daemonp)
(add-hook 'after-make-frame-functions
(lambda (frame)
(with-selected-frame frame (hrs/apply-theme))))
(hrs/apply-theme))
This gives me a truly lovely ribbon-based modeline.
(use-package moody
:config
(setq x-underline-at-descent-line t)
(moody-replace-mode-line-buffer-identification)
(moody-replace-vc-mode))
sensible-defaults
replaces the audible bell with a visual one, but I really
don’t even want that (and my Emacs/Mac pair renders it poorly). This disables
the bell altogether.
(setq ring-bell-function 'ignore)
When point goes outside the window, Emacs usually recenters the buffer point. I’m not crazy about that. This changes scrolling behavior to only scroll as far as point goes.
(setq scroll-conservatively 100)
global-hl-line-mode
softly highlights the background color of the line
containing point. It makes it a bit easier to find point, and it’s useful when
pairing or presenting code.
(global-hl-line-mode)
Use the diff-hl
package to highlight changed-and-uncommitted lines when
programming.
(use-package diff-hl
:config
(add-hook 'prog-mode-hook 'turn-on-diff-hl-mode)
(add-hook 'vc-dir-mode-hook 'turn-on-diff-hl-mode))
I use a few packages in virtually every programming or writing environment to manage the project, handle auto-completion, search for terms, and deal with version control. That’s all in here.
Set up ag
for displaying search results.
(use-package ag)
Use company-mode
everywhere.
(use-package company)
(add-hook 'after-init-hook 'global-company-mode)
Use M-/
for completion.
(global-set-key (kbd "M-/") 'company-complete-common)
Git interface
(use-package magit)
I like shallow indentation, but tabs are displayed as 8 characters by default. This reduces that.
(setq-default tab-width 4)
Treating terms in CamelCase symbols as separate words makes editing a little
easier for me, so I like to use subword-mode
everywhere.
(use-package subword
:config (global-subword-mode 1))
Compilation output goes to the *compilation*
buffer. I rarely have that window
selected, so the compilation output disappears past the bottom of the window.
This automatically scrolls the compilation window so I can always see the
output.
(setq compilation-scroll-output t)
(use-package company-tabnine :ensure t)
(add-to-list 'company-backends #'company-tabnine)
Tree layout file explorer (For Java Development for now)
(use-package treemacs
:ensure t
:defer t
:init
(with-eval-after-load 'winum
(define-key winum-keymap (kbd "M-0") #'treemacs-select-window))
:config
(progn
(setq treemacs-collapse-dirs (if treemacs-python-executable 3 0)
treemacs-deferred-git-apply-delay 0.5
treemacs-display-in-side-window t
treemacs-eldoc-display t
treemacs-file-event-delay 5000
treemacs-file-follow-delay 0.2
treemacs-follow-after-init t
treemacs-git-command-pipe ""
treemacs-goto-tag-strategy 'refetch-index
treemacs-indentation 2
treemacs-indentation-string " "
treemacs-is-never-other-window nil
treemacs-max-git-entries 5000
treemacs-missing-project-action 'ask
treemacs-no-png-images nil
treemacs-no-delete-other-windows t
treemacs-project-follow-cleanup nil
treemacs-persist-file (expand-file-name ".cache/treemacs-persist" user-emacs-directory)
treemacs-position 'left
treemacs-recenter-distance 0.1
treemacs-recenter-after-file-follow nil
treemacs-recenter-after-tag-follow nil
treemacs-recenter-after-project-jump 'always
treemacs-recenter-after-project-expand 'on-distance
treemacs-show-cursor nil
treemacs-show-hidden-files t
treemacs-silent-filewatch nil
treemacs-silent-refresh nil
treemacs-sorting 'alphabetic-desc
treemacs-space-between-root-nodes t
treemacs-tag-follow-cleanup t
treemacs-tag-follow-delay 1.5
treemacs-width 35)
;; The default width and height of the icons is 22 pixels. If you are
;; using a Hi-DPI display, uncomment this to double the icon size.
;;(treemacs-resize-icons 44)
(treemacs-follow-mode t)
(treemacs-filewatch-mode t)
(treemacs-fringe-indicator-mode t)
(pcase (cons (not (null (executable-find "git")))
(not (null treemacs-python-executable)))
(`(t . t)
(treemacs-git-mode 'deferred))
(`(t . _)
(treemacs-git-mode 'simple))))
:bind
(:map global-map
("M-0" . treemacs-select-window)
("C-x t 1" . treemacs-delete-other-windows)
("C-x t t" . treemacs)
("C-x t B" . treemacs-bookmark)
("C-x t C-t" . treemacs-find-file)
("C-x t M-t" . treemacs-find-tag)))
(use-package treemacs-projectile
:after treemacs projectile
:ensure t)
(use-package treemacs-icons-dired
:after treemacs dired
:ensure t
:config (treemacs-icons-dired-mode))
(use-package treemacs-magit
:after treemacs magit
:ensure t)
Emacs Java IDE using Eclipse JDT Language Server See Github lsp-java
(use-package lsp-mode)
(use-package hydra)
(use-package company-lsp)
(use-package lsp-ui)
(use-package lsp-java :after (lsp)
:config (add-hook 'java-mode-hook 'lsp))
(use-package dap-mode
:after lsp-mode
:config
(dap-mode t)
(dap-ui-mode t))
(require 'dap-java)
(use-package lsp-treemacs)
(use-package web-mode)
(use-package emmet-mode)
(use-package js2-mode)
Indent by 2 spaces.
(use-package css-mode
:config
(setq css-indent-offset 2))
Don’t compile the current SCSS file every time I save.
(use-package scss-mode
:config
(setq scss-compile-at-save nil))
Install Less.
(use-package less-css-mode)
Install go-mode
and related packages:
(use-package go-mode)
(use-package go-errcheck)
(use-package company-go)
(add-to-list 'company-backends 'company-go)
(use-package flycheck
:ensure t
:init (global-flycheck-mode))
(use-package go-eldoc)
(add-hook 'go-mode-hook 'go-eldoc-setup)
(set-face-attribute 'eldoc-highlight-function-argument nil
:underline t :foreground "green"
:weight 'bold)
Define my $GOPATH
and tell Emacs where to find the Go binaries.
(setenv "GOPATH" "/home/flofeld/go")
(hrs/append-to-path (concat (getenv "GOPATH") "/bin"))
Run goimports
on every file when saving, which formats the file and
automatically updates the list of imports. This requires that the goimports
binary be installed.
(setq gofmt-command "goimports")
(add-hook 'before-save-hook 'gofmt-before-save)
When I open a Go file,
- Start up
company-mode
with the Go backend. This requires that thegocode
binary is installed, - Redefine the default
compile
command to something Go-specific, and - Enable
flycheck
.
(add-hook 'go-mode-hook
(lambda ()
(set
(company-mode)
(if (not (string-match "go" compile-command))
(set (make-local-variable 'compile-command)
"go build -v && go test -v && go vet"))
(flycheck-mode))))
Config for company-go
(when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize))
(use-package company-go)
;;For company-go
(require 'company)
(require 'company-go)
(use-package company
:defer 2
:diminish
:custom
(company-begin-commands '(self-insert-command))
(company-echo-delay 0) ; remove annoying blinking
(company-idle-delay .1)
(company-minimum-prefix-length 1)
(company-show-numbers t)
(company-tooltip-align-annotations 't)
(company-tooltip-limit 20)
(company-begin-commands '(self-insert-command))
(global-company-mode t))
(add-hook 'go-mode-hook
(lambda ()
(company-mode)))
Company extensions for C
; (use-package company-rtags
; :config (add-to-list 'company-backends 'company-rtags))
(use-package company-c-headers
:config (add-to-list 'company-backends 'company-c-headers))
; (use-package flycheck-rtags)
(use-package irony)
(use-package flycheck-irony)
(eval-after-load 'flycheck
'(add-hook 'flycheck-mode-hook #'flycheck-irony-setup))
(use-package company-irony
:config (add-to-list 'company-backends 'company-irony))
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
Install coffee-mode
from editing CoffeeScript code.
(use-package coffee-mode)
Indent everything by 2 spaces.
(setq js-indent-level 2)
(add-hook 'coffee-mode-hook
(lambda ()
(yas-minor-mode 1)
(setq coffee-tab-width 2)))
I like to use paredit
in Lisp modes to balance parentheses (and more!).
(use-package paredit)
rainbow-delimiters
is convenient for coloring matching parentheses.
(use-package rainbow-delimiters)
All the lisps have some shared features, so we want to do the same things for
all of them. That includes using paredit
, rainbow-delimiters
, and
highlighting the whole expression when point is on a parenthesis.
(setq lispy-mode-hooks
'(clojure-mode-hook
emacs-lisp-mode-hook
lisp-mode-hook
scheme-mode-hook))
(dolist (hook lispy-mode-hooks)
(add-hook hook (lambda ()
(setq show-paren-style 'expression)
(paredit-mode)
(rainbow-delimiters-mode))))
If I’m writing in Emacs lisp I’d like to use eldoc-mode
to display
documentation.
(use-package eldoc
:config
(add-hook 'emacs-lisp-mode-hook 'eldoc-mode))
I also like using flycheck-package
to ensure that my Elisp packages are
correctly formatted.
(use-package flycheck-package)
(eval-after-load 'flycheck
'(flycheck-package-setup))
(use-package company-edbi
:config (add-to-list 'company-backends 'company-edbi))
Fix Agenda Shortcut
(require 'org-agenda)
(global-set-key "\C-ca" 'org-agenda)
(use-package org)
I like to see an outline of pretty bullets instead of a list of asterisks.
(use-package org-bullets
:init
(add-hook 'org-mode-hook 'org-bullets-mode))
I like seeing a little downward-pointing arrow instead of the usual ellipsis
(...
) that org displays when there’s stuff under a header.
(setq org-ellipsis "⤵")
Use syntax highlighting in source blocks while editing.
(setq org-src-fontify-natively t)
Make TAB act as if it were issued in a buffer of the language’s major mode.
(setq org-src-tab-acts-natively t)
When editing a code snippet, use the current window rather than popping open a new one (which shows the same information).
(setq org-src-window-setup 'current-window)
Record the time that a todo was archived.
(setq org-log-done 'time)
Allow export to markdown and beamer (for presentations).
(require 'ox-md)
(require 'ox-beamer)
(org-babel-do-load-languages ‘org-babel-load-languages ‘((emacs-lisp . t)))
Translate regular ol’ straight quotes to typographically-correct curly quotes when exporting.
(setq org-export-with-smart-quotes t)
Don’t include a footer with my contact and publishing information at the bottom of every exported HTML document.
(use-package htmlize)
(setq org-html-postamble nil)
enable latex
;(load "auctex.el" nil t t)
;(load "preview-latex.el" nil t t)
(customize-set-value 'org-latex-with-hyperref nil)
(require 'ox-latex)
(unless (boundp 'org-latex-classes)
(setq org-latex-classes nil))
(add-to-list 'org-latex-classes
'("article"
"\\documentclass{article}"
("\\section{%s}" . "\\section*{%s}")))
I want to produce PDFs with syntax highlighting in the code. The best way to do
that seems to be with the minted
package, but that package shells out to
pygments
to do the actual work. pdflatex
usually disallows shell commands;
this enables that.
(setq org-latex-pdf-process
'("xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
Include the minted
package in all of my LaTeX exports.
(add-to-list 'org-latex-packages-alist '("" "minted"))
(setq org-latex-listings 'minted)
I rarely write LaTeX directly any more, but I often export through it with org-mode, so I’m keeping them together.
Automatically parse the file after loading it.
(setq TeX-parse-self t)
Always use pdflatex
when compiling LaTeX documents. I don’t really have any
use for DVIs.
(setq TeX-PDF-mode t)
Open compiled PDFs in okular
instead of in the editor.
(add-hook 'org-mode-hook
'(lambda ()
(delete '("\\.pdf\\'" . default) org-file-apps)
(add-to-list 'org-file-apps '("\\.pdf\\'" . "okular %s"))))
AutoFillMode
automatically wraps paragraphs, kinda like hitting M-q
. I wrap
a lot of paragraphs, so this automatically wraps ‘em when I’m writing text,
Markdown, or Org.
(add-hook 'text-mode-hook 'auto-fill-mode)
(add-hook 'gfm-mode-hook 'auto-fill-mode)
(add-hook 'org-mode-hook 'auto-fill-mode)
(hrs/append-to-path "/usr/local/bin")
Using save-place-mode
saves the location of point for every file I visit. If I
close the file or close the editor, then later re-open it, point will be at the
last place I visited.
(save-place-mode t)
When splitting a window, I invariably want to switch to the new window. This makes that automatic.
(defun hrs/split-window-below-and-switch ()
"Split the window horizontally, then switch to the new pane."
(interactive)
(split-window-below)
(balance-windows)
(other-window 1))
(defun hrs/split-window-right-and-switch ()
"Split the window vertically, then switch to the new pane."
(interactive)
(split-window-right)
(balance-windows)
(other-window 1))
(global-set-key (kbd "C-x 2") 'hrs/split-window-below-and-switch)
(global-set-key (kbd "C-x 3") 'hrs/split-window-right-and-switch)
Install and enable smart-parens
globally
(use-package smartparens)
(require 'smartparens-config)
(smartparens-global-mode t)
For quickly inserting snippets for C, C++, Perl, Python, Ruby, SQL, Latex, HTML, Css…
(use-package yasnippet)
(use-package yasnippet-snippets)
(yas-minor-mode t)
Show syntax errors
(use-package flycheck)
(global-flycheck-mode t)