[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat c8bc47b671 18/27: Add replace-string-in-region
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat c8bc47b671 18/27: Add replace-string-in-region |
Date: |
Sat, 5 Mar 2022 04:57:28 -0500 (EST) |
branch: externals/compat
commit c8bc47b671fd1852c2cc916e1867c65b7fb4eaae
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add replace-string-in-region
---
MANUAL | 1 +
compat-28.el | 27 +++++++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/MANUAL b/MANUAL
index 51009a7926..56d6967cdd 100644
--- a/MANUAL
+++ b/MANUAL
@@ -331,6 +331,7 @@ provided by compat by default:
- Function ~always~ :: [[info:elisp#Calling Functions][(elisp) Calling
Functions]].
- Function ~insert-into-buffer~ :: See [[info:elisp#Insertion][(elisp)
Insertion]].
- Function ~replace-regexp-in-region~ :: See [[info:elisp#Search and
Replace][(elisp) Search and Replace]].
+- Function ~replace-string-in-region~ :: See [[info:elisp#Search and
Replace][(elisp) Search and Replace]].
- Function ~buffer-local-boundp~ :: See [[info:elisp#Creating
Buffer-Local][(elisp) Creating Buffer-Local]].
- Function ~with-existing-directory~ :: See [[info:elisp#Testing
Accessibility][(elisp) Testing Accessibility]].
- Macro ~dlet~ :: See [[info:elisp#Local Variables][(elisp) Local Variables]].
diff --git a/compat-28.el b/compat-28.el
index d60ef5c2f6..37d12f9e1c 100644
--- a/compat-28.el
+++ b/compat-28.el
@@ -332,6 +332,33 @@ Point in BUFFER will be placed after the inserted text."
(with-current-buffer buffer
(insert-buffer-substring current start end))))
+(compat-defun replace-string-in-region (string replacement &optional start end)
+ "Replace STRING with REPLACEMENT in the region from START to END.
+The number of replaced occurrences are returned, or nil if STRING
+doesn't exist in the region.
+
+If START is nil, use the current point. If END is nil, use `point-max'.
+
+Comparisons and replacements are done with fixed case."
+ (if start
+ (when (< start (point-min))
+ (error "Start before start of buffer"))
+ (setq start (point)))
+ (if end
+ (when (> end (point-max))
+ (error "End after end of buffer"))
+ (setq end (point-max)))
+ (save-excursion
+ (let ((matches 0)
+ (case-fold-search nil))
+ (goto-char start)
+ (while (search-forward string end t)
+ (delete-region (match-beginning 0) (match-end 0))
+ (insert replacement)
+ (setq matches (1+ matches)))
+ (and (not (zerop matches))
+ matches))))
+
(compat-defun replace-regexp-in-region (regexp replacement &optional start end)
"Replace REGEXP with REPLACEMENT in the region from START to END.
The number of replaced occurrences are returned, or nil if REGEXP
- [elpa] externals/compat efb9ff712a 10/27: Add completion-table-merge and completion-table-with-cache, (continued)
- [elpa] externals/compat efb9ff712a 10/27: Add completion-table-merge and completion-table-with-cache, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 4aca90834f 09/27: Add get-pos-property to missing functions in 24.4, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 3f511afce0 12/27: Add directory-files-recursively, ELPA Syncer, 2022/03/05
- [elpa] externals/compat efa6e171e5 13/27: Document define-advice as not implemented, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 441539ae8b 11/27: Add face-spec-set, ELPA Syncer, 2022/03/05
- [elpa] externals/compat b3b75333b1 14/27: Document generators as not implemented, ELPA Syncer, 2022/03/05
- [elpa] externals/compat c4893fa014 15/27: Document bufferpos-to-filepos as not implemented, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 35072b3d25 22/27: Fix if-let and add tests, ELPA Syncer, 2022/03/05
- [elpa] externals/compat ece91a5b89 03/27: Add function-put, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 9034bcc0ac 05/27: Fix broken markup in some deftest docstrings, ELPA Syncer, 2022/03/05
- [elpa] externals/compat c8bc47b671 18/27: Add replace-string-in-region,
ELPA Syncer <=
- [elpa] externals/compat a92aec7251 19/27: Add file-modes-number-to-symbolic, ELPA Syncer, 2022/03/05
- [elpa] externals/compat ba2918d6d3 21/27: Add file-backup-file-names, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 15ca463a9e 20/27: Document that null-device and path-separator are not implemented, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 6b14d5fa3b 24/27: Exclude the generated manual from the repository, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 63ac5dd347 16/27: Add assoc-delete-all, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 8eb72a2739 25/27: Convert JSON advice for Emacs 28 to prefixed functions, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 9fa3fbab8a 27/27: Fix (provide) in compat-tests.el, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 5514de45e1 26/27: Rewrite test macros to generate more individual tests, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 212f8c7c77 17/27: Add color-values-from-color-spec, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 158edd3161 23/27: Mark all currently untested functions, ELPA Syncer, 2022/03/05