PDA

View Full Version : Nice neat code posts



Charles Linquis
- 14th September 2011, 03:56
How is it that everyone else gets the nice formatted code in their posts?

I do a cut-and-past from either MCS or NOTEPAD and my postings are virtually unreadable. The formatting is all messed up, and there are lots of extra spaces, etc.

I swear that the code I write doesn't look so bad to me, but when I post it on the forum, it is a mess.

What should I do?

mister_e
- 14th September 2011, 04:12
Any decent code editor allows you to convert TABs to SPACE, MCS do a decent job at this, MPLAB too.

However, seems from time to any ANY vBulletin board, and some other may screw things up a little bit.

Bellow, two piece of useless code, using the same tab indentation,
in Notepad

VarA VAR BYTE

LABEL1:
IF SOMETHING THEN
GOSUB LABEL1
DO USELESS THING
ENDIFIn MCSP

VarA VAR BYTE

LABEL1:
IF SOMETHING THEN
GOSUB LABEL1
DO USELESS THING
ENDIFMCSP being the one who keep MY personnal indentation. But yeah, from time to time some line WILL be screwed up.

HenrikOlsson
- 14th September 2011, 06:35
I always have to go back in and re-edit code that is cut'n'pasted to the forum. Blank lines gets removed, "columns" that "straight" when I copy the code is not in the post and so on. Add to that the preview doesn't properly reflect the way it shows in the actual post makes it very time consuming.

Like Charles I ask, what am I doing wrong.

/Henrik.

EDIT: Then we have posts where the code has been posted as HTML to preserve the color-syntax etc (nice!) that are now messed up. Darrel linked to one of his pieces just the other day.

lester
- 14th September 2011, 08:25
HTML posting is NOT allowed on the PICBASIC Community Forum, not only because of security issues, but also because we cannot prevent people using MS word to create a document and then posting the garbage Word HTML in the forum...which causes a number of issues that may prevent the post or the forum area from displaying correctly.

Thus if you wish to post formatted text, you may use the editor and some BB code. All of the articles in the WIKI are produced that way and they are not unreadable.

