librelist archives

« back to archive

how to make a function accept prefix arg C-u

how to make a function accept prefix arg C-u

From:
Makmiller Pedroso
Date:
2014-10-12 @ 17:46
In the Conkeror webpage, someone wrote a nice function that allows you
to select webjumps with one key:


-----------------------------------------------------------------------------------------

function create_selection_search(webjump, key) {
    interactive("prompted-"+webjump+"-search", null,
        function (I) {
                    var term = yield I.minibuffer.read_url($prompt =
"Search "+webjump+":",

$initial_value = webjump+" ");
                    browser_object_follow(I.buffer, FOLLOW_DEFAULT, term);
                });
    define_key(content_buffer_normal_keymap, key, "prompted-" +
webjump + "-search");
}

create_selection_search("google","g");


------------------------------------------------------------------------------------------

I would also like to run the above function in a new buffer. I can do
that by changing the target "FOLLOW_DEFAULT" to "OPEN_NEW_BUFFER." But
this would force me to have two separate keybindings (one for each
target).  A better way of doing this would be to use a prefix argument
(like in find-url). How can I implement this? That is, how can I
rewrite the above function so that the use of a prefix argument allows
me to search in a new buffer? (I tried to read find-url from
commands.js but I couldn't quite figure it out).

mak

Re: [conkeror] how to make a function accept prefix arg C-u

From:
Scott Jaderholm
Date:
2014-10-12 @ 22:04
Well what you have there is not a selection search, since it does not
use the selected text, so you should rename create_selection_search.

You can use alternates, like below:

function create_selection_search(webjump, key) {
    interactive(webjump+"-selection-search",
                "Search " + webjump + " with selection contents",
                alternates(follow, follow_new_buffer, follow_new_window),
        $browser_object = function (I) {
                    return webjump + " " + I.buffer.top_frame.getSelection();});
    define_key(content_buffer_normal_keymap, key.toUpperCase(),
webjump + "-selection-search");

    interactive("prompted-"+webjump+"-search", null,
                alternates(follow, follow_new_buffer_follow_new_window),
                $browser_object = function (I) {
                    var term = I.minibuffer.read_url($prompt = "Search
"+webjump+":",

$initial_value = webjump+" ");
                    return term;
                });
    define_key(content_buffer_normal_keymap, key, "prompted-" +
webjump + "-search");
}
Scott


On Sun, Oct 12, 2014 at 10:46 AM, Makmiller Pedroso <makmiller@gmail.com> wrote:
> In the Conkeror webpage, someone wrote a nice function that allows you
> to select webjumps with one key:
>
> 
-----------------------------------------------------------------------------------------
>
> function create_selection_search(webjump, key) {
>     interactive("prompted-"+webjump+"-search", null,
>         function (I) {
>                     var term = yield I.minibuffer.read_url($prompt =
> "Search "+webjump+":",
>
> $initial_value = webjump+" ");
>                     browser_object_follow(I.buffer, FOLLOW_DEFAULT, term);
>                 });
>     define_key(content_buffer_normal_keymap, key, "prompted-" +
> webjump + "-search");
> }
>
> create_selection_search("google","g");
>
> 
------------------------------------------------------------------------------------------
>
> I would also like to run the above function in a new buffer. I can do
> that by changing the target "FOLLOW_DEFAULT" to "OPEN_NEW_BUFFER." But
> this would force me to have two separate keybindings (one for each
> target).  A better way of doing this would be to use a prefix argument
> (like in find-url). How can I implement this? That is, how can I
> rewrite the above function so that the use of a prefix argument allows
> me to search in a new buffer? (I tried to read find-url from
> commands.js but I couldn't quite figure it out).
>
> mak

Re: [conkeror] how to make a function accept prefix arg C-u

From:
Makmiller Pedroso
Date:
2014-10-13 @ 04:11
Thanks a bunch! This is exactly what I was trying to do.

mak

On Sun, Oct 12, 2014 at 6:04 PM, Scott Jaderholm <jaderholm@gmail.com> wrote:
> Well what you have there is not a selection search, since it does not
> use the selected text, so you should rename create_selection_search.
>
> You can use alternates, like below:
>
> function create_selection_search(webjump, key) {
>     interactive(webjump+"-selection-search",
>                 "Search " + webjump + " with selection contents",
>                 alternates(follow, follow_new_buffer, follow_new_window),
>         $browser_object = function (I) {
>                     return webjump + " " + I.buffer.top_frame.getSelection();});
>     define_key(content_buffer_normal_keymap, key.toUpperCase(),
> webjump + "-selection-search");
>
>     interactive("prompted-"+webjump+"-search", null,
>                 alternates(follow, follow_new_buffer_follow_new_window),
>                 $browser_object = function (I) {
>                     var term = I.minibuffer.read_url($prompt = "Search
> "+webjump+":",
>
> $initial_value = webjump+" ");
>                     return term;
>                 });
>     define_key(content_buffer_normal_keymap, key, "prompted-" +
> webjump + "-search");
> }
> Scott
>
>
> On Sun, Oct 12, 2014 at 10:46 AM, Makmiller Pedroso <makmiller@gmail.com> wrote:
>> In the Conkeror webpage, someone wrote a nice function that allows you
>> to select webjumps with one key:
>>
>> 
-----------------------------------------------------------------------------------------
>>
>> function create_selection_search(webjump, key) {
>>     interactive("prompted-"+webjump+"-search", null,
>>         function (I) {
>>                     var term = yield I.minibuffer.read_url($prompt =
>> "Search "+webjump+":",
>>
>> $initial_value = webjump+" ");
>>                     browser_object_follow(I.buffer, FOLLOW_DEFAULT, term);
>>                 });
>>     define_key(content_buffer_normal_keymap, key, "prompted-" +
>> webjump + "-search");
>> }
>>
>> create_selection_search("google","g");
>>
>> 
------------------------------------------------------------------------------------------
>>
>> I would also like to run the above function in a new buffer. I can do
>> that by changing the target "FOLLOW_DEFAULT" to "OPEN_NEW_BUFFER." But
>> this would force me to have two separate keybindings (one for each
>> target).  A better way of doing this would be to use a prefix argument
>> (like in find-url). How can I implement this? That is, how can I
>> rewrite the above function so that the use of a prefix argument allows
>> me to search in a new buffer? (I tried to read find-url from
>> commands.js but I couldn't quite figure it out).
>>
>> mak