How to make QTextCursor::WordUnderCursor include more characters or larger words - c++

I'm trying to show a tooltip when the cursor is over a keyword in a text editor using:
QTextCursor cursor = cursorForPosition(pos);
cursor.select(QTextCursor::WordUnderCursor);
This works well but the definition of a word does not fits my needs. For exemple the keyword \abcde is recognized as 2 words \ and abcde. Similarly the word a1:2 is recognized in three parts a1, : and 1. Basically what I'd like is to change the behavior such as a word is defined as a set of characters separated by space.
I tryied QTextCursor::BlockUnderCursor but it does the same than QTextCursor::LineUnderCursor and returns the entire line.

Related

Split mixed upper and lowercase in the same word into two lines

I have a string in cells that is lacking new lines.
It looks like this:
Text Text TextText Text Text T5df Tdfcv TextNeu
In other words:
If there is a change from Lowercase to Uppercase within a word, this is where a new line should be inserted as \n.
So the example would convert to
Text Text Text
Text Text Text T5df Tdfcv Text
Neu
Resp.:
Text Text Text\nText Text Text T5df Tdfcv Text\nNeu
I found
String[] r = s.split("(?=\\p{Lu})");
I tried REGAUS(F2;"(?=\\p{Upper})";"\n";"g") yet I get a 502, as something is wrong with the regex.
Which formula do I need for calc to do this?
With english formula names, the following formula will do the trick:
=REGEX(A1;"([:lower:])([:upper:])";"$1"&CHAR(10)&"$2";"g")
Same on multiple lines for sake of readability:
=REGEX(
A1;
"([:lower:])([:upper:])";
"$1" & CHAR(10) & "$2";
"g"
)
It matches a lower-case letter followed by an upper-case letter, and inserts a newline using the CHAR() function.
You'll have to adapt the line heigth manually, otherwise you will see only "Neu" (the last line).
For localised formula names (german), it would be:
=REGAUS(A1;"([:lower:])([:upper:])";"$1"&ZEICHEN(10)&"$2";"g")
I would have expected that inserting "\n" should work, too, but i did'nt manage got get it working, thus the recourse to CHAR(10).

Tkinter - Underline only letters in Labels?

a = Label(root,text='h e l l o',underline=0)
So basically I want to be able to choose which parts of the string I want to underline. Right now it only lets me choose one at a time. If I try:
a = Label(root,text='h e l l o',underline=0,1)
I get the error:
a = Label(root,text='h e l l o',underline=0,2)
SyntaxError: non-keyword arg after keyword arg
I have looked at other posts and they suggest making a font to make the whole string underlined. I want to make just the letters underlined. Is there a way to do this?
Multiple character underlining is possible with unicode '\u0332' (underline of previous character). This avoids using the underline styling of the tkinter Label widget and allows multiple items to be underlined. To make just the letters underlined, use list comprehension and isalpha() to identify the letters. In the example below, the required text is moved to a string (mylabel) and preprocessed using:
mylabel='h e l l o'
utext=''.join([letter+'\u0332' if letter.isalpha() else letter for letter in mylabel])
a = Label(root,text=utext)
The above was tested on Python 3.7 on Windows 10. Note the previous limitations identifed with using unicode '\u0332' on some platforms.
Your choice with a Label is to underline a single character with the underline option, or to underline the entire string by using a font with underline option turned on.
The text widget allows you to underline individual characters, so my recommendation is to use a single-line text widget, or to use a canvas widget with multiple text items for each group of characters that are to be underlined or not.

Copying only the value at column n Vim

I have a file with long lines and need to see/ copy what the values are in a specic location(s) for the whole file but copy the rest of the line.
If the text width is small enough, ~184 columns, I can use :set colorcolumnnum to highlight the value. However over 184 characters it gets a bit unwieldy scrolling.
I tried :g/\%1237c/y Z, for one of the positions I needed, but that yanked the entire line.
eg for a smaller sample :g/\%49c/y Z will yank all of line 1 and 2 but I want to yank, or copy, the character at that column ie = on line 1 and x on line 2.
vim: filetype=help foldmethod=indent foldclose=all modifiable noreadonly
Table of Contents *sfcontents* *vim* *regex* *sfregex*
*sfsearch* - Search specific commands
|Ampersand-replaces-previous-pattern|
|append-a-global-search-to-a-register|
*sfHelp* Various Help related commands
There are two problems with your :g command:
For each matching line, the cursor is positioned on the first column. So even though you've matched at a particular column, that position is lost.
The \%c atom actually matches byte indices (what Vim somewhat confusingly names "columns"), so your measurement will be off for Tab and non-ASCII characters. Use the virtual column atom \%v instead.
Instead of :global, I would use :substitute with a replace-expression, in the idiom described at how to extract regex matches using vim:
:let t=[] | %s/\%49v./\=add(t, submatch(0))[-1]/g | let ## = join(t, "\n")
Alternatively, if you install my ExtractMatches plugin, I'd be that short command invocation:
:YankMatchesToReg /\%50v./

Stata: removing line feed control characters

I have a dataset which I export with command outsheet into a csv-file. There are some rows which breaks line at a certain place. Using a hexadecimal editor I could recognize the control character for line feed "0a" in the record. The value of the variable producing the line break shows visually (in Stata) only 5 characters. But if I count the number of characters:
gen xlen = length(x)
I get 6. I could write a Perl programm to get rid of this problem but I prefer to remove the control characters in Stata before exporting (for example using regexr()). Does anyone have an idea how to remove the control characters?
The char() function calls up particular ASCII characters. So, you can delete such characters by replacing them with empty strings.
replace x = subinstr(x, char(10), "", .)

Add spaces at cursor position

I would like to know if it is possible to add spaces (30 spaces) at cursor position
I tried to do it with regex but I don't know how to represent the actual cursor position in regex.
30iSPACE will add 30 spaces at the cursor position in command mode.
You can use vim register for this:
"a defines register a and if you cut a whitespace with "ax makes register a has whitespace. Then use:
30"ap
Cut a whitespace with x and paste it with 30p
Note: Registers don't forget its value so first solution is more useful.
In addition to already given answers I can say that cursor position is represented in regex with \%#, so s/\%#/\=repeat(" ", 30)/ will add 30 spaces at cursor position just like 30i<Space><Esc>.