aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/subr.el88
1 files changed, 3 insertions, 85 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 63e02ae26ca..970ba2ee4f6 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -448,93 +448,11 @@ Please convert your programs to use the variable `baud-rate' directly."
448 448
449;;;; Hook manipulation functions. 449;;;; Hook manipulation functions.
450 450
451(defun run-hooks (&rest hooklist) 451;; We used to have this variable so that C code knew how to run hooks. That
452 "Takes hook names and runs each one in turn. Major mode functions use this. 452;; calling convention is made obsolete now the hook running functions are in C.
453Each argument should be a symbol, a hook variable.
454These symbols are processed in the order specified.
455If a hook symbol has a non-nil value, that value may be a function
456or a list of functions to be called to run the hook.
457If the value is a function, it is called with no arguments.
458If it is a list, the elements are called, in order, with no arguments.
459
460To make a hook variable buffer-local, use `make-local-hook', not
461`make-local-variable'."
462 (while hooklist
463 (let ((sym (car hooklist)))
464 (and (boundp sym)
465 (symbol-value sym)
466 (let ((value (symbol-value sym)))
467 (if (and (listp value) (not (eq (car value) 'lambda)))
468 (while value
469 (if (eq (car value) t)
470 ;; t indicates this hook has a local binding;
471 ;; it means to run the global binding too.
472 (let ((functions (default-value sym)))
473 (while functions
474 (funcall (car functions))
475 (setq functions (cdr functions))))
476 (funcall (car value)))
477 (setq value (cdr value)))
478 (funcall value)))))
479 (setq hooklist (cdr hooklist))))
480
481(defun run-hook-with-args-until-success (hook &rest args)
482 "Run HOOK with the specified arguments ARGS.
483HOOK should be a symbol, a hook variable. Its value should
484be a list of functions. We call those functions, one by one,
485passing arguments ARGS to each of them, until one of them
486returns a non-nil value. Then we return that value.
487If all the functions return nil, we return nil.
488
489To make a hook variable buffer-local, use `make-local-hook', not
490`make-local-variable'."
491 (and (boundp hook)
492 (symbol-value hook)
493 (let ((value (symbol-value hook))
494 success)
495 (while (and value (not success))
496 (if (eq (car value) t)
497 ;; t indicates this hook has a local binding;
498 ;; it means to run the global binding too.
499 (let ((functions (default-value hook)))
500 (while (and functions (not success))
501 (setq success (apply (car functions) args))
502 (setq functions (cdr functions))))
503 (setq success (apply (car value) args)))
504 (setq value (cdr value)))
505 success)))
506
507(defun run-hook-with-args-until-failure (hook &rest args)
508 "Run HOOK with the specified arguments ARGS.
509HOOK should be a symbol, a hook variable. Its value should
510be a list of functions. We call those functions, one by one,
511passing arguments ARGS to each of them, until one of them
512returns nil. Then we return nil.
513If all the functions return non-nil, we return non-nil.
514
515To make a hook variable buffer-local, use `make-local-hook', not
516`make-local-variable'."
517 ;; We must return non-nil if there are no hook functions!
518 (or (not (boundp hook))
519 (not (symbol-value hook))
520 (let ((value (symbol-value hook))
521 (success t))
522 (while (and value success)
523 (if (eq (car value) t)
524 ;; t indicates this hook has a local binding;
525 ;; it means to run the global binding too.
526 (let ((functions (default-value hook)))
527 (while (and functions success)
528 (setq success (apply (car functions) args))
529 (setq functions (cdr functions))))
530 (setq success (apply (car value) args)))
531 (setq value (cdr value)))
532 success)))
533
534;; Tell C code how to call this function.
535(defconst run-hooks 'run-hooks 453(defconst run-hooks 'run-hooks
536 "Variable by which C primitives find the function `run-hooks'. 454 "Variable by which C primitives find the function `run-hooks'.
537Don't change it.") 455Don't change it. Don't use it either; use the hook running C primitives.")
538 456
539(defun make-local-hook (hook) 457(defun make-local-hook (hook)
540 "Make the hook HOOK local to the current buffer. 458 "Make the hook HOOK local to the current buffer.