This question already has answers here:
What's a quick way to comment/uncomment lines in Vim?
(52 answers)
Closed 7 years ago.
I'm new(bie) in vim. I've got the following mapping to comment my python code :
nmap cc 0i#<ESC>
I would like to have the same mapping to uncomment a line. I think I need an function to check the first character of the line. Do you know how I could do the tricks ?
thanks.
edit : It's not the same as that question , I wonder how to do that without plugin.
You shouldn't attempt to implement this (poorly) yourself; this is a solved problem, and you can choose from several good plugins. See Comment Lines according to a given filetype for a list of plugins.
As a learning experience, attempting a mapping is fine, though. Here's one approach that uses :help map-expr to check the line for the existence of a comment first:
nnoremap <expr> cc getline('.') =~# '^#' ? '0x' : '0i#<ESC>'
PS: You should use :noremap; it makes the mapping immune to remapping and recursion.
There is this plugin. It's very good and he works for many languages.
Related
This question already has an answer here:
How can we execute WebUI feature file against multiple browsers using parallel runner or distributed testing?
(1 answer)
Closed 1 year ago.
We have a requirement to run the entire test suite more than once considering different parameters.
Say, I have 5 feature files and each has 10 scenarios. I have a requirement to run these feature files twice one after the other.
There is a way to achieve this using Scenario Outline, which will execute each scenario for the number of parameters. But can we have all the scenarios run once for the 1st parameter and then all the scenario again for the 2nd parameter. Something like an Outline at Feature level.
Please suggest.
I think this should be done at the JUnit / Java runner level. Teams usually use tags to enable or disable features at run time.
Or you can create a "wrapper" feature that calls a second feature etc.
Otherwise please assume that what you want is not directly supported, you are welcome to contribute code to Karate if needed. My honest opinion is that this is not required in a testing framework, maybe you should just write code.
EDIT - see this answer, I think you will be able to figure out an approach based on it: https://stackoverflow.com/a/60387907/143475 - and keep in mind Karate supports a "dynamic" Scenario Outline.
There are at least three major overviews that come up when searching for information on using sql with emacs (due to my insufficient reputation I can't 'afford' to link to them here).
I can find no mention in any of them of the need to set the variable sql-mysql-program when working with mysql servers. Yet I could not get M-x sql-mysql to work without following the advice from this SO question to set this variable as follows:
(setq sql-mysql-program "/path/to/your/mysql")
In fact, the only tutorials/documentation I've seen highlighting this variable are in the above SO question and another SO question about "emacs-how-to-use-ssh-tunnel-to-connect-to-remote-mysql" (which again I can't link to because of insufficient reputation.)
An alternate solution seems to be suggested here How to work with emacs and mysql, which suggests changing the value of the emacs exec-path.
The question is, which of these options is preferable, or is it simply a matter of taste?
And what is the significance of the fact that none of the above-linked overviews of sql/emacs mentions the need to get emacs to recognize the binary? Is there something wrong with my emacs?
I spent a long time combing the sql.el source to try to understand what was going on and I do see a (defcustom sql-mysql-program "mysql"…)but in my case at least that did not seem to do the trick (perhaps because I'm starting emacs up with -q option?).
PS. In case it matters, my M-x emacs-version is GNU Emacs 24.5.1 (x86_64-apple-darwin12.5.0, NS apple-appkit-1187.40) of 2015-05-01, which I am running on an older Mac (10.8.5)
Note that this can be generalised to a question of:
What do I do if Emacs can't find an executable?
which is where the exec-path list comes into play.
As noted in C-hig (emacs) Shell RET, the exec-path list is initialised from the environment variable PATH when Emacs is started (see also (emacs) General Variables), so there are multiple ways to populate that list with the values you need.
Using an absolute path to sql-mysql-program is also fine, but potentially less portable. It's up to you, really.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
differences between 2 JUnit Assert classes
I have two junit-4.8.1.jars in my class path and my IDE's autocomplete is giving me the following two Assert classes:
junit.framework.Assert
org.junit.Assert
Which one should I use???
To quote a duplicate...
JUnit 3.X: junit.framework.Assert JUnit 4.X: org.junit.Assert
Prefer the newest one, especially when running JDK5 and higher with
annotation support.
I prefer org.junit package in all things JUnit. It's the source URL that the code comes from. The other is legacy that's left so it doesn't break old code.
Pick one and be consistent.
Niether, use MatcherAssert and Hamcrest with assertThat instead of assertTrue / assertFalse
MatcherAssert
This question already has answers here:
What to do Regular expression pattern doesn't match anywhere in string?
(8 answers)
Closed 8 years ago.
Reading this amusing rant ( RegEx match open tags except XHTML self-contained tags ) I wondered ... how could regexes be changed to successfully parse HTML?
I'm looking here for suggestions that :
make the minimal addition to regexes as we know and love them (ie. not "make them look like XSLT!" type answers)
are robust enough to work properly.
suggest syntax (not just list the general requirements)
Has anyone actually made something like this?
Add a new escape sequence:
\H -- match HTML document
DOM/XML parsers internally use regex to parse html. The difference between them and using ONLY regex is to make up for the shortcomings of regex. One of the major shortcomings of regex is handling nested tags and malformed code (like missing tags). So around the basic regex, all sorts of algorithms and conditions are written to try and handle those things. And then there is of course the parts that actually create an object out of it.
So you asked what it would take to make regex do what a DOM/XML parser does? You would have to somehow cram all those algorithms and conditions into the regex engine, internally and within pattern syntax.
I personally do not wish for this to happen. IMO regex should be straight pattern matching. IMO it already has some stuff in it that IMO is questionable (some regex flavors do in fact have a way to use conditions, for instance). Taking the regex engine and then building a larger tool around it (like a DOM/XML parser) IMO is the best way to go.
It's interesting that real world tools can be and often are modified to perform tasks they might not otherwise be suited for. For example, if someone were to attempt to eat broth with a fork, they would be largely unsuccessful. Enter the spork.
I don't think programmers necessarily work that way all the time. It's not uncommon for tools to expand their scope, but it's also been a long tradition that programmers try to use specific tools for specific purposes.
Now, it just so happens that in order for regex to be able to parse HTML, it would have to be a pattern matcher/recognizer that also remembered state. This is, to a T, exactly what a parser does. It uses pattern matching (indeed, it often uses regex!) in order to match tokens. It then remembers combinations of tokens.
So in fact regex is used very frequently to parse HTML, along with other functions that remember larger patterns that cannot be described or processed using regex alone.
Hope that answers the question.
Perl 6 has a regex extension that is designed to do that: http://en.wikipedia.org/wiki/Perl_6_rules.
Depends what you mean by "parse". Typically this involves transforming a character stream into an object tree. To do this with regular expressions you would need to completely change capturing groups to be runtime-variable multi-node tree, rather than the compile-time-fixed array that they currently are. Once you've done that you've just re-written lex/yacc.
What language(s) have comments with side effects? In essence, comments which are not comments....
English. Do I win?
DOS Batch Shell programming
The REM (Remark) allows you to put in a comment. But it has the side-effect of modifying the ERRORLEVEL variable to 0.
In a sense, it makes last operation a success.
I don't know how a comment can fail, but if it does, you are covered.
I can think of several places where comments aren't really comments.
HTML and script tags (providing support for browsers that don't allow or support scripts).
And then, considerably more obscurely:
IBM Informix 4GL (I4GL) and 4J's Genero (successor to Informix Dynamic 4GL, D4GL). The notation '--#' was used by D4GL to include material only applicable to D4GL; I4GL would see that as a comment. The inverse notation was '--#', which looked like a comment to D4GL but was treated as active material by I4GL.
And, even more obscurely:
I wrote an I4GL file which was dual-languaged, exploiting I4GL's multiple comment facilities. Material starting '#' (hash) marked the start of a comment outside of strings - up to the next newline, as does '--' (double-dash). Also, '{...}' (braces) enclose multiline comments.
The top of the source file was actually a shell script, mostly enclosed in '{...}' which is, of course, perfectly legitimate in shell. The shell script was a data-driven code generator that copied itself to the top of the output, and then generated about 100 functions which were all depressingly similar but slightly different (in a language without templates or a pre-processor). The code had to validate what was in the database for a given ship against incoming data from an external source (Lloyds of London, in fact), to see what had changed since the last time the external data was received. Non-trivial comparison work, especially since it had to deal with database (SQL) nulls.
The file was not really a Quine program, but it had some points in common with it. In particular, you could feed the script broken I4GL code and the regenerated file would be perfect again, basically because it ignored the existing I4GL code.
Haskell can turn the usual comments in code paradigm upside down by having code in comments - also Mathematica and the like; literal programming is a nice feature for the more mathematically inclined languages.
I also find annotations in Java are like comments with behaviour.
Then of course there are "polyglots" -- programs which can be compiled/executed in multiple languages. Usually these rely on the fact that the same line is a comment in one language, but an actual line of code in another.
QBasic has a use of comments all its own: REM $STATIC or REM $DYNAMIC set how arrays are allocated.
Another example: When web browsers parse comments <!-- -- -->in<!-- -- -->correctly.
CSS for clever cross-browser hacks. Of course, I wouldn't really call CSS a language.
Just stumbled upon this old question and my first thought was javadoc comments.