How to customize syntax highlight in PL\SQL Developer to mark aliases? - editor

I found myself scanning through long and complicated selects often searching for the right alias.
Is there a way to highlight them all?
For example 'strings' have a special style.
How do I set custom style for aliases like "column_name"?

There is an official solution for this very Stack Overflow question! (Thats how I got here... :) )
This can be found in SQL Ddeveloper:
Preferences... / Code Editor / PL/SQL Syntax Colors / PL/SQL Custom Syntax Rules
So now we can set the color for "PlSqlColTabAlases" (Sic!) in the Syntax Colors list. (Default is light brown.)
/**
* The list of syntax highlighting rules:
https://vadimtropashko.wordpress.com/2018/10/10/custom-syntax-coloring/
* In-depth description of the Arbori language:
https://vadimtropashko.wordpress.com/2017/02/11/arbori-the-missing-manuals/
**/
/**
* Highlighting all the column and table aliases
* https://stackoverflow.com/questions/49193403/how-to-customize-syntax-highlight-in-pl-sql-developer-to-mark-aliases
*/
PlSqlColTabAlases: --
[node) c_alias -- Search all the nodes in the parse tree which are column aliases
| [node) identifier -- Or nodes with identifier payload,
& [node-1) query_table_expression -- which younger siblings are labeled with table names
-> -- The semantic action symbol (to trigger syntax highlighting).
; -- End of the rule

Related

Is there a way to make TFS code search recognize the "#" symbol?

I am searching for all occurrences of an out of date email domain in my codebase on TFS. Specifically, I am searching for "#testexample.com". However, the search seems to completely ignore the "#" symbol.
If I search "#testexample.com", I get all occurrences of "testexample.com". I have also tried "*#testexample.com" but prefix wildcards aren't allowed in code search.
That's not supported.
Checked for some characters in code search. You can't use the symbol characters except * and ? as part of your search query, which including below characters: . , : ; / \ ` ' " # = ! # $ & + ^ | ~ < > ( ) { } [ ]. The search will simply ignore these symbols.
But you can use wildcard characters * and ? to broaden your search.
You can use wildcard characters anywhere in your search string except
as a prefix in a simple search string or a query that uses a code type
filter. For example, you cannot use a search query such as
*RequestHandler or class:?RequestHandler. However, you can use prefix wildcards with the other search filter functions; for example, the
search query strings file:*RequestHandler.cs and repo:?Handlers are
valid.
Please see Broaden your search with wildcards for details.
If you want to search the strings including these symbol exactly(such as '#' here), you can code search with other strings (eg, testexample.com here) to narrow down the scope first, then copy the specific code to text editor which support the symbols (eg, Notepad++), then search stings with the symbol characters.
Besides, if you are using Git, another workaround is using the code search tool Hound: a lightning fast code search tool, it supports the symbol characters. Reference this thread to use it: How can I publish source code (Visual Studio) on a intranet?

How can I create cross-reference when a sigil is required for referring but not for defining?

In my DSL, I have something similar to:
x = 14
y = $x + 1
So an element is defined with just its name, but when referred to, some sigil must be added. Any whitespace between the sigil and the name is forbidden when referencing the element.
How can I do this in Xtext, while still allowing cross-reference between these elements?
Because it seems to me that I either have to use two different terminals for this - one to match x and the other to match $x - but then how would the cross-reference mechanism associate them together? Or alternatively, if I define:
ElementRef: '$' [Element|ELEMENT_NAME];
then Xtext will allow whitespace between the sigil and the name, which is illegal in my DSL. I guess an option such as "do not accept whitespace at this point" would be great, but I could not find anything in the Xtext documentation about something like that.
You have to use a datatype rule for the cross-reference token and register a value converter that strips the $ sign.
ElementRef: [Element|ReferenceID];
ReferenceID hidden(): '$' ID;
The value converter is responsible for the conversion between the abstract syntax (the ID) and the concrete syntax ($ID) for your tokens. Please refer to the docs for details.

Easiest way to remove Latex tag (but not its content)?

