2012-12-29 16:54:16 +01:00
|
|
|
|
/* markam -- Store/retrieve/manage bookmarks
|
2013-02-11 23:04:53 +01:00
|
|
|
|
Copyright (C) 2012,2013 Tom Willemsen <tom at ryuslash dot org>
|
2012-12-28 20:45:32 +01:00
|
|
|
|
|
2013-02-16 12:22:53 +01:00
|
|
|
|
This file is part of Markam
|
|
|
|
|
|
|
|
|
|
Markam is free software: you can redistribute it and/or modify it
|
|
|
|
|
under the terms of the GNU General Public License as published by
|
2012-12-28 20:45:32 +01:00
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
2013-02-16 12:22:53 +01:00
|
|
|
|
Markam 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.
|
2012-12-28 20:45:32 +01:00
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-02-16 12:22:53 +01:00
|
|
|
|
along with Markam. If not, see <http://www.gnu.org/licenses/>.
|
2012-12-28 20:45:32 +01:00
|
|
|
|
*/
|
|
|
|
|
/// Commentary:
|
|
|
|
|
|
|
|
|
|
// A wrapper script that should allow conkeror to interface with
|
2012-12-29 16:54:16 +01:00
|
|
|
|
// markam. Does not yet allow searching through collected bookmarks,
|
|
|
|
|
// only adding new ones.
|
2012-12-28 20:45:32 +01:00
|
|
|
|
|
|
|
|
|
/// Code:
|
|
|
|
|
|
2012-12-29 16:54:16 +01:00
|
|
|
|
define_variable("markam_program", "markam",
|
|
|
|
|
"The location of the markam executable.");
|
2012-12-28 20:24:20 +01:00
|
|
|
|
|
2013-02-11 23:04:53 +01:00
|
|
|
|
define_browser_object_class(
|
|
|
|
|
"markam-bookmark", null,
|
|
|
|
|
function (I, prompt) {
|
|
|
|
|
check_buffer(I.buffer, content_buffer);
|
|
|
|
|
var result = yield I.buffer.window.minibuffer.read(
|
|
|
|
|
$prompt = prompt, $completer = markam_complete
|
|
|
|
|
);
|
|
|
|
|
yield co_return(result);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2012-12-29 16:54:16 +01:00
|
|
|
|
function markam_add_url(I, url, title)
|
|
|
|
|
{ // Add URL to markam, ask for a title (provide TITLE as a
|
2012-12-28 22:03:55 +01:00
|
|
|
|
// default), description and any number of tags.
|
2012-12-28 20:24:20 +01:00
|
|
|
|
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): "
|
|
|
|
|
);
|
2012-12-29 16:54:16 +01:00
|
|
|
|
let command = markam_program + ' "' + url_string + '" "' + title
|
2012-12-28 20:24:20 +01:00
|
|
|
|
+ '" "' + description + '" \''
|
|
|
|
|
+ tags.split(',').map(function (str)
|
|
|
|
|
{ return str.trim(); }).join("' '")
|
|
|
|
|
+ "'";
|
|
|
|
|
yield shell_command(command);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-29 16:54:16 +01:00
|
|
|
|
function markam_add(I) {
|
2012-12-28 20:24:20 +01:00
|
|
|
|
check_buffer(I.buffer, content_buffer);
|
2012-12-29 16:54:16 +01:00
|
|
|
|
let result = yield markam_add_url(I, I.buffer.top_frame,
|
2012-12-28 20:24:20 +01:00
|
|
|
|
I.buffer.title);
|
|
|
|
|
|
|
|
|
|
if (!result)
|
2012-12-29 16:54:16 +01:00
|
|
|
|
I.window.minibuffer.message('Added to markam');
|
2012-12-28 20:24:20 +01:00
|
|
|
|
else
|
2012-12-29 16:54:16 +01:00
|
|
|
|
I.window.minibuffer.message('Couldn\'t add to markam');
|
2012-12-28 20:24:20 +01:00
|
|
|
|
}
|
2012-12-29 16:54:16 +01:00
|
|
|
|
interactive("markam-add",
|
|
|
|
|
"Bookmark the current page in markam",
|
|
|
|
|
markam_add);
|
2012-12-28 20:24:20 +01:00
|
|
|
|
|
2012-12-29 16:54:16 +01:00
|
|
|
|
function markam_add_link(I) {
|
2012-12-28 20:24:20 +01:00
|
|
|
|
check_buffer(I.buffer, content_buffer);
|
|
|
|
|
bo = yield read_browser_object(I);
|
2012-12-29 16:54:16 +01:00
|
|
|
|
let result = yield markam_add_url(I, encodeURIComponent(bo),
|
2012-12-28 20:24:20 +01:00
|
|
|
|
bo.textContent);
|
|
|
|
|
|
|
|
|
|
if (!result)
|
2012-12-29 16:54:16 +01:00
|
|
|
|
I.window.minibuffer.message('Added to markam');
|
2012-12-28 20:24:20 +01:00
|
|
|
|
else
|
2012-12-29 16:54:16 +01:00
|
|
|
|
I.window.minibuffer.message('Couldn\'t add to markam');
|
2012-12-28 20:24:20 +01:00
|
|
|
|
}
|
2012-12-29 16:54:16 +01:00
|
|
|
|
interactive("markam-add-link",
|
|
|
|
|
"Select and bookmark a link in markam",
|
|
|
|
|
markam_add_link);
|
2012-12-28 20:24:20 +01:00
|
|
|
|
|
2013-02-11 23:04:53 +01:00
|
|
|
|
function markam_complete(input, pos, conservative)
|
|
|
|
|
{
|
|
|
|
|
if (pos == 0 && conservative)
|
|
|
|
|
yield co_return(undefined);
|
|
|
|
|
|
|
|
|
|
let str = input.substring(0, pos);
|
|
|
|
|
|
|
|
|
|
var data = "", error = "", ret = [];
|
2013-02-12 20:44:47 +01:00
|
|
|
|
var result = 0;
|
|
|
|
|
|
|
|
|
|
if (str == "")
|
|
|
|
|
result = yield shell_command(
|
|
|
|
|
markam_program + " --script",
|
|
|
|
|
$fds = [{ output: async_binary_string_writer("") },
|
|
|
|
|
{ input: async_binary_reader(function (s) data += s || "") },
|
|
|
|
|
{ input: async_binary_reader(function (s) error += s || "") }]);
|
|
|
|
|
else
|
|
|
|
|
result = yield shell_command_with_argument(
|
|
|
|
|
markam_program + " --script search {}", str,
|
|
|
|
|
$fds = [{ output: async_binary_string_writer("") },
|
|
|
|
|
{ input: async_binary_reader(function (s) data += s || "") },
|
|
|
|
|
{ input: async_binary_reader(function (s) error += s || "") }]);
|
2013-02-11 23:04:53 +01:00
|
|
|
|
|
|
|
|
|
if (result != 0 || error != "")
|
2013-02-13 09:09:38 +01:00
|
|
|
|
throw new Error("result: " + result + ", error: " + error);
|
2013-02-11 23:04:53 +01:00
|
|
|
|
else if (data != "") {
|
|
|
|
|
data.split('').forEach(function (row) {
|
|
|
|
|
ret.push(row.split(''));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let c = { count: ret.length,
|
|
|
|
|
get_string: function (i) ret[i][0],
|
|
|
|
|
get_description: function (i) ret[i][1],
|
|
|
|
|
get_input_state: function (i) [ret[i][2]] };
|
|
|
|
|
yield co_return(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interactive("markam-find-url",
|
|
|
|
|
"Find a page from markam in the current buffer",
|
|
|
|
|
"find-url",
|
|
|
|
|
$browser_object = browser_object_markam_bookmark);
|
|
|
|
|
interactive("markam-find-url-new-buffer",
|
|
|
|
|
"Find a page from markam in a new buffer",
|
|
|
|
|
"find-url-new-buffer",
|
|
|
|
|
$browser_object = browser_object_markam_bookmark);
|
|
|
|
|
|
|
|
|
|
|
2012-12-29 16:54:16 +01:00
|
|
|
|
provide("markam");
|