aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/clark.lisp
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-06-04 00:35:52 +0200
committerGravatar Tom Willemse2013-06-04 01:12:13 +0200
commit9e6199a5aa54b8ef2af1999981cafa0becb3049e (patch)
tree3fa7f08236f670eb048e59f291388b55eebe0ed7 /lisp/clark.lisp
parent9badf67e274837d0e8a1af5554717dc94fa8bbcf (diff)
downloadclark-9e6199a5aa54b8ef2af1999981cafa0becb3049e.tar.gz
clark-9e6199a5aa54b8ef2af1999981cafa0becb3049e.zip
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'.
Diffstat (limited to 'lisp/clark.lisp')
-rw-r--r--lisp/clark.lisp11
1 files changed, 11 insertions, 0 deletions
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 [<tag>]
+
+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