I am using TeXnicCenter to edit a LaTeX document.
I now want to remove a certain tag (say, emph{blabla}} which occurs multiple times in my document , but not tag's content (so in this example, I want to remove all emphasization).
What is the easiest way to do so?
May also be using another program easily available on Windows 7.
Edit: In response to regex suggestions, it is important that it can deal with nested tags.
Edit 2: I really want to remove the tag from the text file, not just disable it.
Using a regular expression do something like s/\\emph\{([^\}]*)\}/\1/g. If you are not familiar with regular expressions this says:
s -- replace
/ -- begin match section
\\emph\{ -- match \emph{
( -- begin capture
[^\}]* -- match any characters except (meaning up until) a close brace because:
[] a group of characters
^ means not or "everything except"
\} -- the close brace
and * means 0 or more times
) -- end capture, because this is the first (in this case only) capture, it is number 1
\} -- match end brace
/ -- begin replace section
\1 -- replace with captured section number 1
/ -- end regular expression, begin extra flags
g -- global flag, meaning do this every time the match is found not just the first time
This is with Perl syntax, as that is what I am familiar with. The following perl "one-liners" will accomplish two tasks
perl -pe 's/\\emph\{([^\}]*)\}/\1/g' filename will "test" printing the file to the command line
perl -pi -e 's/\\emph\{([^\}]*)\}/\1/g' filename will change the file in place.
Similar commands may be available in your editor, but if not this will (should) work.
Crowley should have added this as an answer, but I will do that for him, if you replace all \emph{ with { you should be able to do this without disturbing the other content. It will still be in braces, but unless you have done some odd stuff it shouldn't matter.
The regex would be a simple s/\\emph\{/\{/g but the search and replace in your editor will do that one too.
Edit: Sorry, used the wrong brace in the regex, fixed now.
\renewcommand{\emph}[1]{#1}
any reasonably advanced editor should let you do a search/replace using regular expressions, replacing emph{bla} by bla etc.

bib-style format for bibtext bst file- explained by an example

my question is regarding the way a bibtex-style field is defined in a bst file. I would like to have the following example below explained piece by piece, to understand what each piece is doing. I would like to be in a position to make changes to that example myself.
FUNCTION {format.eprint}
{ eprint duplicate$ empty$
'skip$
{ "\eprint"
archive empty$
'skip$
{ "[" * archive * "]" * }
if$
"{" * swap$ * "}" *
}
if$
}
The BibTeX language is a bit complex: for a full reference take a look at Tame the BeaST. The key things to remember are that it is a stack language and that it uses a postfix approach. Almost all of the built-in functions also remove their input from the stack.
Taking it piece by piece, the first line starts with FUNCTION, which means it will define a new function (format.eprint) that can be used elsewhere in the .bst file. Importantly, this new function can only be used below here: the order of functions in the .bst file is important. The braces are used to show different arguments: FUNCTION needs two, the name of the function and the code that implements it.
In the code itself, eprint will be a field. Using the name of a field adds the value of the field to the stack (for the current record). We then have duplicate$, which duplicates the top item on the stack. This is a BibTeX build-in instruction, shown by the terminal $. So the stack will now contain two copies of the value of eprint.
The next instruction is empty$. This will test if the top item of the stack is empty and deletes it, hence the need for the duplicate$. The result of the test is either 1 or 0, which is left on the stack. So the top item on the stack is now either 1 or 0, and the next item is the value of eprint.
Next you have an if$ statement, which is in postfix and so has the two branches before the if$. As the language is postfix, what happens is that the if$ will select the true branch if the top item on the stack is 1 and the false branch otherwise. That also removes the top item from the stack. (If you want the real detail, the two branches are actually placed on the stack, and the if$ statement then removes the appropriate one and leaves the rest of the material to be executed.)
The first (true) branch reads 'skip$, which is a 'do nothing' instruction. The braces around a single instruction can be missed out if you include the leading '. An alternative which is (slightly) easier to read for new users would be
FUNCTION {format.eprint}
{ eprint duplicate$ empty$
{ }
{ "\eprint"
archive empty$
{ }
{ "[" * archive * "]" * }
if$
"{" * swap$ * "}" *
}
if$
}
i.e. simply using an empty set of braces for the 'do nothing' (true) branch. So the aim here is to do nothing if the eprint field was empty.
The false branch starts "\eprint", which will place the literal \eprint onto the top of the stack. The next part them places the archive field onto the stack and does another test for an empty field. If the archive field is available, the code
"[" * archive * "]" *
will place [ onto the stack then join it to the top item on the stack (which was \eprint): this joining operation is what * does. The value of the archive field is then added to the stack and joined on, followed by another ]. So the top of the stack will contain
\eprint[<archive>]
(where <archive> is the value of the archive field) if there is anything given for archive, and still just \eprint otherwise.
Finally, there is some more string-building to do. We have
"{" * swap$ * "}" *
which first places { onto the stack. This is joined onto the top item (\eprint or \eprint[<archive>]) to give \eprint{. The swap$ function swaps the top two items on the stack, so the top item is name <eprint> (the value of the eprint field). There is a joint to make
\eprint{<eprint>
followed by a final addition of } to the end.
The result is that the stack will gain one item on the top. If eprint is empty there will be an empty item on the top of the stack, otherwise it will read
\eprint{<eprint>}

Can you grab or delete between parentheses in vi/vim?

Given this line of code in C:
printf("%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32)));
Is there a way to delete or yank from the first bold parenthesis to its matching parenthesis? I thought about df), but that only will get you to just after the 9.0.
Is there a similar way to get vim to grab everything between matching braces, regardless of newlines?
What about dib or di(.
It will delete the inner (...) block where the cursor is.
I love text-object motions and selections!
Various Motions: %
The % command jumps to the match of the item under the cursor. Position the cursor on the opening (or closing) paren and use y% for yanking or d% for deleting everything from the cursor to the matching paren.
This works because % is a "motion command", so it can be used anywhere vim expects such a command. From :help y:
["x]y{motion} Yank {motion} text [into register x]. When no
characters are to be yanked (e.g., "y0" in column 1),
this is an error when 'cpoptions' includes the 'E'
flag.
By default, "item" includes brackets, braces, parens, C-style comments and various precompiler statements (#ifdef, etc.).
There is a plugin for "extended % matching" that you can find on the Vim homepage.
You can read the documentation on % and related motion commands by entering :help various-motions in command mode.
object-select
There is another set of motion commands that you can use in Visual mode to select various text objects.
To solve your specific problem you would do the following:
printf("%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32)));
^
Let's say your cursor is positioned at ^. Enter the following sequence to select the part you are looking for:
v2a)
First v enters Visual mode, then you specify that you want to go 2 levels of parens up. Finally the a) selects "a block". After that you can use d or x to delete, etc.
If you don't want to include the outer parens, you can use "inner block" instead:
v2i)
See :help object-select for the complete list of related commands.
To delete all that is inside a pair of parentheses, you can always issue di( and its derivatives.
Note :
As #porglezomb suggested in his comment, you can use a ("along with") instead of i ("inside") to include the parentheses. So, using da( deletes everything inside ( and ) including ( and ).
Deleting text inside the immediate outer pair of parentheses :
So, for this line of code
printf("%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32)));
^ ^
| |
\_______\___---> Cursor range
assuming that your cursor is inside the above mentioned cursor range, you can issue the following commands :
di( --> Deletes '5.0/9.0'
ci( --> Substitutes '5.0/9.0'
yi( --> Yanks '5.0/9.0'
Deleting text inside the n-th outer pair of parentheses :
To grab everything inside the n-th outer pair of parentheses, just add n before the above command. So, with the same cursor position as above,
2di( --> Deletes '(5.0/9.0) * (fahr-32)'
2ci( --> Substitutes '(5.0/9.0) * (fahr-32)'
2yi( --> Yanks '(5.0/9.0) * (fahr-32)'
3di( --> Deletes '"%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32))'
3ci( --> Substitutes '"%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32))'
3yi( --> Yanks '"%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32))'
You can use d% for deleting and y% for yanking.
Place your cursor on the first parenthesis, then press v%y or v%d.
Try ci[block-surrounder]
In your case, place the cursor anywhere between the 2 parenthesis that you highlighed and try the keys: ci(
As answer of David Norman says,
Place your cursor on the first parenthesis, then press v%y or v%d.
Explanation from http://vimdoc.sourceforge.net/htmldoc/vimindex.html:
tag char note action in Normal mode
------------------------------------------------------------------------------
|v| v start characterwise Visual mode
|%| % 1 find the next (curly/square) bracket on
this line and go to its match, or go to
matching comment bracket, or go to matching
|d| ["x]d{motion} 2 delete Nmove text [into buffer x]
This means it will select everything between and including the two brackets (%) while showing the selection to you visually (v) and then yank/copy y or delete/cut d it. (To the default buffer.)
You can put/paste with p.
Made this answer to "teach myself to fish".

Resources