diff options
| author | Karl Heuer | 1994-04-05 06:04:27 +0000 |
|---|---|---|
| committer | Karl Heuer | 1994-04-05 06:04:27 +0000 |
| commit | f676868dc69651e8464de821e5cafc075001161e (patch) | |
| tree | e2af9784ff53ed4a8b2136c2b01a023a39bce8e7 | |
| parent | c4d460ce6b9321bff1cbb47f7b688e586e73b8ac (diff) | |
| download | emacs-f676868dc69651e8464de821e5cafc075001161e.tar.gz emacs-f676868dc69651e8464de821e5cafc075001161e.zip | |
(file_name_completion): Honor completion-regexp-list.
| -rw-r--r-- | src/dired.c | 147 |
1 files changed, 83 insertions, 64 deletions
diff --git a/src/dired.c b/src/dired.c index f30072a75b4..79fdce83c42 100644 --- a/src/dired.c +++ b/src/dired.c | |||
| @@ -93,6 +93,7 @@ extern struct re_pattern_buffer searchbuf; | |||
| 93 | #endif | 93 | #endif |
| 94 | 94 | ||
| 95 | extern int completion_ignore_case; | 95 | extern int completion_ignore_case; |
| 96 | extern Lisp_Object Vcompletion_regexp_list; | ||
| 96 | extern Lisp_Object Ffind_file_name_handler (); | 97 | extern Lisp_Object Ffind_file_name_handler (); |
| 97 | 98 | ||
| 98 | Lisp_Object Vcompletion_ignored_extensions; | 99 | Lisp_Object Vcompletion_ignored_extensions; |
| @@ -375,80 +376,98 @@ file_name_completion (file, dirname, all_flag, ver_flag) | |||
| 375 | } | 376 | } |
| 376 | } | 377 | } |
| 377 | 378 | ||
| 378 | /* Unless an ignored-extensions match was found, | 379 | /* If an ignored-extensions match was found, |
| 379 | process this name as a completion */ | 380 | don't process this name as a completion. */ |
| 380 | if (passcount || !CONSP (tem)) | 381 | if (!passcount && CONSP (tem)) |
| 382 | continue; | ||
| 383 | |||
| 384 | if (!passcount) | ||
| 381 | { | 385 | { |
| 382 | /* Update computation of how much all possible completions match */ | 386 | Lisp_Object regexps; |
| 387 | Lisp_Object zero; | ||
| 388 | XFASTINT (zero) = 0; | ||
| 389 | |||
| 390 | /* Ignore this element if it fails to match all the regexps. */ | ||
| 391 | for (regexps = Vcompletion_regexp_list; CONSP (regexps); | ||
| 392 | regexps = XCONS (regexps)->cdr) | ||
| 393 | { | ||
| 394 | tem = Fstring_match (XCONS (regexps)->car, elt, zero); | ||
| 395 | if (NILP (tem)) | ||
| 396 | break; | ||
| 397 | } | ||
| 398 | if (CONSP (regexps)) | ||
| 399 | continue; | ||
| 400 | } | ||
| 383 | 401 | ||
| 384 | matchcount++; | 402 | /* Update computation of how much all possible completions match */ |
| 385 | 403 | ||
| 386 | if (all_flag || NILP (bestmatch)) | 404 | matchcount++; |
| 405 | |||
| 406 | if (all_flag || NILP (bestmatch)) | ||
| 407 | { | ||
| 408 | /* This is a possible completion */ | ||
| 409 | if (directoryp) | ||
| 387 | { | 410 | { |
| 388 | /* This is a possible completion */ | 411 | /* This completion is a directory; make it end with '/' */ |
| 389 | if (directoryp) | 412 | name = Ffile_name_as_directory (make_string (dp->d_name, len)); |
| 390 | { | 413 | } |
| 391 | /* This completion is a directory; make it end with '/' */ | 414 | else |
| 392 | name = Ffile_name_as_directory (make_string (dp->d_name, len)); | 415 | name = make_string (dp->d_name, len); |
| 393 | } | 416 | if (all_flag) |
| 394 | else | 417 | { |
| 395 | name = make_string (dp->d_name, len); | 418 | bestmatch = Fcons (name, bestmatch); |
| 396 | if (all_flag) | ||
| 397 | { | ||
| 398 | bestmatch = Fcons (name, bestmatch); | ||
| 399 | } | ||
| 400 | else | ||
| 401 | { | ||
| 402 | bestmatch = name; | ||
| 403 | bestmatchsize = XSTRING (name)->size; | ||
| 404 | } | ||
| 405 | } | 419 | } |
| 406 | else | 420 | else |
| 407 | { | 421 | { |
| 408 | compare = min (bestmatchsize, len); | 422 | bestmatch = name; |
| 409 | p1 = XSTRING (bestmatch)->data; | 423 | bestmatchsize = XSTRING (name)->size; |
| 410 | p2 = (unsigned char *) dp->d_name; | 424 | } |
| 411 | matchsize = scmp(p1, p2, compare); | 425 | } |
| 412 | if (matchsize < 0) | 426 | else |
| 413 | matchsize = compare; | 427 | { |
| 414 | if (completion_ignore_case) | 428 | compare = min (bestmatchsize, len); |
| 429 | p1 = XSTRING (bestmatch)->data; | ||
| 430 | p2 = (unsigned char *) dp->d_name; | ||
| 431 | matchsize = scmp(p1, p2, compare); | ||
| 432 | if (matchsize < 0) | ||
| 433 | matchsize = compare; | ||
| 434 | if (completion_ignore_case) | ||
| 435 | { | ||
| 436 | /* If this is an exact match except for case, | ||
| 437 | use it as the best match rather than one that is not | ||
| 438 | an exact match. This way, we get the case pattern | ||
| 439 | of the actual match. */ | ||
| 440 | if ((matchsize == len | ||
| 441 | && matchsize + !!directoryp | ||
| 442 | < XSTRING (bestmatch)->size) | ||
| 443 | || | ||
| 444 | /* If there is no exact match ignoring case, | ||
| 445 | prefer a match that does not change the case | ||
| 446 | of the input. */ | ||
| 447 | (((matchsize == len) | ||
| 448 | == | ||
| 449 | (matchsize + !!directoryp | ||
| 450 | == XSTRING (bestmatch)->size)) | ||
| 451 | /* If there is more than one exact match aside from | ||
| 452 | case, and one of them is exact including case, | ||
| 453 | prefer that one. */ | ||
| 454 | && !bcmp (p2, XSTRING (file)->data, XSTRING (file)->size) | ||
| 455 | && bcmp (p1, XSTRING (file)->data, XSTRING (file)->size))) | ||
| 415 | { | 456 | { |
| 416 | /* If this is an exact match except for case, | 457 | bestmatch = make_string (dp->d_name, len); |
| 417 | use it as the best match rather than one that is not | 458 | if (directoryp) |
| 418 | an exact match. This way, we get the case pattern | 459 | bestmatch = Ffile_name_as_directory (bestmatch); |
| 419 | of the actual match. */ | ||
| 420 | if ((matchsize == len | ||
| 421 | && matchsize + !!directoryp | ||
| 422 | < XSTRING (bestmatch)->size) | ||
| 423 | || | ||
| 424 | /* If there is no exact match ignoring case, | ||
| 425 | prefer a match that does not change the case | ||
| 426 | of the input. */ | ||
| 427 | (((matchsize == len) | ||
| 428 | == | ||
| 429 | (matchsize + !!directoryp | ||
| 430 | == XSTRING (bestmatch)->size)) | ||
| 431 | /* If there is more than one exact match aside from | ||
| 432 | case, and one of them is exact including case, | ||
| 433 | prefer that one. */ | ||
| 434 | && !bcmp (p2, XSTRING (file)->data, XSTRING (file)->size) | ||
| 435 | && bcmp (p1, XSTRING (file)->data, XSTRING (file)->size))) | ||
| 436 | { | ||
| 437 | bestmatch = make_string (dp->d_name, len); | ||
| 438 | if (directoryp) | ||
| 439 | bestmatch = Ffile_name_as_directory (bestmatch); | ||
| 440 | } | ||
| 441 | } | 460 | } |
| 442 | |||
| 443 | /* If this dirname all matches, see if implicit following | ||
| 444 | slash does too. */ | ||
| 445 | if (directoryp | ||
| 446 | && compare == matchsize | ||
| 447 | && bestmatchsize > matchsize | ||
| 448 | && p1[matchsize] == '/') | ||
| 449 | matchsize++; | ||
| 450 | bestmatchsize = matchsize; | ||
| 451 | } | 461 | } |
| 462 | |||
| 463 | /* If this dirname all matches, see if implicit following | ||
| 464 | slash does too. */ | ||
| 465 | if (directoryp | ||
| 466 | && compare == matchsize | ||
| 467 | && bestmatchsize > matchsize | ||
| 468 | && p1[matchsize] == '/') | ||
| 469 | matchsize++; | ||
| 470 | bestmatchsize = matchsize; | ||
| 452 | } | 471 | } |
| 453 | } | 472 | } |
| 454 | closedir (d); | 473 | closedir (d); |