26 lines
3.6 KiB
Plaintext
26 lines
3.6 KiB
Plaintext
<p>In some modes in Emacs, the <code>hl-line</code> (‘hl’ for ‘highlight’) is used. That’s not intended to highlight the current line when you edit text; it’s used for things like feed readers and email, where you operate on items that are represented on lines. This highlight is way too subtle for my taste.</p>
|
||
|
||
<p>I use the very excellent dark and light [<code>modus-themes</code>][modus] in Emacs. The light theme has black text on white background, and that is pretty much what you see in macOS Finder, too, when you browse directories. In Finder, when you select something, you get the classic blue bakcground with white foreground color.</p>
|
||
|
||
<p>That’s what was missing from my life, so I overwrite the colors. Native GUI Emacs on macOS has named colors like <a href="https://developer.apple.com/documentation/appkit/nscolor/ui_element_colors">the <code>NSColor</code>s from AppKit</a>, so I can just use <code>selectedContentBackgroundColor</code> and <code>alternateSelectedControlTextColor</code>. This could, in theory, also adapt to dark vs light mode, but on macOS, the color is actually the same for both modes. (At least from eyeballing it.)</p>
|
||
|
||
<figure><a href="https://christiantietze.de/posts/2021/05/macos-native-highlight-colors/20210523122157-macos-highlight.png"><img alt="" src="https://christiantietze.de/posts/2021/05/macos-native-highlight-colors/20210523122157-macos-highlight.png" /></a>Some random newsletter emails with the new colors</figure>
|
||
|
||
<p><strong>Update 2021-11-09:</strong> This approach has been <a href="https://christiantietze.de/content/posts/2021/11/lin.el-macos-system-colors.md">improved and in part superseded by the introduction of LIN</a> so I can apply these colors to selection UIs but not to regular text documents.</p>
|
||
|
||
<p>Here’s how I hook into dark/light mode changes to make sure the color is replaced:</p>
|
||
|
||
<div class="language-elisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nb">defun</span> <span class="nv">ct/theme-mac-os-hl-line</span> <span class="p">()</span>
|
||
<span class="s">"On macOS, use the system selection color combo. Should work for dark and light mode."</span>
|
||
<span class="p">(</span><span class="nb">when</span> <span class="p">(</span><span class="nv">memq</span> <span class="nv">window-system</span> <span class="o">'</span><span class="p">(</span><span class="nv">mac</span> <span class="nv">ns</span><span class="p">))</span>
|
||
<span class="p">(</span><span class="nv">set-face-attribute</span> <span class="ss">'hl-line</span> <span class="no">nil</span>
|
||
<span class="ss">:foreground</span> <span class="s">"alternateSelectedControlTextColor"</span>
|
||
<span class="ss">:background</span> <span class="s">"selectedContentBackgroundColor"</span><span class="p">)))</span>
|
||
<span class="p">(</span><span class="nv">add-hook</span> <span class="ss">'ns-system-appearance-change-functions</span> <span class="nf">#'</span><span class="nv">ct/theme-mac-os-hl-line</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>I also hook this up to <code>modus-themes</code>.</p>
|
||
|
||
<div class="language-elisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nv">add-hook</span> <span class="ss">'modus-themes-after-load-theme-hook</span> <span class="nf">#'</span><span class="nv">ct/theme-mac-os-hl-line</span><span class="p">)</span>
|
||
</code></pre></div></div>
|
||
<hr /><p>Receive Christian’s <a href="https://christiantietze.de/newsletter/">new posts via email</a></p> |