config-editing.el (6286B)
1 ;;; config-editing.el --- -*- lexical-binding: t; -*- 2 ;;; Commentary: 3 ;;; Editing configuration 4 ;;; Code: 5 6 (setq-default enable-remote-dir-locals t) 7 8 ;; When finding file in non-existing directory, offer to create the 9 ;; parent directory. 10 (defun with-buffer-name-prompt-and-make-subdirs () 11 (let ((parent-directory (file-name-directory buffer-file-name))) 12 (when (and (not (file-exists-p parent-directory)) 13 (y-or-n-p (format "Directory `%s' does not exist! Create it? " parent-directory))) 14 (make-directory parent-directory t)))) 15 16 (add-to-list 'find-file-not-found-functions #'with-buffer-name-prompt-and-make-subdirs) 17 18 ;; Fix long line "problems" 19 ;; Disable some right-to-left behavior that might not be needed. 20 ;; Learning arabic might make me change this, but for now.. 21 (setq-default bidi-paragraph-direction 'left-to-right) 22 (if (version<= "27.1" emacs-version) 23 (setq bidi-inhibit-bpa t)) 24 ;; Detect if the line in a buffer are so long they could have a performance impact 25 (if (version<= "27.1" emacs-version) 26 (global-so-long-mode 1)) 27 28 (use-package saveplace 29 :unless noninteractive 30 :config 31 (save-place-mode 1)) 32 33 (use-package vundo 34 :bind (("M-u" . undo) 35 ("M-U" . undo-redo) 36 ("C-x u" . vundo))) 37 38 (use-package whitespace 39 :unless noninteractive 40 :commands (whitespace-mode vde/toggle-invisibles) 41 :config 42 (setq-default whitespace-style '(face tabs spaces trailing space-before-tab newline indentation empty space-after-tab space-mark tab-mark newline-mark)) 43 (defun vde/toggle-invisibles () 44 "Toggles the display of indentation and space characters." 45 (interactive) 46 (if (bound-and-true-p whitespace-mode) 47 (whitespace-mode -1) 48 (whitespace-mode))) 49 :bind ("<f6>" . vde/toggle-invisibles)) 50 51 (use-package easy-kill 52 :unless noninteractive 53 :commands (easy-kill) 54 :config 55 (global-set-key [remap kill-ring-save] 'easy-kill) 56 (global-set-key [remap mark-sexp] 'easy-mark)) 57 58 (use-package display-line-numbers 59 :unless noninteractive 60 :hook (prog-mode . display-line-numbers-mode) 61 :config 62 (setq-default display-line-numbers-type 'relative) 63 (defun vde/toggle-line-numbers () 64 "Toggles the display of line numbers. Applies to all buffers." 65 (interactive) 66 (if (bound-and-true-p display-line-numbers-mode) 67 (display-line-numbers-mode -1) 68 (display-line-numbers-mode))) 69 :bind ("<f7>" . vde/toggle-line-numbers)) 70 71 (add-hook 'prog-mode-hook 'toggle-truncate-lines) 72 73 (use-package newcomment 74 :unless noninteractive 75 :config 76 (setq-default comment-empty-lines t 77 comment-fill-column nil 78 comment-multi-line t 79 comment-style 'multi-line) 80 (defun prot/comment-dwim (&optional arg) 81 "Alternative to `comment-dwim': offers a simple wrapper 82 around `comment-line' and `comment-dwim'. 83 84 If the region is active, then toggle the comment status of the 85 region or, if the major mode defines as much, of all the lines 86 implied by the region boundaries. 87 88 Else toggle the comment status of the line at point." 89 (interactive "*P") 90 (if (use-region-p) 91 (comment-dwim arg) 92 (save-excursion 93 (comment-line arg)))) 94 95 :bind (("C-;" . prot/comment-dwim) 96 ("C-:" . comment-kill) 97 ("M-;" . comment-indent) 98 ("C-x C-;" . comment-box))) 99 100 (use-package delsel 101 :unless noninteractive 102 :config 103 (delete-selection-mode 1)) 104 105 (use-package emacs 106 :unless noninteractive 107 :custom 108 (repeat-on-final-keystroke t) 109 (set-mark-command-repeat-pop t) 110 :bind (("M-z" . zap-up-to-char) 111 ("M-S-<up>" . duplicate-dwim))) 112 113 (use-package visual-regexp 114 :unless noninteractive 115 :commands (vr/replace vr/query-replace) 116 :bind (("C-c r" . vr/replace) 117 ("C-c %" . vr/query-replace))) 118 119 (use-package emacs 120 :config 121 :bind (("M-SPC" . cycle-spacing) 122 ("M-o" . delete-blank-lines) 123 ("<C-f6>" . tear-off-window))) 124 125 ;; (use-package pdf-tools 126 ;; :unless noninteractive 127 ;; :mode ("\\.pdf\\'" . pdf-view-mode) 128 ;; :config 129 ;; (setq-default pdf-view-display-size 'fit-page) 130 ;; (setq pdf-annot-activate-created-annotations t) 131 ;; (setq pdf-view-midnight-colors '("#ffffff" . "#000000")) 132 ;; (pdf-tools-install :no-query) 133 ;; (require 'pdf-occur)) 134 135 (use-package scratch 136 :unless noninteractive 137 :commands (scratch) 138 :config 139 (defun vde/scratch-buffer-setup () 140 "Add contents to `scratch' buffer and name it accordingly. 141 If region is active, add its contents to the new buffer." 142 (let* ((mode major-mode) 143 (string (format "Scratch buffer for: %s\n\n" mode)) 144 (region (with-current-buffer (current-buffer) 145 (if (region-active-p) 146 (buffer-substring-no-properties 147 (region-beginning) 148 (region-end))) 149 "")) 150 (text (concat string region))) 151 (when scratch-buffer 152 (save-excursion 153 (insert text) 154 (goto-char (point-min)) 155 (comment-region (point-at-bol) (point-at-eol))) 156 (forward-line 2)) 157 (rename-buffer (format "*Scratch for %s*" mode) t))) 158 :hook (scratch-create-buffer . vde/scratch-buffer-setup) 159 :bind ("C-c s" . scratch)) 160 161 (use-package subword 162 :diminish 163 :hook (prog-mode-hook . subword-mode)) 164 165 ;; (use-package selection-highlight-mode 166 ;; :preface 167 ;; (unless (package-installed-p 'selection-highlight-mode) 168 ;; (package-vc-install "https://github.com/balloneij/selection-highlight-mode")) 169 ;; :config (selection-highlight-mode)) 170 171 (use-package surround 172 :bind-keymap ("M-'" . surround-keymap)) 173 174 (use-package substitute 175 :bind (("M-<insert> s" . substitute-target-below-point) 176 ("M-<insert> r" . substitute-target-above-point) 177 ("M-<insert> d" . substitute-target-in-defun) 178 ("M-<insert> b" . substitute-target-in-buffer))) 179 180 (use-package jinx 181 :hook (emacs-startup . global-jinx-mode) 182 :bind (([remap ispell-word] . jinx-correct) ;; ("M-$" . jinx-correct) 183 ("C-M-$" . jinx-languages))) 184 185 (use-package re-builder) 186 (use-package casual-re-builder 187 :bind (:map 188 reb-mode-map ("C-o" . casual-re-builder-tmenu) 189 :map 190 reb-lisp-mode-map ("C-o" . casual-re-builder-tmenu)) 191 :after (re-builder)) 192 193 (provide 'config-editing) 194 ;;; config-editing.el ends here