Using the built in editor and some BB Code (http://picbasic.co.uk/forum/misc.php?do=bbcode) does NOT prevent the creation of clean and readable posts.

HenrikOlsson
- 14th September 2011, 08:49
Well, if you say so Lester but that's the first time I've heard it's not allowed. There's even been guides on how to do it, here's a thread (http://www.picbasic.co.uk/forum/showthread.php?t=11794) where one of the moderators explains how to do it (though I don't think Dave was a moderator at the time) and also the code that at the time looked perfect but not any more. And I belive this is the orignal thread (http://www.darreltaylor.com/files/Show%20us%20your%20Colors_%20-%20MEL%20PICBASIC%20Forum.htm).

I'm not saying it's not possible to create good looking readable code but simply copy and paste from MCSP to within code tags usually doesn't work that well.

/Henrik.

lester
- 14th September 2011, 09:57
OK, a few posts went through with HTML in them. BUT as the Moderators are aware and a few forum users are aware. there were one or two posts that had really badly bloated and badly formatted HTML in them, that caused the forum pages NOT to load or Crash when viewing those threads.

HTML will not solve your problem, but WILL definitely allow users to crash certain pages and damage the smooth running of the forum.

Sorry, but at present i don't have time to produce a tutorial on how to post code examples, formatted with colour. But if you google it you'll see that its quite faesable, if you really have to.

For sure, I will not enable HTML posting for users, I don't have the time to sort out the issues that will arise !

HenrikOlsson
- 14th September 2011, 11:17
Hi Lester,
No, I'm not particularly interested in the colours and I'm not asking you to enable/allow .html if that's a problem. My point was that many of the posts were they have already been used are no longer readable, like the ones in the thread I linked to. But if they wasn't supposed to be there in the first place then you've made your point.

Again, I know how to format the code using BB-code but that's just it - simply cut'n'paste well formated code from an editor/IDE to a post usually needs quite a bit of touch-up afterwards. Again, disregard the colours, I'm talking about tabs, blank lines etc. Just what Charles mentioned in his original post. I'm not saying it's yours or the forums fault. I'm, like Charles, asking what's needed to preserve the formatting when copying code into a post.

/Henrik.

Charles Linquis
- 14th September 2011, 13:40
Below is an unedited cut-and-paste from MCS. Even when I go back and try to clean it up, the final results look terrible. I'd post more code if it didn't look so bad.




GetNum:
Result =
0
MaxNum =
5 ; set for max number of digits you will
accept
YY =
1

POSN=0
IsNeg =
0
TimedOut =
0
ArrayWrite InputString,[Rep
$FF\8] ; Fill with
$FF

GetMoreN:

HSERIN
9000,InputTimeout,[Keyin]

IF Keyin = ESC THEN
ZeroNum
If
Keyin = CR THEN
DunInputn

If allowNeg
then
IF
Keyin = "-" and Posn = 0 THEN


IsNeg =
1

Hserout
["-"]

goto
GetMoreN

ENDIF

endif

IF Keyin
= BS
THEN

HSEROUT
[BS,SP,BS]

IF POSN > 0
THEN

POSN = POSN -
1

InputString [POSN] =
$FF

GOTO
GetMoreN

ENDIF


ENDIF
IF Keyin < "0" or Keyin
> "9" THEN GetMoreN
HSEROUT
[Keyin]
InputString [POSN] = Keyin
- "0"
IF POSN >= (MaxNum -1)
THEN DunInputN
POSN = POSN
+1
GOTO
GetMoreN
DunInputN:
For xN = 7
to 0 STEP - 1

IF InputString[XN]= 255 THEN
NoMoreNum

Result = Result +
(InputString[xN]*YY)

YY = YY
*10
NoMoreNum:

Next
XN


If Isneg
then
If result <
32768
then

Result = 0 - Result

else

mackrackit
- 14th September 2011, 14:20
Charles,

Attach your code (BAS/PBP) so I can try it if you do not mind.

HankMcSpank
- 14th September 2011, 14:28
I have to agree with others here ...not only posting code snippets can be plain ugly....also reading others' old snippets with with the wrong (now incompatible) formatting renders them virtually unreadable.

mackrackit
- 14th September 2011, 14:33
Just testing...

Copy/Paste from Programmers Notepad


' 12F675
' 09/05/2011
DEFINE OSC 4
' SET FOR INTERNAL OSC AND MCLRE OFF
#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
#ENDCONFIG

ANSEL=%00000000 ' ADC SET FOR DIGITAL
CMCON=7 ' COMPARATOR SET FOR DIGITAL
SWITCH_OFF VAR GPIO.1 ' PUSH BUTTON FOR PUMP OFF
SWITCH_RUN VAR GPIO.2 ' PUSH BUTTON FOR PUMP ON
LED_RUN VAR GPIO.0 ' INDICATE RUN SIGNAL SENT
LED_OFF VAR GPIO.5 ' INDICAT STOP SIGNAL SENT
TX VAR GPIO.4 ' DATA SEND PIN
BAUD CON 18030 ' 18030 = 600 BAUD

START: ' SEND OFF SIGNAL AT POWER UP
PAUSE 1000
HIGH LED_OFF
SEROUT2 TX, BAUD,["OFF",13]
DO ' LOOP TO CHECK PUSH BUTTONS
DO WHILE SWITCH_RUN = 1 ' CHECK ON PUSH BUTTON
' IF BUTTON PUSHED
HIGH LED_RUN ' RUN INDICATOR ON
LOW LED_OFF ' OFF INDICATOR OFF
PAUSE 50 ' SETTLE TIME
SEROUT2 TX, BAUD,["RUN",13]
' SEROUT2 TX, BAUD,[HEX CNT,13]
LOOP
DO WHILE SWITCH_OFF = 1 ' CHECK OFF PUSH BUTTON
' IF BUTTON PUSHED
HIGH LED_OFF ' OFF INDICATOR ON
LOW LED_RUN ' RUN INDICATOR OFF
PAUSE 50 ' SETTLE TIME
SEROUT2 TX, BAUD,["OFF",13]
' SEROUT2 TX, BAUD,[DEC CNT,13]
LOOP
LOOP



Copy/Paste from MCS


' 12F675
' 09/05/2011
DEFINE OSC 4
' SET FOR INTERNAL OSC AND MCLRE OFF
#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
#ENDCONFIG

ANSEL=%00000000 ' ADC SET FOR DIGITAL
CMCON=7 ' COMPARATOR SET FOR DIGITAL
SWITCH_OFF VAR GPIO.1 ' PUSH BUTTON FOR PUMP OFF
SWITCH_RUN VAR GPIO.2 ' PUSH BUTTON FOR PUMP ON
LED_RUN VAR GPIO.0 ' INDICATE RUN SIGNAL SENT
LED_OFF VAR GPIO.5 ' INDICAT STOP SIGNAL SENT
TX VAR GPIO.4 ' DATA SEND PIN
BAUD CON 18030 ' 18030 = 600 BAUD

START: ' SEND OFF SIGNAL AT POWER UP
PAUSE 1000
HIGH LED_OFF
SEROUT2 TX, BAUD,["OFF",13]
DO ' LOOP TO CHECK PUSH BUTTONS
DO WHILE SWITCH_RUN = 1 ' CHECK ON PUSH BUTTON
' IF BUTTON PUSHED
HIGH LED_RUN ' RUN INDICATOR ON
LOW LED_OFF ' OFF INDICATOR OFF
PAUSE 50 ' SETTLE TIME
SEROUT2 TX, BAUD,["RUN",13]
' SEROUT2 TX, BAUD,[HEX CNT,13]
LOOP
DO WHILE SWITCH_OFF = 1 ' CHECK OFF PUSH BUTTON
' IF BUTTON PUSHED
HIGH LED_OFF ' OFF INDICATOR ON
LOW LED_RUN ' RUN INDICATOR OFF
PAUSE 50 ' SETTLE TIME
SEROUT2 TX, BAUD,["OFF",13]
' SEROUT2 TX, BAUD,[DEC CNT,13]
LOOP
LOOP

dhouston
- 14th September 2011, 14:51
The problem lies with most of the IDEs/editors. They use a varying number of spaces for tabs - some allow users to specify the value. As Mr. E noted, most have a convert tabs to spaces function but the simplest thing to do is to make your various editors agree on how many spaces make a tab or always use spaces rather than tabs.

Heckler
- 14th September 2011, 18:32
OK... I'll jump in here with a question :D

In order to go back and reclaim those posts that were originally posted with HTML (when it was allowed)...

Would it be possible to re-enable HTML, for a short time, then copy the code that was posted and paste back in the code, without the HTML, then dis-able the HTML??

Thus re-covering the VALUABLE code examples that have for now been lost.

This might entail a lot of manual work... but there are VALUABLE code examples, like LCD BARGRAPHS, that are currently unusable.

I sure hate to see all those posts and thread lost.

mackrackit
- 14th September 2011, 18:37
As time permits and when I run across those I convert them to BB code.

Let me know where they are and I will add them to the list.

Charles Linquis
- 14th September 2011, 18:56
I always have MCSP set to "convert tabs to spaces". I tried to attach my source but, it didn't "take". I'll send you a link instead.

http://dl.dropbox.com/u/566712/GetNumber_part.bas

mackrackit
- 14th September 2011, 19:13
Straight from the link...
Who knows... but what browser do you use? It maybe something other than the code editor.


'************************************************* ***************
'* Name : Number Input routine *
'* Author : Charles Linquist *
'* Notice : Copyright (c) 2011 Charles Linquist *
'* : All Rights Reserved *
'* Date : 9/13/2011 *
'* Version : 1.0 *
'* Notes : For the forum *
'* : *
'************************************************* ***************

DEFINE OSC 40
DEFINE NO_CLRWDT 1
DEFINE _18F8723 1
DEFINE HSER_RCSTA 90H
DEFINE HSER_TXSTA 20H
DEFINE HSER_CLROERR 1
define HSER_BAUD 9600



Keyin var byte
Maxnum var byte
YY var word
POSN var byte
IsNeg var bit
AllowNeg var bit
TimedOut var bit
InputString var byte [10]
Result Var word
XN var byte

BS CON 8
ESC cON 27
LF con 10
SP con 32
CR con 13

TRISC = %10111111 ; Just for the serial port
topp:
allowneg = 1

hserout [CR,Lf,"Input a number "]
gosub getnum
hserout [CR,LF,"You entered "]

IF isneg = 1 then
Hserout [SDEC Result,CR,LF]
ELSE
hserout [dec Result,CR,LF]
ENDIF

Goto topp


GetNum:
Result = 0
MaxNum = 5 ; set for max number of digits you will accept
YY = 1
POSN=0
IsNeg = 0
TimedOut = 0
ArrayWrite InputString,[Rep $FF\8] ; Fill with $FF

GetMoreN:
HSERIN 9000,InputTimeout,[Keyin]
IF Keyin = ESC THEN ZeroNum
If Keyin = CR THEN DunInputn
If allowNeg then
IF Keyin = "-" and Posn = 0 THEN
IsNeg = 1
Hserout ["-"]
goto GetMoreN
ENDIF
endif
IF Keyin = BS THEN
HSEROUT [BS,SP,BS]
IF POSN > 0 THEN
POSN = POSN - 1
InputString [POSN] = $FF
GOTO GetMoreN
ENDIF
ENDIF
IF Keyin < "0" or Keyin > "9" THEN GetMoreN
HSEROUT [Keyin]
InputString [POSN] = Keyin - "0"
IF POSN >= (MaxNum -1) THEN DunInputN
POSN = POSN +1
GOTO GetMoreN
DunInputN:

More code here

HankMcSpank
- 14th September 2011, 19:18
This might entail a lot of manual work... but there are VALUABLE code examples, like LCD BARGRAPHS, that are currently unusable.



Yeah, that was the one I gave up trying to read just a couple of nights ago...

http://www.picbasic.co.uk/forum/showthread.php?t=2359&page=1

mackrackit
- 14th September 2011, 19:38
Yeah, that was the one I gave up trying to read just a couple of nights ago...

http://www.picbasic.co.uk/forum/showthread.php?t=2359&page=1

That is one that the converter did not like. I just tried it again and no luck. Darrel should be able to fix it quicker than me hand coding it being he has the source code...

Charles Linquis
- 14th September 2011, 20:24
I guess next time I'll just send you my code and you can post it!

mackrackit
- 14th September 2011, 20:57
I guess next time I'll just send you my code and you can post it!
OK, That will work too :)

