From df47a68535beb8522e105894cef6088ca39aadc4 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 2 Jul 2013 22:30:46 +0200 Subject: [PATCH] Add remove-tags command This command removes the given tags (or all if none are specified) from a bookmark's tag list. --- doc/clark.texi | 5 +++++ lisp/Makefile | 2 +- lisp/clark.lisp | 8 ++++++++ lisp/queries.lisp | 18 +++++++++++++++--- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/doc/clark.texi b/doc/clark.texi index 69f1ba5..b036104 100644 --- a/doc/clark.texi +++ b/doc/clark.texi @@ -158,6 +158,11 @@ Replace @var{url}'s tags with @var{tags}. @var{tags} may be omitted, in which case all the tags for @var{url} are removed. @end deffn +@deffn Command remove-tags URL [TAGS...] +Remove @var{tags} from @var{url}'s tag list. If @var{tags} is omitted, +remove all tags from @var{url}'s tag list. +@end deffn + @node Miscellaneous, , Management, Usage @section Other things that can be done diff --git a/lisp/Makefile b/lisp/Makefile index 6dec1dc..ae6a1bf 100644 --- a/lisp/Makefile +++ b/lisp/Makefile @@ -36,5 +36,5 @@ $(install-binaries): install-%: % $(uninstall-binaries): uninstall-%: rm -f "$(DESTDIR)/bin/$*" -clark: clark.lisp make-image.lisp +clark: clark.lisp queries.lisp make-image.lisp $(LISP) --load make-image.lisp diff --git a/lisp/clark.lisp b/lisp/clark.lisp index b84e360..4d7deea 100644 --- a/lisp/clark.lisp +++ b/lisp/clark.lisp @@ -285,6 +285,14 @@ 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 remove-tags (url &rest tags) + "Remove given tags from bookmark's tag list." + "Usage: clark remove-tags [ ...] + +Remove the given TAGS from URL's tag list. If no tags are given, +remove all tags from bookmark." + (delete-tags url tags)) + (defcommand version () "Show version." "Usage: clark version diff --git a/lisp/queries.lisp b/lisp/queries.lisp index 4651ed6..2b43b78 100644 --- a/lisp/queries.lisp +++ b/lisp/queries.lisp @@ -68,10 +68,22 @@ (execute-non-query *db* (sql delete from "bookmark" where "url" = ?) url)) -(defun delete-tags (id) +(defun delete-tags (id &optional tags) "Clear the tags for bookmark with id ID." - (execute-non-query *db* (sql delete from "bookmark_tag" - where "bookmark_id" = ?) id)) + (if tags + (map nil + (lambda (tag) + (execute-non-query + *db* (sql delete from "bookmark_tag" + where "bookmark_id" = (select "rowid" + from "bookmark" + where "url" = ?) + and "tag_id" in (select "rowid" + from "tag" + where "name" = ?)) + id tag)) tags) + (execute-non-query *db* (sql delete from "bookmark_tag" + where "bookmark_id" = ?) id))) (defun get-bookmark-id (url) "Get the id of the bookmark for URL."