0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-29 23:17:49 +00:00

`org-set-tags' cleans tag even when new tags are identical

* lisp/org.el (org-set-tags): Clean old tags unconditionally.

Even if the tags are the same, the line could contain noise, e.g.,
blanks after the tags, that could be cleaned up anyway.
This commit is contained in:
Nicolas Goaziou 2018-04-28 23:50:18 +02:00
parent 1615261cdc
commit 8785052735

View file

@ -14316,30 +14316,32 @@ TAGS may be a tags string like \":aa:bb:cc:\", or a list of tags.
If TAGS is nil or the empty string, all tags are removed.
This function assumes point is on a headline."
(let ((tags (pcase tags
((pred listp) tags)
((pred stringp) (split-string (org-trim tags) ":" t))
(_ (error "Invalid tag specification: %S" tags))))
(change-flag nil))
(when (functionp org-tags-sort-function)
(setq tags (sort tags org-tags-sort-function)))
(org-with-wide-buffer
(unless (equal tags (org-get-tags nil t))
(setq change-flag t)
;; Delete previous tags and any trailing white space.
(goto-char (if (looking-at org-tag-line-re) (match-beginning 1)
(line-end-position)))
(skip-chars-backward " \t")
(delete-region (point) (line-end-position))
(when tags
(save-excursion (insert " " (org-make-tag-string tags)))
;; When text is being inserted on an invisible region
;; boundary, it can be inadvertently sucked into
;; invisibility.
(unless (org-invisible-p (line-beginning-position))
(org-flag-region (point) (line-end-position) nil 'outline))))
;; Align tags, if any. Fix tags column if `org-indent-mode' is
;; on.
(org-with-wide-buffer
(let ((tags (pcase tags
((pred listp) tags)
((pred stringp) (split-string (org-trim tags) ":" t))
(_ (error "Invalid tag specification: %S" tags))))
(old-tags (org-get-tags nil t))
(change-flag nil))
(when (functionp org-tags-sort-function)
(setq tags (sort tags org-tags-sort-function)))
(unless (equal tags old-tags) (setq change-flag t))
;; Delete previous tags and any trailing white space.
(goto-char (if (org-match-line org-tag-line-re) (match-beginning 1)
(line-end-position)))
(skip-chars-backward " \t")
(delete-region (point) (line-end-position))
;; Deleting white spaces may break an otherwise empty headline.
;; Re-introduce one space in this case.
(unless (org-at-heading-p) (insert " "))
(when tags
(save-excursion (insert " " (org-make-tag-string tags)))
;; When text is being inserted on an invisible region
;; boundary, it can be inadvertently sucked into
;; invisibility.
(unless (org-invisible-p (line-beginning-position))
(org-flag-region (point) (line-end-position) nil 'outline)))
;; Align tags, if any.
(when tags (org-align-tags))
(when change-flag (run-hooks 'org-after-tags-change-hook)))))