reddit / emacs

Completions in org-roam: Columns are not aligned

pragmat1c1 · 2022-06-30 10:39
When I call `org-roam-node-find`, the columns in my completions window are not aligned anymore. See screenshot. My display template is this: (setq org-roam-node-display-template (concat "${title:60}" (propertize "${tags:60}" 'face 'org-tag) "${file:50}") ) It used to be perfectly fine. I was guessing that an emoji in one of the document titles or filenames must have screwed it, but after removing those, the problem still persists. ​ https://preview.redd.it/kbq19blnlq891.png?width=1780&format=png&auto=webp&s=96960d40c9908371fdf75762359df8371cbdd917 # Edit Here is the manual related to this: >If you’re using a vertical completion framework, such as Ivy and Selectrum, Org-roam supports the generation of an aligned, tabular completion interface. Btw: I am using "ivy" [https://www.orgroam.com/manual.html](https://www.orgroam.com/manual.html) / 5.5 Customizing Node Completions # Edit 2 The problem is gone, all of a sudden. I don't even know what caused it. Maybe it was one of those emoji characters in one of the node-names. # Edit 3 Problem persists. No clue why it happens again. Removed all emojis from node names. # Edit 4: Reviewing code Trying to understand what's going on under the hood, I see that this function here does the width calculation for each node: \`**org-roam-node--format-entry**\` But the problem seems to lie in the fact that modus-theme does not use mono spaced font in the completions buffer some times. # Edit 5: Fixed With the help of u/lastnamebird I realized my setup does not stick to monospaced font in the minibuffer. The question then was: How can I set the font for the minibuffer permanently? A little googling leads me to this: Adding a hook to "minibuffer-setup-hook": (defun ugt-minibuffer-setup-hook () (buffer-face-set 'fixed-pitch)) (add-hook 'minibuffer-setup-hook 'ugt-minibuffer-setup-hook) Seen here: [https://www.reddit.com/r/emacs/comments/kff3ur/customizing\_minibuffer\_face/](https://www.reddit.com/r/emacs/comments/kff3ur/customizing_minibuffer_face/)
flyin1501 · 2022-07-01 02:22
~~It is because of the emoji characters. They aren't the same width as other characters even when using a monospace font, and becayse they're typically provided by another font their widths aren't an integer multiple of a monospace character's either.~~ ~~This is a lot more pronounced as a CJK user. Every Han character (Kanji) has the same issue.~~ ~~For this to be fixed Org-roam would have to use pixel alignment, which seems to be possible but not trivial.~~ Edit: I should've looked at your screenshot first. What I described causes one node to be misaligned, so I don't know why every node would be misaligned in the screenshot.
lastnamebird · 2022-07-01 13:09
Does it work if you change your font to a monospace font? If so, perhaps there’s a way to have the spacing in the display template work on a pixel basis. I am not at my computer, but I did something similar with the tab-bar alignment.
pragmat1c1 · 2022-07-01 13:52
Bingo! Set font to a monospace font, (set-face-attribute 'default nil :font "DejaVu Sans Mono") and problem is gone! But then, I have no mixed fonts anymore. Btw: I am using modus-themes. Now I am wondering how to either set monospace in the completion buffer permanently, without effecting other buffers, or how to make non-mono fonts work with the buffer. ## Edit I am wondering if this has to do with the modus-theme. There is this `'(modus-themes-mixed-fonts t)` (setting it to `nil` won't resolve my problem). But modus theme has both fixed and variable spaed fonts. It uses monospaced fonts for tables or code blocks, so I'd expect it also uses it in the completions buffer, but apparently it does not, it seems? Now I am wondering how I can always set monospaced fonts in completion buffer in modus themes.
pragmat1c1 · 2022-07-01 13:58
>I did something similar with the tab-bar alignment May I ask what exactly you did there?
lastnamebird · 2022-07-02 04:41
Apologies for getting to you late, I used a combination of `pixel-string-width` and text properties. However, I've given a bit of a look at org-roam, and it does not seem like a simple change would fix it. I'd suggest opening an issue for them to use `window-text-pixel-size` and/or `string-pixel-width` for their alignment as it would be more robust for both mono and variable fonts. It's even suggested in the manual (https://www.gnu.org/software/emacs/manual/html_node/elisp/Size-of-Displayed-Text.html#index-string_002dwidth). Regarding Modus. I don't believe it changes the font in the minibuffer, so you may have had something else in your config that was causing that. It should use the `default` face. Good to hear you got a working solution though.
pragmat1c1 · 2022-07-02 07:42
Thank you for taking the time to give a detailed answer. I will follow up on your suggestion to open an issue. - Re my config. I thought I had fixed it with a hook that sets a mono font in the minibuffer. But after I restarted Emacs, problem was back. Until I wondered if my font config on my Mac is broken. So I restarted my Mac, and as of now the problem seems gone. Need go observe if it comes back. Again, thank you very much for taking the time. - Btw: Excellent org-ql setup that you shared on github. Keep up!
lastnamebird · 2022-07-02 14:12
One thing I had success with is getting my fontconfig fonts.conf setup correctly. I use linux, but I imagine it should have the same effect in Mac OS. With this setup, I can just set the `default` face to "monospace" and the `variable-pitch` face to "Serif" or "Sans Serif". Perhaps this would help your setup? <?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <!-- Accept deprecated 'mono' alias, replacing it with 'monospace' --> <match target="pattern"> <test qual="any" name="family"><string>mono</string></test> <edit name="family" mode="assign"><string>monospace</string></edit> </match> <!-- Default serif fonts --> <match target="pattern"> <test qual="any" name="family"><string>serif</string></test> <edit name="family" mode="prepend" binding="same"><string>Valkyrie OT A</string></edit> <edit name="family" mode="prepend" binding="same"><string>Charter</string></edit> <edit name="family" mode="prepend" binding="same"><string>Linux Libertine O</string></edit> </match> <!-- Default sans-serif font --> <match target="pattern"> <test qual="any" name="family"><string>sans-serif</string></test> <edit name="family" mode="prepend" binding="same"><string>Concourse OT</string></edit> <edit name="family" mode="prepend" binding="same"><string>Cooper Hewitt</string></edit> <edit name="family" mode="prepend" binding="same"><string>Linux Biolinum O</string></edit> </match> <!-- Default monospace fonts --> <match target="pattern"> <test qual="any" name="family"><string>monospace</string></test> <edit name="family" mode="prepend" binding="same"><string>Triplicate OT A</string></edit> <edit name="family" mode="prepend" binding="same"><string>Source Code Pro </string></edit> </match> <!-- Default aliasing fonts --> <match target="font"> <edit mode="assign" name="autohint"> <bool>false</bool> </edit> <edit mode="assign" name="antialias"> <bool>true</bool> </edit> <edit mode="assign" name="hinting"> <bool>true</bool> </edit> <edit mode="assign" name="hintstyle"> <const>hintfull</const> </edit> <edit mode="assign" name="lcdfilter"> <const>lcddefault</const> </edit> <edit mode="assign" name="rgba"> <const>rgb</const> </edit> </match> <!-- Default DPI --> <match target="pattern"> <edit name="dpi" mode="assign"><double>144</double></edit> </match> <!-- Disable hinting for bold fonts --> <match target="font"> <test name="weight" compare="more"> <const>medium</const> </test> <edit name="autohint" mode="assign"> <bool>false</bool> </edit> </match> </fontconfig>