diff options
| author | Gregory Heytings | 2023-08-16 15:58:39 +0000 |
|---|---|---|
| committer | Gregory Heytings | 2023-08-16 16:06:38 +0000 |
| commit | c287a0fdc7e3f70d819ef8efd1d7922b33df164c (patch) | |
| tree | 843fc9f866f1e110934066d7e7ecf0eefa8cfd31 | |
| parent | 9e9e11648d3d5514de85edfb69f0949a062f4716 (diff) | |
| download | emacs-c287a0fdc7e3f70d819ef8efd1d7922b33df164c.tar.gz emacs-c287a0fdc7e3f70d819ef8efd1d7922b33df164c.zip | |
Simplify 'with-restriction' and 'without-restriction'
* lisp/subr.el (with-restriction, without-restriction): Merge the
bodies of the 'internal--with-restriction' and
'internal--without-restriction' function into the macros. The
result is more efficient than a funcall.
(internal--with-restriction, internal--without-restriction):
Remove.
Suggested by Mattias EngdegÄrd.
| -rw-r--r-- | lisp/subr.el | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 08e6f816dee..616f0a8dfb6 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -4116,17 +4116,10 @@ buffer, use `without-restriction' with the same LABEL argument. | |||
| 4116 | \(fn START END [:label LABEL] BODY)" | 4116 | \(fn START END [:label LABEL] BODY)" |
| 4117 | (declare (indent 2) (debug t)) | 4117 | (declare (indent 2) (debug t)) |
| 4118 | (if (eq (car rest) :label) | 4118 | (if (eq (car rest) :label) |
| 4119 | `(internal--with-restriction ,start ,end (lambda () ,@(cddr rest)) | 4119 | `(save-restriction |
| 4120 | ,(cadr rest)) | 4120 | (internal--labeled-narrow-to-region ,start ,end ,(cadr rest)) |
| 4121 | `(internal--with-restriction ,start ,end (lambda () ,@rest)))) | 4121 | ,@(cddr rest)) |
| 4122 | 4122 | `(save-restriction (narrow-to-region ,start ,end) ,@rest))) | |
| 4123 | (defun internal--with-restriction (start end body &optional label) | ||
| 4124 | "Helper function for `with-restriction', which see." | ||
| 4125 | (save-restriction | ||
| 4126 | (if label | ||
| 4127 | (internal--labeled-narrow-to-region start end label) | ||
| 4128 | (narrow-to-region start end)) | ||
| 4129 | (funcall body))) | ||
| 4130 | 4123 | ||
| 4131 | (defmacro without-restriction (&rest rest) | 4124 | (defmacro without-restriction (&rest rest) |
| 4132 | "Execute BODY without restrictions. | 4125 | "Execute BODY without restrictions. |
| @@ -4139,17 +4132,8 @@ by `with-restriction' with the same LABEL argument are lifted. | |||
| 4139 | \(fn [:label LABEL] BODY)" | 4132 | \(fn [:label LABEL] BODY)" |
| 4140 | (declare (indent 0) (debug t)) | 4133 | (declare (indent 0) (debug t)) |
| 4141 | (if (eq (car rest) :label) | 4134 | (if (eq (car rest) :label) |
| 4142 | `(internal--without-restriction (lambda () ,@(cddr rest)) | 4135 | `(save-restriction (internal--labeled-widen ,(cadr rest)) ,@(cddr rest)) |
| 4143 | ,(cadr rest)) | 4136 | `(save-restriction (widen) ,@rest))) |
| 4144 | `(internal--without-restriction (lambda () ,@rest)))) | ||
| 4145 | |||
| 4146 | (defun internal--without-restriction (body &optional label) | ||
| 4147 | "Helper function for `without-restriction', which see." | ||
| 4148 | (save-restriction | ||
| 4149 | (if label | ||
| 4150 | (internal--labeled-widen label) | ||
| 4151 | (widen)) | ||
| 4152 | (funcall body))) | ||
| 4153 | 4137 | ||
| 4154 | (defun find-tag-default-bounds () | 4138 | (defun find-tag-default-bounds () |
| 4155 | "Determine the boundaries of the default tag, based on text at point. | 4139 | "Determine the boundaries of the default tag, based on text at point. |