init.el (5823B)
1 ;; base settings 2 (if (display-graphic-p) 3 (progn 4 (tool-bar-mode 0) 5 (scroll-bar-mode 0))) 6 (menu-bar-mode 0) 7 8 (setq make-backup-files nil) 9 (setq auto-save-default nil) 10 11 (setq sentence-end-double-space nil) 12 13 (setq inhibit-startup-screen t) 14 15 (setq vc-follow-symlinks t) 16 17 ;; can use s-<arrow> for window switching 18 (windmove-default-keybindings) 19 20 ;; abbrev mode 21 (setq-default abbrev-mode t) 22 (setq save-abbrevs 'silently) 23 24 ;; isearch settings 25 (setq search-whitespace-regexp ".*") 26 27 ;; dired settings 28 (setq dired-listing-switches "-lap") 29 30 (defun knh-dired-find-file-other-frame () 31 "Open file in dired and move it in another emacs frame" 32 (interactive) 33 (dired-find-file) 34 (display-buffer-use-least-recent-window 35 (current-buffer) nil) 36 (previous-buffer)) 37 38 (add-hook 'dired-mode-hook 39 (lambda () 40 "Dired settings" 41 (dired-hide-details-mode) 42 (define-key dired-mode-map (kbd "M-o") 'knh-dired-find-file-other-frame))) 43 44 ;; settings for packages 45 (require 'package) 46 (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) 47 48 (package-install 'markdown-mode) 49 (require 'markdown-mode) 50 (add-hook 'markdown-mode-hook 'auto-fill-mode) 51 (add-hook 'markdown-mode-hook 'flyspell-mode) 52 53 (defun knh-set-buffer-name-md () 54 "Rename md buffer to their header" 55 (interactive) 56 (save-excursion 57 (beginning-of-buffer) 58 (if (search-forward "# " nil t) 59 (let ((beg (point))) 60 (move-end-of-line nil) 61 (rename-buffer 62 (string-trim (buffer-substring beg (point)))))))) 63 (add-hook 'markdown-mode-hook 'knh-set-buffer-name-md) 64 65 (define-key markdown-mode-map (kbd "M-<up>") 'markdown-previous-visible-heading) 66 (define-key markdown-mode-map (kbd "M-<down>") 'markdown-next-visible-heading) 67 68 (package-install 'howm) 69 (require 'howm) 70 (setq howm-file-name-format "%Y-%m-%d-%H%M%S.md") 71 (setq howm-template "# %title%cursor\n\n%file\n\n") 72 (setq howm-keyword-file (expand-file-name ".howm-keys" howm-directory)) 73 (setq howm-history-file (expand-file-name ".howm-history" howm-directory)) 74 (define-key howm-menu-mode-map "\C-h" nil) 75 (define-key riffle-summary-mode-map "\C-h" nil) 76 (define-key howm-view-contents-mode-map "\C-h" nil) 77 78 (require 'recentf) 79 (recentf-mode 1) 80 (global-set-key (kbd "C-x M-f") 'recentf-open-files) 81 82 (fido-mode t) 83 84 (package-install 'expand-region) 85 (require 'expand-region) 86 (global-set-key (kbd "C-=") 'er/expand-region) 87 88 (package-install 'restclient) 89 (require 'restclient) 90 (require 'misc) 91 (require 'hideshow) 92 93 (require 'eshell) 94 (defalias 'e 'find-file) 95 (setq eshell-destroy-buffer-when-process-dies nil) 96 (setq eshell-visual-subcommands '()) 97 (add-to-list 'eshell-visual-subcommands '("git" "log" "diff" "show")) 98 99 (package-install 'which-key) 100 (require 'which-key) 101 (setq which-key-idle-delay 0.5) 102 (which-key-mode t) 103 104 ;; custom functions and key bindings 105 (global-set-key (kbd "M-o") 'other-window) 106 (global-set-key (kbd "M-z") 'zap-up-to-char) 107 (global-set-key (kbd "M-SPC") 'cycle-spacing) 108 (global-set-key (kbd "C-x C-b") 'buffer-menu-other-window) 109 110 (global-set-key (kbd "M-<f5>") 'compile) 111 (global-set-key (kbd "<f5>") 'recompile) 112 113 (define-key help-mode-map (kbd "n") 'next-line) 114 (define-key help-mode-map (kbd "p") 'previous-line) 115 116 (defun knh/new-line-below () 117 "Insert new line below, without breaking current line" 118 (interactive) 119 (end-of-line) 120 (newline-and-indent)) 121 (global-set-key (kbd "C-c RET") 'knh/new-line-below) 122 123 ;; borrowed from https://www.omarpolo.com/post/emacs-side-window.html 124 (defun op/buffer-to-side-window () 125 "Place the current buffer in the side window at the bottom." 126 (interactive) 127 (let ((buf (current-buffer))) 128 (display-buffer-in-side-window 129 buf '((window-height . 0.25) 130 (side . bottom) 131 (slot . -1) 132 (window-parameters . ((no-delete-other-windows t))))) 133 (delete-window))) 134 135 (defun knh/next-input-mark () 136 "Jump to next '<++>' and delete it." 137 (interactive) 138 (search-forward "<++>") 139 (delete-char -4)) 140 (global-set-key (kbd "C-c C-SPC") 'knh/next-input-mark) 141 142 ;; emacs as shell-editor 143 (eshell) 144 (defun knh/jump-to-shell () 145 "Jump to exist shell buffer, or open new" 146 (interactive) 147 (let ((dir (eshell/pwd))) 148 (eshell) 149 (message dir) 150 (eshell/cd dir) 151 ;; update shell prompt 152 (eshell-interrupt-process))) 153 (global-set-key (kbd "C-x j") 'knh/jump-to-shell) 154 155 (package-install 'todotxt) 156 (require 'todotxt) 157 (global-set-key (kbd "C-x t") 'todotxt) 158 ;you should set todotxt-file 159 160 ;; my hacks for todotxt 161 (defun knh/todotxt-filter-out-all-lists () 162 "Hide all tasks, who already tagged with lists" 163 (interactive) 164 (todotxt-show-incomplete) 165 (cl-flet 166 ((hide (tag) (todotxt-filter (eval `(lambda () (todotxt-current-line-match ,tag)))))) 167 (mapcar #'hide '("+maybe" "+todo" "+waiting")))) 168 169 (defun knh/todotxt-add-text (text) 170 "Add text at the end of task" 171 (let ((new-text (concat (todotxt-get-current-line-as-string) " " text))) 172 (setq inhibit-read-only 't) 173 (todotxt-delete-line) 174 (insert new-text) 175 (if todotxt-save-after-change (save-buffer)) 176 (setq inhibit-read-only nil))) 177 178 (defun knh/todotxt-move-to-todo () 179 "Add +todo tag on task" 180 (interactive) 181 (knh/todotxt-add-text "+todo")) 182 183 (defun knh/todotxt-move-to-maybe () 184 "Add +maybe tag on task" 185 (interactive) 186 (knh/todotxt-add-text "+maybe")) 187 188 (defun knh/todotxt-move-to-waiting () 189 "Add +waiting tag on task" 190 (interactive) 191 (knh/todotxt-add-text "+waiting")) 192 193 (defun knh/todotxt-mark-active () 194 "Add +active tag on task" 195 (interactive) 196 (knh/todotxt-add-text "+active")) 197 198 (define-key todotxt-mode-map (kbd "I") 'knh/todotxt-filter-out-all-lists) 199 (define-key todotxt-mode-map (kbd "T") 'knh/todotxt-move-to-todo) 200 (define-key todotxt-mode-map (kbd "M") 'knh/todotxt-move-to-maybe) 201 (define-key todotxt-mode-map (kbd "W") 'knh/todotxt-move-to-waiting) 202 (define-key todotxt-mode-map (kbd "A") 'knh/todotxt-mark-active)