Ticket #5047, #5048: Separate mc.keydef file, updated syntax#5061
Ticket #5047, #5048: Separate mc.keydef file, updated syntax#5061egmontkob wants to merge 6 commits intoMidnightCommander:masterfrom
Conversation
|
This is a cleanup before finalizing the real work in #4632 & friends. Documentation (manpage etc.) is yet to be updated, but I'd prefer to hear a round of feedback first. |
db0ee31 to
cab7821
Compare
| s++; | ||
| } | ||
|
|
||
| return g_string_free (ret, FALSE); |
There was a problem hiding this comment.
Let's return GString itself.
There was a problem hiding this comment.
Let's return GString itself.
Is there a generic guideline here? Should we always prefer GString to char* as retval? How about input parameters?
Or should the API depend on how the internals were the most convenient to implement: if we already have a GString then return that?
I was tempted to change the input of this function, as well as the retval of the decode_controls() function to GString, for the reason that theoretically a terminal's escape sequence may contain a NUL byte (although in practice I really don't think it does, except for Ctrl+@ a.k.a. Ctrl+space which is the single NUL byte, handled elsewhere in the code).
For the retval of this function, as well as the input parameter of the decoding counterpart, the semantics is C-style string: cannot contain embedded NUL byte. What's the point of changing the return type to GString? Also, for consistency, shouldn't we then change the input parameter of the decoder too, making it possibly more cumbersome for the caller? Or have 3 GStrings and 1 char*?
Would love to learn more about the preference in general, and its reasons; thanks! :)
cab7821 to
cffe511
Compare
|
Added a new first commit, moving from I haven't yet addressed the char * / GString issue for decode/encode, I'd like to see a consistent full picture which of the 2+2 input parameters and retvals should be changed, please help me here :) |
You do use a GString object within a function. Then you destroy it in parts in two different places: the container and some its members in the function, the char array in the caller function. It would be logical to destroy the entire object at once. And if you need the length of the string in the caller function, you have to call |
I happen to use it, in both the I do not write the implementation first, and then tailor the interface to that, this wouldn't make sense to me. I first create the interface, with whatever types that I believe make the most sense, which in this case was
Destroying at two parts is a standard practice, this is explicitly what
I don't think I use the length in the caller. But even if I did... I know, for some reason, mc has an extremely strong aversion against running Accessing data via a What we need to optimize for is code cleanness, consistency, and quick development flow. For the And how far would you go with your logic? E.g. I honestly really don't like this philosophy of adjusting the interface: the return value (and you didn't respond: what about the input parameters?) to the implementation, rather than designing the interface first. I really don't like trying to micro-optimize the most insignificant bit, let alone with no information whether it would actually speed up things or not if the caller cared about the string length, let alone the caller now doesn't even care. I really don't like being so afraid of maybe (but in fact: not) calling I'm tempted to say that if you firmly insist on returning It might look like I'm just spending 15 minutes to type this comment instead of changing what you asked for. Behind it is much more unpublished work actually trying to adjust the code, and if we're going with I'd really like to stick to the |
98c3c4a to
a5ebd7d
Compare
|
How do you like the direction of the latest push? Since I've worked on it a lot, I thought I'd upload it. The
The retval of Much of the internals have been reworked to carry a possible internal NUL of the escape sequence, although it doesn't work, it would need further investigation which is not my focus right now. That being said, if we ever happen to need that, the current underlying work might become useful. Please advise whether I should continue this latest version, or the one before (with |
You love the hand-made memory management, don't you?
Possible is not mandatory.
It's not an argument. The code written in old years is needed to be refactored from time to time.
First we avoid micro-optimization, then we avoid any optimization at all. As a result we have a software that works hardly on multi-core multi-GHz CPUs. Don't forget than mc runs not only on desktops but in embedded devices where CPUs are not so productive.
Getting
In
I don't want to argue anymore. I just can modify myself your code from my point of view (in the separate branch). |
Move the method to get a config file's full name from keymap to mcconfig, because in the next commit keydef will need the same method. Signed-off-by: Egmont Koblinger <egmont@gmail.com>
…o a separate file Move the escape sequences from the global "mc.lib" and user "ini" file to new global and user "mc.keydef". Add command line option --keydef/--nokeydef and environment variable MC_KEYDEF, analogously to the keymap feature. Signed-off-by: Egmont Koblinger <egmont@gmail.com>
Repeated keys aren't supported. Signed-off-by: Egmont Koblinger <egmont@gmail.com>
No, I absolutely hate hand-made memory management, I truly wish we had something even higher level than GLib. When I said plain
It's absolutely not obvious that What I am convinced about is that it doesn't matter at all. Performance is not going to measurably increase finding whichever of
I wanted to stay consistent with the Also, as I've already stated: I wouldn't want the function signature to be based on whatever internals I happened to have picked (manual array allocation or
Again, my primary reason was consistency with
... but above you said ...
So at one point you argue that I don't see a consistent guideline from you.
I don't want to submit code that you really dislike and would jump on to refactor. But I don't yet understand the rationale behind your requests, nor do I see those requests being consistent. Do you like that in my latest version I changed many I'm happy to change the internals from For the retval: Okay, I can return As for the input parameter of the setter: |
Separate entries by space rather than semicolon. Semicolons are no longer escaped. The escape character is represented by \e, \E or ^[, rather than \\e. Other special characters also have more standard notation, e.g. ^H and ^?. Change the internal variables to hold the raw value rather than the escaped string. Signed-off-by: Egmont Koblinger <egmont@gmail.com>
This makes us one step closer to supporting escape sequences with an embedded NUL byte, although we probably won't need this. Signed-off-by: Egmont Koblinger <egmont@gmail.com>
…ydef section names Also rename [general] to [_common_], emphasizing that it's not a terminal name and that it's always loaded. Signed-off-by: Egmont Koblinger <egmont@gmail.com>
a5ebd7d to
442b04e
Compare
|
Changed the getter's return type to Yet to address the setter's input parameter according to clarified instructions. I'm not a 100% satisfied with the design of returning For one, it doesn't convey whether its elements are Then, it doesn't convey whether the array is NULL-terminated or not. This is only answered for us because NULL-terminated is a recent GLib addition and we support much older versions, too. It also doesn't convey the message whether the array has been set up to automatically free the members, or not. Currently, for me, it's not. As far as I can see, in order to set up automatic freeing, I'd need a tiny helper function to pass that Anyone who uses this method either needs to reads its documentation where all these details have to be carefully specified – which I'm yet to do!!! –, or has to check the implementation. Returning a This direction of returning |
|
GString is sort of a pointer type. it wouldn't be unreasonable to just return it by value. |
Yup (and same for GPtrArray). It's not an existing pattern of mc, though. Out of the many possible solutions I'd preferably pick one that matches our existing practices. |
|
@egmontkob please look at branch |
Proposed changes
Move the escape sequences from the global "mc.lib" and user "ini" file to new global and user "mc.keydef".
Saner escaping, nicer look.
Removed "terminal:" prefix.
Checklist
👉 Our coding style can be found here: https://midnight-commander.org/coding-style/ 👈
git commit --amend -smake indent && make check)