emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Tags right alignment with font-lock
@ 2023-12-02 11:28 Nicolas P. Rougier (inria)
  2023-12-08 15:45 ` Ihor Radchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas P. Rougier (inria) @ 2023-12-02 11:28 UTC (permalink / raw)
  To: emacs-orgmode


Hello,

I'm using font lock to have tags right aligned with the following 
code:

;; Right alignment (char wise)
(add-to-list 'font-lock-extra-managed-props 'display)
(font-lock-add-keywords 'org-mode
  `(("^\\*+.*?\\( \\)\\(:[[:alnum:]_@#%:]+:\\)$"
     (1 `(face nil
               display (space :align-to (- right 3
                                           ,(org-string-width 
                                           (match-string 2)))))
        prepend))) t)

;; Right alignment (pixel wise)
;;(font-lock-add-keywords 'org-mode
;;   `(("^\\*+.*?\\( \\)\\(:[[:alnum:]_@#%:]+:\\)$"
;;      (1 `(face nil
;;                display (space :align-to (- right 3
;;                                            (,(org-string-width 
                                              (match-string 2) 
                                              t)))))
;;         prepend))) t)

I've not tested it thoroughly but it seems to be working 
reasonably well on my machine. It is pretty similar to the code 
posted by Ihor Radchenko (thread on "variable-pitch-mode misaligns 
org-mode heading tags") and I wonder if there are any drawback 
with such techniques (too slow? does not work on all situations?)

Nicolas

-- 
Nicolas P. Rougier —— www.labri.fr/perso/nrougier
Institute of Neurodegenerative Diseases, Bordeaux


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Tags right alignment with font-lock
  2023-12-02 11:28 Tags right alignment with font-lock Nicolas P. Rougier (inria)
@ 2023-12-08 15:45 ` Ihor Radchenko
  2023-12-08 16:21   ` Nicolas P. Rougier (inria)
  0 siblings, 1 reply; 3+ messages in thread
From: Ihor Radchenko @ 2023-12-08 15:45 UTC (permalink / raw)
  To: Nicolas P. Rougier (inria); +Cc: emacs-orgmode

"Nicolas P. Rougier (inria)" <nicolas.rougier@inria.fr> writes:

> I'm using font lock to have tags right aligned with the following 
> code:
>
> ;; Right alignment (char wise)
> (add-to-list 'font-lock-extra-managed-props 'display)
> (font-lock-add-keywords 'org-mode
>   `(("^\\*+.*?\\( \\)\\(:[[:alnum:]_@#%:]+:\\)$"
>      (1 `(face nil
>                display (space :align-to (- right 3
>                                            ,(org-string-width 
>                                            (match-string 2)))))
>         prepend))) t)
> ...
> I've not tested it thoroughly but it seems to be working 
> reasonably well on my machine. It is pretty similar to the code 
> posted by Ihor Radchenko (thread on "variable-pitch-mode misaligns 
> org-mode heading tags") and I wonder if there are any drawback 
> with such techniques (too slow? does not work on all situations?)

The above code has problems when you try editing the heading near the
end of the title (before the :align-to space). Especially when the
window is narrow. Also, when `org-auto-align-tags' is nil.

Not that they cannot be solved, but it is not just as trivial as the
above code.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Tags right alignment with font-lock
  2023-12-08 15:45 ` Ihor Radchenko
@ 2023-12-08 16:21   ` Nicolas P. Rougier (inria)
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolas P. Rougier (inria) @ 2023-12-08 16:21 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode


> The above code has problems when you try editing the heading 
> near the
> end of the title (before the :align-to space). Especially when 
> the
> window is narrow. Also, when `org-auto-align-tags' is nil.
> Not that they cannot be solved, but it is not just as trivial as 
> the
> above code.

Thanks, I noticed the problem and alleviated it by having two 
spaces at end of the title (and set org-tags-column to nil) but I 
see why it's not really usable

Nicolas

-- 
Nicolas P. Rougier —— www.labri.fr/perso/nrougier
Institute of Neurodegenerative Diseases, Bordeaux


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-08 16:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-02 11:28 Tags right alignment with font-lock Nicolas P. Rougier (inria)
2023-12-08 15:45 ` Ihor Radchenko
2023-12-08 16:21   ` Nicolas P. Rougier (inria)

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).