Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Spaces in a pasted code message get all messed up

Status
Not open for further replies.

MrAl

Well-Known Member
Most Helpful Member
Hello there,

I am bringing this up because it has been a long time issue now and we were talking about it in another thread and the thread started suggested starting a new thread for this issue which is a little different. The one talked about in that thread is about color for text inside 'code' tags, this one is about loosing spaces when pasting text with more than one space in it.

First, it appears to work ok when we type the text in the forum text editor although i havent tested this extensively.
So if we select Courier New and use code tags and type the following:
wordA wordB
we get exactly 5 spaces between those two words which i will enumerate here:
wordA12345wordB


and the above should line up with the first line when copy and pasted:
wordA wordB
wordA12345wordB


and as you can see already it does not. Both lines were copy and pasted RIGHT FROM THIS VERY EDITOR not even from another editor.

Try it inside code tags:
Code:
wordA  wordB
wordA12345wordB
and as you can see it still does not line up. If i paste it into another editor however, it works fine.


So the problem only appears when someone pastes text into the editor. That means it falls under the menu event "Paste" and should not be too hard to fix.

Also, the text font seems to change by itself too. As you can see i am no longer typing in the font Courier New, it changed to something else by itself.

I would appreciate it if this could be fixed as it is very bothersome. As you can see it changed back to Courier New by itself again :)

Thanks much.
 
So do mine, usually ;) There are some tricks. 1) Always use spaces, not tabs (MPLab can be set to substitute spaces for tabs). 2) Download Pommie's "code tidy" application (I have a copy, if you can't find it). It helps clean things up. However, I have found that using [code=asm] helps a lot, and I haven't had to use code tidy recently.

John
 
Hi,

John, what is this code+asm you are always talking about???

This may have worked although a little harder to do:

Code:
Testing     Testing

I'll have to test this some more very soon.

Code:
Vin o-----R1-----+-----o Vout
                 |
                 C1
                 |
GND o------------+-----o GND

Ok it worked, but wow, what a pain :)
I had to do:
1. Copy the text from somewhere.
2. Place the cursor where the text was going to start.
3. Click the menu "Insert", then "Code".
4. The resulting code still isnt right, so i have to select the whole body of the code and then click the icon for "Courier New", then the whole thing gets re-spaced back to normal.


So pasting into the editor messes up the spaces, but it does at least keep track of them so that when Courier New is selected from the font menu all the code chars (including spaces) get back to their real equal widths.

And note that this does not work with the main editor, only with the "Insert" editor.

It would be nicer to just copy and paste as usual if this can be made possible.
 
Last edited:
MrAl When using code tags most of us manually type the code in

For instance.. This:-
upload_2016-1-6_19-18-34.png

works out as this:-
Code:
      Hello!!      Text
      Margined      Text

This:-
upload_2016-1-6_19-20-35.png

is this
Code:
      Hello!!      Text
      Margined      Text

No!! No difference
 
Mr Al

In order to "compose" ASCII art, you HAVE to switch to a fixed proportion font, e.g. Courier New, while composing. between the CODE tags.

The "quoted" text will ALWAYS be wrong, so if you want to "fix it", again, you have to switch to "Courier New" between the CODE tags after quoting.

I know, silly.

but, you would almost have to parse continuously. i.e. When you type [code] the font should change to say courier new. Then when you type [/code] it switches back. Kinda like a software "shift key". Then there is the mismatched issue.

Your right, the presence of a correctly placed CODE tag should change the font automagicly.
 
Hello again,

This is not working for me.

Code:
[FONT=Courier New]
This     That
This12345That[/FONT]

Ok it appears to work for the spacing when it is TYPED into the editor. Now lets see what happens when i copy and paste that back in...
Code:
[FONT=Courier New]
This     That
This12345That[/FONT]

And now copy and paste the very same thing from another editor:
Code:
[FONT=Courier New]
This  That
This12345That[/FONT]

I am getting tired of stating the problem only to have it misinterpreted.

The problem is when you PASTE text from another editor (which you typed up nicely in your home text editor). The editor here can not interpret the font correctly when it is converting chars.

