SCI_AUTOCSHOW on Scintilla - mfc

I have a question, when I use
CallScintilla(SCI_AUTOCSHOW, nLen, (LPARAM)m_strCandidate.c_str())
to show the window about autocompletion, it works when I input a word but it doesn't always work when I press the backspace button, I wonder if there are some conflicts about the key backspace?

use SCI_AUTOCSETSEPARATOR to set the separator character used to separate words in the SCI_AUTOCSHOW list. The default is the space character.

Related

How to write a QRegExp that will accept only strings made of characters or normal symbols?

Let me clarify the question. I need to process keyboard input on the fly. So if the user presses something like the home button or the delete button I need to ignore the input. But any normal printable symbol I want to catch. I get the input in the text field() method of a QKeyEvent.
I've tried two regexps
The first one was:
QRegExp("[\\S]");
Which did not work as apparently pressing delete is considered a non-whitespace character.
The second one was
QRegExp("[\\w]");
This one was much better as it would only accept letters, number and underscore but no symbols such as + or *. Which I want to accept.
I was thinking of modifying the last expression to include any symbol in my keyboard. But how would I do that? Or how can I write an RegExp for what I want?

Moving over tab spaces in ncurses

I am creating a basic text editor using ncurses. It can display text fine, but navigating with arrow keys causes a problem when tabs are encountered. Calling move(y, x) will freely move the cursor onto a tab space, where most text editors will jump to the next character. Is there functionality within ncurses to jump over tab spaces or do I need to find a way to do it myself?
You have to do it yourself: wmove moves to the given coordinates, ignoring the way characters are displayed on the screen.
If a destructive (filling with spaces) tab works for your application, then you could use waddch:
If ch is a tab, newline, carriage return or backspace, the
cursor is moved appropriately within the window:
Tabs are considered to be at every eighth column. The
tab interval may be altered by setting the TABSIZE
variable.
For an editor, you probably do not want that behavior (though it probably would be helpful to use the TABSIZE feature when displaying text).

Add trailing zeroes to line in notepad++

I have a file containing (hundreds) of blocks of numbers like below;
This one is fine (16x20, correct number of rows and columns)
11111111111111111110
16666616666666661110
16111616111111162610
16111646111663132610
16162616261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261626132610
16166313661116632610
16111111111116132610
16666666666666136610
11111111111111111110
This one needs to be padded with trailing zeroes so it is (16x20)
111111111111111111
166616666666663661
166611111111111661
166666366663661661
113161111111161611
1316166666616161
1616162262616161
11616166112616161
16616166116616161
16616162262616161
16616166266616161
16616111161116161
1661666666666616111
1661666166163366661
1641666166166613661
1111111111111111111
I would like to pad them with zeroes so they are all like the first example. I'm aware of the regular expressions feature in notepad++ but am struggling to get it to work. I appreciate any help given.
You could do it via a macro.
First append a large number of zeroes to the end of each line using a macro.
Caret on the first entry
click record macro
press end
type out 20 zeroes
press down arrow
click stop recording
play the macro until all lines look like this
11111111111111111100000000000000000000000000000000000000000000
16661666666666366100000000000000000000000000000000000000000000
16661111111111166100000000000000000000000000000000000000000000
16666636666366166100000000000000000000000000000000000000000000
11316111111116161100000000000000000000000000000000000000000000
131616666661616100000000000000000000000000000000000000000000
161616226261616100000000000000000000000000000000000000000000
1161616611261616100000000000000000000000000000000000000000000
1661616611661616100000000000000000000000000000000000000000000
1661616226261616100000000000000000000000000000000000000000000
1661616626661616100000000000000000000000000000000000000000000
1661611116111616100000000000000000000000000000000000000000000
166166666666661611100000000000000000000000000000000000000000000
166166616616336666100000000000000000000000000000000000000000000
164166616616661366100000000000000000000000000000000000000000000
111111111111111111100000000000000000000000000000000000000000000
Then...
Caret on first line
click record
press home key
press the right arrow key 20 times
hold shift and press end key
press delete key
press down arrow
click stop recording
play the macro until all lines are processed
You could save the entire process as a single macro so its just a single click in the future.
I can give you a macro solution
go to the beginning of your text
select Macro/Start Recording
press end, press 0 16 times then press Home and down arrow key
select Macro/End Recording
You now have a macro to add sixteen zeros to the end of all lines.
Playback this macro on all lines.
You now have appended zeroes to all lines.
Pressing Alt key and using mouse select the required block(columns) of text you want and paste it into another empty notepad tab
help on column mode editing is there inside notepad ? / help contents menu
Good luck
You can use the plugin ConyEdit to do this.
With ConyEdit running in the background, follow these steps:
use the command line cc.aal 00000000000000000000 to append after lines with twenty zero character.
use the command line cc.gc 1/\d{20}/ to get the first column of regex match.
Looking to do this manualy and not progomaticly ?
Open Findreplace
Copy from the last to rhe first WITHOUT NUMBERS on a line so...
in this example
111111111111111111 <---from here
to here ---> 166616666666663661
166611111111111661
paste that into the fine ( yes your effecticly copying the return wich some applications allow you to manualy input others wont )
then in the replace box, type '0' then your return
Hit that magic replace all :D
This will then add a 0 every time it hits a new line, then add a new... new line....
edit : quickly reviewing another method a second to recover for alternate options :P give me 10
edit 2:
Ah ok somthing like this will work :P just tested it.
use [0-9] in the find replace. so if im looking for 123123123123 ( wich is 12 long ) and i need to buff i up to 20,
Your FIND must be in ()
so..
the find would be
([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] )
and the replace is referd to as \1 no the regex, this was my mistake
\100000000
tested and confirmed !dont forget YOU NEED MATCH ALL on, WRAP off!
And so on for your other numbers, Not sure if you can loop this with macros nd stuff :P but hope it helps more than you have now
two good resources.
http://blog.creativeitp.com/posts-and-articles/editors/understanding-regex-with-notepad/comment-page-1/
http://regexpal.com/
base on OP's comment: you could try an editor called vim/gvim
open your file in vim, then type:
:%s/.*/\=printf("%-20s",getline("."))/|%s/ *$/\=substitute(submatch(0)," ","0","g")/
don't forget pressing <Enter> after the above typing.
then you will see the text has been changed into what you want.
of course vim macro can work as well, however, I feel command better... :)

