cadadr / elisp

Göktuğ's Emacs Lisp programs
79 stars 21 forks source link

org-variable-pitch: Right-justify or align tags #53

Closed ksafford closed 1 year ago

ksafford commented 4 years ago

Tags in an org-mode file are jagged when org-variable-pitch-minor-mode is enabled. It would be nicer if they were either aligned or right-justified. I'm not sure if this is within the scope of this project.

Given some guidance, I'd be happy to take a crack at this. Screen Shot 2020-09-04 at 8 39 21 AM

cadadr commented 4 years ago

Hi, thanks for the report. I'll try to reproduce this, but this is happening probably because the headline is in variable pitch too. Org probably aligns tags to the right edge using window width or fill column measured in characters. In that case you could add org-level-* faces to org-variable-pitch-fixed-faces or set org-tags-column to 0 causing them to not be right-justified but simply appended to the title with a preceding space.

I doubt we can both keep the headlines in variable pitch and align tags perfectly, but I'll look into it.

In any case could you add a screenshot for clarity? And maybe relevant parts of your config?

ksafford commented 4 years ago

I've uploaded a screen shot showing a sample org-mode buffer both with org-variable-pitch enabled and disabled. I will try adding the the org-level faces to -org-variable-pitch-fixed-faces some time today. Thanks for the reply!

cadadr commented 4 years ago

You're welcome. I was going to close this issue, but I'll keep it open because it might be possible to handle this in a neater way later, but that'll take a bit of a research.

cadadr commented 3 years ago

Note to self:

The following piece of code could be helpful in resolving this:

(use-package org
  :if init-flag
  :custom
  (org-auto-align-tags nil)
  :config
  ;; (add-hook 'org-mode-hook (lambda () (font-lock-add-keywords 'org-mode '(yant/org-align-tags) t)) 100)
  (add-hook! 'org-mode-hook (add-to-list 'font-lock-extra-managed-props 'org-tag-aligned))

  (add-hook! 'org-mode-hook (setq-local adaptive-fill-function #'org-adaptive-fill-function))
  (defun org-adaptive-fill-function ()
    "Fill headlines to the beginning of headline in org."
    (save-excursion
      (when (org-at-heading-p)
    (beginning-of-line)
        (looking-at org-complex-heading-regexp)
        (goto-char (match-beginning 4)) ;; at headline
        (make-string (current-column) ?\ ))))

  (defun yant/org-align-tags (limit &optional force)
    "Align all the tags in org buffer."
    (save-match-data
      (when (eq major-mode 'org-mode)
    (while (re-search-forward "^\\*+ \\(.+?\\)\\([ \t]+\\)\\(:\\(?:[^ \n]+:\\)+\\)$" limit t)
      (when (and (match-string 2)
             (or force
             (not (get-text-property (match-beginning 2) 'org-tag-aligned))))
        (with-silent-modifications
              (put-text-property (match-beginning 2) (match-end 2) 'org-tag-aligned t)
          (put-text-property (if (>= 2 (- (match-end 2) (match-beginning 2)))
                     (match-beginning 2)
                   ;; multiple whitespaces may mean that we are in process of typing
                   (1+ (match-beginning 2)))
                 (match-end 2)
                 'display
                 `(space . (:align-to (- right
                             (,(+ 3 ;; no idea, but otherwise it is sometimes not enough
                                  (string-display-pixel-width org-ellipsis)
                                  (string-display-pixel-width (or (match-string 3)
                                                  ""))))))))))))))

Taken with permission from here

cadadr commented 1 year ago

OVP no longer maintained, cf. b28a70665b8db82323b57c2ee2f6e019cb9b92d3

telenieko commented 3 weeks ago

For anyone arriving here searching about org-mode tag alignment with variable pitch, there is an email thread on orgmode about the issue which makes for a nice read. The last post there is the code two comments above.