aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Marshall1995-07-31 12:07:10 +0000
committerSimon Marshall1995-07-31 12:07:10 +0000
commitff936e5324812012bfe7e8aae34ae301913abe0e (patch)
treea2e9b2bb85d9e912068d49febdd1ee49e4aca828 /src
parentf1b6e5fc820e9f22db1a59f90148aec14187916f (diff)
downloademacs-ff936e5324812012bfe7e8aae34ae301913abe0e.tar.gz
emacs-ff936e5324812012bfe7e8aae34ae301913abe0e.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/eval.c115
1 files changed, 103 insertions, 12 deletions
diff --git a/src/eval.c b/src/eval.c
index 0adc9a7a87f..bc09eb2871e 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1816,7 +1816,39 @@ Thus, (apply '+ 1 2 '(3 4)) returns 10.")
1816 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args)); 1816 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args));
1817} 1817}
1818 1818
1819DEFUN ("run-hook-with-args", Frun_hook_with_args, Srun_hook_with_args, 1, MANY, 0, 1819/* Run hook variables in various ways. */
1820
1821enum run_hooks_condition {to_completion, until_success, until_failure};
1822
1823DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 1, MANY, 0,
1824 "Run each hook in HOOKS. Major mode functions use this.\n\
1825Each argument should be a symbol, a hook variable.\n\
1826These symbols are processed in the order specified.\n\
1827If a hook symbol has a non-nil value, that value may be a function\n\
1828or a list of functions to be called to run the hook.\n\
1829If the value is a function, it is called with no arguments.\n\
1830If it is a list, the elements are called, in order, with no arguments.\n\
1831\n\
1832To make a hook variable buffer-local, use `make-local-hook',\n\
1833not `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
1850DEFUN ("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\
1821HOOK should be a symbol, a hook variable. If HOOK has a non-nil\n\ 1853HOOK should be a symbol, a hook variable. If HOOK has a non-nil\n\
1822value, that value may be a function or a list of functions to be\n\ 1854value, that value may be a function or a list of functions to be\n\
@@ -1827,18 +1859,67 @@ with the given arguments ARGS.\n\
1827It is best not to depend on the value return by `run-hook-with-args',\n\ 1859It is best not to depend on the value return by `run-hook-with-args',\n\
1828as that may change.\n\ 1860as that may change.\n\
1829\n\ 1861\n\
1830To make a hook variable buffer-local, use `make-local-hook', not\n\ 1862To make a hook variable buffer-local, use `make-local-hook',\n\
1831`make-local-variable'.") 1863not `make-local-variable'.")
1864 (nargs, args)
1865 int nargs;
1866 Lisp_Object *args;
1867{
1868 return run_hook_with_args (nargs, args, to_completion);
1869}
1870
1871DEFUN ("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\
1875HOOK should be a symbol, a hook variable. Its value should\n\
1876be a list of functions. We call those functions, one by one,\n\
1877passing arguments ARGS to each of them, until one of them\n\
1878returns a non-nil value. Then we return that value.\n\
1879If all the functions return nil, we return nil.\n\
1880\n\
1881To make a hook variable buffer-local, use `make-local-hook',\n\
1882not `make-local-variable'.")
1832 (nargs, args) 1883 (nargs, args)
1833 int nargs; 1884 int nargs;
1834 Lisp_Object *args; 1885 Lisp_Object *args;
1835{ 1886{
1836 Lisp_Object sym, val; 1887 return run_hook_with_args (nargs, args, until_success);
1888}
1889
1890DEFUN ("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\
1894HOOK should be a symbol, a hook variable. Its value should\n\
1895be a list of functions. We call those functions, one by one,\n\
1896passing arguments ARGS to each of them, until one of them\n\
1897returns nil. Then we return nil.\n\
1898If all the functions return non-nil, we return non-nil.\n\
1899\n\
1900To make a hook variable buffer-local, use `make-local-hook',\n\
1901not `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
1909Lisp_Object
1910run_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;
@@ -1846,7 +1927,11 @@ To make a hook variable buffer-local, use `make-local-hook', not\n\
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 {
@@ -1854,23 +1939,26 @@ To make a hook variable buffer-local, use `make-local-hook', not\n\
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 */
1875Lisp_Object 1963Lisp_Object
1876apply1 (fn, arg) 1964apply1 (fn, arg)
@@ -2711,8 +2799,11 @@ Otherwise, nil (in a bare Emacs without preloaded Lisp code).");
2711 defsubr (&Sautoload); 2799 defsubr (&Sautoload);
2712 defsubr (&Seval); 2800 defsubr (&Seval);
2713 defsubr (&Sapply); 2801 defsubr (&Sapply);
2714 defsubr (&Srun_hook_with_args);
2715 defsubr (&Sfuncall); 2802 defsubr (&Sfuncall);
2803 defsubr (&Srun_hooks);
2804 defsubr (&Srun_hook_with_args);
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);