Browse Source

Fix spurious colons next to TODO keywords

* lisp/org.el (org-toggle-tag): Fix spurious colons next to TODO
  keywords.

Reported-by: Colin Baxter <m43cap@yandex.com>
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-08/msg00075.html>
Nicolas Goaziou 7 years ago
parent
commit
15f112259b
1 changed files with 16 additions and 22 deletions
  1. 16 22
      lisp/org.el

+ 16 - 22
lisp/org.el

@@ -14739,30 +14739,24 @@ ignore inherited ones."
 (defun org-toggle-tag (tag &optional onoff)
   "Toggle the tag TAG for the current line.
 If ONOFF is `on' or `off', don't toggle but set to this state."
-  (let (res current)
-    (save-excursion
-      (org-back-to-heading t)
-      (if (re-search-forward "[ \t]:\\([[:alnum:]_@#%:]+\\):[ \t]*$"
-			     (point-at-eol) t)
-	  (progn
-	    (setq current (match-string 1))
-	    (replace-match ""))
-	(setq current ""))
-      (setq current (nreverse (org-split-string current ":")))
-      (cond
-       ((eq onoff 'on)
-	(setq res t)
-	(or (member tag current) (push tag current)))
-       ((eq onoff 'off)
-	(or (not (member tag current)) (setq current (delete tag current))))
-       (t (if (member tag current)
-	      (setq current (delete tag current))
-	    (setq res t)
-	    (push tag current))))
-      (end-of-line 1)
+  (save-excursion
+    (org-back-to-heading t)
+    (let ((current
+	   (when (re-search-forward "[ \t]:\\([[:alnum:]_@#%:]+\\):[ \t]*$"
+				    (point-at-eol) t)
+	     (replace-match "")
+	     (nreverse (org-split-string (match-string 1) ":"))))
+	  res)
+      (pcase onoff
+	(`off (setq current (delete tag current)))
+	((or `on (guard (not (member tag current))))
+	 (setq res t)
+	 (cl-pushnew tag current :test #'equal))
+	(_ (setq current (delete tag current))))
+      (end-of-line)
       (if current
 	  (progn
-	    (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
+	    (insert " :" (mapconcat #'identity (nreverse current) ":") ":")
 	    (org-set-tags nil t))
 	(delete-horizontal-space))
       (run-hooks 'org-after-tags-change-hook))