I have a JavaScript line similar to:
var a = (b / 2) + (c / 2);
In Dreamweaver, it highlights this segment as a comment and treats it like this:
var a = (b /* 2 ) + (c */ 2);
It's incorrect syntax highlighting and very annoying. Where do I find syntax highlighting definitions and how do I modify them to correct this?
You can delete/modify the regex definition yourself by finding CodeColoring.xml in your Dreamweaver's configuration path. For CS6 in Windows 7, the default is:
C:\Program Files (x86)\Adobe\Adobe Dreamweaver CS6\configuration\
You will then need to find the JavaScript scheme:
<scheme MMString:name="JavaScript/scheme/name" id="JavaScript" ...>
And within it, you'll find the regexp definition:
<regexp name="RegExp" id="CodeColor_JavascriptRegexp" delimiter="/" escape="\\">
<searchPattern><![CDATA[/\e+\\/]]></searchPattern>
</regexp>
This can probably be refined, but I don't use regular expressions in most scenarios so I just deleted this segment. Restart DW, and voila.
If you want to refine the definition, StackOverflow seems to have its regex highlighting down:
var regex = /a+b/;
var number = (window.innerWidth / window.innerHeight) / 2;
This article explains how to do it:
Modifying Dreamweaver’s syntax highlighting
http://realworldz.wordpress.com/2007/10/04/modifying-dreamweavers-syntax-highlighting/
It gives an example of how to add syntax highlighting to the keyword new for VBScript:
Close Dreamweaver if it’s already open.
Go to C:\Documents and Settings\<YOUR USERNAME>\Application Data\Macromedia\Dreamweaver 8\Configuration\CodeColoring
Open the “ASP VBScript.xml” file in Notepad.
Look for the tags and after the one for “Mod”, add in a new one called for the keyword “New” like this; <keyword>New</keyword>
I have looked everywhere and I agree with the answer from this previous question: Dreamweaver CS5 code hinting
There is just not that much control over syntax highlighting. You can use the method described by Robert's answer here to add more reserved words and such. But editing that file does not apply to changing how Dreamweaver handles highlighting of constants and operators.
Here is a reasonable way to change the way you write you code so that you syntax will still be highlighted in examples like this.
<script>
var a =
(b/2) //Because the forward slashes are not on the same line,
+(c/2); //Dreamweaver will not stop highlighting the numbers
//and operators
document.write(a);
</script>
Note: in this specific example your code can also be simplified to var a = (b+c)/2;
Since the characters /([{;,=!|&~^<>+-*%?:} can't be followed by a division sign, this is what I came up with:
<searchPattern><![CDATA[/\s+/\e+\\/]]></searchPattern>
(this one must have at least one whitespace character to avoid conflicts with end-of-line comments)
<searchPattern><![CDATA[(\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[[\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[{\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[;\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[,\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[=\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[!\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[|\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[&\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[~\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[^\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[<\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[>\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[+\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[-\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[*\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[%\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[?\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[:\s*/\e+\\/]]></searchPattern>
<searchPattern><![CDATA[}\s*/\e+\\/]]></searchPattern>
For scenarios like if (x) /foo/.exec('bar'), just put the RegExp in parenthesis to format it properly. The only other ill effect is that the preceding character will just be formatted as regular text (not bold or colored).
Related
I'm writing a test for my C# diagnostic analyzer with code fixes, which requires input code and expected fixed code.
The most simple way to specify the codes is to write them as string literal.
However, it bothers me because there is no syntax highlighting in the string literal.
So I thought it would be better to write the codes as separate files.
At this time I'm considering the following syntax:
class C
{
void M()
{
var i = 0;
- {|#0:i = 1|};
+ var i1 = 1;
}
}
- and + represent the rows to be deleted and added by the code fix, respectively, and {|#n:...|} indicates the location of the diagnostic result.
However, writing in a separate file does not solve the syntax highlighting problem.
I'd like to indicate deletions and additions with colors (like red and green) and also apply C# syntax highlighting.
So my question is, is there a simple way to apply my own syntax highlighting to a specific extension (e.g. cst) in Visual Studio?
If it is too difficult or too much work for the benefits, I'll give up.
I am new to Sphinx. I am writing some documentation for embedded UDFs that requires a code block to contain 2 languages (e.g. SQL and python). At present I can only see how to have a single highlight language in a block.
Is it possible to "switch" languages within a block? Below is an example of reStructuredText that results in 3 code block that I want to merge into one.
Simply removing the second and third "::" doesn't work.
.. highlight:: sql
::
SELECT * FROM
EXTERNAL SCRIPT(
.. highlight:: R
::
#Some R markup
MEANS = matrix(runif(nclust*ndim)*sqrt(nclust)*sep, nrow = nclust)
VARS = matrix(runif(nclust)*ndim, nrow = nclust)
ps = 1:nclust
ps = ps/sum(ps)
.. highlight:: sql
::
)
FROM myshema.mySQLtable
I am 99% sure that this cannot be done by default, and your solution of using separate 'highlight' blocks is the standard procedure to show multiple languages.
I believe that this is for the best anyway as mixing code in one block is usually a bad idea as it can confuse readers.
Also, when converting reStructuredText into HTML for example, a style sheet is used to make everything look pretty, and a default style sheet is included. If you do some research, I'm sure you could edit that style sheet or make your own, perhaps making the 'border' invisible and the 'margin-bottom' zero pixels for 'highlight' blocks.
You can try this extension to have different languages in tabs:
https://bitbucket.org/birkenfeld/sphinx-contrib/src/c30b46a0a1b5c21ec9977e6abc598d0654316ac2/examplecode/?at=default
I want to modify Xcode syntax highlighting. Namely, I do a lot of 'NSAsserts', which I find visually distracting, and so I would like lines starting with 'NSAssert' to be a light gray. This way, I can focus upon my code logic instead of having to cognitively filter-out the NSAssert lines.
I use a lot of these too, and I liked your idea enough to work out the answer. Well, sort of: I have not worked out how to treat NSAsserts as a new item but I have worked out how to make them appear as comments in the syntax highlighter.
Create the directory ~/Library/Application Support/Developer/Shared/Xcode/Specifications
Copy BaseSupport.xclangspec from /Developer/Library/PrivateFrameworks/XcodeEdit.framework/Versions/A/Resources to that directory
Apply this patch to the new copy:
--- /Developer/Library/PrivateFrameworks/XcodeEdit.framework/Versions/A/Resources/BaseSupport.xclangspec 2010-10-05 00:27:45.000000000 +0100
+++ /Users/philwill/Library/Application Support/Developer/Shared/Xcode/Specifications/BaseSupport.xclangspec 2010-12-14 11:36:51.000000000 +0000
## -100,9 +100,8 ##
Identifier = "xcode.lang.comment.singleline";
BasedOn = "xcode.lang.comment"; // for text macros
Syntax = {
- Start = "//";
- EscapeChar = "\\";
- Until = "\n";
+ StartChars = "/N";
+ Match=("//.*$","NSC?Assert[12345]?[[:space:]]*\\([^;]*\\)[[:space:]]*;");
IncludeRules = ( "xcode.lang.url", "xcode.lang.url.mail", "xcode.lang.comment.mark" );
Type = "xcode.syntax.comment";
};
Caveats:
This will mess up any //-comments
which contain escaped newline
characters. Don't do that.
This will theoretically slow down
syntax highlighting a little. I
haven't noticed any difference.
This will affect all languages you use in Xcode which normally allow //-comments.
This is the best that Xcode currently permits you to do.
I recently dived into LaTeX, starting with the help of a WYSIWYM editor like Lix. Now I'm staring writing tex files in Sci-TE, It already has syntax higlighting and I adapted the tex.properties file to work in Windows showing a preview on Go [F5]
One pretty thing Lyx does, and it's hard to acheive with a common text editor, is to format text in 80 columns: I can write a paragraph and hit Return each time I reach near the edge column but if, after the first draft, I want to add or cut some words here and there I end up breaking the layout and having to rearrange newlines.
It would be useful to have a tool in Sci-TE so I can select a paragraph of text I added or deleted some words in and have it rearranged in 80 columns. Probably not something working on the whole document since it could probably break some intended anticipated line break.
Probably I could easily write a Python plugin for geany, I saw vim has something similar, but I'd like to know if its' possible in Sci-TE too.
I was a bit disappointed when I found no answer as I was searching for same. No helpers by Google either, so I searched for Lua examples and syntax in a hope to craft it myself. I don't know Lua so this can perhaps be made differently or efficiently but its better then nothing I hope - here is Lua function which needs to be put in SciTE start-up Lua script:
function wrap_text()
local border = 80
local t = {}
local pos = editor.SelectionStart
local sel = editor:GetSelText()
if #sel == 0 then return end
local para = {}
local function helper(line) table.insert(para, line) return "" end
helper((sel:gsub("(.-)\r?\n", helper)))
for k, v in pairs(para) do
line = ""
for token in string.gmatch(v, "[^%s]+") do
if string.len(token .. line) >= border then
t[#t + 1] = line
line = token .. " "
else
line = line .. token .. " "
end
end
t[#t + 1] = line:gsub("%s$", "")
end
editor:ReplaceSel(table.concat(t, "\n"))
editor:GotoPos(pos)
end
Usage is like any other function from start-up script, but for completness I'll paste my tool definition from SciTE properties file:
command.name.8.*=Wrap Text
command.mode.8.*=subsystem:lua,savebefore:no,groupundo
command.8.*=wrap_text
command.replace.selection.8.*=2
It does respect paragraphs, so it can be used on broader selection, not just one paragraph.
This is one way to do it in scite: first, add this to your .SciTEUser.properties (Options/Open User Options file):
# Column guide, indicates long lines (https://wiki.archlinux.org/index.php/SciTE)
# this is what they call "margin line" in gedit (at right),
# in scite, "margin" is the area on left for line numbers
edge.mode=1
edge.column=80
... and save, so you can see a line at 80 characters.
Then scale the scite window, so the text you see is wrapped at the line.
Finally, select the long line text which is to be broken into lines, and do Edit / Paragraph / Split (for me the shortcut Ctrl-K also works for that).
Unfortunately, there seems to be no "break-lines-as-you-type" facility in scite, like the "Line Breaking" facility in geany. not anymore, now there's a plugin - see this answer
Well, I was rather disappointed that there seems to be no "break-lines-as-you-type" facility in scite; and I finally managed to code a small Lua plugin/add-on/extension for that, and released it here:
lua-users wiki: Scite Line Break
Installation and usage instructions are in the script itself. Here is how SciTE may look when the extension properly installed, and toggle activated after startup:
Note that it's pretty much the same functionality as in geany - it inserts linebreaks upon typing text - but not on pressing backspace, nor upon copy/pasting.
the same but more easy, I think...
put this in the user properties:
command.name.0.*=swrap
command.0.*=fold -s $(FileNameExt) > /tmp/scite_temp ; cat /tmp/scite_temp >$(FileNameExt)
command.is.filter.0.*=1
Ciao
Pietro
This question already has answers here:
How can I reverse code around an equal sign in Visual Studio?
(6 answers)
Closed 4 years ago.
I have a bunch of assignment operations in Visual Studio, and I want to reverse them:
i.e
i = j;
would become
j = i;
i.e. replacing everything before the equals with what's after the equals, and vice versa
Is there any easy way to do this, say something in the regular expression engine?
Select the lines you want to swap, Ctrl+H, then replace:
{:i}:b*=:b*{:i};
with:
\2 = \1;
with "Look in:" set to "Selection"
That only handles C/C++ style identifiers, though (via the ":i"). Replace that with:
{.*}:b*=:b*{.*};
to replace anything on either side of the "=".
Also, since you mentioned in a comment you use ReSharper, you can just highlight the "=", Alt+Enter, and "Reverse assignment".
Just a slight improvement on Chris's answer...
Ctrl+H, then replace:
{:b*}{[^:b]*}:b*=:b*{[^:b]*}:b*;
with:
\1\3 = \2;
(better handling of whitespace, esp. at beginning of line)
EDIT:
For Visual Studio 2012 and higher (I tried it on 2015):
Replace
(\s*)([^\s]+)\s*=\s*([^\s]+)\s*;
with:
$1$3 = $2;
In Visual Studio 2015+ after selecting code block press Ctrl + H (Find & Replace window) and check "Use Regular Expression" option, then:
Find: (\w+.\w+) = (\w+);
Replace: $2 = $1;
For example:
entity.CreateDate = CreateDate;
changes to:
CreateDate = entity.CreateDate;
Thank you #Nagesh and Revious, mentioned details added.
The robust way to do this is to use a refactoring tool. They know the syntax of the language, so they understand the concept of "assignment statement" and can correctly select the entire expression on either side of the assignment operator rather than be limited to a single identifier, which is what I think all the regular expressions so far have covered. Refactoring tools treat your code as structured code instead of just text. I found mention two Visual Studio add-ins that can do it:
ReSharper
MZ-Tools
(Inverting assignment isn't technically refactoring since it changes the behavior of the program, but most refactoring tools extend the meaning to include other generic code modifications like that.)
Please see this question: Is there a method to swap the left and right hand sides of a set of expressions in Visual Studio?
My answer to that question has a macro that you can use to swap the assignments for a block of code.
I've improved the expression a little.
Replace
(\t+)(\s*)(\S*) = (\S*);
with
$1$2$4 = $3;
The reason is, it will look for lines starting with tab (\t). It will skip the lines starting with definition. E.g.:
TestClass tc = new TestClass();
int a = 75;
int b = 76;
int c = 77;
a = tc.a;
b = tc.b;
a = tc.c;
Would ignore the int a, int b and int c and swap only the assignments.
what about replace all (CTRL-H)
you can replace for example "i = j;" by "j = i;"
you can use regular expressions in that dialog. I'm not so sure about how you should pop-up help about them however. In that dialog, press F1, then search that page for more information on regular expressions.
I like this dialog because it allows you to go through each replacement. Because the chance of breaking something is high, I think this is a more secure solution
You can do search and replace with regular expressions in Visual Studio, but it would be safer to just do a normal search and replace for each assignment you want to change rather than a bulk change.
Unfortunatly I don't have Visual Studio, so I can't try in the target environment, but if it uses standard regexps, you could probably do it like this:
Search for "(:Al) = (:Al);", and replace with "\2 = \1". (\1 and \2 are references to the first and second capture groups, in this case the parenthesises around the \w:s)
EDIT
Ok, not \w... But according to MSDN, we can instead use :Al. Edited above to use that instead.
Also, from the MSDN page I gather that it should work, as the references seem to work as usual.