Add url lookup for conkeror
Add simple url lookup for conkeror. Currently loads all bookmarks into the completion buffer, but this will be changed.
This commit is contained in:
parent
d5dbe8ed27
commit
6fdc8f2f5a
2 changed files with 71 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
|||
/* markam -- Store/retrieve/manage bookmarks
|
||||
Copyright (C) 2012 Tom Willemsen <tom at ryuslash dot org>
|
||||
Copyright (C) 2012,2013 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
|
||||
|
@ -25,6 +25,17 @@
|
|||
define_variable("markam_program", "markam",
|
||||
"The location of the markam executable.");
|
||||
|
||||
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);
|
||||
}
|
||||
);
|
||||
|
||||
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.
|
||||
|
@ -74,4 +85,45 @@ interactive("markam-add-link",
|
|||
"Select and bookmark a link in markam",
|
||||
markam_add_link);
|
||||
|
||||
function markam_complete(input, pos, conservative)
|
||||
{
|
||||
if (pos == 0 && conservative)
|
||||
yield co_return(undefined);
|
||||
|
||||
let str = input.substring(0, pos);
|
||||
|
||||
var data = "", error = "", ret = [];
|
||||
var 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 || "") }]);
|
||||
|
||||
if (result != 0 || error != "")
|
||||
throw new interactive_exception("result: " + result +
|
||||
", error: " + error);
|
||||
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_value: function (i) ret[i][2],
|
||||
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);
|
||||
|
||||
|
||||
provide("markam");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
;;; markam -- Store/retrieve/manage bookmarks
|
||||
;; Copyright (C) 2012 Tom Willemsen <tom at ryuslash dot org>
|
||||
;; Copyright (C) 2012,2013 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
|
||||
|
@ -42,9 +42,13 @@
|
|||
;; stream.
|
||||
(: print-row (string fixnum string string -> void))
|
||||
(define (print-row url seconds name description)
|
||||
(if script?
|
||||
(format #t "~a~a~a"
|
||||
(string-no-null name) (string-no-null description)
|
||||
(string-no-null url))
|
||||
(format #t "~a~% ~a~% ~a~% ~a~%~%" (string-no-null name)
|
||||
(string-no-null description) (string-no-null url)
|
||||
(seconds->string seconds)))
|
||||
(seconds->string seconds))))
|
||||
|
||||
;; Add NAME to the `tag' table in DB.
|
||||
(define (add-tag db name)
|
||||
|
@ -120,9 +124,19 @@ END
|
|||
(format #t "Unrecognized option: ~a~%" (car args))))
|
||||
(set! args (cdr args))))
|
||||
|
||||
(define (check-script args)
|
||||
(if (member "--script" args)
|
||||
(begin
|
||||
(set! script? #t)
|
||||
(delete "--script" args))
|
||||
args))
|
||||
|
||||
(define script? #f)
|
||||
|
||||
;; Open a database connection, list bookmarks, create a bookmark or
|
||||
;; pass arguments on to `handle-regular-args'.
|
||||
(define (main args)
|
||||
(set! args (check-script args))
|
||||
(let ((db (open-database (data-file "markam.db"))))
|
||||
(cond
|
||||
((null? args)
|
||||
|
|
Loading…
Reference in a new issue