aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-07-02 22:30:46 +0200
committerGravatar Tom Willemse2013-07-02 22:30:46 +0200
commitdf47a68535beb8522e105894cef6088ca39aadc4 (patch)
tree4a89951ad1aac13978a2272d707bd23d973223dc
parent612189139623bfc6cb45dadee3aeb0f8491d9fc7 (diff)
downloadclark-df47a68535beb8522e105894cef6088ca39aadc4.tar.gz
clark-df47a68535beb8522e105894cef6088ca39aadc4.zip
Add remove-tags command
This command removes the given tags (or all if none are specified) from a bookmark's tag list.
-rw-r--r--doc/clark.texi5
-rw-r--r--lisp/Makefile2
-rw-r--r--lisp/clark.lisp8
-rw-r--r--lisp/queries.lisp18
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 <url> [<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."