How do I replace or find non-printable characters in vim regex?

I have a file with some non-printable characters that come up as ^C or ^B, I want to find and replace those characters, how do I go about doing that?
Removing control symbols only:
:%s/[[:cntrl:]]//g
Removing non-printable characters (note that in versions prior to ~8.1.1 this removes non-ASCII characters also):
:%s/[^[:print:]]//g
The difference between them could be seen if you have some non-printable-non-control characters, e.g. zero-width space:
Say you want to replace ^C with C:
:%s/CtrlVC/C/g
Where CtrlVC means type V then C while holding Ctrl pressed.
CtrlV lets you enter control characters.
Try this after saving your file in vim (assuming you are in Linux environment)
:%!tr -cd '[:print:]\n'
None of the answers here using Vim's control characters worked for me. I had to enter a unicode range.
:%s/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]//g
That unicode range was found on this other post: https://stackoverflow.com/a/8171868/231914
You can use:
:%s/^C//g
To get the ^C hold the control key, press V then C (Both while holding the control key) and the ^C will appear. This will find all occurrences and replace them with nothing.
To remove both ^C and ^B you can do:
:%s/^C\|^B//g
You can use the CTRL-V prefix to enter them, or if they're not easily typeable, yank and insert them using CTRL-R ".
An option not mentioned in other answers.
Delete a specific unicode character with a long hex code, e.g. <200b>:
:%s/\%U200b//g

Way to exclude a char from a word selection

I'm extending a QPlainTextEdit.
When I double click on a word containing a pipe char ex : {"foo"|upper|reverse}
the whole text is surrounded.
I'd like to exclude the pipe char "|" from the selection and don't know what to do
Is there a way to change the behavior of QTextCursor::WordUnderCursor?
I'd like that char to act the same as a space or more generally as an unselectable char.
As stated in QT docs:
Selects the word under the cursor. If
the cursor is not positioned within a
string of selectable characters, no
text is selected.
Currently there is no official way to change the way a text edit finds the word boundaries. See http://bugreports.qt-project.org/browse/QTBUG-150.
You may use their private API to change the behaviour of QTextEngine::atWordSeparator. This way is not recommanded by Qt. The pipe is recognized as word separator in 4.6 but not in 4.5.1 or earlier. I would suggest to update your Qt version, if that is an option. Otherwise you may give your QTextEdit a new QTextLayout with a modified QTextEngine.