From 848664002a4e3a875927bc6d48ef1d3e74b3b2d0 Mon Sep 17 00:00:00 2001 From: Isak Johansson Date: Fri, 17 Apr 2020 10:17:49 +0200 Subject: [PATCH 1/2] ADDED new api interfaces for interacting with tags. --- ebuku.el | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/ebuku.el b/ebuku.el index 36859ef..d9db3c3 100644 --- a/ebuku.el +++ b/ebuku.el @@ -853,6 +853,49 @@ If an argument is excluded, get it from `ebuku-cache-default-args'." (setq tags (nconc (map-elt bookmark 'tags) tags))) (setq ebuku-tags (sort (seq-uniq tags) 'string-collate-lessp)))) +(defun ebuku-append-tag-to-bookmark () + "Interactive function to append tag to bookmark." + ;; TODO fix an issue where it moves the cursor to the top after adding + (interactive) + (ebuku-update-tags-cache) + (let ((tag (completing-read "Append tag? " ebuku-tags)) + (index (ebuku--get-index-at-point)) + (inhibit-read-only t)) + (ebuku--tags-add index tag) + (ebuku-refresh) + (message "Added tag to bookmark"))) + +(defun ebuku--tags-join (tags) + "Internal function that joins a list of tags into a comma separated string of tags." + (typecase tags + (stringp tags) + (listp (mapconcat 'identity tags ",")))) + +(defun ebuku--tags-add (index tags) + "Append tag to the list of tags on the index" + (with-temp-buffer + (ebuku--call-buku + `("--update" , index + "--tag", "+" , (ebuku--tags-join tags))))) + +(defun ebuku--tags-remove (index tags) + "Remove tag from the list of tags on the index" + (with-temp-buffer + (ebuku--call-buku + `("--update" , index + "--tag", "-" , (ebuku--tags-join tags))))) + +(defun ebuku--tags-set (index tags) + "Replace the current list of tags on the index with the one provided to this bookmark." + (with-temp-buffer + (ebuku--call-buku-no-output + `("--update" , index + "--tag", (ebuku--tags-join tags))))) + +(defun ebuku--tags-reset (index) + "Remove all tags from index." + (ebuku--tags-set index "")) + ;;;###autoload (define-derived-mode ebuku-mode special-mode "Ebuku" From dafd90cde35a20408710011c6bde35bd810ec461 Mon Sep 17 00:00:00 2001 From: Isak Johansson Date: Thu, 23 Apr 2020 01:19:55 +0200 Subject: [PATCH 2/2] Update Removed `cl` dependecy and improved docstrings. --- ebuku.el | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/ebuku.el b/ebuku.el index d9db3c3..5398739 100644 --- a/ebuku.el +++ b/ebuku.el @@ -854,8 +854,7 @@ If an argument is excluded, get it from `ebuku-cache-default-args'." (setq ebuku-tags (sort (seq-uniq tags) 'string-collate-lessp)))) (defun ebuku-append-tag-to-bookmark () - "Interactive function to append tag to bookmark." - ;; TODO fix an issue where it moves the cursor to the top after adding + "Append tag to bookmark at point." (interactive) (ebuku-update-tags-cache) (let ((tag (completing-read "Append tag? " ebuku-tags)) @@ -866,34 +865,39 @@ If an argument is excluded, get it from `ebuku-cache-default-args'." (message "Added tag to bookmark"))) (defun ebuku--tags-join (tags) - "Internal function that joins a list of tags into a comma separated string of tags." - (typecase tags - (stringp tags) - (listp (mapconcat 'identity tags ",")))) + "Internal function to join a list of TAGS into a comma separated string." + (cond ((stringp tags) + tags) + ((listp tags) + (mapconcat 'identity tags ",")) + (t + (error "Tags need to be either a string or list")))) (defun ebuku--tags-add (index tags) - "Append tag to the list of tags on the index" + "Internal function to append TAGS to the list of tags on the INDEX." (with-temp-buffer (ebuku--call-buku `("--update" , index "--tag", "+" , (ebuku--tags-join tags))))) (defun ebuku--tags-remove (index tags) - "Remove tag from the list of tags on the index" + "Internal function to remove TAGS from the list of tags on the INDEX." (with-temp-buffer (ebuku--call-buku `("--update" , index "--tag", "-" , (ebuku--tags-join tags))))) (defun ebuku--tags-set (index tags) - "Replace the current list of tags on the index with the one provided to this bookmark." + "Internal function to set TAGS on the INDEX. + +This function does not append to the current list of TAGS it replaces it." (with-temp-buffer - (ebuku--call-buku-no-output + (ebuku--call-buku `("--update" , index "--tag", (ebuku--tags-join tags))))) -(defun ebuku--tags-reset (index) - "Remove all tags from index." +(defun ebuku--tags-clear (index) + "Internal function to clear all tags from INDEX." (ebuku--tags-set index ""))