Heckler
- 14th September 2011, 21:36
Hey Dave,

I went into my PIC files and found that way back when... I had saved a copy of the LCDbargraphs thread as a "web page complete".

I looked at it and it looks complete. I have attached it. I wonder if you (or Darrel) can use it to rebuild that thread.

If NOT then others can down load this attachment and they should be able to get the gist of the LCD bargraphs from it.
(It coud be attached to that thread also as a downloadable file)

here ya go...
P.S. I had to zip it up because it was causing an error when I tried to upload the .mht file.

dhouston
- 14th September 2011, 22:02
Anyone who wants to see it can unzip it and open it in Internet Explorer. It's probably viewable in other browsers - I just double-clicked and IE loaded the MHTML file.

In fact, one can probably convert it to PDF or any other desired form.

Charles Linquis
- 15th September 2011, 03:09
I normally use IE9. I'll try it with FireFox.

lester
- 15th September 2011, 07:50
There are TWO issues being addressed in this thread:


Use of HTML in posts
posting clean readable code examples

The posting of clean readable code examples is clearly possible for the vast majority of users on this and out other forums. Mackrackit has shown by example above, that its possible to post clear text. And the use of BBCode will allow for additioanl text formatting.

Where the use of BBCode is too tiresome, a zip file can be uploaded - within the limits of file size allowed. If users would like a file repository into which files can be uploaded and linked to from the forum posts, i'll arrange that - just let me know.


