diff --git a/README.md b/README.md index df6ead4..8b6edf4 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Subscribe via [RSS](https://jakelazaroff.github.io/til/rss.xml)! --- -40 TILs so far: +41 TILs so far: ## bash @@ -17,6 +17,10 @@ Subscribe via [RSS](https://jakelazaroff.github.io/til/rss.xml)! - [Export a Blender file to GLB from the command line](/blender/export-a-blender-file-to-glb-from-the-command-line.md) +## c + +- [Prevent ClangFormat from breaking before curly braces](/c/prevent-clangformat-from-breaking-before-curly-braces.md) + ## css - [Dynamically change styles from HTML or JSX](/css/dynamically-change-styles-from-html-or-jsx.md) diff --git a/rss.xml b/rss.xml index 44cdce0..223ddf4 100644 --- a/rss.xml +++ b/rss.xml @@ -5,6 +5,33 @@ A collection of useful things I've learned. https://github.com/jakelazaroff/til +https://github.com/jakelazaroff/til/blob/main/c/prevent-clangformat-from-breaking-before-curly-braces.md +https://github.com/jakelazaroff/til/blob/main/c/prevent-clangformat-from-breaking-before-curly-braces.md +TIL (c): Prevent ClangFormat from breaking before curly braces +Fri, 22 Dec 2023 22:30:45 GMT +<p>For some unfathomable reason, C and C++ developers sometimes put line breaks before curly braces:</p> +<pre><code class="language-c">int main() +{ + for (int i = 0; i &lt; 10; i++) + { + printf(&quot;%d\n&quot;, i); + } +} +</code></pre> +<p>It&#39;s also the default formatting style in the code formatter <a href="https://clang.llvm.org/docs/ClangFormat.html">ClangFormat</a>.</p> +<p>Fortunately, it&#39;s configurable by setting the <a href="https://clang.llvm.org/docs/ClangFormatStyleOptions.html#breakbeforebraces"><code>BreakBeforeBraces</code> option</a> to <code>Attach</code> in your <code>.clang-format</code> file:</p> +<pre><code>BreakBeforeBraces: Attach +</code></pre> +<p>Much more readable:</p> +<pre><code class="language-c">int main() { + for (int i = 0; i &lt; 10; i++) { + printf(&quot;%d\n&quot;, i); + } +} +</code></pre> + + + https://github.com/jakelazaroff/til/blob/main/htmx/load-modal-content-when-shoelace-dialog-opens.md https://github.com/jakelazaroff/til/blob/main/htmx/load-modal-content-when-shoelace-dialog-opens.md TIL (htmx): Load modal content when a Shoelace dialog opens @@ -242,26 +269,5 @@ URL.revokeObjectURL(url); </code></pre> - -https://github.com/jakelazaroff/til/blob/main/css/use-css-variables-in-a-dialog-backdrop.md -https://github.com/jakelazaroff/til/blob/main/css/use-css-variables-in-a-dialog-backdrop.md -TIL (css): Use CSS variables in a `<dialog>` backdrop -Tue, 15 Aug 2023 18:43:02 GMT -<p>I was building a native modal using the new(ish) <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog"><code>&lt;dialog&gt;</code> element</a> when I realized that I couldn&#39;t use CSS variables (officially called <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties">custom properties</a>) in the <code>::backdrop</code> pseudo-element.</p> -<p>I found <a href="https://stackoverflow.com/questions/58818299/css-variables-not-working-in-dialogbackdrop">this Stack Overflow post</a> that links to a (now-removed) paragraph in the spec for the <code>::backdrop</code>:</p> -<blockquote> -<p>It does not inherit from any element and is not inherited from. No restrictions are made on what properties apply to this pseudo-element either.</p> -</blockquote> -<p>Since variables propagate via inheritance, that means that the <code>::backdrop</code> doesn&#39;t have access to variables defined on the <code>:root</code> selector.</p> -<p>Fortunately, the fix is pretty simple: just define any variables that should be globally available on both the <code>:root</code> and <code>::backdrop</code> selectors.</p> -<pre><code class="language-css">:root, -::backdrop { - --some-variable-name: 10px; - --some-other-variable-name: #f00; - /* etc etc */ -} -</code></pre> - - \ No newline at end of file