Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
291 lines (239 sloc) 8.39 KB

General configuration

These are my settings that are called in dotspacemacs/user-config. This function is called at the very end of Spacemacs initialization after layers configuration.

General

Hitting TAB always just indents the current line.

(setq tab-always-indent t)

Only one auth source for magit & co.

(setq auth-sources '("~/.netrc"))

Utf-8

(prefer-coding-system 'utf-8)

Enable line wrapping

(setq truncate-lines nil)

Appearance

Clean up spaceline contents.

(with-eval-after-load 'spaceline-segments
  (spaceline-toggle-minor-modes-off)
  (spaceline-toggle-buffer-size-off))

Major Mode Settings

Ruby

Don’t automatically insert the magic encoding comment.

(setq ruby-insert-encoding-magic-comment nil)

Keybinding to toggle between new and old hash syntax.

(evil-leader/set-key
  "xrh" 'ruby-toggle-hash-syntax)

Underscore should be a word delimiter in slim.

(add-hook 'slim-mode-hook #'(lambda () (modify-syntax-entry ?_ "_")))

Elixir

Better formatting for test output buffers.

(setq alchemist-test-truncate-lines nil)

Call elixir-format before save.

(add-hook 'elixir-mode-hook
          (lambda () (add-hook 'before-save-hook 'elixir-format nil t)))

Go

Set tab width to 4.

(setq-default tab-width 4)

Call go-format before save.

(setq go-format-before-save t)

Enable flycheck for Go mode.

(add-hook 'go-mode-hook
          (lambda () (flycheck-mode 1)))

Web Mode

Intendation settings

(setq web-mode-css-indent-offset 2)
(setq js2-basic-offset 2)
(setq web-mode-markup-indent-offset 2)
(setq web-mode-code-indent-offset 2)
(setq css-indent-offset 2)
(setq-default js2-basic-offset 2
              js-indent-level 2)

JavaScript

Allow .dir-locals.el files to set prettier-related settings.

(put 'prettier-js-args 'safe-local-variable 'listp)
(put 'prettier-js-command 'safe-local-variable 'stringp)

Setup nodejs-repl.el keybindings.

(spacemacs/set-leader-keys-for-major-mode 'js2-mode "ne" 'nodejs-repl-send-last-expression)
(spacemacs/set-leader-keys-for-major-mode 'js2-mode "nl" 'nodejs-repl-send-line)
(spacemacs/set-leader-keys-for-major-mode 'js2-mode "nr" 'nodejs-repl-send-region)
(spacemacs/set-leader-keys-for-major-mode 'js2-mode "nb" 'nodejs-repl-send-buffer)
(spacemacs/set-leader-keys-for-major-mode 'js2-mode "nf" 'nodejs-repl-load-file)
(spacemacs/set-leader-keys-for-major-mode 'js2-mode "n'" 'nodejs-repl-switch-to-repl)
(spacemacs/set-leader-keys-for-major-mode 'js2-mode "ns" 'nodejs-repl-switch-to-repl)

SQL

The sqlfmt does not work very well with Postgres and is also outdated. This uses pgFormatter instead, installed with brew install pgformatter.

(setq sqlfmt-executable "pg_format")
(setq sqlfmt-options '())

Keybindings

Movements

Make evil-mode up/down operate in screen lines instead of logical lines.

(define-key evil-motion-state-map "j" 'evil-next-visual-line)
(define-key evil-motion-state-map "k" 'evil-previous-visual-line)

Also in visual mode…

(define-key evil-visual-state-map "j" 'evil-next-visual-line)
(define-key evil-visual-state-map "k" 'evil-previous-visual-line)

Move line under cursor with C-j/k.

(define-key evil-normal-state-map (kbd "C-j") 'move-text-down)
(define-key evil-normal-state-map (kbd "C-k") 'move-text-up)

Pressing H in any edit mode moves the cursor to the first non-blank character.

(evil-global-set-key 'normal "H" 'evil-first-non-blank)
(evil-global-set-key 'visual "H" 'evil-first-non-blank)
(evil-global-set-key 'motion "H" 'evil-first-non-blank)

Pressing L in any edit mode moves the cursor to the end of line.

(evil-global-set-key 'normal "L" (lambda () (interactive) (evil-end-of-line)))
(evil-global-set-key 'visual "L" (lambda () (interactive) (evil-end-of-line)))
(evil-global-set-key 'motion "L" (lambda () (interactive) (evil-end-of-line)))

Type g l to get a fast home row friendly jump menu to go to a visible line.

(define-key evil-motion-state-map "gl" 'evil-avy-goto-line)
(define-key evil-normal-state-map "gl" 'evil-avy-goto-line)

Type g o <char> <char> to get a fast home row friendly jump menu to go to a visible word that starts with these characters.

(define-key evil-motion-state-map "go" 'evil-avy-goto-char-2)
(define-key evil-normal-state-map "go" 'evil-avy-goto-char-2)

Macros

Type Q to execute the macro recorded to q.

(evil-global-set-key 'normal (kbd "Q") (lambda () (interactive) (evil-execute-macro 1 "@q")))

Dired

In dired, move to parent directory with h and open thing under cursor with l.

(with-eval-after-load 'dired
  (evil-define-key 'normal dired-mode-map
    "h" 'dired-up-directory
    "l" 'dired-find-file
    )
  )

Umlauts

Make Umlauts work like in the rest of MacOS.

(global-unset-key (kbd "M-s"))
(global-set-key (kbd "M-s")
                (lambda ()
                  "Insert ß."
                  (interactive)
                  (insert "ß")))
(global-unset-key (kbd "M-u"))
(global-set-key (kbd "M-u a")
                (lambda ()
                  "Insert ä."
                  (interactive)
                  (insert "ä")))
(global-set-key (kbd "M-u A")
                (lambda ()
                  "Insert Ä."
                  (interactive)
                  (insert "Ä")))
(global-set-key (kbd "M-u o")
                (lambda ()
                  "Insert ö."
                  (interactive)
                  (insert "ö")))
(global-set-key (kbd "M-u O")
                (lambda ()
                  "Insert Ö."
                  (interactive)
                  (insert "Ö")))
(global-set-key (kbd "M-u u")
                (lambda ()
                  "Insert ü."
                  (interactive)
                  (insert "ü")))
(global-set-key (kbd "M-u U")
                (lambda ()
                  "Insert Ü."
                  (interactive)
                  (insert "Ü")))

Misc

Set hippie expand from M-/ to ctrl-space.

(global-set-key (kbd "C-SPC") 'hippie-expand)

Emojis

Overwrite emoji settings.

(defun --set-emoji-font (frame)
  "Adjust the font settings of FRAME so Emacs can display emoji properly."
  (if (eq system-type 'darwin)
      ;; For NS/Cocoa
      (set-fontset-font t 'symbol (font-spec :family "Apple Color Emoji" :size 10) frame 'prepend)
    ;; For Linux
    (set-fontset-font t 'symbol (font-spec :family "Symbola") frame 'prepend)))

;; For when Emacs is started in GUI mode:
(--set-emoji-font nil)
;; Hook for when a frame is created with emacsclient
;; see https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Frames.html
(add-hook 'after-make-frame-functions '--set-emoji-font)
(setq company-emoji-insert-unicode t)

Custom Functions

Helper functions that I call directly with SPC SPC.

Switch between Rails i18n files

This function switches between the German and the English translation file in a Rails project. Especially handy, if the project has a lot of files per language.

(defun switch-rails-i18n-file()
  "Switches to the i18n file in the other language"
  (interactive)
  (if (search "/de/" buffer-file-name)
    (find-file (replace-regexp-in-string "/de/" "/en/" (buffer-file-name)))
    (find-file (replace-regexp-in-string "/en/" "/de/" (buffer-file-name))))
  )

Finalization

In the end, satisfy the Spacemacs loading mechanism.

(provide 'my-general-config)
You can’t perform that action at this time.