branch: externals/org-gnosis
commit 19332dfd4551c616bd19c5bbb77307938c1a7a4c
Author: Thanos Apollo <pub...@thanosapollo.org>
Commit: Thanos Apollo <pub...@thanosapollo.org>

    insert-tags: Add support for inserting tags for headings.
    
    * Insert a tag or a filetag, with provided completions for tags found
      in gnosis db.
    
    * Rename org-gnosis-insert-tag to org-gnosis-insert-filetag as it is
      only used to insert a filetag
---
 org-gnosis.el | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/org-gnosis.el b/org-gnosis.el
index 86787ae72c..c9caabb9a7 100644
--- a/org-gnosis.el
+++ b/org-gnosis.el
@@ -465,29 +465,34 @@ If JOURNAL-P is non-nil, retrieve/create node as a 
journal entry."
          (t (org-insert-link nil id node)))))
 
 
-(defun org-gnosis-insert-tag (&optional tag)
+(defun org-gnosis-insert-filetag (&optional tag)
   "Insert TAG as filetag."
   (interactive)
   (let* ((filetags (org-gnosis-select 'tag 'tags '1=1 t))
          (tag (or tag (funcall org-gnosis-completing-read-func "Select tag: " 
filetags))))
     (save-excursion
-      (goto-char (point-min))
-      (if (re-search-forward "^#\\+FILETAGS:" nil t)
+      (if (org-at-heading-p)
+         (org-set-tags tag)
+       (goto-char (point-min))
+       (if (re-search-forward "^#\\+FILETAGS:" nil t)
+            (progn
+              (end-of-line)
+              (insert (if (looking-back ":" nil) "" ":") tag ":"))
           (progn
-            (end-of-line)
-            (insert (if (looking-back ":" nil) "" ":") tag ":"))
-        (progn
-          (insert "#+FILETAGS: :" tag ":")
-          (newline))))))
+            (insert "#+FILETAGS: :" tag ":")
+            (newline)))))))
 
 ;;;###autoload
 (defun org-gnosis-insert-tags (tags)
   "Insert TAGS as filetags."
-  (interactive (list (completing-read-multiple
-                     "Select tags (seperated by ,): "
-                     (org-gnosis-select 'tag 'tags '1=1 t))))
-  (dolist (tag tags)
-    (org-gnosis-insert-tag tag)))
+  (interactive
+   (list (completing-read-multiple
+         "Select tags (separated by ,): "
+         (org-gnosis-select 'tag 'tags '1=1 t))))
+  (if (org-before-first-heading-p)
+      (mapc #'org-gnosis-insert-filetag tags)
+    (org-back-to-heading)
+    (org-set-tags tags)))
 
 ;;;###autoload
 (defun org-gnosis-journal-find (&optional title)

Reply via email to