Comments (7)
For what it’s worth, here is my code for pixel-aligning tags. Recently adapted to org-modern. Based on code by Ihor Radchenko at: https://orgmode.org/list/87lfh745ch.fsf@localhost/
Feel free to reuse:
(setq org-tags-column 0
org-auto-align-tags nil)
;; avoid unneccesary calculations, I never need it.
(defalias 'org-align-tags #'ignore)
;; Inspired by Ihor Radchenko’s code at: https://orgmode.org/list/87lfh745ch.fsf@localhost/
(add-hook 'org-modern-mode-hook #'aj/org-set-tag-align-keywords)
(defun aj/org-set-tag-align-keywords ()
(add-to-list 'font-lock-extra-managed-props 'org-tag-aligned)
(font-lock-add-keywords nil '((yant/org-align-tags t)) 'append))
(defun aj/string-pixel-width (string &optional mode)
"Calculate pixel width of STRING.
Optional MODE specifies major mode used for display."
(let ((fra face-remapping-alist))
(with-temp-buffer
(with-silent-modifications
(setf (buffer-string) string))
(when (fboundp mode)
(funcall mode)
(font-lock-ensure))
(setq-local face-remapping-alist fra)
(if (get-buffer-window (current-buffer))
(car (window-text-pixel-size nil (line-beginning-position) (point)))
(set-window-buffer nil (current-buffer))
(car (window-text-pixel-size nil (line-beginning-position) (point)))))))
(defun yant/org-align-tags (limit &optional force)
"Align all the tags in org buffer."
(save-match-data
(when (eq major-mode 'org-mode)
(let ((ellw (aj/string-pixel-width org-ellipsis)))
(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
ellw
(if (match-beginning 3)
(car (window-text-pixel-size nil (match-beginning 3) (match-end 3)))
0))))))))))))))
aj/string-pixel-width
here is unnecessarily complicated for what it is used for here (only org-ellipsis
). It previously was used also for calculating the widths of the tags (next to last line) but this is done much better in buffer, with the complex fontification done by org-modern. And with this done in org-modern-mode-hook
we can be quite sure that it will be done after all the tags have got their final appearance. This have worked well for me since yesterday 😀.
from org-modern.
Thanks. Yes, something like this is the plan.
from org-modern.
@andersjohansson Notwithstanding org-modern, is it feasible to rekindle that mailing list thread? I feel this should be a standard Org feature, though I understand if it is very difficult to do upstream.
from org-modern.
@protesilaos I am not sure if adjustments like this should be part of Org itself. As of now Org does not come with any such more intrusive text property adjustments and assumes that everything is fixed pitch, which is an acceptable assumption in my opinion. However maybe opinion is changing there? There is also the question if Org should try to pixel-align tables. Do you know if there are plans to add this upstream, then I don't have to do anything here?
from org-modern.
Personally, I am perfectly happy with Org's current assumptions. It's
just that people think of it as a bug, which is why I asked if it would
be worth discussing upstream.
More generally, this is not an Org bug. My understanding is that it is
how proportionately spaced fonts reduce the width of the spacing
characters (same principle for varying face :height
s).
I tried a quick-n-dirty hack once of making spaces monospaced by abusing
whitespace-mode
: it made the use of variable-pitch
viable even for
programming. But yeah, that is fragile.
from org-modern.
(Accidentially closed)
from org-modern.
Closing. I am actually happy with not aligning tags to the right. In contrast, better table aligning is a more important issue.
from org-modern.
Related Issues (20)
- New folding indicators do not render well in doom Emacs HOT 2
- Second level folding indicator showing wrong state after folding top level heading
- org-modern-tag-faces does not work as expected HOT 1
- Opt-out for fold indicators? HOT 1
- Can this package work with `visual-fill-column-center-text' set to t?
- fold-stars doesn't work well when org-cycle twice on header HOT 1
- readme screenshot image no longer visible on github
- Org agenda tags go outside the buffer
- Have fringe around dynamics block, like the one around source block.
- org-modern todo stopped working on custom agenda views
- Wrong bullet character HOT 1
- Clock and [%] headlines not aligning properly
- Org-table alignment (divider rows)
- org-modern breaks on blocks that are rendered later
- Timestamps in buffer settings HOT 1
- static-if not available in emacs 29.4 HOT 1
- New invalid-function error with static-if HOT 3
- Triggers (invalid-function static-if) constantly HOT 3
- Change to compat v30 breaks installation on debian systems HOT 1
- Leading stars appear after updating org-modern
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from org-modern.