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