By way of further explaination; storing files in the forum database is OK when the forum is young and empty and the files are small, but when its as old and large as this forum and the files are many, it causes the database to grow to epic proportions - which is costly in storeage and more difficult to manage.

The rest of this, rather long winded post, is related to HTML, an explaination of why we have an issue with HTML in posts.


Would it be possible to re-enable HTML, for a short time, then copy the code that was posted and paste back in the code, without the HTML, then dis-able the HTML??

NO, i'm afraid that re enabling HTML is NOT an option. HTML was never actually allowed. For a relatively short period of time, an oversight did not dis-allow it in all forum areas. Thus we ended up with some HTML that killed some forum areas, which brought the issue to light, after which we ensured that HTML was dis-allowed in all areas.

If we allow HTML now:


some of the HTML posted in the paste WILL break the forum display presented to the user whe the user views it.
I cannot check that all HTML posted is clear of injection issues / malicious code / unintentional css references. Not all of the forum users are nice sensible people - we ahve a fair number of known pirates on this forum ! We dont trust them. I have a duty of care to the users , I will be held respnsible by the users (and others) if they fall foul of malicious code injected via raw HTML in posts.
Many of the posts that include HTML code , are very badly formatted, referencing fonts and formating that is unsupported by the forum. These refernces may / maynot be handled correctly by the forum parser, thus we dont know what effect they will have. - remember the forum has undergone serveral updates since the posting of that poorly formatted code.

