emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/m-buffer edfa6ef412 062/115: m-buffer-at added.


From: ELPA Syncer
Subject: [elpa] externals/m-buffer edfa6ef412 062/115: m-buffer-at added.
Date: Tue, 19 Jul 2022 15:58:49 -0400 (EDT)

branch: externals/m-buffer
commit edfa6ef4122a34094e93d75456c43fcd121b1b53
Author: Phillip Lord <phillip.lord@newcastle.ac.uk>
Commit: Phillip Lord <phillip.lord@newcastle.ac.uk>

    m-buffer-at added.
---
 .ert-runner              |  2 +-
 m-buffer-at.el           | 13 +++++++++
 m-buffer-macro.el        | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
 m-buffer.el              | 48 ++--------------------------------
 test/m-buffer-at-test.el | 31 ++++++++++++++++++++++
 5 files changed, 115 insertions(+), 47 deletions(-)

diff --git a/.ert-runner b/.ert-runner
index bbdf0e0996..3cc6177078 100644
--- a/.ert-runner
+++ b/.ert-runner
@@ -1 +1 @@
--l m-buffer.el
\ No newline at end of file
+--load m-buffer-macro.el m-buffer.el m-buffer-at.el
\ No newline at end of file
diff --git a/m-buffer-at.el b/m-buffer-at.el
new file mode 100644
index 0000000000..11f619b2f7
--- /dev/null
+++ b/m-buffer-at.el
@@ -0,0 +1,13 @@
+;; Return information at location.
+;; Stateless version of emacs code
+(require 'm-buffer-macro)
+
+(defun m-buffer-at-eolp (&rest location)
+  "Return t if LOCATION is at the end of a line.
+See also `eolp'."
+  (m-buffer-with-current-location
+      location
+    (eolp)))
+  
+
+(provide 'm-buffer-at)
diff --git a/m-buffer-macro.el b/m-buffer-macro.el
new file mode 100644
index 0000000000..253b6e601c
--- /dev/null
+++ b/m-buffer-macro.el
@@ -0,0 +1,68 @@
+;;
+;; Macro Support
+;;
+(defmacro m-buffer-with-markers (varlist &rest body)
+  "Bind variables after VARLIST then eval BODY.
+All variables should contain markers or collections of markers.
+All markers are niled after BODY."
+  ;; indent let part specially.
+  (declare (indent 1)(debug let))
+  ;; so, create a rtn var with make-symbol (for hygene)
+  (let* ((rtn-var (make-symbol "rtn-var"))
+         (marker-vars
+          (mapcar 'car varlist))
+         (full-varlist
+          (append
+           varlist
+           `((,rtn-var
+              (progn
+                ,@body))))))
+    `(let* ,full-varlist
+       (m-buffer-nil-marker
+        (list ,@marker-vars))
+       ,rtn-var)))
+
+(defmacro m-buffer-with-current-marker
+    (marker &rest body)
+  "At MARKER location run BODY."
+  (declare (indent 1) (debug t))
+  `(with-current-buffer
+       (marker-buffer ,marker)
+     (save-excursion
+       (goto-char ,marker)
+       ,@body)))
+
+(defmacro m-buffer-with-current-position
+    (buffer location &rest body)
+  "In BUFFER at LOCATION, run BODY."
+  (declare (indent 2)
+           (debug t))
+  `(with-current-buffer
+       ,buffer
+     (save-excursion
+       (goto-char ,location)
+      ,@body)))
+
+(defmacro m-buffer-with-current-location
+    (location &rest body)
+  "At LOCATION, run BODY.
+LOCATION should be a list. If a one element list, it is a marker.
+If a two element, it is a buffer and position."
+  (declare (indent 1) (debug t))
+  ;; multiple eval of location!
+  (let ((loc (make-symbol "loc")))
+    `(let ((,loc ,location))
+       (if (= 1 (length ,loc))
+           (m-buffer-with-current-marker
+               (nth 0 ,loc)
+             ,@body)
+         (if (= 2 (length ,loc))
+             (m-buffer-with-current-position
+                 (nth 0 ,loc)
+                 (nth 1 ,loc)
+               ,@body)
+           (t
+            (error "m-buffer-with-current-location requires a list of one or 
two elements")))))))
+
+
+(provide 'm-buffer-macro)
diff --git a/m-buffer.el b/m-buffer.el
index 47dd489b57..4ffaca1ec9 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -4,7 +4,7 @@
 
 ;; Author: Phillip Lord <phillip.lord@newcastle.ac.uk>
 ;; Maintainer: Phillip Lord <phillip.lord@newcastle.ac.uk>
-;; Version: 0.7
+;; Version: 0.8
 ;; Package-Requires: ((dash "2.8.0")(emacs "24.3"))
 
 ;; The contents of this file are subject to the GPL License, Version 3.0.
@@ -49,51 +49,7 @@
 
 ;;; Code:
 (require 'dash)
-
-;;
-;; Macro Support
-;;
-(defmacro m-buffer-with-markers (varlist &rest body)
-  "Bind variables after VARLIST then eval BODY.
-All variables should contain markers or collections of markers.
-All markers are niled after BODY."
-  ;; indent let part specially.
-  (declare (indent 1)(debug let))
-  ;; so, create a rtn var with make-symbol (for hygene)
-  (let* ((rtn-var (make-symbol "rtn-var"))
-         (marker-vars
-          (mapcar 'car varlist))
-         (full-varlist
-          (append
-           varlist
-           `((,rtn-var
-              (progn
-                ,@body))))))
-    `(let* ,full-varlist
-       (m-buffer-nil-marker
-        (list ,@marker-vars))
-       ,rtn-var)))
-
-(defmacro m-buffer-with-current-marker
-  (marker &rest body)
-  "At MARKER location run BODY."
-  (declare (indent 1) (debug t))
-  `(with-current-buffer
-       (marker-buffer ,marker)
-     (save-excursion
-       (goto-char ,marker)
-       ,@body)))
-
-(defmacro m-buffer-with-current-location
-  (buffer location &rest body)
-  "In BUFFER at LOCATION, run BODY."
-  (declare (indent 2)
-           (debug t))
-  `(with-current-buffer
-       ,buffer
-     (save-excursion
-       (goto-char ,location)
-      ,@body)))
+(require 'm-buffer-macro)
 
 ;;
 ;; Regexp matching
diff --git a/test/m-buffer-at-test.el b/test/m-buffer-at-test.el
new file mode 100644
index 0000000000..026232a133
--- /dev/null
+++ b/test/m-buffer-at-test.el
@@ -0,0 +1,31 @@
+(require 'm-buffer-at)
+
+(ert-deftest m-buffer-at-eolp-1()
+  (should
+   (with-temp-buffer
+     (insert "hello")
+     (m-buffer-at-eolp (point-marker)))))
+
+(ert-deftest m-buffer-at-eolp-2 ()
+  (should
+   (with-temp-buffer
+     (insert "hello")
+     (m-buffer-at-eolp
+      (current-buffer)
+      (point)))))
+
+(ert-deftest m-buffer-at-eolp-3 ()
+  (should-not
+   (with-temp-buffer
+     (insert "hello")
+     (goto-char (point-min))
+     (m-buffer-at-eolp (point-marker)))))
+
+(ert-deftest m-buffer-at-eolp-4 ()
+  (should-not
+   (with-temp-buffer
+     (insert "hello")
+     (goto-char (point-min))
+     (m-buffer-at-eolp
+      (current-buffer)
+      (point)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]