Author Topic: OxygenBasic [code=o2]..[/code]  (Read 3235 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
OxygenBasic [code=o2]..[/code]
« on: November 03, 2014, 03:47:50 AM »
Forum Syntax Highlighting :)

Mike Lobanovsky

  • Guest
Re: OxygenBasic [code=o2]..[/code]
« Reply #1 on: November 03, 2014, 05:47:56 AM »

Arnold

  • Guest
Re: OxygenBasic [code=o2]..[/code]
« Reply #2 on: February 23, 2015, 01:34:57 AM »
Hello,

this kind of Syntax Highlighting looks very nice. As I have not followed the Forum for some months I am going to catch up on previous topics and I found several listings which I copied into a snippets folder. I can also find special highlighted snippets if I search for 'code=o2'.

Unfortunately copying and pasting does not work very well with these special snippets, as line breaks are not copied and linenumbers are included. Therefore I wrote a small utility to format the text in the clipboard and save it to a _.o2bas file which then can be renamed. Maybe it is of some benefit for other users too? I use it this way:

I created a folder "ForumSnippets" and stored code_o2.exe in this directory. I can now select and copy the highlighted snippets into the clipboard. Then in Windows Explorer I start Code_o2.exe. (filename because code=o2).

The mini-app does not catch all cases and can sometimes be confused. But it should save some manual labor.

Roland

Code: OxygenBasic
  1.    ' Small utility to format OxygenBasic Forum code snippets
  2.   ' with Syntax Highlighting. (heading: OxygenBasic)
  3.   ' Usage: Code_o2.exe should be copied into the directory of your code snippets.
  4.   '
  5.   ' Select the code snippet and copy into the clipboard.
  6.   ' In Windows Explorer call Code_o2.exe and the _.o2bas file will be created.
  7.   '
  8.   '
  9.  
  10.    $ filename "Code_o2.exe"
  11.    includepath "$/inc/"
  12.    '#include "RTL32.inc"
  13.   '#include "RTL64.inc"
  14.  
  15.  
  16.    % CF_TEXT 1
  17.    string crlf = chr(13, 10)  
  18.  
  19.    ! GlobalUnlock lib "kernel32.dll" (sys hMem) as bool
  20.    ! GlobalLock lib "kernel32.dll" (sys hMem) as sys
  21.    ! OpenClipboard lib "user32.dll" (sys hWndNewOwner) as bool
  22.    ! CloseClipboard lib "user32.dll" () as bool
  23.    ! GetClipboardData lib "user32.dll" (sys uFormat) as sys  
  24.  
  25.  
  26.    ' From \examples\system\clipboard.o2bas
  27.   '
  28.   '----------------------
  29.   'READING FROM CLIPBOARD
  30.   '======================
  31.   'Get exclusive access to the clipboard
  32.   '=====================================
  33.   OpenClipboard 0 'hwnd
  34.  
  35.    'get data from clipboard
  36.   '=========================
  37.   h = GetClipboardData CF_TEXT
  38.  
  39.    'Lock the handle.
  40.   '================  
  41.   k = GlobalLock h
  42.  
  43.    'Copy it
  44.   '=======
  45.   zstring z at k
  46.    string s=z
  47.  
  48.    'Unlock the memory block
  49.   '=======================
  50.   GlobalUnlock h
  51.  
  52.    'Release the Clipboard
  53.   '=====================
  54.   CloseClipboard '0 'hwnd  
  55.  
  56.  
  57.    ' Removing the linenumbers from captured text
  58.   ' and create _.o2bas file in the current directory
  59.  
  60.  
  61.    int fin=len(s), num=0, pos1=1, pos2=1
  62.    string new_s = "", line, num1_s, num2_s
  63.    
  64.    num1_s = str(num) & "."
  65.    nUM2_s = str(num+1) & "."
  66.  
  67.    ' small check
  68.   x=0
  69.    do
  70.       x += 1: if x = 10 then exit do
  71.       ns = str(x) & "."
  72.       pos2 = instr(1, s, ns)
  73.       if pos2 > 0 then
  74.          num = x-1: exit do
  75.       end if
  76.    end do  
  77.  
  78.    If left(s,2) <> "1." then
  79.       print "Line 1 does not begin with 1." crlf "File can be faulty / incomplete."
  80.    end if  
  81.  
  82.    while pos1 < fin
  83.       num += 1
  84.       num1_s = str(num) & "."
  85.       nUM2_s = str(num+1) & "."
  86.       pos1 = pos2 + len(num1_s)    
  87.       pos2 = instr(pos1, s, num2_s)
  88.       if pos2 = 0 then exit while ' no number found
  89.      length = pos2-pos1
  90.       line = mid(s, pos1, length) & crlf
  91.       new_s &= line
  92.    wend
  93.  
  94.    putfile("_.o2bas", new_s)
  95.      
  96.    print "_.o2bas created." crlf crlf "Done"      
  97.        
  98. done:  
  99.  
  100.  
  101.  

.

Arnold

  • Guest
Re: OxygenBasic [code=o2]..[/code]
« Reply #3 on: March 22, 2016, 03:18:52 AM »
There is another trick which could be helpful:

I select and copy the syntax highlighted code and then open Wordpad. I then paste the code into Wordpad and the line numbers should be suppressed. Then I can save the file as a dos text document as <progname>.o2bas.

Are there other editors available which would suppress the line numbers when pasting Forum Syntax highlighted code? Scite or PsPad do not work for this purpose.

Roland

JRS

  • Guest
Re: OxygenBasic [code=o2]..[/code]
« Reply #4 on: March 22, 2016, 09:20:08 AM »
Quote
There is another trick which could be helpful?

Click the quote graphic and copy the code from there. (raw text, no syntax highlighter issues)

Arnold

  • Guest
Re: OxygenBasic [code=o2]..[/code]
« Reply #5 on: March 22, 2016, 11:45:47 AM »
Hi John,

Quote
Click the quote graphic and copy the code from there. (raw text, no syntax highlighter issues)

Maybe my message was unclear? But how do you paste as a guest e.g. the OxygenBasic Code above into your editor? I get this in Scite or PsPad:

Code: [Select]
1.   ' Small utility to format OxygenBasic Forum code snippets2.   ' with Syntax Highlighting. (heading: OxygenBasic)3.   ' Usage: Code_o2.exe should be copied into the directory of your code snippets.4.   '5.   ' Select the code snippet and copy into the clipboard.6.   ' In Windows Explorer call Code_o2.exe and the _.o2bas file will be created.7.   '8.   '9. 10.   $ filename "Code_o2.exe"11.   includepath "$/inc/"12.   '#include "RTL32.inc"13.   '#include "RTL64.inc"14.  15. 16.   % CF_TEXT 117.   string crlf = chr(13, 10)  18.  and so on ...

Using an editor like Wordpad which can manage rtf or doc files I will get at least the code separated into lines without line numbers.

Roland

JRS

  • Guest
Re: OxygenBasic [code=o2]..[/code]
« Reply #6 on: March 22, 2016, 06:36:18 PM »
Roland,

My response was based on copying code from another users post using the syntax highlighting feature. It opens an edit window with the code in a standard text format to copy / past into your favorite text editor or IDE. You must be a member of the forum to open a quote edit window.

Arnold

  • Guest
Re: OxygenBasic [code=o2]..[/code]
« Reply #7 on: March 23, 2016, 01:35:24 AM »
Hi John,

thank you. Now I understand. I always copied and pasted syntax highlighted code as a guest. Until now I did not notice the quote graphic supplied with the messages when visiting the forum as a member. But using the quote graphic feature works of course fine and will save some unnecessary workaround.

Roland