"John J. Foerch" <[email protected]> writes: > On Thu, Mar 31, 2011 at 03:16:23AM +0800, zwz wrote: >> I found the tip of saving the last save-path, and I modified it a > little >> so as to rename the file-name according to what is selected in the >> buffer. >> Here is the problematic code >> #+BEGIN_SRC js >> { >> var save_path = get_home_directory(); >> >> ... >> >> function suggest_save_path_from_file_name(file_name, buffer) { >> // var cwd = with_current_buffer(buffer, function (I) I.local.cwd); >> var sel = with_current_buffer(buffer, function (I) > I.buffer.top_frame.getSelection()); >> // var file = cwd.clone(); >> var file = make_file(save_path); >> >> if (sel != ""){ >> var index = file_name.lastIndexOf("."); >> if (index >= 0) file_name = sel + file_name.substr(index); >> } >> for (let re in replace_map) { >> if (file_name.match(re)) { >> if (replace_map[re].path) { >> file = make_file(replace_map[re].path); >> } >> file_name = replace_map[re].transformer(file_name); >> } >> } >> file.append(file_name); >> return file.path; >> } >> } >> #+END_SRC >> Some problem happens as >> >> C-x C-s, and C-g immediately; and then C-x C-s again, the saving >> directory changes. >> > > > I think this problem may be due to suggest_save_path_from_file modifying > the global variable save_path. When you do make_file(save_path), if > save_path is already an nsILocalFile, which it is initially, the > argument > is returned unchanged. You need to clone the object before calling > file.append(file_name).
Yes, you're right. When I select some text that is not a file-name for an existing file yet, the problem disappears. But I don't know how to fix it, as I am lacking js knowledge. _______________________________________________ Conkeror mailing list [email protected] https://www.mozdev.org/mailman/listinfo/conkeror
