c editor

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there an editor that allows you to copy c code text and paste it with the code highlighted in color

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you mean just the pasted block in colour? Or the pasted block maintains the original colours of the copied text?

 

This is Notepad++ with a block of defines copied and pasted

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fianawarrior wrote:
Is there an editor that allows you to copy c code text and paste it with the code highlighted in color
You mean copying from the editor to somewhere and there is still the color highlighting at "somewhere"?

How could that work? How could the editor know how colors are done at "somewhere" (Escape sequences? HTML? Whatever?).

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sternst wrote:
How could that work?

I find that copying form Visual Studio (including Atmel Studio) into MS Word does exactly that!

 

I think Eclipse --> Word also does?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did not say that there aren't any working combinations, I questioned an universal "from editor to somewhere".

 

Perhaps the OP should simply state whether he has something specific in mind for "somewhere".

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sternst wrote:
I questioned an universal "from editor to somewhere".

Oh - I see.

 

Clearly, MS Word is specifically designed for dealing with formatted text but, in general, plain text editors are not - that's why they are called text editors.

 

So, as a minimum, the receiving program is going to have to be a "rich" text editor ...

 

Note that "programmers" editors - like Atmel Studio, Eclipse, Notepad++ do not embed the formatting in the text - they simply apply it as they put it to the  display ...

 

 

EDIT

 

typo

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Jul 24, 2018 - 05:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The original question is too general and does not really state what he is asking about. I am going to take a punt and assume that he means that instead of:

FATFS FatFs;   /* Work area (filesystem object) for logical drive */

int main (void)
{
    FIL fil;        /* File object */
    char line[100]; /* Line buffer */
    FRESULT fr;     /* FatFs return code */

    /* Register work area to the default drive */
    f_mount(&FatFs, "", 0);

    /* Open a text file */
    fr = f_open(&fil, "message.txt", FA_READ);
    if (fr) return (int)fr;

    /* Read all lines and display it */
    while (f_gets(line, sizeof line, &fil)) {
        printf(line);
    }

    /* Close the file */
    f_close(&fil);

    return 0;
}

He wants to be able to make posts here that look like:

FATFS FatFs;   /* Work area (filesystem object) for logical drive */

int main (void)
{
    FIL fil;        /* File object */
    char line[100]; /* Line buffer */
    FRESULT fr;     /* FatFs return code */

    /* Register work area to the default drive */
    f_mount(&FatFs, "", 0);

    /* Open a text file */
    fr = f_open(&fil, "message.txt", FA_READ);
    if (fr) return (int)fr;

    /* Read all lines and display it */
    while (f_gets(line, sizeof line, &fil)) {
        printf(line);
    }

    /* Close the file */
    f_close(&fil);

    return 0;
}

or how about something even more exotic like:

 

ATFS FatFs;   /* Work area (filesystem object) for logical drive */

int main (void)
{
    FIL fil;        /* File object */
    char line[100]; /* Line buffer */
    FRESULT fr;     /* FatFs return code */

    /* Register work area to the default drive */
    f_mount(&FatFs, "", 0);

    /* Open a text file */
    fr = f_open(&fil, "message.txt", FA_READ);
    if (fr) return (int)fr;

    /* Read all lines and display it */
    while (f_gets(line, sizeof line, &fil)) {
        printf(line);
    }

    /* Close the file */
    f_close(&fil);

    return 0;
}

I have often used:

 

https://tohtml.com/c/

 

in the past (as I did just now). The above two examples are "Eclipse" and "Neo". A number of color schemes are available. As you can see a copy of the HTML from that page simply pastes easily and correctly here.

 

(it's also the top hit for "online C syntax highlighter" which is how I find it each time when I've forgotten where it is (one day they'll invent browser bookmarks!)

 

EDIT: that "neo" one is a bit dark and doesn't really work!!

 

EDIT2: just tried them all. I think my preference is actually "HomeSite":

FATFS FatFs;   /* Work area (filesystem object) for logical drive */

int main (void)
{
    FIL fil;        /* File object */
    char line[100]; /* Line buffer */
    FRESULT fr;     /* FatFs return code */


    /* Register work area to the default drive */
    f_mount(&FatFs, "", 0);

    /* Open a text file */
    fr = f_open(&fil, "message.txt", FA_READ);
    if (fr) return (int)fr;

    /* Read all lines and display it */
    while (f_gets(line, sizeof line, &fil)) {
        printf(line);
    }

    /* Close the file */
    f_close(&fil);

    return 0;
}

Last Edited: Mon. Jul 23, 2018 - 08:23 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
The original question is too general and does not really state what he is asking about.

Indeed.

 

frown

 

Just to note that if I copy each one if Cliff's examples, and paste into Word, they all retain the formatting ... 

 

Also if I paste back into a post here:

 

FATFS FatFs;   /* Work area (filesystem object) for logical drive */

int main (void)
{
    FIL fil;        /* File object */
    char line[100]; /* Line buffer */
    FRESULT fr;     /* FatFs return code */


    /* Register work area to the default drive */
    f_mount(&FatFs, "", 0);

    /* Open a text file */
    fr = f_open(&fil, "message.txt", FA_READ);
  

 

 

ATFS FatFs;   /* Work area (filesystem object) for logical drive */

int main (void)
{
    FIL fil;        /* File object */
    char line[100]; /* Line buffer */
    FRESULT fr;     /* FatFs return code */

    /* Register work area to the default drive */
    f_mount(&FatFs, "", 0);

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it is just for display/print of the highlighted code, I expect there are many approaches.

 

But "editor" was mentioned.  Thus, when a change is made will the formatting/highlighting be updated also?  Well, it would be in the original "smart" editor.  So we have come full circle.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
when a change is made will the formatting/highlighting be updated also?  

Let's see:

ATFS FatFs;   /* Work area (filesystem object) for logical drive */

int main (void)
{
    FIL fil;                /* File object */
    char line[100];         /* Line buffer */
    char another_line[100]; /* added line - not correctly syntax-highlighted! */
    FRESULT fr;             /* FatFs return code */

So that'll be a "NO", then!

 

No surprise, really.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wonder if the "editor" he mentions is actually this one:

I can see how a lot of people (me included) might be more than a little disappointed that it does the clever color highlighting thing but all you ever really end up with is a sea of green. A real shame it could not have passed HTML highlighting tags back to Drupal (as happens when you paste from that "editor" I linked to above).

Last Edited: Mon. Jul 23, 2018 - 02:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Text editors generally work with text, and plain text has no color info.

The colors are generated by analyzing the code inside the text editor.

However, a bunch of editors are capable of export / save the text as HTML with the color info.

Even the good old PN that came with winavr a long time ago could do that.

 

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com