emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/src/minibuf.c


From: Stefan Monnier
Subject: [Emacs-diffs] Changes to emacs/src/minibuf.c
Date: Tue, 09 Apr 2002 15:28:42 -0400

Index: emacs/src/minibuf.c
diff -c emacs/src/minibuf.c:1.236 emacs/src/minibuf.c:1.237
*** emacs/src/minibuf.c:1.236   Thu Feb 28 17:09:53 2002
--- emacs/src/minibuf.c Tue Apr  9 15:28:42 2002
***************
*** 427,433 ****
    GCPRO5 (map, initial, val, ambient_dir, input_method);
  
    if (!STRINGP (prompt))
!     prompt = build_string ("");
  
    if (!enable_recursive_minibuffers
        && minibuf_level > 0)
--- 427,433 ----
    GCPRO5 (map, initial, val, ambient_dir, input_method);
  
    if (!STRINGP (prompt))
!     prompt = empty_string;
  
    if (!enable_recursive_minibuffers
        && minibuf_level > 0)
***************
*** 1103,1109 ****
    int bestmatchsize = 0;
    /* These are in bytes, too.  */
    int compare, matchsize;
!   int list = CONSP (alist) || NILP (alist);
    int index = 0, obsize = 0;
    int matchcount = 0;
    Lisp_Object bucket, zero, end, tem;
--- 1103,1111 ----
    int bestmatchsize = 0;
    /* These are in bytes, too.  */
    int compare, matchsize;
!   int list = NILP (alist) || (CONSP (alist)
!                             && (!SYMBOLP (XCAR (alist))
!                                 || NILP (XCAR (alist))));
    int index = 0, obsize = 0;
    int matchcount = 0;
    Lisp_Object bucket, zero, end, tem;
***************
*** 1133,1143 ****
  
        if (list)
        {
!         if (NILP (tail))
            break;
!         elt = Fcar (tail);
!         eltstring = Fcar (elt);
!         tail = Fcdr (tail);
        }
        else
        {
--- 1135,1145 ----
  
        if (list)
        {
!         if (!CONSP (tail))
            break;
!         elt = XCAR (tail);
!         eltstring = CONSP (elt) ? XCAR (elt) : elt;
!         tail = XCDR (tail);
        }
        else
        {
***************
*** 1225,1230 ****
--- 1227,1233 ----
                matchsize = XINT (tem) - 1;
  
              if (matchsize < 0)
+               /* When can this happen ?  -stef  */
                matchsize = compare;
              if (completion_ignore_case)
                {
***************
*** 1259,1264 ****
--- 1262,1271 ----
                    bestmatch = eltstring;
                }
              bestmatchsize = matchsize;
+             if (matchsize <= XSTRING (string)->size
+                 && matchcount > 1)
+               /* No need to look any further.  */
+               break;
            }
        }
      }
