Code Monkey home page Code Monkey logo

Comments (8)

WolfgangMehner avatar WolfgangMehner commented on June 23, 2024

I agree, this would be nice. And I will try to add this at the weekend. I can probably do it really fast, so there is no need for you to do it yourself.

Would you really cut of the text, or just let it use more space in case the inserted text is longer?

Eg.

/*-------------------------------------------------------*/
/*   name:   |NAME--------------| <-- COOL NAME          */

Would result in (as it should) [Example 1]:

/*--------------------------------------------------------*/
/*   name:   Morgan Stanley       <-- COOL NAME           */

Which is really useful and therefore should be included. But if the name is to long [Example 2],

/*--------------------------------------------------------*/
/*   name:   Really Long Name of a Dude <-- COOL NAME           */

it would actually break the format (on purpose, see below).

Compare C's sprintf. The format specifier would also completely display text, even if it is longer than 20 characters:

sprintf(buf, "%20s some further text", text);

This is a question of design philosophy. In designing all of this, my approach is that editing stuff is easier than adding new stuff. So I would rather break the format and insert the full name, seeing how this would be easy to fix. Secondly, if it breaks the format, that's easy to spot, while an incompletely inserted variable name, date, ... would be much harder to notice at a glance. You would of course still get the benefit of all the cases where it works correctly, which would hopefully be the vast majority of cases.

So I really like your suggestion, I'm just unsure about the "exception handling". What do you think?

from vim-plugins.

victor-fdez avatar victor-fdez commented on June 23, 2024

By exceptions do you mean text expanded which would be larger than specified macro?

Were it possible, in those cases, symbols like '|' or '-' could be used after the first '|' in the macro expansion to specify whether the expanded text should be cutoff. If one of those symbols were included then it would cutoff the text else it would just proceed as normal expanding the whole text even if it pushed the rest of the line further.

For example without '-':

/*--------------------------------------------------------*/
/*   name:   |NAME----------|     <-- COOL NAME           */

Would expand to ->

/*--------------------------------------------------------*/
/*   name:   Really Long name of Dude     <-- COOL NAME           */

And with '-':

/*--------------------------------------------------------*/
/*   name:   |-NAME----------|     <-- COOL NAME          */

Would expand to ->

/*--------------------------------------------------------*/
/*   name:   Really Long name      <-- COOL NAME          */

I think one can also cutoff text with C's sprintf by adding '.20' after the '20' to make the string no longer than 20 characters, but also occupy 20 characters if less characters are specified by text.

sprintf(buf, "%20.20s some further text", text);

I don't want to push any work on you, because I don't know how difficult it would be to implement this in your code, or whether this would break syntax or other stuff. But I think this is how I would change this.

Thanks for replying 👍

PS: You are right that date, times and those types would be difficult to debug if they were cutoff

from vim-plugins.

WolfgangMehner avatar WolfgangMehner commented on June 23, 2024

Is in the works. I'll push tomorrow.

from vim-plugins.

WolfgangMehner avatar WolfgangMehner commented on June 23, 2024

I've pushed a version of the format specifiers:
1a7cfed

See the documentation:
https://github.com/WolfgangMehner/vim-plugins/blob/master/doc/templatesupport.txt
Look for section

4.1.3 Format Specifiers

from vim-plugins.

WolfgangMehner avatar WolfgangMehner commented on June 23, 2024

Your template now could look like this:

/*--------------------------------------------------------*/
/*     name: |NAME%----------|     <-- COOL NAME          */
/*  comment: <RCURSOR>                                    */
/*--------------------------------------------------------*/

from vim-plugins.

victor-fdez avatar victor-fdez commented on June 23, 2024

Nice, I just read the documentation. I will try your changes this afternoon. The changes on the documentation look awesome 😃

from vim-plugins.

victor-fdez avatar victor-fdez commented on June 23, 2024

Thanks! Your new changes are awesome 😄 I will keep on testing them and will let you know of anything I find. But your changes exceeded my expectations. Thank you so much

from vim-plugins.

WolfgangMehner avatar WolfgangMehner commented on June 23, 2024

Your welcome.

I plan to release the plug-ins with the new template version after Christmas. Until then the behavior may still change. So suggestions (and bug reports) are highly welcome.
That being said, I'm already quiet content with the changes. And they will help me with another extension I planned.

from vim-plugins.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.