Force clang-format to respect doxygen block comments - clang-format

I use long block C-style Doxygen comments in my C/C++ code. This is style #4 listed on http://www.doxygen.nl/manual/docblocks.html and looks like this (running out to 80 characters)...
/**************************************************************************//**
* \file
* \date 2017-01-02
* \author Alex Hogen
******************************************************************************/
If I run clang-format on this, it inserts a single space between the two forward slashes, so it looks all goofy like this....
/**************************************************************************/ /**
* \file
* \date 2017-01-02
* \author Alex Hogen
******************************************************************************/
I have SpacesBeforeTrailingComments set to 2, so that can't be the problem.
Tried CommentPragmas regex \/\*+\/\/\*+.
Tried CommentPragmas regex /\*(.+\n.+)+\*/
I've tried setting ReflowComments to false
... but none of those things have worked.
I understand there are two comments in this block, but I can't find any clang-format parameter addressing block comments on the same line. How can I stop clang-format from inserting this space?
And I don't want to solve this by disabling clang-format for every Doxygen comment block. That seems ridiculous.
Any good suggestions? :-)

In your .clang-format file:
CommentPragmas: '^\\.+'
This will make it not format comment line that starts with a backslash followed by a word. This works even though there is an asterisk before the doxygen comment because clang-format automatically ignores asterisks and whitespace at the beginning of every comment line.

Related

How to prevent clang-format from indenting comments that start at column 0?

I want clang-format to not indent or change at all any comments that start at the beginning of a line.
The reason is that in Eclipse I can comment and uncomment a line by typing ctrl+/ but if once commented and then indented by clang-format and then uncommented the final indentation is wrong.
Any ideas on how to do it?

Building Latex/Tex arguments in lua

I use lua to make some complex job to prepare arguments for macros in Tex/LaTex.
Part I
Here is a stupid minimal example :
\newcommand{\test}{\luaexec{tex.print("11,12")}}% aim to create 11,12
\def\compare#1,#2.{\ifthenelse{#1<#2}{less}{more}}
\string\compare11,12. : \compare11,12.\\ %answer is less
\string\test : \test\\ % answer is 11,12
\string\compare : \compare\test. % generate an error
The last line creates an error. Obviously, Tex did not detect the "," included in \test.
How can I do so that \test is understood as 11 followed by , followed by 12 and not the string 11,12 and finally used as a correctly formed argument for \compare ?
There are several misunderstandings of how TeX works.
Your \compare macro wants to find something followed by a comma, then something followed by a period. However when you call
\compare\test
no comma is found, so TeX keeps looking for it until finding either the end of file or a \par (or a blank line as well). Note that TeX never expands macros when looking for the arguments to a macro.
You might do
\expandafter\compare\test.
provided that \test immediately expands to tokens in the required format, which however don't, because the expansion of \test is
\luaexec{tex.print("11,12")}
and the comma is hidden by the braces, so it doesn't count. But it wouldn't help nonetheless.
The problem is the same: when you do
\newcommand{\test}{\luaexec{tex.print("11,12")}}
the argument is not expanded. You might use “expanded definition” with \edef, but the problem is that \luaexec is not fully expandable.
If you do
\edef\test{\directlua{tex.sprint("11,12")}}
then
\expandafter\compare\test.
would work.

Geany editor snippet for getting literal %cursor%

I write a lot of Geany snippets. I would like to add a snippet for %cursor% when writing snippets. I added this in the [Default] snippets:
cur=%cursor%
Problem being that will evaluate to placing the cursor, so disappears.
I am looking for an escape sequence for the %. I have tried \% and %% but no luck.
cur=%curso%cursor%%
is an OK workaround as I only need to add an r, but is not ideal.
The % is escaped with {pc} in Geany, so:
cur={pc}cursor{pc}
expands to %cursor%

Easiest way to remove Latex tag (but not its content)?