Think:
PASTE PASTE PASTE PASTE

dont type directly into the editor :)

Another try, copied from a Rich Edit control:
Code:
[FONT=Courier New]
This  That
This12345That[/FONT]

That didnt work either, so let me try this...

Code:
This  That
This12345That

Yeah, nothing seems to work for PASTING text right into the editor, unless you have copied that text from THIS very editor using the asm trick.

Procedure for the test:
1. Type one line with 5 spaces between two words.
2. Type the second line with non spaces like 12345 where the spaces in the first line went, typing the same two words also so they would line up in with non proportional font.
3. Copy the text with the menu item "Copy" on the editor.
4. Paste it into the Rich Text editor here in this forum.
5. See spaces get shrunk to maybe 1 or two when there was first 5.


The problem is, when the text is pasted, the pasting operation interprets the font as proportional font or else actively limits the number of spaces in a row. Typing doesnt do it, only PASTING.

PASTE PASTE PASTE PASTE PASTE PASTE PASTE PASTE PASTE PASTE PASTE
not:
TYPE TYPE TYPE etc.


Maybe there is another trick besides using that little bitty editor?

Thanks :)

KISS:
That didnt work either:

Code:
This  That
This12345That

Modified by hand, it should look like this:
Code:
This     That
This12345That

where the numbers 12345 count the spaces in the first line.

It is also of some interest that the teeny tiny editor keeps track of this so when switching to Courier New in the Rich Text editor it corrects all the spaces.

Oh yeah another application is when you want to show data from some circuit input and output or whatever, such as this:


Code:
Vin   Vout
----  ----
   1    10
   2    20
   3    28
   4    35.4

and this could have been data you had obtained from another application either on your computer or on another place on the web so you copy and pasted it into this forum editor.
 
Last edited:
This is what I entered:
upload_2016-1-7_7-33-5.png


This is the result:

Code:
This      That
This12345 That

I don't see the problem. Remember, none of the other tags that we are accustomed to using work within code tags, which was my point in the other thread. So,your font tags need to be outside the code tags.

John
 
Code:
   list   p=16F887     
   include   "P16F887.inc"     
   

LEDS     EQU   b'00000011' ; Initial LEDS
EXTRA_LED   EQU   0x05 ; Extra led to switch on
   org 0
Start:
  ; banka
   banksel   TRISA
   movlw   b'00000000'   
   movwf   TRISA
   banksel   ANSEL
   clrf   ANSEL
   banksel   ANSELH
   clrf   ANSELH
   
   banksel PORTA
   movlw   LEDS
   movwf   PORTA
  bsf  PORTA,EXTRA_LED   

   ; bankb    
   banksel   TRISB
   movlw   b'00000000'   
   movwf   TRISB
   
   banksel PORTB
   movlw   LEDS
   movwf   PORTB
  bsf  PORTB,EXTRA_LED   

   goto    $

end

Nope!!
 
Ian Rogers OK, I see a failure, but there is no clue as to what you started with. Besides, I thought MrAl was worried about ascii art. Using real code may introduce other factors, since the code tags used at ETO may expect some special formatting, e.g., labels in the first column, instruction mnemonics in the second, and so forth. One such format is illustrated in your example with the color used for reserved words and numbers with different radix.

John
 
Ian Rogers
Here is what the code you posted looks like when copy andpasted into my version of MPLab8.92:
upload_2016-1-7_8-24-46.png


Here is what it looked like in MPLab after a little clean up and before posting here:
upload_2016-1-7_8-26-5.png


And here it is with code tags inserted:

Code:
   list      p=16F887 
   include   "P16F887.inc" 


LEDS        EQU   b'00000011' ; Initial LEDS
EXTRA_LED   EQU   0x05 ; Extra led to switch on
   org 0
Start:
  ; banka
   banksel     TRISA
   movlw       b'00000000'
   movwf       TRISA
   banksel     ANSEL
   clrf        ANSEL
   banksel     ANSELH
   clrf        ANSELH

   banksel     PORTA
   movlw       LEDS
   movwf       PORTA
   bsf         PORTA,EXTRA_LED

   ; bankb 
   banksel     TRISB
   movlw       b'00000000'
   movwf       TRISB

   banksel     PORTB
   movlw       LEDS
   movwf       PORTB
   bsf         PORTB,EXTRA_LED

   goto        $

