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.
8.5 KiB
8.5 KiB
- Editing
- Save/load
- Platform dependant
- Tramp configuration
- Major modes
- Minor modes/misc
- Navigation/autocompletion
- Look and feel
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)))))))
Tramp configuration
Tramp append plist to connection properties
(require 'kv)
(defun rlbr/add-config-to-tramp (matches-regexp config-plist)
(let ((config-alist (kvplist->alist config-plist)))
(dolist (pair config-alist)
(let ((config (list
matches-regexp
(car pair)
(cdr pair))))
(add-to-list
'tramp-connection-properties
config)))))
Android
(let ((android-config (let ((default-directory "/data/data/com.termux/files"))
(list "tmpdir" (expand-file-name "home/temp/")
"remote-shell" (expand-file-name "usr/bin/sh")
"remote-process-environment" (append (list (concat "PREFIX=" default-directory "usr")) tramp-remote-process-environment)
"remote-path" (append (mapcar 'expand-file-name '("home/.local/bin" "usr/bin" "usr/bin/applets")) '("/sbin" "/vendor/bin" "/system/sbin" "/system/bin" "/system/xbin"))))))
(rlbr/add-config-to-tramp "/ssh:termux.*:" android-config))
Major modes
Java
JavaScript
(use-package js2-mode
:mode "\\.js\\'"
:hook ((js2-mode . js2-imenu-extras-mode)
(js2-mode . (lambda () (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t))))
:config
(use-package js2-refactor
:hook (js2-mode . js2-refactor-mode)
:bind
(:map js2-mode-map
("C-k" . js2r-kill))
:config
(js2r-add-keybindings-with-prefix "C-c C-r"))
(use-package xref-js2
:demand t)
(define-key js-mode-map (kbd "M-.") nil)
(defun rlbr/jump-to-definition ()
"Jump to a definition."
(interactive)
(condition-case-unless-debug nil
(js2-jump-to-definition)
(error
(progn
(ignore-errors
(xref-pop-marker-stack))
(xref-find-definitions (xref-backend-identifier-at-point (xref-find-backend)))))))
(define-key js-mode-map (kbd "M-.") #'rlbr/jump-to-definition))
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
(use-package web-mode
:mode
(("\\.phtml\\'" . web-mode)
("\\.tpl\\.php\\'" . web-mode)
("\\.[agj]sp\\'" . web-mode)
("\\.as[cp]x\\'" . web-mode)
("\\.erb\\'" . web-mode)
("\\.mustache\\'" . web-mode)
("\\.djhtml\\'" . web-mode)
("\\.html?\\'" . web-mode)))
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))