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();
var replace_map = {
    ".": {
        "transformer": function (filename) {
            return filename.replace( /[\W ]+/g   , "-"   )
                           .replace( /^-+/       , ""    )
                           .replace( /-+$/       , ""    )
                           .replace( /-([^-]+)$/ , ".$1" )
                           .toLowerCase();
        }
    },
    "\.torrent$": {
        "path": "~/media-files",
        "transformer": function (filename) {
            return filename.replace( /isohunt-/i, "" );
        }
    }
};

function update_save_path(info) {
        save_path = info.target_file.parent.path;
}
add_hook("download_added_hook", update_save_path);

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.

And another problem is with download_finished_hook.
After add_hook("download_finished_hook", org_download),
I found that the function org_download is called 7 times after C-x C-s
some buffer.

I am using the latest git-version Conkeror.

Best regards,
zwz

_______________________________________________
Conkeror mailing list
[email protected]
https://www.mozdev.org/mailman/listinfo/conkeror

Reply via email to