Skip to content

Latest commit

 

History

History
391 lines (336 loc) · 9.47 KB

File metadata and controls

391 lines (336 loc) · 9.47 KB

Emacs Config

Initial config

(setq user-full-name "Mathias Nielsen")

Always use y or n instead of yes and no

(defalias 'yes-or-no-p 'y-or-n-p)

Benchmark init

(use-package benchmark-init)

OSX

 (when (eq system-type 'darwin)
   (setq ns-command-modifier 'meta
	ns-option-modifier 'super
	ns-right-option-modifier 'none))

Recentf

(use-package recentf
  :straight (:type built-in)
  :init
  :config
  (recentf-mode 1))

Auto-save-mode

(use-package simple
  :straight (:type built-in)
  :init
  (setq auto-save-file-name-transforms `((".*" ,(expand-file-name ".local/auto-save/" user-emacs-directory)))))

Use Package

Interface

Setup Frame

(let ((font (font-spec :family "Source Code Pro" :size 12)))
  (setq default-frame-alist `((top . 120)
				  (left . 400)
				  (width . 128)
				  (height . 50)
				  (font . "Fira Code-14"))))

Setup “window”

Hide toolbar

(use-package tool-bar
  :straight (:type built-in)
  :config
  (tool-bar-mode -1))

Hide scroll-bar

(use-package scroll-bar
  :straight (:type built-in)
  :config
  (scroll-bar-mode -1))

Theme

;; Doom Themes
  (use-package doom-themes
    :defer t
    :init
    (add-hook 'after-init-hook (lambda () (load-theme
    'doom-palenight t nil))))
(use-package modus-operandi-theme
  :init
  (setq ))

Modeline

(use-package doom-modeline)

General Packages

Smartparens Mode

(use-package smartparens
  :defer t
  :hook (prog-mode . turn-on-smartparens-mode)
  (text-mode . turn-on-smartparens-mode)
  (minibuffer-setup . turn-on-smartparens-mode)
  :config
  (with-eval-after-load 'text-mode
    (require 'smartparens-text))
  ;; disable ' char in lisp mode
  (sp-with-modes sp-lisp-modes
    (sp-local-pair "'" nil :actions nil)
    (sp-local-pair "`" nil :actions nil))
  (show-smartparens-global-mode 1))

Company

(use-package company
  :defer t
  :hook (prog-mode . company-mode)
  (text-mode . company-mode)
  :init
  (setq company-show-numbers t
	  company-idle-delay 0.0)
  :bind (:map company-active-map
		("C-n" . company-select-next)
		("C-p" . company-select-previous)))

Yasnippet

(use-package yasnippet
  :defer t
  :init
  (setq yas-snippet-dirs (expand-file-name ".snippets/" user-emacs-directory)))

Helpful

(use-package helpful
  :defer t
  :init
  (setq counsel-describe-function-function #'helpful-callable
	  counsel-describe-variable-function #'helpful-variable)
  (with-eval-after-load 'evil
    (setq evil-lookup-func #'helpful-at-point)))

Completion

Ivy

I like to use Ivy

(use-package ivy
  :init
  ;; Set initial input to nil
  (setq ivy-initial-inputs-alist nil)
  :config
  (ivy-mode 1))

And Ivy rich to display more information

(use-package ivy-rich
    :after ivy counsel
    :init
    (setq ivy-rich-display-transformers-list '(ivy-switch-buffer
					       (:columns
						((ivy-switch-buffer-transformer (:width 30))    ; add face by the original transformer
						 (ivy-rich-switch-buffer-size (:width 7))  ; return buffer size
						 (ivy-rich-switch-buffer-indicators (:width 4 :face error :align right))  ; return buffer indicator
						 (ivy-rich-switch-buffer-major-mode (:width 12 :face warning))            ; return major mode info
						 (ivy-rich-switch-buffer-project (:width 15 :face success))               ; return project name `projectile'
						 (ivy-rich-switch-buffer-path (:width (lambda (x) (ivy-rich-switch-buffer-shorten-path x (ivy-rich-minibuffer-width 0.3))))))  ; return file path relative to project root or `default-directory' if project is nil
						:predicate
						(lambda (cand) (get-buffer cand)))
					       counsel-find-file
					       (:columns
						((ivy-read-file-transformer)
						 (ivy-rich-counsel-find-file-truename (:face font-lock-doc-face))))
					       counsel-M-x
					       (:columns
						((counsel-M-x-transformer (:width 40))
						 (ivy-rich-counsel-function-docstring (:face font-lock-doc-face)))) ; return docstring of the command
					       counsel-describe-function
					       (:columns
						((counsel-describe-function-transformer (:width 40))
						 (ivy-rich-counsel-function-docstring (:face font-lock-doc-face))))  ; return docstring of the function
					       counsel-describe-variable
					       (:columns
						((counsel-describe-variable-transformer (:width 40))
						 (ivy-rich-counsel-variable-docstring (:face font-lock-doc-face))))  ; return docstring of the variable
					       counsel-recentf
					       (:columns
						((ivy-rich-candidate (:width 0.8))
						 (ivy-rich-file-last-modified-time (:face font-lock-comment-face))))  ; return last modified time of the file
					       package-install
					       (:columns
						((ivy-rich-candidate (:width 30))
						 (ivy-rich-package-version (:width 16 :face font-lock-comment-face))  ; return package version
						 (ivy-rich-package-archive-summary (:width 7 :face font-lock-builtin-face))  ; return archive summary
						 (ivy-rich-package-install-summary (:face font-lock-doc-face))))))  ; return package description
	  :config
	  (ivy-rich-mode 1))

Counsel

(use-package counsel
  :after ivy
  :bind
  ("M-x" . counsel-M-x)
  ("C-x C-f" . counsel-find-file)
  ("C-x b" . counsel-switch-buffer)
  ("C-h f" . counsel-describe-function)
  ("C-h v" . counsel-describe-variable)
  ("C-h b" . counsel-descbinds)
  :config
  (setq ivy-initial-inputs-alist nil))

Keybindings

;;;###autoload
(defun mnie/escape ()
  "Do what I mean when I press ESCAPE."
  (cond ((minibuffer-window-active-p (minibuffer-window))
	   (minibuffer-keyboard-quit))
	  ((keyboard-quit))))

(global-set-key [remap keyboard-quit] #'mnie/escape)

General

Use general to bind keys

(use-package general)


(defmacro set-leader-keys! (&rest keys)
  "Set add keys to leader-key"
 `(general-define-key
:prefix "SPC"
 :non-normal-prefix "M-SPC"
 :states '(normal motion insert replace emacs)
 :keymaps 'override
 ,@keys))

(defmacro set-localleader-keys! (map &rest keys)
  "Set add keys to leader-key"
 `(general-define-key
 :prefix "SPC m"
 :non-normal-prefix "M-SPC m"
 :states '(normal motion insert replace emacs)
 :keymaps ,map
 ,@keys))

(set-leader-keys!
 "w" '(:ignore t :wk "window")
 "wd" 'delete-window
 "wh" 'evil-window-left)

(general-define-key
 :prefix "SPC"
 :non-normal-prefix "M-SPC"
 :states '(normal motion insert replace emacs)
 :keymaps 'override
 "b" '(:ignore t :wk "buffer")
  "bb" 'counsel-switch-buffer
  "bd" 'kill-current-buffer)
(let (keys
        key
        function
        wk)
    (dolist (binding bindings keys)
      (setq key (car binding))
      (if (eq (cadr binding) "")
          (setq function '(:ignore t))
        (setq function (intern (cadr binding))))
      (setq wk (nth 2 binding))
      (unless (or (eq wk nil)
               (eq wk ""))
        (setq function (append function `(:wk ,wk)))))
      (add-to-list 'keys key t)
      (add-to-list 'keys function t))
    )
KeyFunctionWhich-key
ffiles
fssave-buffer
fffind-file
<<set-leader-keys!>>

Evil

Use evil mode

(use-package evil
  :init
  (setq evil-want-keybinding nil
	  evil-want-integration t
	  evil-want-Y-yank-to-eol t)
  :config
  (evil-mode 1))

And evil collection to use evil bindings in more modes

(use-package evil-collection
  :after evil
  :config
  (evil-collection-init))

(use-package evil-escape
:after evil
:config
(evil-escape-mode 1))

(use-package evil-snipe)

Which-key

(use-package which-key
  :config
  (which-key-mode 1))

Test Bindings from table

KeyFunction
C-x g gmagit-status
(mapc (lambda (k) (evil-define-key nil 'global (kbd (nth 0 k)) (intern (nth 1 k)))) keys)

Version Control

Git

(use-package magit
  :defer t
  :bind
  ("C-x g" . magit-status))
(use-package evil-magit
  :after magit)

Major Modes

Programming Modes

Emacs lisp

(use-package elisp-mode
  :straight (:type built-in))

Text Modes

(use-package text-mode
  :straight (:type built-in))

Org Mode

Hledger mode

(use-package hledger-mode
  :defer t
  :mode "\\.hledger$")