While using form fields I stumbled upon the following behavior of dynamically-sized fields. AFAICT, passing a right arrow key event to the form driver leads to appending of spaces to the field buffer. I.e., this:
case KEY_RIGHT:
form_driver(f, REQ_NEXT_CHAR);
break;
when the cursor is at the end of the field string will append spaces to the field buffer. I am baffled as to how this is the default behavior. IMHO, hard stopping at the end of the field buffer string would be the correct, intuitive behavior, and spaces should be appended only when the user explicitly does so.
Reading the source code I see this is tied to a compatibility macro(?) called GROW_IF_NAVIGATE? I see this as a prime example of a simple enhancement that allows the user to opt out of this behavior. In the meantime what are my options? Just trim?
EDIT: the behavior controlled by this macro is more bizarre than I originally thought. It only limits growth when moving after the end of the field as specified in the field creation. IOW, when the macro is disabled (0), after filling some part of the field the growth is still allowed until the cursor reaches the end of the field where the growth indeed stops. Trimming is perhaps the only recourse here.
From a cursory reading of the latest source code field navigation is not taking into the account the content of the field. The field buffer can be grown by either navigating to the right or typing in characters (or a combination of both). Navigation adds padding characters which are replaced with blanks when the field buffer is eventually evaluated. The macro GROW_IF_NAVIGATE allows/controls the growth of fields when the end of the field window has been reached.
It seems that the recourse is to either not issue the request to navigate to the form driver, and this requires keeping track of every and all field input, or simply discard all padding, but this invalidates input with trailing spaces.
Related
I tried having a TYPE_ENUM field but that requires typing some part of one entry (with the field performing autocompletion after that). I then thought about perhaps having a TYPE_ALNUM field that has each of the alternative values set in their respective buffers which I first set with set_field_buffer. But how do you switch between buffers then? Or maybe I should have overlapping fields and switch between them in the app? That seems nasty. Any help?
As a bit of context, I am considering making a plugin for vim that would inline specific debugging and/or profiling information on along the left margin (ideally left of the numbers column) which would need to be 4-5 characters wide. However, I cannot find any means to accomplish this. I've searched around, and the closest thing I can find is vimscript code for inserting signs in the sign column, but the sign column is fixed at 2 characters wide.
I've considered the possibility of making my own makeshift column (to the right of the numbers column, in the normally editable text area) and somehow marking it as readonly, but that doesn't seem possible either- from what I've read, the entire buffer must be readonly or not; you can't have just a portion as readonly.
For completeness here's an example. I would like to programmatically insert a 4-5 character column before some text (with numbers set)
1 Text buffer
2 with some
3 text
to make
My 1 Text buffer
own 2 with some
text 3 text
Is there any way to accomplish this task?
The built-in feature for this is the sign column, but yes it is limited to two characters.
Depending on your use cases, it might be okay to enhance the signs with a tooltip popup (:help balloon-eval explicitly mentions This feature allows a debugger, or other external tool, to display dynamic information based on where the mouse is pointing.), or maybe place the additional information in the quickfix or location list.
Modification of the actual buffer has many downsides (as it effectively prevents editing, and Vim's main purpose is just that). What some plugins do is showing a scratch (that is: unpersisted, unmodifiable) buffer in a vertical split, and setting the 'scrollbind' option so that its contents follow the original buffer. For an example, have a look at the VCSCommand plugin, which uses this for annotating a buffer with commit information.
Sublime Text is so damn advanced and this seems like such a stupid question, but...
I started writing a for loop in PHP (using SFTP), loved that it gave me a choice to auto-generate the loop. However, it enters this weird multi-cursor mode, which
1)I am not really sure how to use/exit without using the mouse;
2) it seems useless, seeing as all 3 type the same thing, even though I need to change, for example, the $i > x or $i = x.
Although Sublime does indeed support the idea of multiple cursors (which is an incredible time saver and useful as all get out, as we're about to see), what you're actually asking about here is a snippet which in this case happens to also include multiple cursors.
The general idea is that for code that you're likely to type many times (e.g. a for loop), you can create a snippet that will generate the bulk of the text for you in one shot, and then allow you to easily customize it as needed. In this case, the snippet in question is part of the default functionality of Sublime and is provided by the shipped PHP package.
To answer point #2 in your question first, this is far from useless. As seen here, I enter the text for and then press Tab to expand the snippet out. The first thing to notice here is that the status line says Field 1 of 4 to tell me that I'm in a snippet and that it contains four fields.
The first field is the name of the control variable for the loop, and all of them are selected so that as I change the name, all of them change at the same time because when there are multiple cursors, the text you type appears at all of them at the same time.
Once I'm done changing the name of the variable, I press Tab again to go to the next field, which allows me to easily change the point at which the loop starts. Another press of Tab takes me to the third field, where I can specify where the loop ends.
One last press of Tab exits the snippet and selects the text in the loop, so I can start writing my code (caveat: I am not a PHP developer).
At this point you can see Sublime offering another snippet for echo, which would expand out to an echo statement complete with quotes, then allow me to edit the text in the echo and skip to the end.
Circling back around to the first point in your question, you can use Esc at any point to jump out of a snippet and go back to regular editing. You can also use Tab or Shift+Tab to move through the fields in the snippet, and pressing Tab at the last field in the snippet exits it as well.
In this particular case, the first field in the snippet sets up multiple cursors, and so exiting the snippet while this field is active leaves multiple cursors in effect. You can jump back to a single cursor by pressing Esc one more time (this is true regardless of how you ended up with multiple cursors).
I am trying to take the readout from an instrument and if the readout matches certain strings (from the instrument programming manual) I want to set an indicator to a specific value, different for each possible string. A case structure seems like the best option, with all the possible readouts as the cases. I did this and added "" as the default case to send out a value for the no-match case. The trouble is that if I wire the readout string to the case structure it always executes the default case no matter what the readout (and yes, before anyone asks, I verified that the readout strings match my cases exactly). To check that the case structure was working I wired a constant to the case structure and it works fine, even when I copy and paste the value from the readout string to the constant. Also, I made sure that case insensitive matching was selected so that's not the issue. Anyone have an idea why this is happening? I can post sample VI's if necessary.
Found the problem. Converted the strings into byte arrays and looked at the ascii values. Apparently one had a new line character at the end even though there was no new line on the indicator. Fixed comparison by trimming white space on strings. Look out for that.
To check exactly what's in your string you can wire it to an indicator, right-click on that indicator and choose '\'Codes Display. This will then show codes such as \n for newline, \00 for ASCII 0, \FF for ASCII 255, etc.
In ncurses:
1.What does the A_PROTECT attribute do? Everywhere on the net, the docs just say: Protected mode. What is that?
2.Also I would like to mark the area where the user inputs characters with an underscore, but I would like when the user deletes or backspaces to have the underscore reappear. Is there an attribute that does that, or I have to manually do that?
Protected mode may refer to a little-used feature of some DEC terminals (notably the VT220 and related), called selective erase.
The general idea is that some text can be internally marked as protected. This doesn't change the way it is rendered on the screen, but character cells so marked are not erased by the DECSEL and DECSED (Selective Erase in Line and Selective Erase Data) commands.
This would typically be used to implement something like a data entry form. Field headings and markup would be protected text, and data entered into the fields would be unprotected. You can erase the contents of the form to reset it by performing Selective Erase; thus erasing the data fields but not the headings.
Protect mode is defined by the terminal I'm not sure if it does anything on modern terminals.
There is an attribute "A_UNDERLINE" that underlines a character if your terminal supports it.
For handling input you may want to look at the form library (distributed with ncurses) or cdk (http://invisible-island.net/cdk/)