aboutsummaryrefslogtreecommitdiffstats
path: root/src/dired.c
diff options
context:
space:
mode:
authorEli Zaretskii2015-12-23 19:34:00 +0200
committerEli Zaretskii2015-12-23 19:34:00 +0200
commit30cc4e4b12d8faf66f64505f25e7288efd9fb5ea (patch)
treea40acc4293563f274a6e602008672b943326d720 /src/dired.c
parent09053075225fec8a6cf7a72017a6dfc1ec6b6f0c (diff)
downloademacs-30cc4e4b12d8faf66f64505f25e7288efd9fb5ea.tar.gz
emacs-30cc4e4b12d8faf66f64505f25e7288efd9fb5ea.zip
Fix file-name completion on OS X
* src/dired.c (file_name_completion): Reject false matches due to file-name-coding-systems that decompose characters when encoding file names, by comparing decoded file names as well. (Bug#22169) (syms_of_dired) <Qdecomposed_characters>: New DEFSYM. * lisp/international/ucs-normalize.el (utf-8-hfs): Give it a non-nil 'decomposed-characters' property.
Diffstat (limited to 'src/dired.c')
-rw-r--r--src/dired.c53
1 files changed, 45 insertions, 8 deletions
diff --git a/src/dired.c b/src/dired.c
index 84bf2472262..89bd908c1e7 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -467,6 +467,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag,
467 well as "." and "..". Until shown otherwise, assume we can't exclude 467 well as "." and "..". Until shown otherwise, assume we can't exclude
468 anything. */ 468 anything. */
469 bool includeall = 1; 469 bool includeall = 1;
470 bool check_decoded = false;
470 ptrdiff_t count = SPECPDL_INDEX (); 471 ptrdiff_t count = SPECPDL_INDEX ();
471 472
472 elt = Qnil; 473 elt = Qnil;
@@ -485,6 +486,28 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag,
485 on the encoded file name. */ 486 on the encoded file name. */
486 encoded_file = ENCODE_FILE (file); 487 encoded_file = ENCODE_FILE (file);
487 encoded_dir = ENCODE_FILE (Fdirectory_file_name (dirname)); 488 encoded_dir = ENCODE_FILE (Fdirectory_file_name (dirname));
489
490 Lisp_Object file_encoding = Vfile_name_coding_system;
491 if (NILP (Vfile_name_coding_system))
492 file_encoding = Vdefault_file_name_coding_system;
493 /* If the file-name encoding decomposes characters, as we do for
494 HFS+ filesystems, we need to make an additional comparison of
495 decoded names in order to filter false positives, such as "a"
496 falsely matching "a-ring". */
497 if (!NILP (file_encoding)
498 && !NILP (Fplist_get (Fcoding_system_plist (file_encoding),
499 Qdecomposed_characters)))
500 {
501 check_decoded = true;
502 if (STRING_MULTIBYTE (file))
503 {
504 /* Recompute FILE to make sure any decomposed characters in
505 it are re-composed by the post-read-conversion.
506 Otherwise, any decomposed characters will be rejected by
507 the additional check below. */
508 file = DECODE_FILE (encoded_file);
509 }
510 }
488 int fd; 511 int fd;
489 DIR *d = open_directory (encoded_dir, &fd); 512 DIR *d = open_directory (encoded_dir, &fd);
490 record_unwind_protect_ptr (directory_files_internal_unwind, d); 513 record_unwind_protect_ptr (directory_files_internal_unwind, d);
@@ -637,6 +660,21 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag,
637 if (!NILP (predicate) && NILP (call1 (predicate, name))) 660 if (!NILP (predicate) && NILP (call1 (predicate, name)))
638 continue; 661 continue;
639 662
663 /* Reject entries where the encoded strings match, but the
664 decoded don't. For example, "a" should not match "a-ring" on
665 file systems that store decomposed characters. */
666 Lisp_Object zero = make_number (0);
667 Lisp_Object compare;
668 Lisp_Object cmp;
669 if (check_decoded && SCHARS (file) <= SCHARS (name))
670 {
671 compare = make_number (SCHARS (file));
672 cmp = Fcompare_strings (name, zero, compare, file, zero, compare,
673 completion_ignore_case ? Qt : Qnil);
674 if (!EQ (cmp, Qt))
675 continue;
676 }
677
640 /* Suitably record this match. */ 678 /* Suitably record this match. */
641 679
642 matchcount += matchcount <= 1; 680 matchcount += matchcount <= 1;
@@ -650,15 +688,13 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag,
650 } 688 }
651 else 689 else
652 { 690 {
653 Lisp_Object zero = make_number (0);
654 /* FIXME: This is a copy of the code in Ftry_completion. */ 691 /* FIXME: This is a copy of the code in Ftry_completion. */
655 ptrdiff_t compare = min (bestmatchsize, SCHARS (name)); 692 compare = min (bestmatchsize, SCHARS (name));
656 Lisp_Object cmp 693 cmp = Fcompare_strings (bestmatch, zero,
657 = Fcompare_strings (bestmatch, zero, 694 make_number (compare),
658 make_number (compare), 695 name, zero,
659 name, zero, 696 make_number (compare),
660 make_number (compare), 697 completion_ignore_case ? Qt : Qnil);
661 completion_ignore_case ? Qt : Qnil);
662 ptrdiff_t matchsize = EQ (cmp, Qt) ? compare : eabs (XINT (cmp)) - 1; 698 ptrdiff_t matchsize = EQ (cmp, Qt) ? compare : eabs (XINT (cmp)) - 1;
663 699
664 if (completion_ignore_case) 700 if (completion_ignore_case)
@@ -1007,6 +1043,7 @@ syms_of_dired (void)
1007 DEFSYM (Qfile_attributes, "file-attributes"); 1043 DEFSYM (Qfile_attributes, "file-attributes");
1008 DEFSYM (Qfile_attributes_lessp, "file-attributes-lessp"); 1044 DEFSYM (Qfile_attributes_lessp, "file-attributes-lessp");
1009 DEFSYM (Qdefault_directory, "default-directory"); 1045 DEFSYM (Qdefault_directory, "default-directory");
1046 DEFSYM (Qdecomposed_characters, "decomposed-characters");
1010 1047
1011 defsubr (&Sdirectory_files); 1048 defsubr (&Sdirectory_files);
1012 defsubr (&Sdirectory_files_and_attributes); 1049 defsubr (&Sdirectory_files_and_attributes);