Uncrustify - whats adding space between 'assert' and '(' - formatting

No matter how I update the config file I seem to always end up with a space
System.assert(true); becomes System.assert (true);
This is only when the function is called assert
The following both format without a space before the '('
System.asser(true);
System.assertt(true);
Uncrustify config https://pastebin.com/4bnNXzhC

I believe your problem is that Java has an assert statement which Uncrustify's confusing your function call as. Although that wouldn't make much sense considering I tried to test if adding/removing spaces before control statements would change this behavior and it didn't.
I did find a workaround for you through the following configuration options parsing as Java. Since Java supports the assert statement it is a bit odd that they don't have a specific configuration option for it. It may be in your best interest to file a bug report / GH issue with the Uncrustify devs to help better resolve this problem.
# Add or remove space between the user function name and '(' on function
# calls. You need to set a keyword to be a user function in the config file,
# like:
# set func_call_user tr _ i18n
sp_func_call_user_paren = remove # ignore/add/remove/force
set func_call_user assert
Keep in mind that Apex is not an officialy supported language of Uncrustify. So if things don't work specifically for Apex then there's really not much else that can be done.

Related

regex limitations within live template / can use live-template functions as replacement?

I'm removing builder pattern on multiple places. Following example would help me with the task, but mainly I'd like to learn how to use live templates more.
Preexisting code:
Something s = s.builder
.a(...)
.b(bbb)
.build();
and I'd like to remove it to:
Something s = new Something();
s.setA(...);
s.setB(bbb);
part of it can be trivially done using intellij regex, pattern: \.(.*)$ and replacement .set\u$1. Well it could be improved, but lets keep it simple.
I can create surround live template using variable:
regularExpression(SELECTION, "\\.(.*)", "\\u$1")
but \\u will be evaluated as u.
question 1: is it possible to get into here somehow \u functionality?
but I might get around is differently, so why not try to use live temlate variable:
regularExpression(SELECTION, "\\.(.)(.*)", concat(capitalize($1), "$2"))
but this does not seem to work either. .abc is replaced to bc
question 2: why? How would correct template look like? And probably, if it worked, this would behave incorrectly for multiline input. How to make it working and also for multiline inputs?
sorry for questions, I didn't find any harder examples of live templates than trivial replacements.
No, there is no \u functionality in the regularExpression() Live Template macro. It is just a way to call String.replaceAll(), which doesn't support \u.
You can create a Live Template like this:
set$VAR$
And set the following expression for the $VAR$ variable:
capitalize(regularExpression(SELECTION, "\\.(.*)", "$1"))

What're the key codes for "Alt+Q Alt+Q"?

I want to create a script that triggers when pressing Q twice while holding Alt, but couldn't figure out what're the correct key codes for that, could someone please shed some light?
P.S. I want to bind this shortcut to Ctrl+F12, which I assigned Sogou IME to turn on the Chinese input mode.
I didn't test this and there's probably a more concise way to do it, but I think something like this should work.
!Q::
If(keyPressed = 1){
...Do a thing...
}
keyPressed := 1
SetTimer, altQTimer, 50
return
altQTimer:
keyPressed := 0
return
TL;DR
In conclusion, even if I do all kinds of hacks and get the script working as intended, it's likely to break in the future, which is really not worth the trouble.
After hours of experimenting, the current conclusion is Sogou IME which uses Ctrl+F12 won't trigger the bound action i.e. switching to the Chinese input mode if it was sent by Alt+[Any Other Key], it can be triggered if it was sent by other shortcuts such as Ctrl+C, which is really unfortunate.
And the weirdest thing is the following code works:
^c::Send !q
!q::Send ^{F12}
And to rule out the potential extra simulated keystrokes (Ctrl by default) effect, the following code also works:
^!q::Send ^{F12}
But the following doesn't (tested on several machines):
!q::Send ^{F12}
Update
After much effort, I did get Alt+Q to turn on the Chinese input mode with the following code, not sure why:
!q::Send ^{F6}
^F6::Send ^{F7}
^F7::Send ^{F12}
But because I also need to trigger a VSCode command using Alt+Q at the same time, I had to modify the above code to the following:
~!q::Send ^{F6} ; with ~ prefixed
^F6::Send ^{F7}
^F7::Send ^{F12}
Now Alt+Q does trigger the VSCode command, but it won't turn on the Chinese input mode...
At last, if I take a step back and bind the VSCode command to Ctrl+C (which could turn on the Chinese input mode with just ^c::Send ^{F12}), I still have to prefix ^c with ~, otherwise it won't trigger the VSCode command, now I'm repeating the cycle all over again...
After all of these attempts, I have to say Sogou IME's logic for determining whether to enable the Chinese input mode is quite indeterminate, making the script for enabling the Chinese input mode very unreliable.
In conclusion, even if I do all kinds of hacks and get the script working as intended, it's likely to break in the future, which is really not worth the trouble.

How do I preserve whitespace in a Maven plugin configuration?

