aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS.org2
-rw-r--r--compat-29.el23
-rw-r--r--compat-tests.el14
-rw-r--r--compat.texi21
4 files changed, 60 insertions, 0 deletions
diff --git a/NEWS.org b/NEWS.org
index 8589332..cbcc0c5 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 ec5b81e..6315a07 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 b9e5a0b..9ff6425 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 9295956..094788c 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}.