aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Blandy1991-07-15 11:14:59 +0000
committerJim Blandy1991-07-15 11:14:59 +0000
commit52b14ac064d4613ead76fc962bda213a659bb140 (patch)
tree8dacfcf24a19249ce0f6d0278c5e215b301a8ac6 /src
parent38010d507a311f3ff9fb780683ef2cc6e0ea8fc6 (diff)
downloademacs-52b14ac064d4613ead76fc962bda213a659bb140.tar.gz
emacs-52b14ac064d4613ead76fc962bda213a659bb140.zip
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r--src/editfns.c49
-rw-r--r--src/minibuf.c76
2 files changed, 99 insertions, 26 deletions
diff --git a/src/editfns.c b/src/editfns.c
index c79f75e4ce7..efdf7f74e8d 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -45,7 +45,7 @@ Lisp_Object Vuser_name; /* user name from USER or LOGNAME. */
45void 45void
46init_editfns () 46init_editfns ()
47{ 47{
48 unsigned char *user_name; 48 char *user_name;
49 register unsigned char *p, *q, *r; 49 register unsigned char *p, *q, *r;
50 struct passwd *pw; /* password entry for the current user */ 50 struct passwd *pw; /* password entry for the current user */
51 extern char *index (); 51 extern char *index ();
@@ -71,17 +71,23 @@ init_editfns ()
71 pw = (struct passwd *) getpwuid (getuid ()); 71 pw = (struct passwd *) getpwuid (getuid ());
72 Vuser_real_name = build_string (pw ? pw->pw_name : "unknown"); 72 Vuser_real_name = build_string (pw ? pw->pw_name : "unknown");
73 73
74 user_name = (unsigned char *) getenv ("USER"); 74 /* Get the effective user name, by consulting environment variables,
75 or the effective uid if those are unset. */
76 user_name = (char *) getenv ("USER");
75 if (!user_name) 77 if (!user_name)
76 user_name = (unsigned char *) getenv ("LOGNAME"); 78 user_name = (char *) getenv ("LOGNAME");
77 if (user_name) 79 if (!user_name)
78 Vuser_name = build_string (user_name); 80 {
79 else 81 pw = (struct passwd *) getpwuid (geteuid ());
80 Vuser_name = Vuser_real_name; 82 user_name = (char *) (pw ? pw->pw_name : "unknown");
83 }
84 Vuser_name = build_string (user_name);
81 85
86 /* If the user name claimed in the environment vars differs from
87 the real uid, use the claimed name to find the full name. */
82 tem = Fstring_equal (Vuser_name, Vuser_real_name); 88 tem = Fstring_equal (Vuser_name, Vuser_real_name);
83 if (!NULL (tem)) 89 if (NULL (tem))
84 pw = (struct passwd *) getpwnam (user_name); 90 pw = (struct passwd *) getpwnam (XSTRING (Vuser_name)->data);
85 91
86 p = (unsigned char *) (pw ? USER_FULL_NAME : "unknown"); 92 p = (unsigned char *) (pw ? USER_FULL_NAME : "unknown");
87 q = (unsigned char *) index (p, ','); 93 q = (unsigned char *) index (p, ',');
@@ -96,7 +102,7 @@ init_editfns ()
96 r = (char *) alloca (strlen (p) + XSTRING (Vuser_name)->size + 1); 102 r = (char *) alloca (strlen (p) + XSTRING (Vuser_name)->size + 1);
97 bcopy (p, r, q - p); 103 bcopy (p, r, q - p);
98 r[q - p] = 0; 104 r[q - p] = 0;
99 strcat (r, XSTRING (user_name)->data); 105 strcat (r, XSTRING (Vuser_name)->data);
100 r[q - p] = UPCASE (r[q - p]); 106 r[q - p] = UPCASE (r[q - p]);
101 strcat (r, q + 1); 107 strcat (r, q + 1);
102 Vuser_full_name = build_string (r); 108 Vuser_full_name = build_string (r);
@@ -538,6 +544,12 @@ insert1 (arg)
538 Finsert (1, &arg); 544 Finsert (1, &arg);
539} 545}
540 546
547
548/* Callers passing one argument to Finsert need not gcpro the
549 argument "array", since the only element of the array will
550 not be used after calling insert or insert_from_string, so
551 we don't care if it gets trashed. */
552
541DEFUN ("insert", Finsert, Sinsert, 0, MANY, 0, 553DEFUN ("insert", Finsert, Sinsert, 0, MANY, 0,
542 "Insert the arguments, either strings or characters, at point.\n\ 554 "Insert the arguments, either strings or characters, at point.\n\
543Point moves forward so that it ends up after the inserted text.\n\ 555Point moves forward so that it ends up after the inserted text.\n\
@@ -549,10 +561,6 @@ Any other markers at the point of insertion remain before the text.")
549 register int argnum; 561 register int argnum;
550 register Lisp_Object tem; 562 register Lisp_Object tem;
551 char str[1]; 563 char str[1];
552 struct gcpro gcpro1;
553
554 GCPRO1 (*args);
555 gcpro1.nvars = nargs;
556 564
557 for (argnum = 0; argnum < nargs; argnum++) 565 for (argnum = 0; argnum < nargs; argnum++)
558 { 566 {
@@ -574,7 +582,6 @@ Any other markers at the point of insertion remain before the text.")
574 } 582 }
575 } 583 }
576 584
577 UNGCPRO;
578 return Qnil; 585 return Qnil;
579} 586}
580 587
@@ -589,10 +596,6 @@ Any other markers at the point of insertion also end up after the text.")
589 register int argnum; 596 register int argnum;
590 register Lisp_Object tem; 597 register Lisp_Object tem;
591 char str[1]; 598 char str[1];
592 struct gcpro gcpro1;
593
594 GCPRO1 (*args);
595 gcpro1.nvars = nargs;
596 599
597 for (argnum = 0; argnum < nargs; argnum++) 600 for (argnum = 0; argnum < nargs; argnum++)
598 { 601 {
@@ -614,7 +617,6 @@ Any other markers at the point of insertion also end up after the text.")
614 } 617 }
615 } 618 }
616 619
617 UNGCPRO;
618 return Qnil; 620 return Qnil;
619} 621}
620 622
@@ -858,6 +860,8 @@ This allows the buffer's full text to be seen and edited.")
858 BEGV = BEG; 860 BEGV = BEG;
859 SET_BUF_ZV (current_buffer, Z); 861 SET_BUF_ZV (current_buffer, Z);
860 clip_changed = 1; 862 clip_changed = 1;
863 /* Changing the buffer bounds invalidates any recorded current column. */
864 invalidate_current_column ();
861 return Qnil; 865 return Qnil;
862} 866}
863 867
@@ -895,6 +899,8 @@ or markers) bounding the text that should remain visible.")
895 if (point > XFASTINT (e)) 899 if (point > XFASTINT (e))
896 SET_PT (XFASTINT (e)); 900 SET_PT (XFASTINT (e));
897 clip_changed = 1; 901 clip_changed = 1;
902 /* Changing the buffer bounds invalidates any recorded current column. */
903 invalidate_current_column ();
898 return Qnil; 904 return Qnil;
899} 905}
900 906
@@ -1007,7 +1013,8 @@ It may contain %-sequences meaning to substitute the next argument.\n\
1007%d means print as number in decimal (%o octal, %x hex).\n\ 1013%d means print as number in decimal (%o octal, %x hex).\n\
1008%c means print a number as a single character.\n\ 1014%c means print a number as a single character.\n\
1009%S means print any object as an s-expression (using prin1).\n\ 1015%S means print any object as an s-expression (using prin1).\n\
1010The argument used for %d, %o, %x or %c must be a number.") 1016 The argument used for %d, %o, %x or %c must be a number.\n\
1017Use %% to put a single % into the output.")
1011 (nargs, args) 1018 (nargs, args)
1012 int nargs; 1019 int nargs;
1013 register Lisp_Object *args; 1020 register Lisp_Object *args;
diff --git a/src/minibuf.c b/src/minibuf.c
index 478e95b4fe4..6369438e700 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -530,14 +530,51 @@ The argument given to PREDICATE is the alist element or the symbol from the obar
530 matchsize = scmp (XSTRING (bestmatch)->data, 530 matchsize = scmp (XSTRING (bestmatch)->data,
531 XSTRING (eltstring)->data, 531 XSTRING (eltstring)->data,
532 compare); 532 compare);
533 bestmatchsize = (matchsize >= 0) ? matchsize : compare; 533 if (matchsize < 0)
534 matchsize = compare;
535 if (completion_ignore_case)
536 {
537 /* If this is an exact match except for case,
538 use it as the best match rather than one that is not an
539 exact match. This way, we get the case pattern
540 of the actual match. */
541 if ((matchsize == XSTRING (eltstring)->size
542 && matchsize < XSTRING (bestmatch)->size)
543 ||
544 /* If there is more than one exact match ignoring case,
545 and one of them is exact including case,
546 prefer that one. */
547 /* If there is no exact match ignoring case,
548 prefer a match that does not change the case
549 of the input. */
550 ((matchsize == XSTRING (eltstring)->size)
551 ==
552 (matchsize == XSTRING (bestmatch)->size)
553 && !bcmp (XSTRING (eltstring)->data,
554 XSTRING (string)->data, XSTRING (string)->size)
555 && bcmp (XSTRING (bestmatch)->data,
556 XSTRING (string)->data, XSTRING (string)->size)))
557 bestmatch = eltstring;
558 }
559 bestmatchsize = matchsize;
534 } 560 }
535 } 561 }
536 } 562 }
537 563
538 if (NULL (bestmatch)) 564 if (NULL (bestmatch))
539 return Qnil; /* No completions found */ 565 return Qnil; /* No completions found */
540 if (matchcount == 1 && bestmatchsize == XSTRING (string)->size) 566 /* If we are ignoring case, and there is no exact match,
567 and no additional text was supplied,
568 don't change the case of what the user typed. */
569 if (completion_ignore_case && bestmatchsize == XSTRING (string)->size
570 && XSTRING (bestmatch)->size > bestmatchsize)
571 return string;
572
573 /* Return t if the supplied string is an exact match (counting case);
574 it does not require any change to be made. */
575 if (matchcount == 1 && bestmatchsize == XSTRING (string)->size
576 && !bcmp (XSTRING (bestmatch)->data, XSTRING (string)->data,
577 bestmatchsize))
541 return Qt; 578 return Qt;
542 579
543 XFASTINT (zero) = 0; /* Else extract the part in which */ 580 XFASTINT (zero) = 0; /* Else extract the part in which */
@@ -752,6 +789,7 @@ temp_echo_area_glyphs (m)
752} 789}
753 790
754Lisp_Object Fminibuffer_completion_help (); 791Lisp_Object Fminibuffer_completion_help ();
792Lisp_Object assoc_for_completion ();
755 793
756/* returns: 794/* returns:
757 * 0 no possible completion 795 * 0 no possible completion
@@ -794,7 +832,8 @@ do_completion ()
794 /* It did find a match. Do we match some possibility exactly now? */ 832 /* It did find a match. Do we match some possibility exactly now? */
795 if (CONSP (Vminibuffer_completion_table) 833 if (CONSP (Vminibuffer_completion_table)
796 || NULL (Vminibuffer_completion_table)) 834 || NULL (Vminibuffer_completion_table))
797 tem = Fassoc (Fbuffer_string (), Vminibuffer_completion_table); 835 tem = assoc_for_completion (Fbuffer_string (),
836 Vminibuffer_completion_table);
798 else if (XTYPE (Vminibuffer_completion_table) == Lisp_Vector) 837 else if (XTYPE (Vminibuffer_completion_table) == Lisp_Vector)
799 { 838 {
800 /* the primitive used by Fintern_soft */ 839 /* the primitive used by Fintern_soft */
@@ -831,7 +870,7 @@ do_completion ()
831 return 4; 870 return 4;
832 /* If the last exact completion and this one were the same, 871 /* If the last exact completion and this one were the same,
833 it means we've already given a "Complete but not unique" 872 it means we've already given a "Complete but not unique"
834 message and the user's hit TAB again, so no we give him help. */ 873 message and the user's hit TAB again, so now we give him help. */
835 last_exact_completion = completion; 874 last_exact_completion = completion;
836 if (!NULL (last)) 875 if (!NULL (last))
837 { 876 {
@@ -840,9 +879,36 @@ do_completion ()
840 Fminibuffer_completion_help (); 879 Fminibuffer_completion_help ();
841 } 880 }
842 return 3; 881 return 3;
843
844} 882}
845 883
884/* Like assoc but assumes KEY is a string, and ignores case if appropriate. */
885
886Lisp_Object
887assoc_for_completion (key, list)
888 register Lisp_Object key;
889 Lisp_Object list;
890{
891 register Lisp_Object tail;
892
893 if (completion_ignore_case)
894 key = Fupcase (key);
895
896 for (tail = list; !NULL (tail); tail = Fcdr (tail))
897 {
898 register Lisp_Object elt, tem, thiscar;
899 elt = Fcar (tail);
900 if (!CONSP (elt)) continue;
901 thiscar = Fcar (elt);
902 if (XTYPE (thiscar) != Lisp_String)
903 continue;
904 if (completion_ignore_case)
905 thiscar = Fupcase (thiscar);
906 tem = Fequal (thiscar, key);
907 if (!NULL (tem)) return elt;
908 QUIT;
909 }
910 return Qnil;
911}
846 912
847DEFUN ("minibuffer-complete", Fminibuffer_complete, Sminibuffer_complete, 0, 0, "", 913DEFUN ("minibuffer-complete", Fminibuffer_complete, Sminibuffer_complete, 0, 0, "",
848 "Complete the minibuffer contents as far as possible.") 914 "Complete the minibuffer contents as far as possible.")