Is there a way to comment M code / comment out lines or blocks of code?
M supports two different types of comments:
Single line comments can be started with //
You can comment out multiple lines or comment out text in the middle of a line using /* */ (e.g. = 1 + /* some comment */ 2)
Comments might seem to disappear in the formula bar if they are at the end of the line, but they are still there. You can verify this by looking at your code in the Advanced Editor.
Related
Basically I want to write one piece of text which qualifies both as a working code and MarkDown (preferably GitHub flavor) for documentation. The language I'm using has C form commenting \\ for rest-of-line and /* ... */ for multi line comments. So far what I can do is:
/* --> start with multi line comments
here some markdown text
# heading
* list
end markdown section with
<!--- */ // -->
or
[//]: # (end of comment block --> */ // <-- inline comment)
_-_-indented code
_-_-_-_-more indented code
The issues are:
the first /* still showing in the documentation
I can't use the proper multiline code block ``` ... ```. I have to indent the code parts once more than what is required. Also the syntax highlighting doen't work in this format AFIK.
I would appreciate if you could help me know first how to solve above issues. and Secondly if there is any better way to do this?
I think I have a proper solution now with colapsible / foldable code section:
/*
This is the markdown **text**
used for documentation
<details>
<summary>Click to see the source code</summary>
``` scilab
*/
This is the
actual code
which will
be executed
/*
```
</details>
<!--- */ // -->
which will be rendered as:
/*
This is the markdown text
used for documentation
*/
This is the
actual code
which will
be executed
/*
The collapsible section makes sure that the documentation is clean and readable. you may see the final result here on GitHub. I used the code from here. Now there are a bunch of /*s and */s which would be nice to get ride of. Next step would be to modularize the MarkDown document into different files as I have asked here.
P.S. Implementation of the same idea using AsciiDoc here.
Say I have code like this
some_line_of_code
some_line_of_code
/* some comment about code */
some_line_of_code
some_line_of_code
and i would like to comment out a whole block like this
/*
some_line_of_code
some_line_of_code
/* some comment about code */
some_line_of_code
some_line_of_code
*/
As you can see even SO code parser will not consider last 2 lines of code comments. Is it possible to comment out blocks of code that contain comments?
edit :
To clarify, I need this to be able to comment out large sections of code to check if a function I changed can compile in a package that otherwise can't be compiled until all changes have been done.
In SQL Developer, I highlight all lines of PL/SQL that I want commented and use Ctrl + /.
Obviously, you would like a way to comment and uncomment multiple lines quickly. This will put -- in front of each line you have highlighted. Do the same command to uncomment.
you can assign a function key through Tools > Preferences > Key Configuration (Edit / Selection / Comment Lines).
Shortcut to comment a line:
Command + Option + /
(in Mac)
As was stated by #Acroneos, there is no way. This is common behaviour of most programming languages. Comments as well as oher tokens are recognized by lexers. And lexers work with context-free grammars. i.e. lexes usually can recognize only reqular expressions.
You can still use C/C++ approach (#if 0/#endif). See Conditional compilation. But it does not look "so nice".
begin
something1;
$if false $then
something2;
$endif;
endl;
you can use --
so this code :
some_line_of_code
some_line_of_code
-- some comment about code
some_line_of_code
some_line_of_code
will be :
--some_line_of_code
--some_line_of_code
---- some comment about code
--some_line_of_code
--some_line_of_code
No, because everything between first delimiter until the next last delimiter will be recognized as comment (=not processed by compiler). Thats how multiline-comments work: If first delimiter (/ * ) is recognized, compiler will ignore anything until the very next last delimiter ( * /) is recognized. Now as you know this, you should be able to understand, why your second / * will never be recognized as a comment-delimiter by the compiler.
However, you can mark comments with special characters or concatenations within the multiline-comment-sector to line out comments into different sections.
in sql developer ; default shortcut is : ctrl + shift + c
In Sql Developer,You can use the following commands...
For Commenting Sql Statements...
ctl and / keys
For un-commenting Sql Statements...
ctl and / keys again
Additionally, to format sql statement
ctl and F7
In C#, is there a reason why multi-line /* */ comments can't overlap? This also applies to HTML (and I'm sure lots of other languages) too.
e.g.
/*
int a = SomeFunction();
/* int i = 0; */
int b = SomeFunction();
*/
won't compile.
When writing code I often want to quickly check the logic, and isolate certain parts by removing a section using multi-line comments, but then have to go through the code block replacing all multi-line comments with single line ones //.
I don't like using single line comments to comment-out code blocks (even though Visual Studio provides shortcuts to do this) as these then affect text comments when it comes to removing all comments in the block using the shortcut.
Is there a reason why the multi-line comment cannot mean: 'ignore everything between here'?
I'm afraid this is the way how it's designed.
I think you should use single line comments as much as possible. It's also much clearer when you are viewing the history of a file in source control. If you commented an entire method with /* */ then only two lines will appear changed, otherwise the entire method will have been changed (// added).
When using nerd commenter in visual mode, the first line is commented differently.
Initial code
const IMG_SIZE_SMALL = '32x32';
const IMG_SIZE_MEDIUM = '64x64';
const IMG_SIZE_LARGE = '192x192';
After doing ,cc in visual mode selecting these lines.
/* const IMG_SIZE_SMALL = '32x32';*/
//const IMG_SIZE_MEDIUM = '64x64';
//const IMG_SIZE_LARGE = '192x192';
What should I do so that the first line is also commented out using // ?
You didn't mention what filetype the file has. I tried creating a small test.c file with only the lines provided in your question and used ,cc to comment out the lines. I tried two different filetype settings. With filetype=c, the lines were all commented out with /* --- */ style comments and with filetype=cpp, the lines were all commented out with // style comments. Have you made sure you are using the latest version of NERD_commenter (2.2.2)?
Ok, now I created a small test file with these lines and some testing lines above and below them. NERD commenter comments them all with the same //-style comments. You don't happen to be selecting lines in character-wise mode? That is pressing v instead of shift-v to select the lines? When i tried that i was able to get different comment styles for some lines.
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