From 7250ca8c3cbdc0e1b884cebce4bc16e260a3aa31 Mon Sep 17 00:00:00 2001
From: Alexey Lebedeff <binarin@gmail.com>
Date: Sun, 25 Dec 2016 13:24:04 +0300
Subject: [PATCH] Reveal tags after setting them

Sometimes freshly added tags can be sucked into invisible outline
region (denoted by ellipsis) - and to see them you need to do the full
global visibilty cycle.
---
 lisp/org.el              |  7 ++++++-
 testing/lisp/test-org.el | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 3ddd80b..375c18d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15096,7 +15096,12 @@ When JUST-ALIGN is non-nil, only align tags."
 	      ;; white spaces.
 	      (end-of-line)
 	      (if (not (equal tags ""))
-		  (insert " " tags)
+		  (let* ((before-point (point)))
+		    (insert " " tags)
+		    ;; When text is being inserted on an invisible
+		    ;; region boundary, it can be inadvertently sucked
+		    ;; into invisibility.
+		    (outline-flag-region before-point (point) nil))
 		(skip-chars-backward " \t")
 		(delete-region (point) (line-end-position)))))
 	  ;; Align tags, if any.  Fix tags column if `org-indent-mode'
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index bbd0c0b..d60364a 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -5130,6 +5130,24 @@ Paragraph<point>"
   (should-not
    (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
 
+(ert-deftest test-org/fast-tag-selection ()
+  "Test `org-fast-tag-selection'."
+  ;; Tags set via fast-tag-selection should be visible afterwards
+  (should
+   (let ((org-tag-alist '(("NEXT" . ?n)))
+	 (org-fast-tag-selection-single-key t))
+     (cl-letf (((symbol-function 'read-char-exclusive) (lambda () ?n))
+	       ((symbol-function 'window-width) (lambda (&rest args) 100)))
+       (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
+	 ;; Show only headlines
+	 (org-content)
+	 ;; Set NEXT tag on current entry
+	 (org-set-tags nil nil)
+	 ;; Move point to that NEXT tag
+	 (search-forward "NEXT") (backward-word)
+	 ;; And it should be visible (i.e. no overlays)
+	 (not (overlays-at (point))))))))
+
 (ert-deftest test-org/show-set-visibility ()
   "Test `org-show-set-visibility' specifications."
   ;; Do not throw an error before first heading.
-- 
2.10.0

