Mercurial > emacs
comparison src/eval.c @ 12732:981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
author | Simon Marshall <simon@gnu.org> |
---|---|
date | Mon, 31 Jul 1995 12:07:10 +0000 |
parents | a8feaa42d775 |
children | 2a8036f0b585 |
comparison
equal
deleted
inserted
replaced
12731:cac1b80e43be | 12732:981b924c832b |
---|---|
1814 } | 1814 } |
1815 | 1815 |
1816 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args)); | 1816 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args)); |
1817 } | 1817 } |
1818 | 1818 |
1819 DEFUN ("run-hook-with-args", Frun_hook_with_args, Srun_hook_with_args, 1, MANY, 0, | 1819 /* Run hook variables in various ways. */ |
1820 | |
1821 enum run_hooks_condition {to_completion, until_success, until_failure}; | |
1822 | |
1823 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 1, MANY, 0, | |
1824 "Run each hook in HOOKS. Major mode functions use this.\n\ | |
1825 Each argument should be a symbol, a hook variable.\n\ | |
1826 These symbols are processed in the order specified.\n\ | |
1827 If a hook symbol has a non-nil value, that value may be a function\n\ | |
1828 or a list of functions to be called to run the hook.\n\ | |
1829 If the value is a function, it is called with no arguments.\n\ | |
1830 If it is a list, the elements are called, in order, with no arguments.\n\ | |
1831 \n\ | |
1832 To make a hook variable buffer-local, use `make-local-hook',\n\ | |
1833 not `make-local-variable'.") | |
1834 (nargs, args) | |
1835 int nargs; | |
1836 Lisp_Object *args; | |
1837 { | |
1838 Lisp_Object hook[1]; | |
1839 register int i; | |
1840 | |
1841 for (i = 0; i < nargs; i++) | |
1842 { | |
1843 hook[0] = args[i]; | |
1844 run_hook_with_args (1, hook, to_completion); | |
1845 } | |
1846 | |
1847 return Qnil; | |
1848 } | |
1849 | |
1850 DEFUN ("run-hook-with-args", | |
1851 Frun_hook_with_args, Srun_hook_with_args, 1, MANY, 0, | |
1820 "Run HOOK with the specified arguments ARGS.\n\ | 1852 "Run HOOK with the specified arguments ARGS.\n\ |
1821 HOOK should be a symbol, a hook variable. If HOOK has a non-nil\n\ | 1853 HOOK should be a symbol, a hook variable. If HOOK has a non-nil\n\ |
1822 value, that value may be a function or a list of functions to be\n\ | 1854 value, that value may be a function or a list of functions to be\n\ |
1823 called to run the hook. If the value is a function, it is called with\n\ | 1855 called to run the hook. If the value is a function, it is called with\n\ |
1824 the given arguments and its return value is returned. If it is a list\n\ | 1856 the given arguments and its return value is returned. If it is a list\n\ |
1825 of functions, those functions are called, in order,\n\ | 1857 of functions, those functions are called, in order,\n\ |
1826 with the given arguments ARGS.\n\ | 1858 with the given arguments ARGS.\n\ |
1827 It is best not to depend on the value return by `run-hook-with-args',\n\ | 1859 It is best not to depend on the value return by `run-hook-with-args',\n\ |
1828 as that may change.\n\ | 1860 as that may change.\n\ |
1829 \n\ | 1861 \n\ |
1830 To make a hook variable buffer-local, use `make-local-hook', not\n\ | 1862 To make a hook variable buffer-local, use `make-local-hook',\n\ |
1831 `make-local-variable'.") | 1863 not `make-local-variable'.") |
1832 (nargs, args) | 1864 (nargs, args) |
1833 int nargs; | 1865 int nargs; |
1834 Lisp_Object *args; | 1866 Lisp_Object *args; |
1835 { | 1867 { |
1836 Lisp_Object sym, val; | 1868 return run_hook_with_args (nargs, args, to_completion); |
1869 } | |
1870 | |
1871 DEFUN ("run-hook-with-args-until-success", | |
1872 Frun_hook_with_args_until_success, Srun_hook_with_args_until_success, | |
1873 1, MANY, 0, | |
1874 "Run HOOK with the specified arguments ARGS.\n\ | |
1875 HOOK should be a symbol, a hook variable. Its value should\n\ | |
1876 be a list of functions. We call those functions, one by one,\n\ | |
1877 passing arguments ARGS to each of them, until one of them\n\ | |
1878 returns a non-nil value. Then we return that value.\n\ | |
1879 If all the functions return nil, we return nil.\n\ | |
1880 \n\ | |
1881 To make a hook variable buffer-local, use `make-local-hook',\n\ | |
1882 not `make-local-variable'.") | |
1883 (nargs, args) | |
1884 int nargs; | |
1885 Lisp_Object *args; | |
1886 { | |
1887 return run_hook_with_args (nargs, args, until_success); | |
1888 } | |
1889 | |
1890 DEFUN ("run-hook-with-args-until-failure", | |
1891 Frun_hook_with_args_until_failure, Srun_hook_with_args_until_failure, | |
1892 1, MANY, 0, | |
1893 "Run HOOK with the specified arguments ARGS.\n\ | |
1894 HOOK should be a symbol, a hook variable. Its value should\n\ | |
1895 be a list of functions. We call those functions, one by one,\n\ | |
1896 passing arguments ARGS to each of them, until one of them\n\ | |
1897 returns nil. Then we return nil.\n\ | |
1898 If all the functions return non-nil, we return non-nil.\n\ | |
1899 \n\ | |
1900 To make a hook variable buffer-local, use `make-local-hook',\n\ | |
1901 not `make-local-variable'.") | |
1902 (nargs, args) | |
1903 int nargs; | |
1904 Lisp_Object *args; | |
1905 { | |
1906 return run_hook_with_args (nargs, args, until_failure); | |
1907 } | |
1908 | |
1909 Lisp_Object | |
1910 run_hook_with_args (nargs, args, cond) | |
1911 int nargs; | |
1912 Lisp_Object *args; | |
1913 enum run_hooks_condition cond; | |
1914 { | |
1915 Lisp_Object sym, val, ret; | |
1837 | 1916 |
1838 sym = args[0]; | 1917 sym = args[0]; |
1839 val = find_symbol_value (sym); | 1918 val = find_symbol_value (sym); |
1919 ret = (cond == until_failure ? Qt : Qnil); | |
1920 | |
1840 if (EQ (val, Qunbound) || NILP (val)) | 1921 if (EQ (val, Qunbound) || NILP (val)) |
1841 return Qnil; | 1922 return ret; |
1842 else if (!CONSP (val) || EQ (XCONS (val)->car, Qlambda)) | 1923 else if (!CONSP (val) || EQ (XCONS (val)->car, Qlambda)) |
1843 { | 1924 { |
1844 args[0] = val; | 1925 args[0] = val; |
1845 return Ffuncall (nargs, args); | 1926 return Ffuncall (nargs, args); |
1846 } | 1927 } |
1847 else | 1928 else |
1848 { | 1929 { |
1849 for (; CONSP (val); val = XCONS (val)->cdr) | 1930 for (; |
1931 CONSP (val) && ((cond == to_completion) | |
1932 || (cond == until_success ? NILP (ret) | |
1933 : !NILP (ret))); | |
1934 val = XCONS (val)->cdr) | |
1850 { | 1935 { |
1851 if (EQ (XCONS (val)->car, Qt)) | 1936 if (EQ (XCONS (val)->car, Qt)) |
1852 { | 1937 { |
1853 /* t indicates this hook has a local binding; | 1938 /* t indicates this hook has a local binding; |
1854 it means to run the global binding too. */ | 1939 it means to run the global binding too. */ |
1855 Lisp_Object globals; | 1940 Lisp_Object globals; |
1856 | 1941 |
1857 for (globals = Fdefault_value (sym); CONSP (globals); | 1942 for (globals = Fdefault_value (sym); |
1943 CONSP (globals) && ((cond == to_completion) | |
1944 || (cond == until_success ? NILP (ret) | |
1945 : !NILP (ret))); | |
1858 globals = XCONS (globals)->cdr) | 1946 globals = XCONS (globals)->cdr) |
1859 { | 1947 { |
1860 args[0] = XCONS (globals)->car; | 1948 args[0] = XCONS (globals)->car; |
1861 Ffuncall (nargs, args); | 1949 ret = Ffuncall (nargs, args); |
1862 } | 1950 } |
1863 } | 1951 } |
1864 else | 1952 else |
1865 { | 1953 { |
1866 args[0] = XCONS (val)->car; | 1954 args[0] = XCONS (val)->car; |
1867 Ffuncall (nargs, args); | 1955 ret = Ffuncall (nargs, args); |
1868 } | 1956 } |
1869 } | 1957 } |
1870 return Qnil; | 1958 return ret; |
1871 } | 1959 } |
1872 } | 1960 } |
1873 | 1961 |
1874 /* Apply fn to arg */ | 1962 /* Apply fn to arg */ |
1875 Lisp_Object | 1963 Lisp_Object |
1876 apply1 (fn, arg) | 1964 apply1 (fn, arg) |
1877 Lisp_Object fn, arg; | 1965 Lisp_Object fn, arg; |
1878 { | 1966 { |
2709 defsubr (&Sinteractive_p); | 2797 defsubr (&Sinteractive_p); |
2710 defsubr (&Scommandp); | 2798 defsubr (&Scommandp); |
2711 defsubr (&Sautoload); | 2799 defsubr (&Sautoload); |
2712 defsubr (&Seval); | 2800 defsubr (&Seval); |
2713 defsubr (&Sapply); | 2801 defsubr (&Sapply); |
2802 defsubr (&Sfuncall); | |
2803 defsubr (&Srun_hooks); | |
2714 defsubr (&Srun_hook_with_args); | 2804 defsubr (&Srun_hook_with_args); |
2715 defsubr (&Sfuncall); | 2805 defsubr (&Srun_hook_with_args_until_success); |
2806 defsubr (&Srun_hook_with_args_until_failure); | |
2716 defsubr (&Sfetch_bytecode); | 2807 defsubr (&Sfetch_bytecode); |
2717 defsubr (&Sbacktrace_debug); | 2808 defsubr (&Sbacktrace_debug); |
2718 defsubr (&Sbacktrace); | 2809 defsubr (&Sbacktrace); |
2719 defsubr (&Sbacktrace_frame); | 2810 defsubr (&Sbacktrace_frame); |
2720 } | 2811 } |