comparison src/insdel.c @ 6787:4fcd24cee757

(before_change_functions_restore): (after_change_functions_restore): New functions. (signal_before_change): Handle Vbefore_change_functions. (signal_after_change): Handle Vafter_change_functions.
author Richard M. Stallman <rms@gnu.org>
date Sun, 10 Apr 1994 02:34:02 +0000
parents 6b0dd4aeca67
children 6e6410985d76
comparison
equal deleted inserted replaced
6786:25280492d514 6787:4fcd24cee757
1 /* Buffer insertion/deletion and gap motion for GNU Emacs. 1 /* Buffer insertion/deletion and gap motion for GNU Emacs.
2 Copyright (C) 1985, 1986, 1993 Free Software Foundation, Inc. 2 Copyright (C) 1985, 1986, 1993, 1994 Free Software Foundation, Inc.
3 3
4 This file is part of GNU Emacs. 4 This file is part of GNU Emacs.
5 5
6 GNU Emacs is free software; you can redistribute it and/or modify 6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
586 Lisp_Object value; 586 Lisp_Object value;
587 { 587 {
588 Vafter_change_function = value; 588 Vafter_change_function = value;
589 } 589 }
590 590
591 static Lisp_Object
592 before_change_functions_restore (value)
593 Lisp_Object value;
594 {
595 Vbefore_change_functions = value;
596 }
597
598 static Lisp_Object
599 after_change_functions_restore (value)
600 Lisp_Object value;
601 {
602 Vafter_change_functions = value;
603 }
604
591 /* Signal a change to the buffer immediately before it happens. 605 /* Signal a change to the buffer immediately before it happens.
592 START and END are the bounds of the text to be changed, 606 START and END are the bounds of the text to be changed,
593 as Lisp objects. */ 607 as Lisp objects. */
594 608
595 signal_before_change (start, end) 609 signal_before_change (start, end)
606 { 620 {
607 int count = specpdl_ptr - specpdl; 621 int count = specpdl_ptr - specpdl;
608 Lisp_Object function; 622 Lisp_Object function;
609 623
610 function = Vbefore_change_function; 624 function = Vbefore_change_function;
625
611 record_unwind_protect (after_change_function_restore, 626 record_unwind_protect (after_change_function_restore,
612 Vafter_change_function); 627 Vafter_change_function);
613 record_unwind_protect (before_change_function_restore, 628 record_unwind_protect (before_change_function_restore,
614 Vbefore_change_function); 629 Vbefore_change_function);
630 record_unwind_protect (after_change_functions_restore,
631 Vafter_change_functions);
632 record_unwind_protect (before_change_functions_restore,
633 Vbefore_change_functions);
615 Vafter_change_function = Qnil; 634 Vafter_change_function = Qnil;
616 Vbefore_change_function = Qnil; 635 Vbefore_change_function = Qnil;
636 Vafter_change_functions = Qnil;
637 Vbefore_change_functions = Qnil;
617 638
618 call2 (function, start, end); 639 call2 (function, start, end);
640 unbind_to (count, Qnil);
641 }
642
643 /* Now in any case run the before-change-function if any. */
644 if (!NILP (Vbefore_change_functions))
645 {
646 int count = specpdl_ptr - specpdl;
647 Lisp_Object functions;
648
649 functions = Vbefore_change_functions;
650
651 record_unwind_protect (after_change_function_restore,
652 Vafter_change_function);
653 record_unwind_protect (before_change_function_restore,
654 Vbefore_change_function);
655 record_unwind_protect (after_change_functions_restore,
656 Vafter_change_functions);
657 record_unwind_protect (before_change_functions_restore,
658 Vbefore_change_functions);
659 Vafter_change_function = Qnil;
660 Vbefore_change_function = Qnil;
661 Vafter_change_functions = Qnil;
662 Vbefore_change_functions = Qnil;
663
664 while (CONSP (functions))
665 {
666 call2 (XCONS (functions)->car, start, end);
667 functions = XCONS (functions)->cdr;
668 }
619 unbind_to (count, Qnil); 669 unbind_to (count, Qnil);
620 } 670 }
621 } 671 }
622 672
623 /* Signal a change immediately after it happens. 673 /* Signal a change immediately after it happens.
637 687
638 record_unwind_protect (after_change_function_restore, 688 record_unwind_protect (after_change_function_restore,
639 Vafter_change_function); 689 Vafter_change_function);
640 record_unwind_protect (before_change_function_restore, 690 record_unwind_protect (before_change_function_restore,
641 Vbefore_change_function); 691 Vbefore_change_function);
692 record_unwind_protect (after_change_functions_restore,
693 Vafter_change_functions);
694 record_unwind_protect (before_change_functions_restore,
695 Vbefore_change_functions);
642 Vafter_change_function = Qnil; 696 Vafter_change_function = Qnil;
643 Vbefore_change_function = Qnil; 697 Vbefore_change_function = Qnil;
698 Vafter_change_functions = Qnil;
699 Vbefore_change_functions = Qnil;
644 700
645 call3 (function, make_number (pos), make_number (pos + lenins), 701 call3 (function, make_number (pos), make_number (pos + lenins),
646 make_number (lendel)); 702 make_number (lendel));
647 unbind_to (count, Qnil); 703 unbind_to (count, Qnil);
648 } 704 }
649 } 705 if (!NILP (Vafter_change_functions))
706 {
707 int count = specpdl_ptr - specpdl;
708 Lisp_Object functions;
709 functions = Vafter_change_functions;
710
711 record_unwind_protect (after_change_function_restore,
712 Vafter_change_function);
713 record_unwind_protect (before_change_function_restore,
714 Vbefore_change_function);
715 record_unwind_protect (after_change_functions_restore,
716 Vafter_change_functions);
717 record_unwind_protect (before_change_functions_restore,
718 Vbefore_change_functions);
719 Vafter_change_function = Qnil;
720 Vbefore_change_function = Qnil;
721 Vafter_change_functions = Qnil;
722 Vbefore_change_functions = Qnil;
723
724 while (CONSP (functions))
725 {
726 call3 (XCONS (functions)->car,
727 make_number (pos), make_number (pos + lenins),
728 make_number (lendel));
729 functions = XCONS (functions)->cdr;
730 }
731 unbind_to (count, Qnil);
732 }
733 }