diff options
| author | Simon Marshall | 1995-07-31 12:07:10 +0000 |
|---|---|---|
| committer | Simon Marshall | 1995-07-31 12:07:10 +0000 |
| commit | ff936e5324812012bfe7e8aae34ae301913abe0e (patch) | |
| tree | a2e9b2bb85d9e912068d49febdd1ee49e4aca828 /src/eval.c | |
| parent | f1b6e5fc820e9f22db1a59f90148aec14187916f (diff) | |
| download | emacs-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/eval.c')
| -rw-r--r-- | src/eval.c | 115 |
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 | ||
| 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\ |
| @@ -1827,18 +1859,67 @@ 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'.") |
| 1864 | (nargs, args) | ||
| 1865 | int nargs; | ||
| 1866 | Lisp_Object *args; | ||
| 1867 | { | ||
| 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'.") | ||
| 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 | |||
| 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; |
| @@ -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 */ |
| 1875 | Lisp_Object | 1963 | Lisp_Object |
| 1876 | apply1 (fn, arg) | 1964 | apply1 (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); |