Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best solution that I have found is writing a custom (and relatively straightforward) indentation function.</p> <p><strong>The Code</strong></p> <pre class="lang-lisp prettyprint-override"><code>(defun c++-template-args-cont (langelem) "Control indentation of template parameters handling the special case of '&gt;'. Possible Values: 0 : The first non-ws character is '&gt;'. Line it up under 'template'. nil : Otherwise, return nil and run next lineup function." (save-excursion (beginning-of-line) (if (re-search-forward "^[\t ]*&gt;" (line-end-position) t) 0))) (add-hook 'c++-mode-hook (lambda () (c-set-offset 'template-args-cont '(c++-template-args-cont c-lineup-template-args +)))) </code></pre> <p>This handles all of the cases that I have come across even with templates nested several levels deep.</p> <p><strong>How It Works</strong></p> <p>For indenting code, if a list of indentation functions is provided, then Emacs will try them in order and if the one currently being executed returns <code>nil</code>, it will invoke the next one. What I have done is added a new indentation function to the beginning of the list that detects whether the first non-whitespace character on the line is '>', and if it is, set the indentation to position 0 (which will line it up with the opening template). This also covers the case where you have template-template parameters as follows:</p> <pre><code>template &lt; template &lt; typename T, typename U, typename... Args &gt; class... CS &gt; </code></pre> <p>because it doesn't care what's after the '>'. So as a result of how the list of indentation functions works, if '>' is not the first character, the function returns <code>nil</code> and the usual indentation function gets invoked.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload