If the buffer is too narrow, if I make a tag for a heading, the amount of whitespace before the tag causes the tag to wrap past the end of the line onto a new line (I have visual-line-mode turned on). This makes it difficult to skim and read the headlines, and wastes vertical screen real-estate.

I think ideally the tag would always display as right aligned, regardless of the true number of spaces. Is there a way to do that? If not, is there some other way of avoiding the wasted space?

  • 2
    How about no right alignment at all?: (setq org-tags-column 0) See the doc-string for said variable: M-x describe-variable RET org-tags-column RET -- "The column to which tags should be indented in a headline. If this number is positive, it specifies the column. If it is negative, it means that the tags should be flushright to that column. For example, -80 works well for a normal 80 character screen. When 0, place tags directly after headline text, with only one space in between." – lawlist Apr 9 '15 at 22:52
  • Thanks! I've been using (setq org-tags-column 0) which is better than nothing, but I'd still like to have a right-aligned solution. I just flagged for mods to move this, thanks for the suggestion! – avv Apr 13 '15 at 22:46

I've been working on some elisp to solve an issue similar to this.

(defun nanny/org-realign-tag-column ()
  (if (and (equal major-mode 'org-mode)
      ;; ignore `message' with flet so org-set-tags doesn't yell at us.
      (flet ((message (&rest args) 'ignore))
        (let ((col (- (- (window-width) 3)))
              (already-modified? (buffer-modified-p)))
          (setq org-tags-column col)
          (org-set-tags 4 t)
          ;; `org-set-tags' modifies the buffer, but I don't really care, so
          ;; mark the buffer as unmodified if it was unmodified previously.
          (if (not already-modified?)
              (set-buffer-modified-p nil))))))
(add-hook 'window-configuration-change-hook 'nanny/org-realign-tag-column)

This should realign the tags column so that it's always the perfect size.

Right now it doesn't work properly if the horizontally-split window widths are not equal.

  • Tried this out, and it appears that this code ensures the tags are always aligned flush with the right side of the window, but doesn't touch tags on wrapped lines. Assuming I didn't miss something, this doesn't really answer the question, since the latter is what the OP was asking about. – Scott Weldon Jul 12 '16 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.