diff options
| author | Stefan Monnier | 2012-03-25 16:37:21 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2012-03-25 16:37:21 -0400 |
| commit | 699c782b7668c44d0fa4446331b0590a6d5dac82 (patch) | |
| tree | 5dcce364741d0761920a3d274b0fc8aba4103d45 /src/minibuf.c | |
| parent | 98fb480ee31bf74cf554044f60f21df16566dd7f (diff) | |
| parent | e99a9b8bdccadded1f6fae88ee7a2a93dfd4eacf (diff) | |
| download | emacs-pending.tar.gz emacs-pending.zip | |
Merge from trunkpending
Diffstat (limited to 'src/minibuf.c')
| -rw-r--r-- | src/minibuf.c | 114 |
1 files changed, 71 insertions, 43 deletions
diff --git a/src/minibuf.c b/src/minibuf.c index cf37c337be4..a9bdf06b735 100644 --- a/src/minibuf.c +++ b/src/minibuf.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Minibuffer input and completion. | 1 | /* Minibuffer input and completion. |
| 2 | 2 | ||
| 3 | Copyright (C) 1985-1986, 1993-2011 Free Software Foundation, Inc. | 3 | Copyright (C) 1985-1986, 1993-2012 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This file is part of GNU Emacs. | 5 | This file is part of GNU Emacs. |
| 6 | 6 | ||
| @@ -19,6 +19,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | #include <config.h> | 21 | #include <config.h> |
| 22 | #include <errno.h> | ||
| 22 | #include <stdio.h> | 23 | #include <stdio.h> |
| 23 | #include <setjmp.h> | 24 | #include <setjmp.h> |
| 24 | 25 | ||
| @@ -48,7 +49,7 @@ static Lisp_Object minibuf_save_list; | |||
| 48 | 49 | ||
| 49 | /* Depth in minibuffer invocations. */ | 50 | /* Depth in minibuffer invocations. */ |
| 50 | 51 | ||
| 51 | int minibuf_level; | 52 | EMACS_INT minibuf_level; |
| 52 | 53 | ||
| 53 | /* The maximum length of a minibuffer history. */ | 54 | /* The maximum length of a minibuffer history. */ |
| 54 | 55 | ||
| @@ -236,8 +237,9 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, | |||
| 236 | int allow_props, int inherit_input_method) | 237 | int allow_props, int inherit_input_method) |
| 237 | { | 238 | { |
| 238 | ptrdiff_t size, len; | 239 | ptrdiff_t size, len; |
| 239 | char *line, *s; | 240 | char *line; |
| 240 | Lisp_Object val; | 241 | Lisp_Object val; |
| 242 | int c; | ||
| 241 | 243 | ||
| 242 | fprintf (stdout, "%s", SDATA (prompt)); | 244 | fprintf (stdout, "%s", SDATA (prompt)); |
| 243 | fflush (stdout); | 245 | fflush (stdout); |
| @@ -246,22 +248,30 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, | |||
| 246 | size = 100; | 248 | size = 100; |
| 247 | len = 0; | 249 | len = 0; |
| 248 | line = (char *) xmalloc (size); | 250 | line = (char *) xmalloc (size); |
| 249 | while ((s = fgets (line + len, size - len, stdin)) != NULL | 251 | |
| 250 | && (len = strlen (line), | 252 | while ((c = getchar ()) != '\n') |
| 251 | len == size - 1 && line[len - 1] != '\n')) | ||
| 252 | { | 253 | { |
| 253 | if (STRING_BYTES_BOUND / 2 < size) | 254 | if (c == EOF) |
| 254 | memory_full (SIZE_MAX); | 255 | { |
| 255 | size *= 2; | 256 | if (errno != EINTR) |
| 256 | line = (char *) xrealloc (line, size); | 257 | break; |
| 258 | } | ||
| 259 | else | ||
| 260 | { | ||
| 261 | if (len == size) | ||
| 262 | { | ||
| 263 | if (STRING_BYTES_BOUND / 2 < size) | ||
| 264 | memory_full (SIZE_MAX); | ||
| 265 | size *= 2; | ||
| 266 | line = (char *) xrealloc (line, size); | ||
| 267 | } | ||
| 268 | line[len++] = c; | ||
| 269 | } | ||
| 257 | } | 270 | } |
| 258 | 271 | ||
| 259 | if (s) | 272 | if (len || c == '\n') |
| 260 | { | 273 | { |
| 261 | char *nl = strchr (line, '\n'); | 274 | val = make_string (line, len); |
| 262 | if (nl) | ||
| 263 | *nl = '\0'; | ||
| 264 | val = build_string (line); | ||
| 265 | xfree (line); | 275 | xfree (line); |
| 266 | } | 276 | } |
| 267 | else | 277 | else |
| @@ -549,6 +559,10 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, | |||
| 549 | minibuffer = get_minibuffer (minibuf_level); | 559 | minibuffer = get_minibuffer (minibuf_level); |
| 550 | Fset_buffer (minibuffer); | 560 | Fset_buffer (minibuffer); |
| 551 | 561 | ||
| 562 | /* Defeat (setq-default truncate-lines t), since truncated lines do | ||
| 563 | not work correctly in minibuffers. (Bug#5715, etc) */ | ||
| 564 | BVAR (current_buffer, truncate_lines) = Qnil; | ||
| 565 | |||
| 552 | /* If appropriate, copy enable-multibyte-characters into the minibuffer. */ | 566 | /* If appropriate, copy enable-multibyte-characters into the minibuffer. */ |
| 553 | if (inherit_input_method) | 567 | if (inherit_input_method) |
| 554 | BVAR (current_buffer, enable_multibyte_characters) = enable_multibyte; | 568 | BVAR (current_buffer, enable_multibyte_characters) = enable_multibyte; |
| @@ -762,10 +776,10 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, | |||
| 762 | used for nonrecursive minibuffer invocations. */ | 776 | used for nonrecursive minibuffer invocations. */ |
| 763 | 777 | ||
| 764 | Lisp_Object | 778 | Lisp_Object |
| 765 | get_minibuffer (int depth) | 779 | get_minibuffer (EMACS_INT depth) |
| 766 | { | 780 | { |
| 767 | Lisp_Object tail, num, buf; | 781 | Lisp_Object tail, num, buf; |
| 768 | char name[24]; | 782 | char name[sizeof " *Minibuf-*" + INT_STRLEN_BOUND (EMACS_INT)]; |
| 769 | 783 | ||
| 770 | XSETFASTINT (num, depth); | 784 | XSETFASTINT (num, depth); |
| 771 | tail = Fnthcdr (num, Vminibuffer_list); | 785 | tail = Fnthcdr (num, Vminibuffer_list); |
| @@ -777,7 +791,7 @@ get_minibuffer (int depth) | |||
| 777 | buf = Fcar (tail); | 791 | buf = Fcar (tail); |
| 778 | if (NILP (buf) || NILP (BVAR (XBUFFER (buf), name))) | 792 | if (NILP (buf) || NILP (BVAR (XBUFFER (buf), name))) |
| 779 | { | 793 | { |
| 780 | sprintf (name, " *Minibuf-%d*", depth); | 794 | sprintf (name, " *Minibuf-%"pI"d*", depth); |
| 781 | buf = Fget_buffer_create (build_string (name)); | 795 | buf = Fget_buffer_create (build_string (name)); |
| 782 | 796 | ||
| 783 | /* Although the buffer's name starts with a space, undo should be | 797 | /* Although the buffer's name starts with a space, undo should be |
| @@ -891,27 +905,36 @@ DEFUN ("read-from-minibuffer", Fread_from_minibuffer, | |||
| 891 | The optional second arg INITIAL-CONTENTS is an obsolete alternative to | 905 | The optional second arg INITIAL-CONTENTS is an obsolete alternative to |
| 892 | DEFAULT-VALUE. It normally should be nil in new code, except when | 906 | DEFAULT-VALUE. It normally should be nil in new code, except when |
| 893 | HIST is a cons. It is discussed in more detail below. | 907 | HIST is a cons. It is discussed in more detail below. |
| 908 | |||
| 894 | Third arg KEYMAP is a keymap to use whilst reading; | 909 | Third arg KEYMAP is a keymap to use whilst reading; |
| 895 | if omitted or nil, the default is `minibuffer-local-map'. | 910 | if omitted or nil, the default is `minibuffer-local-map'. |
| 896 | If fourth arg READ is non-nil, then interpret the result as a Lisp object | 911 | |
| 912 | If fourth arg READ is non-nil, interpret the result as a Lisp object | ||
| 897 | and return that object: | 913 | and return that object: |
| 898 | in other words, do `(car (read-from-string INPUT-STRING))' | 914 | in other words, do `(car (read-from-string INPUT-STRING))' |
| 915 | |||
| 899 | Fifth arg HIST, if non-nil, specifies a history list and optionally | 916 | Fifth arg HIST, if non-nil, specifies a history list and optionally |
| 900 | the initial position in the list. It can be a symbol, which is the | 917 | the initial position in the list. It can be a symbol, which is the |
| 901 | history list variable to use, or it can be a cons cell | 918 | history list variable to use, or a cons cell (HISTVAR . HISTPOS). |
| 902 | (HISTVAR . HISTPOS). In that case, HISTVAR is the history list variable | 919 | In that case, HISTVAR is the history list variable to use, and |
| 903 | to use, and HISTPOS is the initial position for use by the minibuffer | 920 | HISTPOS is the initial position for use by the minibuffer history |
| 904 | history commands. For consistency, you should also specify that | 921 | commands. For consistency, you should also specify that element of |
| 905 | element of the history as the value of INITIAL-CONTENTS. Positions | 922 | the history as the value of INITIAL-CONTENTS. Positions are counted |
| 906 | are counted starting from 1 at the beginning of the list. | 923 | starting from 1 at the beginning of the list. |
| 907 | Sixth arg DEFAULT-VALUE is the default value or the list of default values. | 924 | |
| 908 | If non-nil, it is available for history commands, and as the value | 925 | Sixth arg DEFAULT-VALUE, if non-nil, should be a string, which is used |
| 909 | (or the first element of the list of default values) to return | 926 | as the default to `read' if READ is non-nil and the user enters |
| 910 | if the user enters the empty string. But, unless READ is non-nil, | 927 | empty input. But if READ is nil, this function does _not_ return |
| 911 | `read-from-minibuffer' does NOT return DEFAULT-VALUE if the user enters | 928 | DEFAULT-VALUE for empty input! Instead, it returns the empty string. |
| 912 | empty input! It returns the empty string. | 929 | |
| 930 | Whatever the value of READ, DEFAULT-VALUE is made available via the | ||
| 931 | minibuffer history commands. DEFAULT-VALUE can also be a list of | ||
| 932 | strings, in which case all the strings are available in the history, | ||
| 933 | and the first string is the default to `read' if READ is non-nil. | ||
| 934 | |||
| 913 | Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits | 935 | Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits |
| 914 | the current input method and the setting of `enable-multibyte-characters'. | 936 | the current input method and the setting of `enable-multibyte-characters'. |
| 937 | |||
| 915 | If the variable `minibuffer-allow-text-properties' is non-nil, | 938 | If the variable `minibuffer-allow-text-properties' is non-nil, |
| 916 | then the string which is returned includes whatever text properties | 939 | then the string which is returned includes whatever text properties |
| 917 | were present in the minibuffer. Otherwise the value has no text properties. | 940 | were present in the minibuffer. Otherwise the value has no text properties. |
| @@ -1713,7 +1736,7 @@ the values STRING, PREDICATE and `lambda'. */) | |||
| 1713 | (Lisp_Object string, Lisp_Object collection, Lisp_Object predicate) | 1736 | (Lisp_Object string, Lisp_Object collection, Lisp_Object predicate) |
| 1714 | { | 1737 | { |
| 1715 | Lisp_Object regexps, tail, tem = Qnil; | 1738 | Lisp_Object regexps, tail, tem = Qnil; |
| 1716 | EMACS_INT i = 0; | 1739 | ptrdiff_t i = 0; |
| 1717 | 1740 | ||
| 1718 | CHECK_STRING (string); | 1741 | CHECK_STRING (string); |
| 1719 | 1742 | ||
| @@ -1847,8 +1870,9 @@ The arguments STRING and PREDICATE are as in `try-completion', | |||
| 1847 | while (CONSP (bufs) && SREF (XCAR (bufs), 0) == ' ') | 1870 | while (CONSP (bufs) && SREF (XCAR (bufs), 0) == ' ') |
| 1848 | bufs = XCDR (bufs); | 1871 | bufs = XCDR (bufs); |
| 1849 | if (NILP (bufs)) | 1872 | if (NILP (bufs)) |
| 1850 | /* All bufs in `res' are internal, so don't trip them out. */ | 1873 | return (EQ (Flength (res), Flength (Vbuffer_alist)) |
| 1851 | return res; | 1874 | /* If all bufs are internal don't strip them out. */ |
| 1875 | ? res : bufs); | ||
| 1852 | res = bufs; | 1876 | res = bufs; |
| 1853 | while (CONSP (XCDR (bufs))) | 1877 | while (CONSP (XCDR (bufs))) |
| 1854 | if (SREF (XCAR (XCDR (bufs)), 0) == ' ') | 1878 | if (SREF (XCAR (XCDR (bufs)), 0) == ' ') |
| @@ -1978,7 +2002,7 @@ The function is called with the arguments passed to `read-buffer'. */); | |||
| 1978 | 2002 | ||
| 1979 | DEFVAR_BOOL ("read-buffer-completion-ignore-case", | 2003 | DEFVAR_BOOL ("read-buffer-completion-ignore-case", |
| 1980 | read_buffer_completion_ignore_case, | 2004 | read_buffer_completion_ignore_case, |
| 1981 | doc: /* *Non-nil means completion ignores case when reading a buffer name. */); | 2005 | doc: /* Non-nil means completion ignores case when reading a buffer name. */); |
| 1982 | read_buffer_completion_ignore_case = 0; | 2006 | read_buffer_completion_ignore_case = 0; |
| 1983 | 2007 | ||
| 1984 | DEFVAR_LISP ("minibuffer-setup-hook", Vminibuffer_setup_hook, | 2008 | DEFVAR_LISP ("minibuffer-setup-hook", Vminibuffer_setup_hook, |
| @@ -1990,20 +2014,24 @@ The function is called with the arguments passed to `read-buffer'. */); | |||
| 1990 | Vminibuffer_exit_hook = Qnil; | 2014 | Vminibuffer_exit_hook = Qnil; |
| 1991 | 2015 | ||
| 1992 | DEFVAR_LISP ("history-length", Vhistory_length, | 2016 | DEFVAR_LISP ("history-length", Vhistory_length, |
| 1993 | doc: /* *Maximum length for history lists before truncation takes place. | 2017 | doc: /* Maximum length of history lists before truncation takes place. |
| 1994 | A number means that length; t means infinite. Truncation takes place | 2018 | A number means truncate to that length; truncation deletes old |
| 1995 | just after a new element is inserted. Setting the `history-length' | 2019 | elements, and is done just after inserting a new element. |
| 1996 | property of a history variable overrides this default. */); | 2020 | A value of t means no truncation. |
| 2021 | |||
| 2022 | This variable only affects history lists that don't specify their own | ||
| 2023 | maximum lengths. Setting the `history-length' property of a history | ||
| 2024 | variable overrides this default. */); | ||
| 1997 | XSETFASTINT (Vhistory_length, 30); | 2025 | XSETFASTINT (Vhistory_length, 30); |
| 1998 | 2026 | ||
| 1999 | DEFVAR_BOOL ("history-delete-duplicates", history_delete_duplicates, | 2027 | DEFVAR_BOOL ("history-delete-duplicates", history_delete_duplicates, |
| 2000 | doc: /* *Non-nil means to delete duplicates in history. | 2028 | doc: /* Non-nil means to delete duplicates in history. |
| 2001 | If set to t when adding a new history element, all previous identical | 2029 | If set to t when adding a new history element, all previous identical |
| 2002 | elements are deleted from the history list. */); | 2030 | elements are deleted from the history list. */); |
| 2003 | history_delete_duplicates = 0; | 2031 | history_delete_duplicates = 0; |
| 2004 | 2032 | ||
| 2005 | DEFVAR_LISP ("history-add-new-input", Vhistory_add_new_input, | 2033 | DEFVAR_LISP ("history-add-new-input", Vhistory_add_new_input, |
| 2006 | doc: /* *Non-nil means to add new elements in history. | 2034 | doc: /* Non-nil means to add new elements in history. |
| 2007 | If set to nil, minibuffer reading functions don't add new elements to the | 2035 | If set to nil, minibuffer reading functions don't add new elements to the |
| 2008 | history list, so it is possible to do this afterwards by calling | 2036 | history list, so it is possible to do this afterwards by calling |
| 2009 | `add-to-history' explicitly. */); | 2037 | `add-to-history' explicitly. */); |
| @@ -2018,7 +2046,7 @@ controls the behavior, rather than this variable. */); | |||
| 2018 | completion_ignore_case = 0; | 2046 | completion_ignore_case = 0; |
| 2019 | 2047 | ||
| 2020 | DEFVAR_BOOL ("enable-recursive-minibuffers", enable_recursive_minibuffers, | 2048 | DEFVAR_BOOL ("enable-recursive-minibuffers", enable_recursive_minibuffers, |
| 2021 | doc: /* *Non-nil means to allow minibuffer commands while in the minibuffer. | 2049 | doc: /* Non-nil means to allow minibuffer commands while in the minibuffer. |
| 2022 | This variable makes a difference whenever the minibuffer window is active. */); | 2050 | This variable makes a difference whenever the minibuffer window is active. */); |
| 2023 | enable_recursive_minibuffers = 0; | 2051 | enable_recursive_minibuffers = 0; |
| 2024 | 2052 | ||
| @@ -2074,7 +2102,7 @@ is added with | |||
| 2074 | Vminibuffer_history_position = Qnil; | 2102 | Vminibuffer_history_position = Qnil; |
| 2075 | 2103 | ||
| 2076 | DEFVAR_BOOL ("minibuffer-auto-raise", minibuffer_auto_raise, | 2104 | DEFVAR_BOOL ("minibuffer-auto-raise", minibuffer_auto_raise, |
| 2077 | doc: /* *Non-nil means entering the minibuffer raises the minibuffer's frame. | 2105 | doc: /* Non-nil means entering the minibuffer raises the minibuffer's frame. |
| 2078 | Some uses of the echo area also raise that frame (since they use it too). */); | 2106 | Some uses of the echo area also raise that frame (since they use it too). */); |
| 2079 | minibuffer_auto_raise = 0; | 2107 | minibuffer_auto_raise = 0; |
| 2080 | 2108 | ||