How to comment out the current line? - coderush

Is there a way (shortcut) to quickly comment out the current code line in CodeRush?
I've just moved over from ReSharper which seemed more intuitive in this matter.
And yes - I know about the "/" shortcut that comments out a selection of code. I'm looking for something that will meet my requirement without the need to select a code block.

Built in VS Ctrl K Ctrl C does that job (and Ctrl K U to remove commenting)

At the moment, you need to select the entire line including the leading whitespace to make the '/' shortcut work. See this article to learn more.

Related

How to preserve code folding when formatting source

See also this question: How do I avoid expanding folded regions when I invoke the code formatter?
This is not a dupe, because I'm interested in solving the problem using the ToolsApi.
When I press CTRL + D the code formats nicely (mostly).
But all my folded code sections get unfolded.
Is there a way to keep these sections folded.
If not, is it possible to save the code folding info prior to formatting, so I can restore it later?
I'm thinking of writing IDE-addin using the Open Tools api.
I'm using XE7, but this problem exists in all versions that have source formatting.
Possible scenario's involve:
Record and replay code foldings (hook elide calls).
Only allow formatting to work on the current block (redefine the CTRL + D action).
What you can do is create regions and disable code folding, format code and then reenable the code folding.
To create code regions do:
{$REGION 'Optional text that appears when the code block is folded'}
// code
{$ENDREGION}
To toggle code folding option, press Ctrl+Shift K+O.
so, put your code into regions, fold what you want, press Ctrl+Shift K+O to disable the folding, format by pressing Ctrl+D then press Ctrl+Shift K+O again to re enable the folding.
When you re enable the folding, what was folded with a region is going to stay folded.
information source: http://docwiki.embarcadero.com/RADStudio/XE6/en/Using_Code_Folding
I hope this helps you.

How to get outline view of Latex Project in Sublime text?

As I'm writing Latex more and more on Sublime Text (3), I decide to totally move on to ST from TexnicCenter. However there's one thing I miss from TexnicCenter, that's the ability to show the project in outline view (e.g chapter/subchapter name,...)
For example, writing a long file with one master main.tex file, and each chapter is written in a separate file, TXC gives me this view on the outline panel:
Can I achieve such thing in ST3? (I know about Ctrl + R but it does not help in this case where the chapters are written separately.)
LaTeXing also offers a SHIFT+ Ctrl + R ("Goto Symbol in Project").
LaTeXing actually seems to consider all structure markers such as \chapter{test), irrespective of whether they are \input{} somewhere, so it's not the real logical structure of the document ...
Here's a screen shot:
It's still not just in the command palette, and not a real sidebar of the logical structure and there are some confusing duplications ... but still.
Maybe the folks over at atom latex will get on it at some point; atom might be more suited for this kind of flexible UI.

xtext - how to set code areas, with excluded grammar check

Summary: I wish to set left and right margin for my own language - areas of code in which grammar check is excluded.
Background: Using xtext, I am trying to create nice Cobol editor. So far I finished grammar and encountered problem with margins and comments.
Left margin I can include within grammar: after ‘\n’ up to 6 !‘\n’ chars.
That is not solving my problem though. SLComment starts with '*' being placed at 7th position from left. I would be able to catch that with ‘\n’ '*' -> ‘\n’ rule, once I somehow exclude first 6 chars in each line.
I can’t just leave it as ‘*’ -> ‘\n’ and delegate position check to validate , because its messing up multiply rule, which of course uses ‘*’. Placing comment rule just after grammar margin rule isn’t also a solve, since that way I can’t catch margin within the first line of the code.
Also I know that I won’t solve right margin problem(exclude area after 78 position for example) using grammar rules.
I guess there is a way to interfere in text that xtext is checking, but haven’t found solution or hint how to accomplish this.
Also tried to find out if this can be made through preprocessing somehow, but also failed to find any hint how to do so.
Or maybe It is possible to use two grammars at once. Extra one will get each line and hide margins?
Hope I were able to describe what problem I’m facing and what I tried so far.
I guess you can use something like a LINE_START_COMMENT terminal rule that captures the first 6 characters of every line, and then hide it accross the grammar.
terminal LINE_START_COMMENT:
// Up to 6 chars that are NOT a new line
'\n' (!'\n')? (!'\n')? (!'\n')? (!'\n')? (!'\n')? (!'\n')?
;
Then, using this approach I guess you should also modify your full line comment rule, to something like:
terminal FULL_LINE_COMMENT:
LINE_START_COMMENT '*'
(LINE_START_COMMENT '*' | !(LINE_START_COMMENT) )+
(LINE_START_COMMENT)?
;
Here I have defined the FULL_LINE_COMMENT to end after the following LINE_START_COMMENT. To check for several consecutive commented lines, you have to accept as a comment anything thats not the comment terminator (in this case the LINE_START_COMMENT) or the LINE_START_COMMENT with a new '*' after it.

How do I get auto-conversion of Part [[ double-brackets ]] on paste?