I have a plugin configuration parameter named suffix. I would like the user to be able to specify a newline (a literal character produced by pressing the Return key, not some escaped variant, although I'll get to that) as the value for that parameter.
At the same time, the parameter has a default-value setting. I would like to continue to use that.
How do I specify, in my plugin's configuration stanza, that the suffix parameter should take a newline?
I've tried this:
<suffix><![CDATA[
]]></suffix>
...and this:
<suffix>${line.separator}</suffix>
...(that one actually substitutes the right character in but XML parsing stomps on it) and this:
<suffix><[!CDATA[${line.separator}]]></suffix>
...and this:
<suffix>&x0d;</suffix>
...and this:
<suffix xml:space="preserve">
</suffix>
...all to no avail. Specifically, I see the default value of the parameter instead.
Edit: Interestingly, the whitespace is eaten long before Maven's internals ever get a chance to work on the value. mvn help:effective-pom will show that the whitespace has been removed. Leading, trailing and "only" whitespace content is removed early on in the parsing stage.
This seems to me most likely to be a bug, so I've filed http://jira.codehaus.org/browse/PLX-461 to track it.
The codehaus links don't work anymore, but I found in the maven documentation that since version 3.0.something you can add an attribute xml:space="preserve" to any element you don't want trimmed.
Per instructions, I am answering this question by referring people to the following JIRA: https://issues.apache.org/jira/browse/MNG-5380 (originally at http://jira.codehaus.org/browse/PLX-461 ).
Use $${line.separator}. The double $$ escape it. A chap on the Codehaus IRC channel shared his finding recently, so the credit should actually go to him.

TSearch2 - dots explosion

Following conversion
SELECT to_tsvector('english', 'Google.com');
returns this:
'google.com':1
Why does TSearch2 engine didn't return something like this?
'google':2, 'com':1
Or how can i make the engine to return the exploded string as i wrote above?
I just need "Google.com" to be foundable by "google".
Unfortunately, there is no quick and easy solution.
Denis is correct in that the parser is recognizing it as a hostname, which is why it doesn't break it up.
There are 3 other things you can do, off the top of my head.
You can disable the host parsing in the database. See postgres documentation for details. E.g. something like ALTER TEXT SEARCH CONFIGURATION your_parser_config
DROP MAPPING FOR url, url_path
You can write your own custom dictionary.
You can pre-parse your data before it's inserted into the database in some manner (maybe splitting all domains before going into the database).
I had a similar issue to you last year and opted for solution (2), above.
My solution was to write a custom dictionary that splits words up on non-word characters. A custom dictionary is a lot easier & quicker to write than a new parser. You still have to write C tho :)
The dictionary I wrote would return something like 'www.facebook.com':4, 'com':3, 'facebook':2, 'www':1' for the 'www.facebook.com' domain (we had a unique-ish scenario, hence the 4 results instead of 3).
The trouble with a custom dictionary is that you will no longer get stemming (ie: www.books.com will come out as www, books and com). I believe there is some work (which may have been completed) to allow chaining of dictionaries which would solve this problem.
First off in case you're not aware, tsearch2 is deprecated in favor of the built-in functionality:
http://www.postgresql.org/docs/9/static/textsearch.html
As for your actual question, google.com gets recognized as a host by the parser:
http://www.postgresql.org/docs/9.0/static/textsearch-parsers.html
If you don't want this to occur, you'll need to pre-process your text accordingly (or use a custom parser).

Is there any way I can define a variable in LaTeX?

In LaTeX, how can I define a string variable whose content is used instead of the variable in the compiled PDF?
Let's say I'm writing a tech doc on a software and I want to define the package name in the preamble or somewhere so that if its name changes, I don't have to replace it in a lot of places but only in one place.
add the following to you preamble:
\newcommand{\newCommandName}{text to insert}
Then you can just use \newCommandName{} in the text
For more info on \newcommand, see e.g. wikibooks
Example:
\documentclass{article}
\newcommand\x{30}
\begin{document}
\x
\end{document}
Output:
30
Use \def command:
\def \variable {Something that's better to use as a variable}
Be aware that \def overrides preexisting macros without any warnings and therefore can cause various subtle errors. To overcome this either use namespaced variables like my_var or fall back to \newcommand, \renewcommand commands instead.
For variables describing distances, you would use \newlength (and manipulate the values with \setlength, \addlength, \settoheight, \settolength and \settodepth).
Similarly you have access to \newcounter for things like section and figure numbers which should increment throughout the document. I've used this one in the past to provide code samples that were numbered separatly of other figures...
Also of note is \makebox which allows you to store a bit of laid-out document for later re-use (and for use with \settolength...).
If you want to use \newcommand, you can also include \usepackage{xspace} and define command by \newcommand{\newCommandName}{text to insert\xspace}.
This can allow you to just use \newCommandName rather than \newCommandName{}.
For more detail, http://www.math.tamu.edu/~harold.boas/courses/math696/why-macros.html
I think you probably want to use a token list for this purpose:
to set up the token list
\newtoks\packagename
to assign the name:
\packagename={New Name for the package}
to put the name into your output:
\the\packagename.