diff options
| -rw-r--r-- | lisp/subr.el | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 9074d3bbd3e..ee6eadaa59f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -1089,6 +1089,35 @@ in BODY." | |||
| 1089 | . ,body) | 1089 | . ,body) |
| 1090 | (combine-after-change-execute))) | 1090 | (combine-after-change-execute))) |
| 1091 | 1091 | ||
| 1092 | |||
| 1093 | (defvar combine-run-hooks t | ||
| 1094 | "List of hooks delayed. Or t if we're not delaying hooks.") | ||
| 1095 | |||
| 1096 | (defmacro combine-run-hooks (&rest body) | ||
| 1097 | "Execute BODY, but delay any `run-hooks' until the end." | ||
| 1098 | (let ((saved-combine-run-hooks (make-symbol "saved-combine-run-hooks")) | ||
| 1099 | (saved-run-hooks (make-symbol "saved-run-hooks"))) | ||
| 1100 | `(let ((,saved-combine-run-hooks combine-run-hooks) | ||
| 1101 | (,saved-run-hooks (symbol-function 'run-hooks))) | ||
| 1102 | (unwind-protect | ||
| 1103 | (progn | ||
| 1104 | ;; If we're not delaying hooks yet, setup the delaying mode | ||
| 1105 | (unless (listp combine-run-hooks) | ||
| 1106 | (setq combine-run-hooks nil) | ||
| 1107 | (fset 'run-hooks | ||
| 1108 | ,(lambda (&rest hooks) | ||
| 1109 | (setq combine-run-hooks | ||
| 1110 | (append combine-run-hooks hooks))))) | ||
| 1111 | ,@body) | ||
| 1112 | ;; If we were not already delaying, then it's now time to set things | ||
| 1113 | ;; back to normal and to execute the delayed hooks. | ||
| 1114 | (unless (listp ,saved-combine-run-hooks) | ||
| 1115 | (setq ,saved-combine-run-hooks combine-run-hooks) | ||
| 1116 | (fset 'run-hooks ,saved-run-hooks) | ||
| 1117 | (setq combine-run-hooks t) | ||
| 1118 | (apply 'run-hooks ,saved-combine-run-hooks)))))) | ||
| 1119 | |||
| 1120 | |||
| 1092 | (defmacro with-syntax-table (table &rest body) | 1121 | (defmacro with-syntax-table (table &rest body) |
| 1093 | "Evaluate BODY with syntax table of current buffer set to a copy of TABLE. | 1122 | "Evaluate BODY with syntax table of current buffer set to a copy of TABLE. |
| 1094 | The syntax table of the current buffer is saved, BODY is evaluated, and the | 1123 | The syntax table of the current buffer is saved, BODY is evaluated, and the |