Note: The use of MS Word or MS Frontpage to generate MS proprietary HTML shoould be avoided at all costs, if you ever want compatibility accross browsers and systems.



Thus re-covering the VALUABLE code examples that have for now been lost.

IF, the HTML posted is valid and compliant, there should be NO reason why it cannot be copied from the forum page and pasted into any html editor...viewed and exported into another format.

A very good FREE HTML editor is KOMPOZER (http://kompozer.net/) , KompoZer is a complete web authoring system that combines web file management and easy-to-use WYSIWYG web page editing.

The Editor developers could go a long way to assist in the production of forum ready code output, why not petition them? The forum system used here is the most popular in the world. The issues that you are experiencing affect ALL of the popular forum systems - i.e they dont allow raw HTML in posts because of the security issues, the editors on most of them are very similar to the editor on this forum. Supporting BB-Code.

Note:


if you dont understand why HTML is avoided in forum posts 'Google' it.
To enhance the readability of posts, with additional formatting, use BBCode (http://www.picbasic.co.uk/forum/misc.php?do=bbcode) NOT HTML.

mackrackit
- 15th September 2011, 09:29
Fixed
http://www.picbasic.co.uk/forum/showthread.php?t=2359&p=12482#post12482

Thank you Dwight!

P.S. I had to zip it up because it was causing an error when I tried to upload the .mht file.

Another MS thing....

Charles Linquis
- 16th September 2011, 02:18
I just noticed one thing: I'm using IE9. Sometimes I would get extra lines on my screen while viewing the posts in this forum (still readable, but annoying). The extra lines and slighly malformed characters appeared ONLY when I am on 'the forum'. IE9 works perfectly everywhere else.
At the bottom of the browser window you can select which 'mode' you want IE9 to run in. It lets you choose "IE7 standards", "IE8 standards" or "IE9 standards". I WAS using IE9 standards, but I just switched to IE8 standards. VOILA! Now the forum looks better. Maybe my code posts will work better as well. I'll soon find out.

So, while IE9 works better than IE8 for most everything, that is not true when viewing this forum.

Demon
- 16th September 2011, 04:10
That's interesting. I was getting a sort of "static" across my text before POSTing; as if random lines of pixels were broken on the screen, but only in my reply text.

I don't think I get that on any other forum.

Robert

lester
- 16th September 2011, 05:13
IE9 works perfectly everywhere else.

IE9 works better than IE8 for most everything, that is not true when viewing this forum. 5978

From my experienece and understanding of the current situation (looking at Microsofts Connects outstanding issues list) Those statements are not the norm !

IMHO, the simple answer is dont use IE9....Firefox is an established alternative, that WORKS.

google something like "IE9 extra line breaks" you'll see its NOT just this forum, its an issue with many sites when browsing with IE9.

The next update to the forum will contain some fixes that help with IE9 issues, but thats going to be a few months away.

Sorry, but there is nothing that i can do to fix that at present.

You might want to join Microsoft Connect to keep up with the known issues and some work arounds for IE9 :)......several thousands! though you maybe surprised to see that the main drive now seems to be to get IE10 out of the door in an effort to move forward. Dont take my word for it, get it from the horses mouth. Steves your man!
5979

The forum is not perfect......but the issues you mention are not specific to this forum.

lester
- 16th September 2011, 06:13
OK, before it raises it head, there is another IE issues that you should be aware of

If you create a post with a \ in the subject line, users will not be avle to view the post in IE.

HTML does not diss-allow this. However IE is breaks the url at the slash, its incorrect.

Ioannis
- 16th September 2011, 08:10
On post #28 and when i place the mouse pointer over the images, these images open automatically on a bigger window. It is the first time I encounter something like this.

Is it a new feature? Or an IE8 bug? Ifit is a bug, it is a nice one!

Ioannis

P.S. Is it me or Balmer is really ridiculous??

lester
- 16th September 2011, 08:34
OK, you used to have to click to open the image in a shadow box, now, just hover over the image.

I implemented this a while back. I was expecting someone to complain, but heard nothing.....actually i'd forgotten about it !

Steve, either a complete and utter nutter and fun to work with....or maybe just a complete nutter. I don't know. But for sure MS needs to catch up.

mister_e
- 16th September 2011, 12:42
An interesting WYSIWYG BBCode editor
http://www.ragepank.com/wysiwyg-bbcode/

Another one
http://www.kyrsoft.com/downloads/downloads.html#Bbed

Some emoticons may not work properly but, no real big deal

mister_e
- 16th September 2011, 13:39
Just to avoid confusion on the previous, the first WYSIWYG BBCode editor I was talking about is called WYSIWYG BBCode Editor

Bellow is the direct link
http://www.shajul.net/software/wysiwyg-bbcode-editor/

As I said, some emoticons may not work properly, but this is something that looks easy to fix by editing the smileys.ini file.

lester
- 17th September 2011, 04:26
Has anyone noticed any changes to the editor? or advanced option?


The new Editor



http://www.itsabhik.com/wp-content/uploads/2011/06/ckeditor.jpg
The forum is now running with the new CKEditor (http://ckeditor.com/) (formerly known as FCKeditor). It is more powerful and has more feature than the previous editor.

CKEditor is a text editor to be used inside web pages. It's a WYSIWYG editor, which means that the text being edited on it looks as similar as possible to the results users have when publishing it. It brings to the web common editing features (http://ckeditor.com/end-user-features)found on desktop editing applications like Microsoft Word and OpenOffice.

Currently not every CKeditor feature is available on this forum, additional features will be enabled if the CKeditor proives popular and useful.

Points to note that may address some issues that were lacking in the old editor are;



This Editor has an “Auto Save” function, which comes handy while typing a long blog post or posting a new thread with lots of content. This sis set to auto save every 30 seconds.
CKEditor is full compatibility with “WebKit” browsers (http://en.wikipedia.org/wiki/WebKit) such as Google Chrome and Safari.
CKEditor has an “Paste from Word” feature which lets you preserve the as much of Microsoft Word Text Formatting as possible while pasting the content directly from a document.

CKEditor offers full accessibility functionality, its fast loading and has awesome AJAX capabilities.

mackrackit
- 17th September 2011, 05:53
Yes, I noticed a difference. Looking good.

Is the autosave making use of the HTML5 data storage function?

Ioannis
- 17th September 2011, 11:44
Sure we did!

I had some difficulties in logging in from the update of the system till now...

Tools looking very nice and I think is really WYSIWYG.

Ioannis

Demon
- 17th September 2011, 21:35
I didn't read "formerly known as FCKeditor" the first time. :D

mister_e
- 18th September 2011, 13:05
The missing letter is ?........... :D

lester
- 18th September 2011, 13:34
Now, come on children......stop the giggling!

The FCK in FCKeditor stands for Frederico Caldeira Knabben, the creator of the editor. Those letters resemble a well-known vulgarity in the English language, (something that Frederico, a native Brazilian , was unaware of when he first released the program). As a result, Knabben changed the program's name to CKEditor beginning with v3.0. The CK letters now stand for Content and Knowledge.

The ability to grab attention with those letters in the English speaking community was exploited by the fashion house French Connection in their brand mark FCUK French Connection UK

OK, lesson over...back to work.

Charles Linquis
- 18th September 2011, 22:54
Wow. I didn't mean for my post to cause such a commotion, but now I'm glad. Everyone wins!