branch: externals/compat
commit a64a1f67ec118145187795986e68fb77176d80c4
Author: Daniel Mendler <m...@daniel-mendler.de>
Commit: Daniel Mendler <m...@daniel-mendler.de>

    compat-29: Add use-region-beginning, use-region-end and 
get-scratch-buffer-create
---
 NEWS.org        |  2 ++
 compat-29.el    | 23 +++++++++++++++++++++++
 compat-tests.el | 14 ++++++++++++++
 compat.texi     | 21 +++++++++++++++++++++
 4 files changed, 60 insertions(+)

diff --git a/NEWS.org b/NEWS.org
index 8589332a9f..cbcc0c5c65 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -15,6 +15,8 @@
 - compat-29: Add ~delete-line~.
 - compat-29: Add ~with-narrowing~.
 - compat-29: Add ~buffer-local-set-state~ and ~buffer-local-restore-state~.
+- compat-29: Add ~use-region-beginning~ and ~use-region-end~.
+- compat-29: Add ~get-scratch-buffer-create~.
 
 * Release of "Compat" Version 29.1.2.0
 
diff --git a/compat-29.el b/compat-29.el
index ec5b81e2ad..6315a07bb9 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -350,6 +350,29 @@ CONDITION."
         (push buf bufs)))
     bufs))
 
+;;;; Defined in simple.el
+
+(compat-defun use-region-beginning () ;; <compat-tests:use-region>
+  "Return the start of the region if `use-region-p'."
+  (and (use-region-p) (region-beginning)))
+
+(compat-defun use-region-end () ;; <compat-tests:use-region>
+  "Return the end of the region if `use-region-p'."
+  (and (use-region-p) (region-end)))
+
+(compat-defun get-scratch-buffer-create () ;; 
<compat-tests:get-scratch-buffer-create>
+  "Return the *scratch* buffer, creating a new one if needed."
+  (or (get-buffer "*scratch*")
+      (let ((scratch (get-buffer-create "*scratch*")))
+        ;; Don't touch the buffer contents or mode unless we know that
+        ;; we just created it.
+        (with-current-buffer scratch
+          (when initial-scratch-message
+            (insert (substitute-command-keys initial-scratch-message))
+            (set-buffer-modified-p nil))
+          (funcall initial-major-mode))
+        scratch)))
+
 ;;;; Defined in subr-x.el
 
 (compat-defmacro with-buffer-unmodified-if-unchanged (&rest body) ;; 
<compat-tests:with-buffer-unmodified-if-unchanged>
diff --git a/compat-tests.el b/compat-tests.el
index b9e5a0b2f1..9ff6425444 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -2648,5 +2648,19 @@
   (require 'dired)
   (should-error (compat-call dired-get-marked-files nil nil nil nil t)))
 
+(ert-deftest use-region ()
+  (with-temp-buffer
+    (insert "abc\ndef\n")
+    (set-mark 2)
+    (goto-char 7)
+    (transient-mark-mode)
+    (should (use-region-p))
+    (should-equal 2 (use-region-beginning))
+    (should-equal 7 (use-region-end))))
+
+(ert-deftest get-scratch-buffer-create ()
+  (should-equal "*scratch*" (buffer-name (get-scratch-buffer-create)))
+  (should-equal initial-major-mode (buffer-local-value 'major-mode 
(get-scratch-buffer-create))))
+
 (provide 'compat-tests)
 ;;; compat-tests.el ends here
diff --git a/compat.texi b/compat.texi
index 9295956ff3..094788c4da 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2012,6 +2012,21 @@ provided by Compat. Note that due to upstream changes, 
it might happen
 that there will be the need for changes, so use these functions with
 care.
 
+@c based on lisp/simple.el
+@defun get-scratch-buffer-create
+Return the *scratch* buffer, creating a new one if needed.
+@end defun
+
+@c based on lisp/simple.el
+@defun use-region-end
+Return the end of the region if @code{use-region-p}.
+@end defun
+
+@c based on lisp/simple.el
+@defun use-region-beginning
+Return the start of the region if @code{use-region-p}.
+@end defun
+
 @c copied from lispref/modes.texi
 @findex buffer-local-restore-state
 @defmac buffer-local-set-state variable value...
@@ -2711,6 +2726,12 @@ implemented in 29.1:
 
 @itemize
 @item
+The function @code{imagep}.
+@item
+The function @code{function-documentation}.
+@item
+The function @code{count-sentences}.
+@item
 The command @code{string-edit} and @code{read-string-from-buffer}.
 @item
 The function @code{readablep}.

Reply via email to