***************
*** 1316,1322 ****
  {
    Lisp_Object tail, elt, eltstring;
    Lisp_Object allmatches;
!   int list = CONSP (alist) || NILP (alist);
    int index = 0, obsize = 0;
    Lisp_Object bucket, tem;
    struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
--- 1323,1331 ----
  {
    Lisp_Object tail, elt, eltstring;
    Lisp_Object allmatches;
!   int list = NILP (alist) || (CONSP (alist)
!                             && (!SYMBOLP (XCAR (alist))
!                                 || NILP (XCAR (alist))));
    int index = 0, obsize = 0;
    Lisp_Object bucket, tem;
    struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
***************
*** 1346,1356 ****
  
        if (list)
        {
!         if (NILP (tail))
            break;
!         elt = Fcar (tail);
!         eltstring = Fcar (elt);
!         tail = Fcdr (tail);
        }
        else
        {
--- 1355,1365 ----
  
        if (list)
        {
!         if (!CONSP (tail))
            break;
!         elt = XCAR (tail);
!         eltstring = CONSP (elt) ? XCAR (elt) : elt;
!         tail = XCDR (tail);
        }
        else
        {
***************
*** 1486,1492 ****
    specbind (Qminibuffer_completion_table, table);
    specbind (Qminibuffer_completion_predicate, predicate);
    specbind (Qminibuffer_completion_confirm,
!           EQ (require_match, Qt) ? Qnil : Qt);
    last_exact_completion = Qnil;
  
    position = Qnil;
--- 1495,1501 ----
    specbind (Qminibuffer_completion_table, table);
    specbind (Qminibuffer_completion_predicate, predicate);
    specbind (Qminibuffer_completion_confirm,
!           EQ (require_match, Qt) ? Qnil : require_match);
    last_exact_completion = Qnil;
  
    position = Qnil;
***************
*** 1535,1581 ****
  }
  
  Lisp_Object Fminibuffer_completion_help ();
! Lisp_Object assoc_for_completion ();
  
  /* Test whether TXT is an exact completion.  */
! Lisp_Object
! test_completion (txt)
!      Lisp_Object txt;
  {
!   Lisp_Object tem;
  
!   if (CONSP (Vminibuffer_completion_table)
!       || NILP (Vminibuffer_completion_table))
!     return assoc_for_completion (txt, Vminibuffer_completion_table);
!   else if (VECTORP (Vminibuffer_completion_table))
!     {
!       /* Bypass intern-soft as that loses for nil */
!       tem = oblookup (Vminibuffer_completion_table,
!                     XSTRING (txt)->data,
!                     XSTRING (txt)->size,
!                     STRING_BYTES (XSTRING (txt)));
        if (!SYMBOLP (tem))
        {
!         if (STRING_MULTIBYTE (txt))
!           txt = Fstring_make_unibyte (txt);
          else
!           txt = Fstring_make_multibyte (txt);
  
          tem = oblookup (Vminibuffer_completion_table,
!                         XSTRING (txt)->data,
!                         XSTRING (txt)->size,
!                         STRING_BYTES (XSTRING (txt)));
          if (!SYMBOLP (tem))
            return Qnil;
        }
-       if (!NILP (Vminibuffer_completion_predicate))
-       return call1 (Vminibuffer_completion_predicate, tem);
-       else
-       return Qt;
      }
    else
!     return call3 (Vminibuffer_completion_table, txt,
!                 Vminibuffer_completion_predicate, Qlambda);
  }
  
  /* returns:
--- 1544,1613 ----
  }
  
  Lisp_Object Fminibuffer_completion_help ();
! Lisp_Object Fassoc_string ();
  
  /* Test whether TXT is an exact completion.  */
! DEFUN ("test-completion", Ftest_completion, Stest_completion, 2, 3, 0,
!        doc: /* Return non-nil if STRING is a valid completion.
! Takes the same arguments as `all-completions' and `try-completion'.
! If ALIST is a function, it is called with three arguments:
! the values STRING, PREDICATE and `lambda'.  */)
!        (string, alist, predicate)
!      Lisp_Object string, alist, predicate;
  {
!   Lisp_Object regexps, tem = Qnil;
  
!   CHECK_STRING (string);
! 
!   if ((CONSP (alist) && (!SYMBOLP (XCAR (alist)) || NILP (XCAR (alist))))
!       || NILP (alist))
!     {
!       tem = Fassoc_string (string, alist, completion_ignore_case ? Qt : Qnil);
!       if (CONSP (tem))
!       tem = XCAR (tem);
!       else
!       return Qnil;
!     }
!   else if (VECTORP (alist))
!     {
!       /* Bypass intern-soft as that loses for nil.  */
!       tem = oblookup (alist,
!                     XSTRING (string)->data,
!                     XSTRING (string)->size,
!                     STRING_BYTES (XSTRING (string)));
        if (!SYMBOLP (tem))
        {
!         if (STRING_MULTIBYTE (string))
!           string = Fstring_make_unibyte (string);
          else
!           string = Fstring_make_multibyte (string);
  
          tem = oblookup (Vminibuffer_completion_table,
!                         XSTRING (string)->data,
!                         XSTRING (string)->size,
!                         STRING_BYTES (XSTRING (string)));
          if (!SYMBOLP (tem))
            return Qnil;
        }
      }
    else
!     return call3 (alist, string, predicate, Qlambda);
! 
!   /* Reject this element if it fails to match all the regexps.  */
!   for (regexps = Vcompletion_regexp_list; CONSP (regexps);
!        regexps = XCDR (regexps))
!     {
!       if (NILP (Fstring_match (XCAR (regexps),
!                              SYMBOLP (tem) ? string : tem,
!                              Qnil)))
!       return Qnil;
!     }
! 
!   /* Finally, check the predicate.  */
!   if (!NILP (predicate))
!     return call1 (predicate, tem);
!   else
!     return Qt;
  }
  
  /* returns:
***************
*** 1645,1651 ****
      }
  
    /* It did find a match.  Do we match some possibility exactly now? */
!   tem = test_completion (Fminibuffer_contents ());
    if (NILP (tem))
      {
        /* not an exact match */
--- 1677,1685 ----
      }
  
    /* It did find a match.  Do we match some possibility exactly now? */
!   tem = Ftest_completion (Fminibuffer_contents (),
!                         Vminibuffer_completion_table,
!                         Vminibuffer_completion_predicate);
    if (NILP (tem))
      {
        /* not an exact match */
***************
*** 1679,1688 ****
  
  /* Like assoc but assumes KEY is a string, and ignores case if appropriate.  
*/
  
! Lisp_Object
! assoc_for_completion (key, list)
       register Lisp_Object key;
!      Lisp_Object list;
  {
    register Lisp_Object tail;
  
--- 1713,1727 ----
  
  /* Like assoc but assumes KEY is a string, and ignores case if appropriate.  
*/
  
! DEFUN ("assoc-string", Fassoc_string, Sassoc_string, 2, 3, 0,
!        doc: /* Like `assoc' but specifically for strings.
! Unibyte strings are converted to multibyte for comparison.
! And case is ignored if CASE-FOLD is non-nil.
! As opposed to `assoc', it will also match an entry consisting of a single
! string rather than a cons cell whose car is a string.  */)
!        (key, list, case_fold)
       register Lisp_Object key;
!      Lisp_Object list, case_fold;
  {
    register Lisp_Object tail;
  
***************
*** 1690,1702 ****
      {
        register Lisp_Object elt, tem, thiscar;
        elt = Fcar (tail);
!       if (!CONSP (elt)) continue;
!       thiscar = Fcar (elt);
        if (!STRINGP (thiscar))
        continue;
        tem = Fcompare_strings (thiscar, make_number (0), Qnil,
                              key, make_number (0), Qnil,
!                             completion_ignore_case ? Qt : Qnil);
        if (EQ (tem, Qt))
        return elt;
        QUIT;
--- 1729,1740 ----
      {
        register Lisp_Object elt, tem, thiscar;
        elt = Fcar (tail);
!       thiscar = CONSP (elt) ? XCAR (elt) : elt;
        if (!STRINGP (thiscar))
        continue;
        tem = Fcompare_strings (thiscar, make_number (0), Qnil,
                              key, make_number (0), Qnil,
!                             case_fold);
        if (EQ (tem, Qt))
        return elt;
        QUIT;
***************
*** 1797,1803 ****
    if (XINT (Fminibuffer_prompt_end ()) == ZV)
      goto exit;
  
!   if (!NILP (test_completion (Fminibuffer_contents ())))
      goto exit;
  
    /* Call do_completion, but ignore errors.  */
--- 1835,1843 ----
    if (XINT (Fminibuffer_prompt_end ()) == ZV)
      goto exit;
  
!   if (!NILP (Ftest_completion (Fminibuffer_contents (),
!                              Vminibuffer_completion_table,
!                              Vminibuffer_completion_predicate)))
      goto exit;
  
    /* Call do_completion, but ignore errors.  */
***************
*** 2476,2481 ****
--- 2516,2523 ----
  
    defsubr (&Stry_completion);
    defsubr (&Sall_completions);
+   defsubr (&Stest_completion);
+   defsubr (&Sassoc_string);
    defsubr (&Scompleting_read);
    defsubr (&Sminibuffer_complete);
    defsubr (&Sminibuffer_complete_word);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]