end
I did absolutely no clean up to the pasted code within the tags. I just copy and pasted the text from the MPLab window.

John
 
I ran the cut and pasted code from your post through Code Tidy (Pommie) and got this:

Code:
               Code    (asm):
                      
                      
                list    p=16F887   
                include "P16F887.inc"   
                        
                      
LEDS            EQU     b'00000011'     ; Initial LEDS
EXTRA_LED       EQU     0x05            ; Extra led to switch on
                org     0
Start:                 
                                        ; banka
                banksel TRISA
                movlw   b'00000000' 
                movwf   TRISA
                banksel ANSEL
                clrf    ANSEL
                banksel ANSELH
                clrf    ANSELH
                        
                banksel PORTA
                movlw   LEDS
                movwf   PORTA
                bsf     PORTA,EXTRA_LED 
                      
                                        ; bankb   
                banksel TRISB
                movlw   b'00000000' 
                movwf   TRISB
                        
                banksel PORTB
                movlw   LEDS
                movwf   PORTB
                bsf     PORTB,EXTRA_LED 
                      
                goto    $
                      
                end

Which aside from using Code Tidy, I made absolutely no human corrections to it.

It seems to work for me. Have you tried Code Tidy? Pommie posted it here. I would be more than happy to upload it, but I think that honor belongs to Pommie, if he wants to do it or maybe has a newer version. Mine is from 2008.

John
 
Can you get Pommie to agree to make it a sticky for the microcontroller forum?

As mentioned, I haven't had the need for it with the new forum. But back when I first downloaded it, it was about the only way to get decent looking code when posted as text.

John
 
I see it. I have a "Courier 10" in Libre Office, but not a "Courier New", so paste from Libre Office seems to be in the default font of ETO

Cbb:
automagicically was intentional.
 
Hello again,

Seriously? We need a PROGRAM just to paste code text into the forum editor?
To quote from the movie "Galaxy Quest" when one of the crew members saw the engineer having weird sex with a cute alien girl:
"That's just not right" :)

I can probably make a program to do this too, but that seems way too far out for just pasting text.
Just look at the tiny editor on this forum, that one works fine (almost), so why not the main one?
Like i said it should not be hard to fix, just look at the event code for "Paste" in the forum software.
I wonder what language that is written in, and who is responsible for writing/updating that software.
 
Hello again,

Seriously? We need a PROGRAM just to paste code text into the forum editor?
To quote from the movie "Galaxy Quest" when one of the crew members saw the engineer having weird sex with a cute alien girl:
"That's just not right" :)

I suspect your comment is directed at Ian. I just paste from MPLab 8.92 onto this forum without a problem, as clearly demonstrated earlier.

Like i said it should not be hard to fix, just look at the event code for "Paste" in the forum software.
I wonder what language that is written in, and who is responsible for writing/updating that software.

What "it?" Please demonstrate clearly the problem that seems to be is plaguing you.

Here's my synopsis:
1) Post #1 (you): You identify a "problem" with spaces.
2) Post #6 (me) : Your problem can't be duplicated.
3) Post#8 (you): Code tags aren't working for you.
4) Post#9(me): Your experiment didn't show the same problem when I repeated it.
5) Post#10: Ian posted some code that didn't line up well.
6) Posts 13&14(me): I demonstrate two ways to fix the alignment problem Ian experienced.
7) Post#18(you): You sarcastically condemn the need for a "program" to do alignment of code. As I said in post #16, I haven't needed Code Tidy since we got code tags. However, it still exists as an alternative and might well be useful if someone needs to print code when code tags aren't available, say when using Notepad.

John
 
I did dupiicate Mr. Al's bug (paste from external editor) in Linux. No Courier New font in Linux.

1. open libre office
2. select courier 10
3. Compose:
ABCD1234ABCD
1234 ABCD
Paste into Xenforo
(Font not kept)
Select and change to "Courier New"

OOps!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top