Can you set clang-format's line length? - clang-format

clang-format is breaking up my lines at 80 columns. Is there a way to make stop breaking lines? The documentation doesn't seem to address this.

The configuration option responsible for it is called ColumnLimit. You can remove the column limit by setting it to 0.
ColumnLimit: 0

Find ColumnLimit (under "Configurable Format Style Options" heading) on that page and you'll find the following statement:
ColumnLimit (unsigned)
The column limit.
A column limit of 0 means that there is no column limit. In this case,
clang-format will respect the input’s line breaking decisions within
statements unless they contradict other rules.
Source: Clang-Format Docs (v4.0.0, latest). Italics added for emphasis.
So, just like the docs say, set...
ColumnLimit: 0
... and you should be set.

I had the same issue too - I am using the C++ extension in VSCode and setting ColumnLimit: 0 still wrapped at 80. I worked around this by setting ColumnLimit to a large number; I set ColumnLimit: 200 and it works great.

Related

Force clang-format to respect doxygen block comments

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.

Clang Format - How to remove space between [ and ::namespace?

Clang-format inserts pretty annoying whitespace in the example below:
blahblah[ ::namespace]
I want it to be formatted like this:
blahblah[::namespace]
Is there a way to do this?
Edit:
I've tried setting SpacesInSquareBrackets: false, but it doesn't help.
Starting with clang-format 3.9.0, that space is no longer inserted. In fact, now you can't get that space back even with SpacesInSquareBrackets: true.

Copy a table from iPython notebook into Word?

I want to copy a table from iPython notebook into a Word doc. I'm using Word for Mac 2011. The table is a standard pandas output and looks like this:
If I use Apple+C to copy the table, and then paste it into a Word doc, I get this:
Surely there must be an easier way?
Creating a table with the same number of rows/columns in Word and then trying to paste the cells there doesn't work either.
I guess I could screenshot the table, but I'd like to include the raw data in the document if possible.
The problem in this case (from the Word perspective) is not the table layout - it's the paragraph layout. Each paragraph has a substantial indent on right and left, and more space before/after than you would normally want.
I don't think any of the Paste options (e.g. Paste Special) in Word is going to help, unless you paste as unformatted text, then select the text, convert to a table, then proceed from there.
But, even a simple Word VBA macro such as this one will leave you with something a bit more manageable. (Select a table you copied in, then run the macro). A little bit more work on the code would probably allow you to get most of the formatting you want, most of the time.
Sub fixupSelectedTable()
With Selection.Tables(1).Range.ParagraphFormat
.LeftIndent = 0
.RightIndent = 0
.SpaceBefore = 0
.SpaceAfter = 0
.LineSpacingRule = wdLineSpaceSingle
End With
End Sub
If you are more familiar with Applescript, the equivalent looks something like this:
-- you may need to fix up the application name
-- (I use this to ensure that the script uses the Open Word 2011 doc
-- and does not try to start Word for Mac 15 (2016))
tell application "/Applications/Microsoft Office 2011/Microsoft Word.app"
tell the paragraph format of the text object of table 1 of the text object of the selection
set paragraph format left indent to 0
set paragraph format right indent to 0
set space before to 0
set space after to 0
set line spacing rule to line space single
end tell
end tell

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.

Labeled constants in LaTeX

I have several lemmas in which I specify constants $C_1$, $C_2$, and so forth for later reference. Naturally, this is annoying when I later insert a new constant definition in the middle. What I'd like is a macro that lets me assign labels to constants and handles the numbering for me. I'm thinking something along the lines of
%% Pseudocode
\begin{lemma}
\newconstant{important-bound}
We will show that $f(x) \le \ref{important-bound} g(x)$ for all $x$.
\end{lemma}
Is this possible?
Expanding on rcollyer's suggestions of using a counter:
%counter of current constant number:
\newcounter{constant}
%defines a new constant, but does not typeset anything:
\newcommand{\newconstant}[1]{\refstepcounter{constant}\label{#1}}
%typesets named constant:
\newcommand{\useconstant}[1]{C_{\ref{#1}}}
(This code was edited to allow labels longer than one character)
And here is a code snippet that seems to work:
I want to define two constants:\newconstant{A}\newconstant{B}$\useconstant{A}$ and
$\useconstant{B}$. Then I want to use $\useconstant{A}$ again.
What you're looking for is to create your own counter.
Expanding on Aniko's answer, I used
this layered macro so that it created a shorthand for the label,
\newcounter{constant}
\newcommand{\newconstant}[1]{\refstepcounter{constant}\label{#1}}
\newcommand{\useconstant}[1]{C_{\ref{#1}}}
\newcommand{\defconstant}[1]{ \newconstant{c_#1}\expandafter\newcommand\csname c#1\endcsname{\useconstant{c_#1}} } %
So to use this, you would then do
\defconstant{a}
\defconstant{b}
There exist constant $\ca$ and $\cb$ such that ....
careful not to overwrite existing commands (i'm sure it would warn you anyhow)

Resources