From 9e6199a5aa54b8ef2af1999981cafa0becb3049e Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 4 Jun 2013 00:35:52 +0200 Subject: Add random command This command simply prints a random URL. A tag may be specified to limit the search to that tag. In the Conkeror module this command immediately loads the random bookmark in the current buffer. - js/clark.js: If `error' is empty, return the value of `data'. This makes it easier for some commands to use the result of the command. Add `clark-random' to `clark_keymap'. --- lisp/clark.lisp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lisp/clark.lisp') diff --git a/lisp/clark.lisp b/lisp/clark.lisp index bfb0868..d9477e8 100644 --- a/lisp/clark.lisp +++ b/lisp/clark.lisp @@ -330,6 +330,17 @@ list of tags." (clear-tags url) (add-tags url tags)) +(defun random-item (lst) + (nth (random (length lst) (make-random-state t)) lst)) + +(defcommand random (&optional tag) + "Pick a random bookmark, possibly from TAG." + "Usage: clark random [] + +Get a random bookmark. If TAG is given limit the result to a bookmark +having the tag TAG." + (format t "~a~%" (random-item (url-list tag)))) + (defcommand version () "Show version." "Usage: clark version -- cgit v1.2.3-54-g00ecf