summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--init.el171
-rw-r--r--lisp/acdw-re.el109
2 files changed, 193 insertions, 87 deletions
diff --git a/init.el b/init.el index 9c3b03b..25aaad6 100644 --- a/init.el +++ b/init.el
@@ -317,19 +317,6 @@
317 "C-c C-k" #'acdw/eval-region-or-buffer 317 "C-c C-k" #'acdw/eval-region-or-buffer
318 "C-c C-z" #'ielm))) 318 "C-c C-z" #'ielm)))
319 319
320(setup pulse
321 (:option pulse-flag nil)
322
323 (defun pulse-line (&rest _)
324 "Pulse the current line."
325 (pulse-momentary-highlight-one-line (point)))
326
327 (dolist (command '(scroll-up-command
328 scroll-down-command
329 recenter-top-bottom other-window
330 switch-to-buffer))
331 (advice-add command :after #'pulse-line)))
332
333(setup emacs 320(setup emacs
334 ;; "Et cetera" settings 321 ;; "Et cetera" settings
335 ;; This should stay as /minimal/ as possible. Anything that can go somewhere 322 ;; This should stay as /minimal/ as possible. Anything that can go somewhere
@@ -365,6 +352,7 @@
365 (global-set-key (kbd "C-c l") lookup-map) 352 (global-set-key (kbd "C-c l") lookup-map)
366 353
367 (:global "M-=" #'count-words 354 (:global "M-=" #'count-words
355 "C-M-;" #'comment-or-uncomment-sexp
368 "C-w" #'kill-region-or-backward-word 356 "C-w" #'kill-region-or-backward-word
369 "C-c d" #'acdw/insert-iso-date 357 "C-c d" #'acdw/insert-iso-date
370 "M-`" nil 358 "M-`" nil
@@ -734,14 +722,40 @@ specific to most general, they are these:
734 show-paren-when-point-in-periphery t 722 show-paren-when-point-in-periphery t
735 smie-indent-basic tab-width) 723 smie-indent-basic tab-width)
736 724
737 (:hook show-paren-mode 725 (:hook #'show-paren-mode
738 electric-pair-local-mode 726 #'electric-pair-local-mode
739 acdw/setup-fringes 727 #'acdw/setup-fringes
728 #'display-fill-column-indicator-mode
740 729
741 (defun prog-mode@auto-fill () 730 (defun prog-mode@auto-fill ()
742 (setq-local comment-auto-fill-only-comments t) 731 (setq-local comment-auto-fill-only-comments t)
743 (turn-on-auto-fill)))) 732 (turn-on-auto-fill))))
744 733
734(setup pulse
735 (:option pulse-flag t
736 pulse-delay 0.5
737 pulse-iterations 1)
738
739 (defun pulse-line (&rest _)
740 "Pulse the current line."
741 (pulse-momentary-highlight-one-line (point)))
742
743 (dolist (command '(scroll-up-command
744 scroll-down-command
745 recenter-top-bottom other-window
746 switch-to-buffer))
747 (advice-add command :after #'pulse-line)))
748
749(setup re-builder
750 (require 'acdw-re)
751 (:global "C-M-5" #'re-builder
752 "C-M-%" #'re-builder)
753 (:with-map reb-mode-map
754 (:bind "C-c C-k" #'reb-quit
755 "RET" #'reb-replace-regexp))
756 (:with-map reb-lisp-mode-map
757 (:bind "RET" #'reb-replace-regexp)))
758
745(setup repeat 759(setup repeat
746 ;; new for Emacs 28! 760 ;; new for Emacs 28!
747 (:only-if (fboundp #'repeat-mode)) 761 (:only-if (fboundp #'repeat-mode))
@@ -1091,11 +1105,13 @@ specific to most general, they are these:
1091 lui-track-behavior 'before-switch-to-buffer 1105 lui-track-behavior 'before-switch-to-buffer
1092 lui-track-indicator 'fringe 1106 lui-track-indicator 'fringe
1093 lui-fill-remove-face-from-newline nil) 1107 lui-fill-remove-face-from-newline nil)
1094 1108
1095 (:hook #'visual-fill-column-mode 1109 (:hook #'visual-fill-column-mode
1096 #'visual-line-mode) 1110 #'visual-line-mode)
1097 1111
1098 (:local-set fringes-outside-margins t 1112 (:local-set visual-fill-column-extra-text-width (cons acdw-irc/left-margin
1113 0)
1114 fringes-outside-margins t
1099 right-margin-width 5 1115 right-margin-width 5
1100 scroll-margin 0 1116 scroll-margin 0
1101 word-wrap t 1117 word-wrap t
@@ -1207,8 +1223,8 @@ specific to most general, they are these:
1207 (crux-reopen-as-root-mode +1)) 1223 (crux-reopen-as-root-mode +1))
1208 1224
1209(setup (:straight-if (define-repeat-map 1225(setup (:straight-if (define-repeat-map
1210 :host nil 1226 :host nil
1211 :repo "https://tildegit.org/acdw/define-repeat-map.el") 1227 :repo "https://tildegit.org/acdw/define-repeat-map.el")
1212 (acdw/system :home)) 1228 (acdw/system :home))
1213 1229
1214 (require 'define-repeat-map ; just for me 1230 (require 'define-repeat-map ; just for me
@@ -1732,7 +1748,7 @@ browser defined in `browse-url-secondary-browser-function'."
1732 modus-themes-bold-constructs t 1748 modus-themes-bold-constructs t
1733 modus-themes-fringes nil 1749 modus-themes-fringes nil
1734 modus-themes-mode-line '(borderless moody) 1750 modus-themes-mode-line '(borderless moody)
1735 modus-themes-region '(bg-only no-extend) 1751 modus-themes-region '(bg-only)
1736 modus-themes-org-blocks 'gray-background 1752 modus-themes-org-blocks 'gray-background
1737 modus-themes-headings '((t . (background))) 1753 modus-themes-headings '((t . (background)))
1738 modus-themes-lang-checkers '(straight-underline) 1754 modus-themes-lang-checkers '(straight-underline)
@@ -1744,27 +1760,27 @@ browser defined in `browse-url-secondary-browser-function'."
1744 (add-hook 'modus-themes-after-load-theme-hook 1760 (add-hook 'modus-themes-after-load-theme-hook
1745 (defun modus-themes@customize-faces () 1761 (defun modus-themes@customize-faces ()
1746 "Customize faces of modus-themes." 1762 "Customize faces of modus-themes."
1747 (dolist (face '(font-lock-builtin-face 1763 ;; (dolist (face '(font-lock-builtin-face
1748 ;; font-lock-comment-delimiter-face 1764 ;; ;; font-lock-comment-delimiter-face
1749 ;; font-lock-coment-face 1765 ;; ;; font-lock-coment-face
1750 font-lock-constant-face 1766 ;; font-lock-constant-face
1751 ;; font-lock-doc-face 1767 ;; ;; font-lock-doc-face
1752 font-lock-function-name-face 1768 ;; font-lock-function-name-face
1753 font-lock-keyword-face 1769 ;; font-lock-keyword-face
1754 font-lock-negation-char-face 1770 ;; font-lock-negation-char-face
1755 font-lock-preprocessor-face 1771 ;; font-lock-preprocessor-face
1756 font-lock-regexp-grouping-backslash 1772 ;; font-lock-regexp-grouping-backslash
1757 font-lock-regexp-goruping-construct 1773 ;; font-lock-regexp-goruping-construct
1758 font-lock-string-face 1774 ;; font-lock-string-face
1759 font-lock-type-face 1775 ;; font-lock-type-face
1760 font-lock-variable-name-face 1776 ;; font-lock-variable-name-face
1761 font-lock-warning-face)) 1777 ;; font-lock-warning-face))
1762 (modus-themes-with-colors 1778 ;; (modus-themes-with-colors
1763 (custom-set-faces 1779 ;; (custom-set-faces
1764 `(,face 1780 ;; `(,face
1765 ((,class :foreground ,fg-main 1781 ;; ((,class :foreground ,fg-main
1766 :weight normal 1782 ;; :weight normal
1767 :slant normal)))))) 1783 ;; :slant normal))))))
1768 ;; Other faces 1784 ;; Other faces
1769 (modus-themes-with-colors 1785 (modus-themes-with-colors
1770 (custom-set-faces 1786 (custom-set-faces
@@ -1801,15 +1817,15 @@ browser defined in `browse-url-secondary-browser-function'."
1801 (:option nov-text-width fill-column) 1817 (:option nov-text-width fill-column)
1802 (:file-match (rx ".epub" eos))) 1818 (:file-match (rx ".epub" eos)))
1803 1819
1804(setup (:straight olivetti) 1820;; (setup (:straight olivetti)
1805 (:option olivetti-body-width (+ fill-column 4) 1821;; (:option olivetti-body-width (+ fill-column 4)
1806 olivetti-minimum-body-width fill-column) 1822;; olivetti-minimum-body-width fill-column)
1807 1823
1808 (:hook (defun olivetti-mode@setup () 1824;; (:hook (defun olivetti-mode@setup ()
1809 (if olivetti-mode 1825;; (if olivetti-mode
1810 (setq-local indicate-empty-lines nil 1826;; (setq-local indicate-empty-lines nil
1811 indicate-buffer-boundaries nil) 1827;; indicate-buffer-boundaries nil)
1812 (acdw/setup-fringes))))) 1828;; (acdw/setup-fringes)))))
1813 1829
1814(setup (:straight (orderless 1830(setup (:straight (orderless
1815 :host github 1831 :host github
@@ -2055,32 +2071,30 @@ the default is \"/\"."
2055(setup (:straight org-sticky-header) 2071(setup (:straight org-sticky-header)
2056 (:hook-into org-mode)) 2072 (:hook-into org-mode))
2057 2073
2058(setup (:straight package-lint)) 2074(setup (:straight package-lint
2059 2075 package-lint-flymake))
2060(setup (:straight package-lint-flymake))
2061 2076
2062(setup (:straight page-break-lines) 2077(setup (:straight page-break-lines)
2063 (global-page-break-lines-mode +1)) 2078 (global-page-break-lines-mode +1))
2064 2079
2065(setup (:straight paredit) 2080;; (setup (:straight paredit)
2066 (:bind "DEL" #'paredit-backward-delete 2081;; (:bind "DEL" #'paredit-backward-delete
2067 "C-M-;" #'comment-or-uncomment-sexp 2082;; "C-<backspace>" #'paredit-backward-kill-word
2068 "C-<backspace>" #'paredit-backward-kill-word 2083;; "M-w" #'paredit-copy-as-kill
2069 "M-w" #'paredit-copy-as-kill 2084;; "RET" #'paredit-newline)
2070 "RET" #'paredit-newline)
2071 2085
2072 (:unbind "M-s" ; paredit-splice-sexp 2086;; (:unbind "M-s" ; paredit-splice-sexp
2073 "C-j" ; paredit-newline (rebound to RET) 2087;; "C-j" ; paredit-newline (rebound to RET)
2074 ) 2088;; )
2075 2089
2076 (:hook-into emacs-lisp-mode 2090;; (:hook-into emacs-lisp-mode
2077 ielm-mode sly-repl-mode 2091;; ielm-mode sly-repl-mode
2078 lisp-mode 2092;; lisp-mode
2079 lisp-interaction-mode 2093;; lisp-interaction-mode
2080 scheme-mode) 2094;; scheme-mode)
2081 2095
2082 (:also-load eldoc) 2096;; (:also-load eldoc)
2083 (eldoc-add-command 'paredit-backward-delete 'paredit-close-round)) 2097;; (eldoc-add-command 'paredit-backward-delete 'paredit-close-round))
2084 2098
2085(setup (:straight paren-face) 2099(setup (:straight paren-face)
2086 (:hook-into emacs-lisp-mode 2100 (:hook-into emacs-lisp-mode
@@ -2206,6 +2220,10 @@ the default is \"/\"."
2206 2220
2207 (:bind "C-c C-c" #'sly-mrepl-return))) 2221 (:bind "C-c C-c" #'sly-mrepl-return)))
2208 2222
2223(setup (:straight smartparens)
2224 (require 'smartparens-config)
2225 (add-hook 'prog-mode #'smartparens-strict-mode))
2226
2209(setup (:straight ssh-config-mode) 2227(setup (:straight ssh-config-mode)
2210 (:file-match (rx "/.ssh/config" eos) 2228 (:file-match (rx "/.ssh/config" eos)
2211 (rx "/ssh" (? "d") "_config" eos)) 2229 (rx "/ssh" (? "d") "_config" eos))
@@ -2232,7 +2250,16 @@ the default is \"/\"."
2232(setup (:straight (topsy 2250(setup (:straight (topsy
2233 :host github 2251 :host github
2234 :repo "alphapapa/topsy.el")) 2252 :repo "alphapapa/topsy.el"))
2235 (:hook-into prog-mode)) 2253 (:hook-into prog-mode)
2254 (:when-loaded
2255 (:option topsy-header-line-format
2256 '(:eval
2257 (list
2258 (propertize " "
2259 'display
2260 '((space :align-to
2261 ,(unless visual-fill-column-mode 0))))
2262 (funcall topsy-fn))))))
2236 2263
2237(setup (:straight trashed) 2264(setup (:straight trashed)
2238 (:option trashed-action-confirmer #'y-or-n-p)) 2265 (:option trashed-action-confirmer #'y-or-n-p))
diff --git a/lisp/acdw-re.el b/lisp/acdw-re.el index 1fc0a9c..eff61e1 100644 --- a/lisp/acdw-re.el +++ b/lisp/acdw-re.el
@@ -23,21 +23,22 @@
23 23
24;;; Code: 24;;; Code:
25 25
26(defvar acdw/re-builder-positions nil 26(require 're-builder)
27 "Store point and region bounds before calling re-builder")
28 27
29(defun acdw/re-builder-save-state (&rest _) 28(defvar my/re-builder-positions nil
30 "Save into `acdw/re-builder-positions' the point and region 29 "Store point and region bounds before calling `re-builder'.")
31positions before calling `re-builder'." 30
32 (setq acdw/re-builder-positions 31(defun my/re-builder-save-state (&rest _)
32 "Save the point and region before calling `re-builder'."
33 (setq my/re-builder-positions
33 (cons (point) 34 (cons (point)
34 (when (region-active-p) 35 (when (region-active-p)
35 (list (region-beginning) 36 (list (region-beginning)
36 (region-end)))))) 37 (region-end))))))
37 38
38(defun reb-replace-regexp (&optional delimited) 39(defun reb-replace-regexp (&optional delimited)
39 "Run `query-replace-regexp' with the contents of re-builder. With 40 "Run `query-replace-regexp' with the contents of `re-builder'.
40non-nil optional argument DELIMITED, only replace matches 41With non-nil optional argument DELIMITED, only replace matches
41surrounded by word boundaries." 42surrounded by word boundaries."
42 (interactive "P") 43 (interactive "P")
43 (reb-update-regexp) 44 (reb-update-regexp)
@@ -56,17 +57,95 @@ surrounded by word boundaries."
56 " in region" 57 " in region"
57 "")) 58 ""))
58 t)) 59 t))
59 (pnt (car acdw/re-builder-positions)) 60 (pnt (car my/re-builder-positions))
60 (beg (cadr acdw/re-builder-positions)) 61 (beg (cadr my/re-builder-positions))
61 (end (caddr acdw/re-builder-positions))) 62 (end (caddr my/re-builder-positions)))
62 (with-selected-window reb-target-window 63 (with-selected-window reb-target-window
63 ;; replace with (goto-char (match-beginning 0)) if you want to control 64 (goto-char (or pnt 0))
64 ;; where in the buffer the replacement starts with re-builder 65 (setq my/re-builder-positions nil)
65 (goto-char pnt)
66 (setq acdw/re-builder-positions nil)
67 (reb-quit) 66 (reb-quit)
68 (query-replace-regexp re replacement delimited beg end)))) 67 (query-replace-regexp re replacement delimited beg end))))
69 68
69;; Restrict re-builder matches to region
70
71(defun reb-update-overlays (&optional subexp)
72 "Switch to `reb-target-buffer' and mark all matches of `reb-regexp'.
73If SUBEXP is non-nil mark only the corresponding sub-expressions."
74 (let* ((re (reb-target-binding reb-regexp))
75 (subexps (reb-count-subexps re))
76 (matches 0)
77 (submatches 0)
78 firstmatch
79 here
80 start end
81 firstmatch-after-here)
82 (with-current-buffer reb-target-buffer
83 (setq here
84 (if reb-target-window
85 (with-selected-window reb-target-window (window-point))
86 (point))
87 start
88 (if (region-active-p)
89 (nth 1 my/re-builder-positions)
90 (nth 0 my/re-builder-positions))
91 end
92 (if (region-active-p)
93 (nth 2 my/re-builder-positions)
94 (point-max)))
95 (reb-delete-overlays)
96 (goto-char (or start 0))
97 (while (and (not (eobp))
98 (re-search-forward re end t)
99 (or (not reb-auto-match-limit)
100 (< matches reb-auto-match-limit)))
101 (when (and (= 0 (length (match-string 0)))
102 (not (eobp)))
103 (forward-char 1))
104 (let ((i 0)
105 suffix max-suffix)
106 (setq matches (1+ matches))
107 (while (<= i subexps)
108 (when (and (or (not subexp) (= subexp i))
109 (match-beginning i))
110 (let ((overlay (make-overlay (match-beginning i)
111 (match-end i)))
112 ;; When we have exceeded the number of provided faces,
113 ;; cycle thru them where `max-suffix' denotes the maximum
114 ;; suffix for `reb-match-*' that has been defined and
115 ;; `suffix' the suffix calculated for the current match.
116 (face
117 (cond
118 (max-suffix
119 (if (= suffix max-suffix)
120 (setq suffix 1)
121 (setq suffix (1+ suffix)))
122 (intern-soft (format "reb-match-%d" suffix)))
123 ((intern-soft (format "reb-match-%d" i)))
124 ((setq max-suffix (1- i))
125 (setq suffix 1)
126 ;; `reb-match-1' must exist.
127 'reb-match-1))))
128 (unless firstmatch (setq firstmatch (match-data)))
129 (unless firstmatch-after-here
130 (when (> (point) here)
131 (setq firstmatch-after-here (match-data))))
132 (setq reb-overlays (cons overlay reb-overlays)
133 submatches (1+ submatches))
134 (overlay-put overlay 'face face)
135 (overlay-put overlay 'priority i)))
136 (setq i (1+ i))))))
137 (let ((count (if subexp submatches matches)))
138 (message "%s %smatch%s%s"
139 (if (= 0 count) "No" (int-to-string count))
140 (if subexp "subexpression " "")
141 (if (= 1 count) "" "es")
142 (if (and reb-auto-match-limit
143 (= reb-auto-match-limit count))
144 " (limit reached)" "")))
145 (when firstmatch
146 (store-match-data (or firstmatch-after-here firstmatch))
147 (reb-show-subexp (or subexp 0)))))
148
70(provide 'acdw-re) 149(provide 'acdw-re)
71 150
72;;; acdw-re.el ends here 151;;; acdw-re.el ends here