diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2023-01-18 08:10:53 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2023-01-18 08:37:33 +0100 |
| commit | a28ce55d8efd3c25c0c0daff93008e626d4bf678 (patch) | |
| tree | 4aeda8fde2583505d347636f936c714a710122a3 /compat-29.el | |
| parent | 12e2d82a5a469aabadb1082678f7a33539779d8b (diff) | |
compat-29: Add with-narrowing
Diffstat (limited to 'compat-29.el')
| -rw-r--r-- | compat-29.el | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/compat-29.el b/compat-29.el index 9373c0c..4010a9e 100644 --- a/compat-29.el +++ b/compat-29.el @@ -187,6 +187,23 @@ This function does not move point. Also see `line-end-position'." "Delete the current line." (delete-region (pos-bol) (pos-bol 2))) +(compat-defmacro with-narrowing (start end &rest rest) + "Execute BODY with restrictions set to START and END. + +The current restrictions, if any, are restored upon return. + +With the optional :locked TAG argument, inside BODY, +`narrow-to-region' and `widen' can be used only within the START +and END limits, unless the restrictions are unlocked by calling +`narrowing-unlock' with TAG. See `narrowing-lock' for a more +detailed description. + +\(fn START END [:locked TAG] BODY)" + `(save-restriction + (narrow-to-region ,start ,end) + ;; Locking is ignored + ,@(if (eq (car rest) :locked) (cddr rest) rest))) + (compat-defmacro with-memoization (place &rest code) ;; <compat-tests:with-memoization> "Return the value of CODE and stash it in PLACE. If PLACE's value is non-nil, then don't bother evaluating CODE |