I am using TeXnicCenter to edit a LaTeX document.
I now want to remove a certain tag (say, emph{blabla}} which occurs multiple times in my document , but not tag's content (so in this example, I want to remove all emphasization).
What is the easiest way to do so?
May also be using another program easily available on Windows 7.
Edit: In response to regex suggestions, it is important that it can deal with nested tags.
Edit 2: I really want to remove the tag from the text file, not just disable it.
Using a regular expression do something like s/\\emph\{([^\}]*)\}/\1/g. If you are not familiar with regular expressions this says:
s -- replace
/ -- begin match section
\\emph\{ -- match \emph{
( -- begin capture
[^\}]* -- match any characters except (meaning up until) a close brace because:
[] a group of characters
^ means not or "everything except"
\} -- the close brace
and * means 0 or more times
) -- end capture, because this is the first (in this case only) capture, it is number 1
\} -- match end brace
/ -- begin replace section
\1 -- replace with captured section number 1
/ -- end regular expression, begin extra flags
g -- global flag, meaning do this every time the match is found not just the first time
This is with Perl syntax, as that is what I am familiar with. The following perl "one-liners" will accomplish two tasks
perl -pe 's/\\emph\{([^\}]*)\}/\1/g' filename will "test" printing the file to the command line
perl -pi -e 's/\\emph\{([^\}]*)\}/\1/g' filename will change the file in place.
Similar commands may be available in your editor, but if not this will (should) work.
Crowley should have added this as an answer, but I will do that for him, if you replace all \emph{ with { you should be able to do this without disturbing the other content. It will still be in braces, but unless you have done some odd stuff it shouldn't matter.
The regex would be a simple s/\\emph\{/\{/g but the search and replace in your editor will do that one too.
Edit: Sorry, used the wrong brace in the regex, fixed now.
\renewcommand{\emph}[1]{#1}
any reasonably advanced editor should let you do a search/replace using regular expressions, replacing emph{bla} by bla etc.

How to put line break in a math

I'd like to express the following sentence (source_location is also italic, it's not correctly rendered):
Each entry has a list of tuple: < source_location, R/W, trip_counter, occurrence, killed (explained in the later) >
My current workaround for this is:
$ \left\langle
\textit{source\_location}, \textit{R/W}, \textit{trip\_counter},
\textit{occurrence}, \textit{killed} \text{(explained in the later)}
\right\rangle $
I'm using 2-column paper. This < .. > is too long, but no line break because it is a math. How do I automatically (or manually) put line break in such case? It seems that \left\langle and \right\rangle should be in a single math. So, hard to break into multiple maths.
$<$ and $>$ would be an alternative, but I don't like it.
LaTeX does allow inline maths to break over lines by default, but there are a number of restrictions. Specifically, in your case, using \left...\right puts everything inside a non-breakable math group, so the first step is to replace them with either just plain \langle...\rangle or perhaps \bigl\langle...\bigr\rangle.
However, this still isn't enough to permit linebreaking; usually that's still only allowed after relations or operators, not punctuation such as the comma. (I think this is what's going on anyway; I haven't stopped to look this up.) So you want indicate where allowable line breaks may occur by writing \linebreak[1] after each comma.
Depending how often you have to do this, it may be preferable to write a command to wrap your "tuples" into a nice command. In order to write this in your source:
$ \mytuple{ source\_location, R/W, trip\_counter, occurrence,
killed\upshape (explained in the later) } $
here's a definition of \mytuple that takes all of the above into account:
\makeatletter
\newcommand\mytuple[1]{%
\#tempcnta=0
\bigl\langle
\#for\#ii:=#1\do{%
\#insertbreakingcomma
\textit{\#ii}
}%
\bigr\rangle
}
\def\#insertbreakingcomma{%
\ifnum \#tempcnta = 0 \else\,,\ \linebreak[1] \fi
\advance\#tempcnta\#ne
}
\makeatother
Why not define a new command:
\newcommand{\tuple}[5]{$\langle$\textit{#1}, \textit{#2}, \textit{#3}, \textit{#4},
\textit{#5} (explained in the latter)$\rangle$}
Then use \tuple{sourcelocation}{R/W}{tripcounter}{occurrence}{killed}
There seems to be a package that addresses that problem, called breqn. You can try this and let us know (I haven't used that).
I'd use the align* environment from AMSmath. Furthermore you could just add "\" to break the lines? Should work in math environments, too. Alternatively you could separate the equations.
Use \linebreak inside the math expression wherever you want a new line even between 2 brackets. This will enforce the line to be broken.

Resources