diff lisp/subr.el @ 2135:e6d43c299b9c

[xemacs-hg @ 2004-06-17 03:01:10 by james] Synch with Emacs 21.3 derived.el, plus new stuff in subr.el to support it, as well as some documentation.
author james
date Thu, 17 Jun 2004 03:01:17 +0000
parents 124ce9dc008b
children 2f37290328b0
line wrap: on
line diff
--- a/lisp/subr.el	Wed Jun 16 21:50:51 2004 +0000
+++ b/lisp/subr.el	Thu Jun 17 03:01:17 2004 +0000
@@ -521,7 +521,14 @@
 	   (buffer-string)
 	 (kill-buffer nil)))))
 
-;; FSF 21.2.
+(defmacro with-local-quit (&rest body)
+  "Execute BODY with `inhibit-quit' temporarily bound to nil."
+  `(condition-case nil
+       (let ((inhibit-quit nil))
+	 ,@body)
+     (quit (setq quit-flag t))))
+
+;; FSF 21.3.
 
 ; (defmacro combine-after-change-calls (&rest body)
 ;   "Execute BODY, but don't call the after-change functions till the end.
@@ -535,11 +542,41 @@
 
 ; Do not alter `after-change-functions' or `before-change-functions'
 ; in BODY."
+;   (declare (indent 0) (debug t))
 ;   `(unwind-protect
 ;        (let ((combine-after-change-calls t))
 ; 	 . ,body)
 ;      (combine-after-change-execute)))
 
+
+(defvar delay-mode-hooks nil
+  "If non-nil, `run-mode-hooks' should delay running the hooks.")
+(defvar delayed-mode-hooks nil
+  "List of delayed mode hooks waiting to be run.")
+(make-variable-buffer-local 'delayed-mode-hooks)
+(put 'delay-mode-hooks 'permanent-local t)
+
+(defun run-mode-hooks (&rest hooks)
+  "Run mode hooks `delayed-mode-hooks' and HOOKS, or delay HOOKS.
+Execution is delayed if `delay-mode-hooks' is non-nil.
+Major mode functions should use this."
+  (if delay-mode-hooks
+      ;; Delaying case.
+      (dolist (hook hooks)
+	(push hook delayed-mode-hooks))
+    ;; Normal case, just run the hook as before plus any delayed hooks.
+    (setq hooks (nconc (nreverse delayed-mode-hooks) hooks))
+    (setq delayed-mode-hooks nil)
+    (apply 'run-hooks hooks)))
+
+(defmacro delay-mode-hooks (&rest body)
+  "Execute BODY, but delay any `run-mode-hooks'.
+Only affects hooks run in the current buffer."
+  `(progn
+     (make-local-variable 'delay-mode-hooks)
+     (let ((delay-mode-hooks t))
+       ,@body)))
+
 (defmacro with-syntax-table (table &rest body)
   "Evaluate BODY with syntax table of current buffer set to a copy of TABLE.
 The syntax table of the current buffer is saved, BODY is evaluated, and the