summaryrefslogtreecommitdiffstats
path: root/conkeror/markam.js
blob: 2151b17a0c63b275244a300c5c0d9e66438402bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* markam -- Store/retrieve/manage bookmarks
   Copyright (C) 2012  Tom Willemsen <tom at ryuslash dot org>

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/// Commentary:

// A wrapper script that should allow conkeror to interface with
// markam.  Does not yet allow searching through collected bookmarks,
// only adding new ones.

/// Code:

define_variable("markam_program", "markam",
                "The location of the markam executable.");

function markam_add_url(I, url, title)
{   // Add URL to markam, ask for a title (provide TITLE as a
    // default), description and any number of tags.
    let url_string = load_spec_uri_string(load_spec(url));
    let title = yield I.minibuffer.read($prompt="name (required): ",
                                        $initial_value=title);
    let description = yield I.minibuffer.read(
        $prompt="extended description: "
    );
    let tags = yield I.minibuffer.read(
        $prompt="tags (comma delimited): "
    );
    let command = markam_program + ' "' + url_string + '" "' + title
            + '" "' + description + '" \''
            + tags.split(',').map(function (str)
                                  { return str.trim(); }).join("' '")
            + "'";
    yield shell_command(command);
}

function markam_add(I) {
    check_buffer(I.buffer, content_buffer);
    let result = yield markam_add_url(I, I.buffer.top_frame,
                                        I.buffer.title);

    if (!result)
        I.window.minibuffer.message('Added to markam');
    else
        I.window.minibuffer.message('Couldn\'t add to markam');
}
interactive("markam-add",
            "Bookmark the current page in markam",
            markam_add);

function markam_add_link(I) {
    check_buffer(I.buffer, content_buffer);
    bo = yield read_browser_object(I);
    let result = yield markam_add_url(I, encodeURIComponent(bo),
                                        bo.textContent);

    if (!result)
        I.window.minibuffer.message('Added to markam');
    else
        I.window.minibuffer.message('Couldn\'t add to markam');
}
interactive("markam-add-link",
            "Select and bookmark a link in markam",
            markam_add_link);

provide("markam");