aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS.org1
-rw-r--r--compat-30.el15
-rw-r--r--compat-tests.el27
-rw-r--r--compat.texi11
4 files changed, 54 insertions, 0 deletions
diff --git a/NEWS.org b/NEWS.org
index 043d45a..b081c4c 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -11,6 +11,7 @@
- compat-30: New variables =completion-lazy-hilit= and =completion-lazy-hilit-fn=
and new function =completion-lazy-hilit=.
- compat-30: New function =require-with-check=.
+- compat-30: New functions =find-buffer= and =get-truename-buffer=.
* Release of "Compat" Version 29.1.4.4
diff --git a/compat-30.el b/compat-30.el
index 36e6a19..b68cc40 100644
--- a/compat-30.el
+++ b/compat-30.el
@@ -27,6 +27,21 @@
;; TODO Update to 30.1 as soon as the Emacs emacs-30 branch version bumped
(compat-version "30.0.50")
+;;;; Defined in buffer.c
+
+(compat-defun find-buffer (variable value) ;; <compat-tests:find-buffer>
+ "Return the buffer with buffer-local VARIABLE equal to VALUE.
+If there is no such live buffer, return nil."
+ (cl-loop for buffer the buffers
+ if (equal (buffer-local-value variable buffer) value)
+ return buffer))
+
+(compat-defun get-truename-buffer (filename) ;; <compat-tests:get-truename-buffer>
+ "Return the buffer with `file-truename' equal to FILENAME (a string).
+If there is no such live buffer, return nil.
+See also `find-buffer-visiting'."
+ (find-buffer 'buffer-file-truename filename))
+
;;;; Defined in files.el
(compat-defun require-with-check (feature &optional filename noerror) ;; <compat-tests:require-with-check>
diff --git a/compat-tests.el b/compat-tests.el
index 12e52ea..88992f6 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -3084,5 +3084,32 @@
(should-equal 'compat-reload (require-with-check 'compat-reload nil 'noerror))
(should-equal 'compat-reload (require-with-check 'compat-reload nil 'reload)))))))
+(defvar compat-tests-find-buffer nil)
+(ert-deftest compat-find-buffer ()
+ ;; TODO enable test on Emacs 30 as soon as the CI supports it.
+ (static-if (< emacs-major-version 30)
+ (let ((buf1 (get-buffer-create "*compat-tests-buf1*"))
+ (buf2 (get-buffer-create "*compat-tests-buf2*")))
+ (with-current-buffer buf1
+ (setq-local compat-tests-find-buffer 1))
+ (with-current-buffer buf2
+ (setq-local compat-tests-find-buffer 2))
+ (should-equal buf1 (find-buffer 'compat-tests-find-buffer 1))
+ (should-equal buf2 (find-buffer 'compat-tests-find-buffer 2))
+ (should-not (find-buffer 'compat-tests-find-buffer 3)))))
+
+(ert-deftest compat-get-truename-buffer ()
+ ;; TODO enable test on Emacs 30 as soon as the CI supports it.
+ (static-if (< emacs-major-version 30)
+ (let ((buf1 (get-buffer-create "*compat-tests-buf1*"))
+ (buf2 (get-buffer-create "*compat-tests-buf2*")))
+ (with-current-buffer buf1
+ (setq-local buffer-file-truename "compat-tests-file1"))
+ (with-current-buffer buf2
+ (setq-local buffer-file-truename "compat-tests-file2"))
+ (should-equal buf1 (get-truename-buffer "compat-tests-file1"))
+ (should-equal buf2 (get-truename-buffer "compat-tests-file2"))
+ (should-not (get-truename-buffer "compat-tests-file3")))))
+
(provide 'compat-tests)
;;; compat-tests.el ends here
diff --git a/compat.texi b/compat.texi
index 95c9257..696418b 100644
--- a/compat.texi
+++ b/compat.texi
@@ -3348,6 +3348,17 @@ older than 30.1. Note that due to upstream changes, it might happen
that there will be the need for changes, so use these functions with
care.
+@defun get-truename-buffer filename
+Return the buffer with @code{file-truename} equal to @var{filename} (a string).
+If there is no such live buffer, return nil.
+See also @code{find-buffer-visiting}.
+@end defun
+
+@defun find-buffer variable value
+Return the buffer with buffer-local @var{variable} equal to @var{value}.
+If there is no such live buffer, return nil.
+@end defun
+
@c copied from lispref/loading.texi
@defun require-with-check feature &optional filename noerror
This function works like @code{require}, except if @var{feature} is