Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

6.3 KiB

Editing

IEdit mode

  (use-package iedit
    :bind ("C-;" . iedit-mode))

Spellcheck

  (global-set-key (kbd "C-!") 'ispell-buffer)

Undo tree

  (use-package undo-tree
    :config
    (global-undo-tree-mode))

Save/load

Backup/auto-save

  (let ((backup-dir "~/.emacs.d/backup")
	(auto-save-dir "~/.emacs.d/autosave"))
    (if (not (file-directory-p backup-dir))
	(make-directory backup-dir))
    (if (not (file-directory-p
	      auto-save-dir))
	(make-directory auto-save-dir)))

On save

  (add-hook 'before-save-hook 'delete-trailing-whitespace)

Recent files mode

  (use-package recentf
    :config
    (recentf-mode 1))

Platform dependant

Windows

  (when (string-equal system-type "windows-nt")
    (progn
      (defun rlbr/quote-exe (path)
	(w32-short-file-name path))
      (defun rlbr/start-external-shell ()
	(interactive)
	(start-process-shell-command (format "cmd(%s)" default-directory) nil "start default.bat"))
      (global-set-key (kbd "C-S-C") 'rlbr/start-external-shell)
      (defun rlbr/start-windows-explorer-here ()
	(interactive)
	(start-process-shell-command "explorer" nil (format "explorer %s" (replace-regexp-in-string "/" (regexp-quote "\\") (expand-file-name default-directory)))))
      (global-set-key (kbd "C-S-E") 'rlbr/start-windows-explorer-here)
      (defun rlbr/case-insensitive-match (string1 string2)
	(apply 'string-equal (mapcar 'downcase (list string1 string2))))
      (defun rlbr/output-matches (output-matches-p exe args)
	"locate the executable whose output satifies output-matches-p when fed args and return the fullpath"
	(let ((exec-path exec-path)
	      (output)
	      (bad)
	      (command-output)
	      (current-exe)
	      (failed))
	  (while (not (or output failed))
	    (setq current-exe
		  (executable-find exe))
	    (if current-exe
		(progn
		  (setq command-output
			(shell-command-to-string (format "%s %s" (rlbr/quote-exe current-exe) args)))
		  (if (funcall output-matches-p command-output)
		      (setq output current-exe)
		    (progn
		      (setq bad
			    (replace-regexp-in-string "/$" "" (file-name-directory current-exe)))
		      (setq exec-path
			    (seq-filter (lambda (item) (not (rlbr/case-insensitive-match item bad))) exec-path)))))
	      (setq failed t)))
	  output))
      (let ((find)
	    (grep)
	    (ls))
	(progn
	  (setq find
		(rlbr/output-matches
		 (lambda (output) (string-equal ".\n" output))
		 "find" "-maxdepth 0"))
	  (if find
	      (setq find-program (rlbr/quote-exe find)))
	  (setq grep (rlbr/output-matches
		      (lambda (output) (string-match "grep (\\w+ grep)" output))
		      "grep" "-V"))
	  (if grep
	      (setq grep-program
		    (rlbr/quote-exe grep)))
	  (setq ls (rlbr/output-matches
		    (lambda (output) (string-match "ls: .*'\\?/': No such file or directory" output))
		    "ls" "?/"))
	  (if ls
	      (setq insert-directory-program (rlbr/quote-exe ls)))))))

Major modes

Java

JavaScript

Magit

  (use-package magit
    :bind (("C-x g" . magit-status))
    :config
    (use-package git-commit
      :hook (git-commit-setup . git-commit-turn-on-flyspell)))

Python

Platform specific

  (cond
   ((string-equal system-type "gnu/linux")
    "python3")
   ((string-equal system-type "windows-nt")
    "python.exe"))

custom feature

bindings/settings

  (use-package python
    :config
    (use-package elpy
      :bind (("C-=" . elpy-goto-assignment))
      :config (when (require 'flycheck nil t)
		(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))))
    (elpy-enable)
    (blacken-mode))

SSH config mode

  (use-package ssh-config-mode
    :mode "~/.ssh/config\\'")

Tramp

Webmode

YAML

  (use-package yaml-mode
    :mode "\\.yml\\'")

Minor modes/misc

Kill the things

Buffer

(global-set-key (kbd "C-x k") 'kill-this-buffer)

Emacs

(global-set-key (kbd "C-x C-k C-x C-k") 'kill-emacs)

Lispy

  (use-package lispy
    :hook ((emacs-lisp-mode) . lispy-mode))

Navigation/autocompletion

Ace window

  (use-package ace-window
    :bind (("M-Q" . ace-window)))

Hippie expand

  (use-package hippie-exp
    :bind ("M-/" . hippie-expand))

IBuffer mode

  (use-package ibbufer-vc
    :hook ((ibuffer-mode . ibuffer-vc-set-filter-groups-by-vc-root)))
  (use-package ibuffer
    :bind (("C-x C-b" . ibuffer))
    :config
    (define-ibuffer-column size-h
      ;; Use human readable Size column instead of original one
      (:name "Size" :inline t)
      (cond ((> (buffer-size) 1000000)
	     (format "%7.1fM" (/ (buffer-size) 1000000.0)))
	    ((> (buffer-size) 100000)
	     (format "%7.0fk" (/ (buffer-size) 1000.0)))
	    ((> (buffer-size) 1000)
	     (format "%7.1fk" (/ (buffer-size) 1000.0)))
	    (t
	     (format "%8d" (buffer-size))))))

Ivy

  (use-package ivy
    :config
    (use-package swiper
      :bind ("C-s" . swiper))
    (ivy-mode))

Look and feel

Line numbers

  (global-display-line-numbers-mode)

Mode line bell

  (use-package mode-line-bell
    :config
    (mode-line-bell-mode))

Spaceline

  (use-package spaceline-config
    :config
    (use-package winum
      :init
      (setq winum-keymap
	    (let ((map (make-sparse-keymap)))
	      (define-key map (kbd "M-0") 'winum-select-window-0-or-10)
	      (define-key map (kbd "M-1") 'winum-select-window-1)
	      (define-key map (kbd "M-2") 'winum-select-window-2)
	      (define-key map (kbd "M-3") 'winum-select-window-3)
	      (define-key map (kbd "M-4") 'winum-select-window-4)
	      (define-key map (kbd "M-5") 'winum-select-window-5)
	      (define-key map (kbd "M-6") 'winum-select-window-6)
	      (define-key map (kbd "M-7") 'winum-select-window-7)
	      (define-key map (kbd "M-8") 'winum-select-window-8)
	      map)))
    (spaceline-spacemacs-theme)
    (winum-mode))