A pet peeve of mine is the use of double square brackets for Part rather than the single character \[LeftDoubleBracket] and \[RightDoubleBracket]. I would like to have these automatically replaced when pasting plain-text code (from StackOverflow for example) into a Mathematica Notebook. I have been unable to configure this.
Can it be done with ImportAutoReplacements or another automatic method (preferred), or will I need use a method like the "Paste Tabular Data Palette" referenced here?
Either way, I am not good with string parsing, and I want to learn the best way to handle bracket counting.
Sjoerd gave Defer and Simon gave Ctrl+Shift+N which both cause Mathematica to auto-format code. These are fine options.
I am still interested in a method that is automatic and/or preserves as much of the original code as possible. For example, maintaining prefix f#1, infix 1 ~f~ 2, and postfix 1 // f functions in their original forms.
A subsection of this question was reposted as Matching brackets in a string and received several good answers.
Not really an answer, but a thread on entering the double [[ ]] pair (with the cursor between both pairs) using a single keystroke occurred a couple of weeks ago on the mathgroup. It didn't help me, but for others this was a solution apparently.
EDIT
to make good on my slightly off-topic first response here's a pattern replacement that seems to do the job (although I have difficulties myself to understand why it should be b and not b_; the latter doesn't work):
Defer[f[g[h[[i[[j[2], k[[1, m[[1, n[2]]]]]]]]]]]] /.
HoldPattern[Part[b, a_]] -> HoldPattern[b\[LeftDoubleBracket]a\[RightDoubleBracket]]
I leave the automation part to you.
EDIT 2
I discovered that if you add the above rule to ImportAutoReplacements and paste your SO code in a notebook in a Defer[] and evaluate this, you end up with a usable form with double brackets which can be used as input somewhere else.
EDIT 3
As remarked by Mr.Wizard invisibly below in the comments, the replacement rule isn't necessary. Defer does it on its own! Scientific progress goes "Boink", to cite Bill Watterson.
EDIT 4
The jury is still out on Defer. It has some peculiar side effects, and doesn't work well on all expressions. try the "Paste Tabular Data Palette" in the toolbag question for instance. Pasting this block of code in Defer and executing gives me this:
It worked much better in another code snippet from the same thread:
The second part is how it looks after turning it in to input by editing the output of the first block (basically, I inserted a couple of returns to restore the format). This turns it into Input. Please notice that all double brackets turned into the correct corresponding symbol, but notice also the changing position of ReleaseHold.
Simon wrote in a comment, but declined to post as an answer, something fairly similar to what I requested, though it is not automatic on paste, and is not in isolation from other formatting.
(One can) select the text and press Ctrl+Shift+N to translate to StandardForm

Replace strings in LaTeX

I want LaTeX to automatically replace strings like " a ", " s ", " z " with " a~", " s~", " z~", because they can't be at line end. Any suggestions?
For Czech typographic rules, there is a preprocessor called Vlna" by Petr Olšák - download . The set of (usually prepositions in czech) is customizable - so it might be usable for other languages as well.
You can use \StrSubstitute from xstring package.
e.g.
\StrSubstitute{change ME}{ ME}{d}
will convert change ME into changed.
Although, nesting is not possible, so to make another substitution you must use an intermediate variable in this way
\StrSubstitute{change ME}{ ME}{d}[\mystring]
\StrSubstitute{\mystring}{ed}{ing}
Finally, your solution would be
\usepackage{xstring}
\def\mystring{...source string here...}
\begin{document}
\StrSubstitute{\mystring}{ a }{a~{}}[\mystring]
\StrSubstitute{\mystring}{ s }{s~{}}[\mystring]
\StrSubstitute{\mystring}{ z }{z~{}}[\mystring]
\mystring
\end{document}
Note the use of the empty string {} to avoid the sequence ~}.
I'm afraid (to the best of my knowledge) this is basically impossible with LaTeX. A LuaTeX-based solution might be possible, though.
It's not actually clear to me, however, that " a ", for example, shouldn't appear at the end of a
line. Although I might be used to different typographic rules.
(Is there anything wrong with the line break in the last paragraph? :))
As far as I know there is no way to do this in LaTeX itself. I'd go for automating this with some external tools, as my typical setup involves a Makefile handling the LaTeX run by itself. This makes it rather easy to run tools like sed on the sources and do some replacements using regular expressions, and a simple rule would do this for your case.
If you use some LaTeX editor that does everything for you you should check the editors regular expression search and replace functionality.
Yes, this is the age old argument of data processing vs. data composition. We have always done these things in a pre-processor environment responsible for extracting the information from its source environment, SQL or plain-text, and created the contents of a \input(file.tex).
But yes, it is possible (TeX is after all a programming language) but you will have to become a wizard. Get the 4 volume set TeX in Practice by Stephan von Bechtolsheim.
The approach would be to begin an environment (execute a macro) whose ''argument'' was all text down to the end of the environment. Then just munge though the tokens fixing the ones you want.
Still, I don't think any of us are advocating this approach.
If you are using TeXmaker to write your LaTeX file, then you may click on the Edit button on the toolbar, then click on Replace.
A dialogue box will come up, and you can enter your strings one after the other.
You put the strings to be changed in the Find text input and what you want it to be changed to in the Replace text input.
You can also specify where you want the replacement to start from.
Click Find and Replace (or similiar) in the menu of your text editor and do it.

Resources