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