commit 8b9a85c9be5b7476cf1e1fefe9955d4bb4e4d66d
parent c5f2388f495732438e9fb3034d7f3c90765e1709
Author: Yuval Langer <yuval.langer@gmail.com>
Date: Wed, 25 Sep 2024 09:20:01 +0300
Add a new region detubifying function and rename top of kill ring function.
Diffstat:
1 file changed, 33 insertions(+), 12 deletions(-)
diff --git a/detubifier.el b/detubifier.el
@@ -48,21 +48,42 @@
:type '(list (cons regexp string))
:group 'detubifier)
-(defun detubifier-replace-contents ()
- "Replace all occurances of the regular expressions in `detubifier-regexp-replacement-pairs' with their replacement targets."
-
+(defun detubifier-detubify-region ()
+ "Replace, in region, all occurances of the regular expressions in `detubifier-regexp-replacement-pairs' with their replacement targets."
+
(interactive)
+
+ (save-excursion
+ (save-restriction ;; Save narrowing setting and revert to it when finishing.
+ (narrow-to-region (mark) (point))
+ (dolist (regexp-replacement-pairs detubifier-regexp-replacement-pairs)
+ (pcase regexp-replacement-pairs
+ (`(,current-regexp . ,current-replacement)
+ (goto-char (point-min))
+ (while (re-search-forward current-regexp nil t)
+ (replace-match current-replacement nil nil))))))))
+
+(defun detubifier-detubify-top-kill ()
+ "Replace, in the top of the kill ring, all occurances of the regular expressions in `detubifier-regexp-replacement-pairs' with their replacement targets."
- (with-temp-buffer
- (save-excursion
- (yank))
- (dolist (regexp-replacement-pairs detubifier-regexp-replacement-pairs)
- (pcase regexp-replacement-pairs
- (`(,current-regexp . ,current-replacement)
- (save-excursion
+ (interactive)
+
+ (save-excursion
+ (with-temp-buffer
+ (yank)
+ (goto-char (point-min))
+ (dolist (regexp-replacement-pairs detubifier-regexp-replacement-pairs)
+ (pcase regexp-replacement-pairs
+ (`(,current-regexp . ,current-replacement)
+ (goto-char (point-min))
(while (re-search-forward current-regexp nil t)
- (replace-match current-replacement nil nil))))))
- (kill-region (point-min) (point-max))))
+ (replace-match current-replacement nil nil)))))
+ (kill-region (point-min) (point-max)))))
+
+(define-obsolete-function-alias
+ 'detubifier-replace-contents
+ 'detubifier-detubify-top-kill
+ "2024-09-25")
(provide 'detubifier)
;;; detubifier.el ends here