branch: externals/m-buffer
commit 1ab361ed3275c417ac3f178af192d9adc0a89eec
Author: Phillip Lord <[email protected]>
Commit: Phillip Lord <[email protected]>
with-markers and with-current-location added.
Two new macros one of which works like let, but auto nils markers, and
the other which runs the body in a given buffer and location.
---
m-buffer.el | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/m-buffer.el b/m-buffer.el
index a94e557426..90866a91ff 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -45,6 +45,41 @@
;;; 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-location
+ (buffer location &rest body)
+ "Run BODY in BUFFER at LOCATION."
+ (declare (indent 2)
+ (debug t))
+ `(with-current-buffer
+ ,buffer
+ (save-excursion
+ (goto-char ,location)
+ ,@body)))
+
;;
;; Regexp matching
;;