Mercurial > emacs
changeset 112041:9c611deb66fa
For nextstep: Handle bad utf-8 in buffer name, always use buffer name for title.
* nsfns.m (ns_set_name_as_filename): Always use buffer name for
title and buffer filename only for RepresentedFilename.
Handle bad UTF-8 in buffer name.
author | Jan D. <jan.h.d@swipnet.se> |
---|---|
date | Fri, 31 Dec 2010 14:16:16 +0100 |
parents | 491d94613848 |
children | c92bc8723d4b |
files | src/ChangeLog src/nsfns.m |
diffstat | 2 files changed, 44 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Thu Dec 30 21:23:13 2010 +0100 +++ b/src/ChangeLog Fri Dec 31 14:16:16 2010 +0100 @@ -1,3 +1,9 @@ +2010-12-31 Jan Djärv <jan.h.d@swipnet.se> + + * nsfns.m (ns_set_name_as_filename): Always use buffer name for + title and buffer filename only for RepresentedFilename. + Handle bad UTF-8 in buffer name (Bug#7517). + 2010-12-30 Jan Djärv <jan.h.d@swipnet.se> * coding.h (ENCODE_UTF_8): Remove "Used by ..." comment.
--- a/src/nsfns.m Thu Dec 30 21:23:13 2010 +0100 +++ b/src/nsfns.m Fri Dec 31 14:16:16 2010 +0100 @@ -602,12 +602,13 @@ ns_set_name_as_filename (struct frame *f) { NSView *view; - Lisp_Object name; + Lisp_Object name, filename; Lisp_Object buf = XWINDOW (f->selected_window)->buffer; const char *title; NSAutoreleasePool *pool; struct gcpro gcpro1; - Lisp_Object encoded_name; + Lisp_Object encoded_name, encoded_filename; + NSString *str; NSTRACE (ns_set_name_as_filename); if (f->explicit_name || ! NILP (f->title) || ns_in_resize) @@ -615,16 +616,16 @@ BLOCK_INPUT; pool = [[NSAutoreleasePool alloc] init]; - name = XBUFFER (buf)->filename; - if (NILP (name) || FRAME_ICONIFIED_P (f)) name = XBUFFER (buf)->name; - - if (FRAME_ICONIFIED_P (f) && !NILP (f->icon_name)) - name = f->icon_name; + filename = XBUFFER (buf)->filename; + name = XBUFFER (buf)->name; if (NILP (name)) - name = build_string ([ns_app_name UTF8String]); - else - CHECK_STRING (name); + { + if (! NILP (filename)) + name = Ffile_name_nondirectory (filename); + else + name = build_string ([ns_app_name UTF8String]); + } GCPRO1 (name); encoded_name = ENCODE_UTF_8 (name); @@ -642,33 +643,39 @@ return; } - if (! FRAME_ICONIFIED_P (f)) + str = [NSString stringWithUTF8String: SDATA (encoded_name)]; + if (str == nil) str = @"Bad coding"; + + if (FRAME_ICONIFIED_P (f)) + [[view window] setMiniwindowTitle: str]; + else { + NSString *fstr; + + if (! NILP (filename)) + { + GCPRO1 (filename); + encoded_filename = ENCODE_UTF_8 (filename); + UNGCPRO; + + fstr = [NSString stringWithUTF8String: SDATA (encoded_filename)]; + if (fstr == nil) fstr = @""; #ifdef NS_IMPL_COCOA - /* work around a bug observed on 10.3 where - setTitleWithRepresentedFilename does not clear out previous state - if given filename does not exist */ - NSString *str = [NSString stringWithUTF8String: SDATA (encoded_name)]; - if (![[NSFileManager defaultManager] fileExistsAtPath: str]) - { - [[view window] setTitleWithRepresentedFilename: @""]; - [[view window] setTitle: str]; + /* work around a bug observed on 10.3 and later where + setTitleWithRepresentedFilename does not clear out previous state + if given filename does not exist */ + if (! [[NSFileManager defaultManager] fileExistsAtPath: fstr]) + [[view window] setRepresentedFilename: @""]; +#endif } else - { - [[view window] setTitleWithRepresentedFilename: str]; - } -#else - [[view window] setTitleWithRepresentedFilename: - [NSString stringWithUTF8String: SDATA (encoded_name)]]; -#endif + fstr = @""; + + [[view window] setRepresentedFilename: fstr]; + [[view window] setTitle: str]; f->name = name; } - else - { - [[view window] setMiniwindowTitle: - [NSString stringWithUTF8String: SDATA (encoded_name)]]; - } + [pool release]; UNBLOCK_INPUT; }