diff options
| author | Gregory Heytings | 2022-11-27 22:19:41 +0100 |
|---|---|---|
| committer | Gregory Heytings | 2022-11-27 22:19:41 +0100 |
| commit | 849223fba1ef899f90a6edff05bce24b90fbb043 (patch) | |
| tree | b5ab707f2da7d13ba2cb10c8af441547152c83ef /lisp | |
| parent | 89a10ffcc49c5832619649b7876cc339fa9d0dcf (diff) | |
| parent | 18fa159fa91b515f2281b83648961fdc5e21aca7 (diff) | |
| download | emacs-849223fba1ef899f90a6edff05bce24b90fbb043.tar.gz emacs-849223fba1ef899f90a6edff05bce24b90fbb043.zip | |
Merge branch 'feature/improved-locked-narrowing'
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/subr.el | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 4f671de918b..cfce5b18c55 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -3936,6 +3936,31 @@ See also `locate-user-emacs-file'.") | |||
| 3936 | "Return non-nil if the current buffer is narrowed." | 3936 | "Return non-nil if the current buffer is narrowed." |
| 3937 | (/= (- (point-max) (point-min)) (buffer-size))) | 3937 | (/= (- (point-max) (point-min)) (buffer-size))) |
| 3938 | 3938 | ||
| 3939 | (defmacro with-narrowing (start end &rest rest) | ||
| 3940 | "Execute BODY with restrictions set to START and END. | ||
| 3941 | |||
| 3942 | The current restrictions, if any, are restored upon return. | ||
| 3943 | |||
| 3944 | With the optional :locked TAG argument, inside BODY, | ||
| 3945 | `narrow-to-region' and `widen' can be used only within the START | ||
| 3946 | and END limits, unless the restrictions are unlocked by calling | ||
| 3947 | `narrowing-unlock' with TAG. See `narrowing-lock' for a more | ||
| 3948 | detailed description. | ||
| 3949 | |||
| 3950 | \(fn START END [:locked TAG] BODY)" | ||
| 3951 | (if (eq (car rest) :locked) | ||
| 3952 | `(internal--with-narrowing ,start ,end (lambda () ,@(cddr rest)) | ||
| 3953 | ,(cadr rest)) | ||
| 3954 | `(internal--with-narrowing ,start ,end (lambda () ,@rest)))) | ||
| 3955 | |||
| 3956 | (defun internal--with-narrowing (start end body &optional tag) | ||
| 3957 | "Helper function for `with-narrowing', which see." | ||
| 3958 | (save-restriction | ||
| 3959 | (progn | ||
| 3960 | (narrow-to-region start end) | ||
| 3961 | (if tag (narrowing-lock tag)) | ||
| 3962 | (funcall body)))) | ||
| 3963 | |||
| 3939 | (defun find-tag-default-bounds () | 3964 | (defun find-tag-default-bounds () |
| 3940 | "Determine the boundaries of the default tag, based on text at point. | 3965 | "Determine the boundaries of the default tag, based on text at point. |
| 3941 | Return a cons cell with the beginning and end of the found tag. | 3966 | Return a cons cell with the beginning and end of the found tag. |