TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: highflyingbird on December 22, 2010, 05:28:02 AM

Title: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: highflyingbird on December 22, 2010, 05:28:02 AM
Can I use Syntax Highlighting for my Lisp code In my blog?(e.g, blogspot)
Thanks for your any help!
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: qjchen on December 22, 2010, 07:27:22 AM
 :-D

you can get something from this page:

http://ivox-tech.blogspot.com/2006/10/autolisp-highlighter.html
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: ElpanovEvgeniy on December 22, 2010, 08:27:59 AM
my variant... (http://elpanov.com/index.php?id=22)
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: MP on December 22, 2010, 09:36:51 AM
Just add some definitions to your site's css style sheet:

Code: [Select]
/* ...*/

/******************** LISP Attributes ********************/

.function {
    font-weight: bold;
    color: yellow;
}

.command {
    font-weight: bold;
    color: yellow;
}

.call {
    color: #ff6633;
}

.comment1 {
    color: #00ff00;
}
   
.comment2 {
    color: #ff66ff;
}

.copyright {
    color: #4080ff;
}

.result {
    color: #5090ff;
}

.notes {
    color: #ffff80;
}
 
.error {
    font-weight: bold;
    color: #ff0000;
}

.data {
    color: #66ffff;
}

.alert {
    font-weight: bold;
    color: #00ffff;
}

/******************** pre definition ********************/
 
#content pre {
    background: #202020;
    font-size: 12px;
    color: #e0e0e0;
    margin: 5px 5px 10px 5px;
    padding: 5px 5px 5px 10px;
    border: 1px solid #DDDDDD;
    font-family: Consolas, "lucida console", "courier new", monospace;   
}

/* ... */

Take some code:

Code: [Select]
(defun _ToBase64 ( text )

    ;;  Copyright (c) 2008 Michael Puckett All rights reserved.
    ;;  For terms of use see http://XXXXXXXXXX.com/terms-of-use

    (if (/= "" text)

        (   (lambda ( codes map / _MaskThenShift _Map len result )

                (defun _MaskThenShift ( int mask shift )
                    (lsh (logand int mask) shift)
                )

                (defun _Map ( key ) (nth key map))

                (while (< 2 (setq len (length codes)))
                    (setq result
                        (append result
                            (mapcar '_Map
                                (list
                                    (_MaskThenShift (car codes) 252 -2)
                                    (logior
                                        (_MaskThenShift (car codes) 3 4)
                                        (_MaskThenShift (cadr codes) 240 -4)
                                    )
                                    (logior
                                        (_MaskThenShift (cadr codes) 15 2)
                                        (_MaskThenShift (caddr codes) 192 -6)
                                    )
                                    (logand (caddr codes) 63)
                                )
                            )
                        )
                        codes (cdddr codes)
                    )
                )

                (vl-list->string
                    (if (null codes) result
                        (append result
                            (mapcar '_Map
                                (if (eq 1 len)
                                    (list
                                        (_MaskThenShift (car codes) 252 -2)
                                        (_MaskThenShift (car codes) 3 4)
                                    )
                                    (list
                                        (_MaskThenShift (car codes) 252 -2)
                                        (logior
                                            (_MaskThenShift (car codes) 3 4)
                                            (_MaskThenShift (cadr codes) 240 -4)
                                        )
                                        (_MaskThenShift (cadr codes) 15 2)
                                    )
                                )
                            )
                        )
                    )
                )
            )

            (vl-string->list text)

            (_Base64Map) ;; external call

        )
        ""
    )
)

Format it accordingly for html posting (I have a proggy I'm working on (not public yet) that does it for me):

Code: [Select]
<pre>(defun <span class="function">_ToBase64</span> ( text )

    <span class="comment1">;;  Copyright (c) 2008 Michael Puckett All rights reserved.
    ;;  For terms of use see http://XXXXXXXXXX.com/terms-of-use</span>

    (if (/= "" text)

        (   (lambda ( codes map / _MaskThenShift _Map len result )

                (defun <span class="function">_MaskThenShift</span> ( int mask shift )
                    (lsh (logand int mask) shift)
                )

                (defun <span class="function">_Map</span> ( key ) (nth key map))

                (while (&lt; 2 (setq len (length codes)))
                    (setq result
                        (append result
                            (mapcar '<span class="call">_Map</span>
                                (list
                                    (<span class="call">_MaskThenShift</span> (car codes) 252 -2)
                                    (logior
                                        (<span class="call">_MaskThenShift</span> (car codes) 3 4)
                                        (<span class="call">_MaskThenShift</span> (cadr codes) 240 -4)
                                    )
                                    (logior
                                        (<span class="call">_MaskThenShift</span> (cadr codes) 15 2)
                                        (<span class="call">_MaskThenShift</span> (caddr codes) 192 -6)
                                    )
                                    (logand (caddr codes) 63)
                                )
                            )
                        )
                        codes (cdddr codes)
                    )
                )

                (vl-list-&gt;string
                    (if (null codes) result
                        (append result
                            (mapcar '<span class="call">_Map</span>
                                (if (eq 1 len)
                                    (list
                                        (<span class="call">_MaskThenShift</span> (car codes) 252 -2)
                                        (<span class="call">_MaskThenShift</span> (car codes) 3 4)
                                    )
                                    (list
                                        (<span class="call">_MaskThenShift</span> (car codes) 252 -2)
                                        (logior
                                            (<span class="call">_MaskThenShift</span> (car codes) 3 4)
                                            (<span class="call">_MaskThenShift</span> (cadr codes) 240 -4)
                                        )
                                        (<span class="call">_MaskThenShift</span> (cadr codes) 15 2)
                                    )
                                )
                            )
                        )
                    )
                )
            )

            (vl-string-&gt;list text)

            (<span class="call">_Base64Map</span>) <span class="comment2">;; external call</span>

        )
        ""
    )
)</pre>

Voila (sorry for the ugly grab: the swamp is resizing the image, here's the crispy original: http://i56.tinypic.com/35ls1th.jpg):

(http://i56.tinypic.com/35ls1th.jpg)

My bent on highlighting is I only want to see 2 variations of comments, function definitions, calls, errors, data and output. Adding colors for all functions, strings etc. just gets too garish for me and detracts from what I want to achieve: clarity showing what I've done.

An aside, many folks use a syntax highlighter by Alex Gorbatchev. Search the net, there's many adaptions, e.g. for wordpress etc. All you have to do is tweak it for lisp. I didn't go that route because I had specific wants not available with his plug-in.
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: Lee Mac on December 22, 2010, 09:39:34 AM
Another couple of examples  :-)

http://lee-mac.com/attractors.html (http://lee-mac.com/attractors.html)

http://lee-mac.com/layerstatus.html (http://lee-mac.com/layerstatus.html)

I use quite a few more colours than Michael however  :lol:
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: MP on December 22, 2010, 09:56:15 AM
I use quite a few more colours than Michael however  :lol:

Nothing readability (http://lab.arc90.com/experiments/readability) can't fix. :evil:
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: Lee Mac on December 22, 2010, 10:06:01 AM
I use quite a few more colours than Michael however  :lol:

Nothing readability (http://lab.arc90.com/experiments/readability) can't fix. :evil:

^^ Pretty cool  8-)
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: alanjt on December 22, 2010, 10:07:52 AM
I use quite a few more colours than Michael however  :lol:

Nothing readability (http://lab.arc90.com/experiments/readability) can't fix. :evil:
Very cool!
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: JohnK on December 22, 2010, 10:54:52 AM
I use my editor.
Code: [Select]
( (lambda (/ vim)
    (setq vim (vlax-create-object "Vim.Application"))
    (vlax-import-type-library
      :tlb-filename "C:/vim/vim72/gvim.exe"
      :methods-prefix "vimm-")
    (vimm-sendkeys vim ":e\ c:\\tmp\\lsp_file.lsp<CR>")
    (vimm-sendkeys vim ":cd\ %:p:h<CR>")
    (vimm-sendkeys vim ":TOhtml<CR>")
    (vimm-sendkeys vim ":w<CR>")
    (vimm-sendkeys vim ":close<CR>")
    (vimm-sendkeys vim ":qa<CR>")
    (vlax-release-object vim)
    (princ)
    )
 )
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: MP on December 22, 2010, 11:07:10 AM
That works pretty well John. If only I didn't hate vim. :/
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: JohnK on December 22, 2010, 11:10:42 AM
Hey, don't take it out on Vim; Its not Vim's fault that you like to use inferior tools.

[poke-poke]


:)
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: MP on December 22, 2010, 11:14:48 AM
 :lmao:
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: David Bethel on December 22, 2010, 11:16:27 AM
I wrote a lsp2htm converter a long time ago.  There were a few others out there if I remember correctly. -David
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: JohnK on December 22, 2010, 01:01:31 PM
@David
Cool colors; That kinda looks like my color scheme i created for Vim.

I know its not Lisp but Ive been playing around with Doxygen for my C++ stuff. Very cool!
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: CAB on December 22, 2010, 01:35:46 PM
Sister Thread
http://www.theswamp.org/index.php?topic=27946.msg335202#msg335202
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: Oak3s on December 22, 2010, 04:45:29 PM
Nothing readability (http://lab.arc90.com/experiments/readability) can't fix. :evil:

Or perhaps Readable (http://readable-app.appspot.com/setup.html).
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: qjchen on December 22, 2010, 07:20:08 PM
Another couple of examples  :-)

http://lee-mac.com/attractors.html (http://lee-mac.com/attractors.html)

http://lee-mac.com/layerstatus.html (http://lee-mac.com/layerstatus.html)

I use quite a few more colours than Michael however  :lol:

Lee, I like your site, codes with picture or animation. ~ :-D
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: highflyingbird on December 22, 2010, 08:28:21 PM
Another couple of examples  :-)

http://lee-mac.com/attractors.html (http://lee-mac.com/attractors.html)

http://lee-mac.com/layerstatus.html (http://lee-mac.com/layerstatus.html)

I use quite a few more colours than Michael however  :lol:

Lee,your attarctors  are very cute! fabulous!

Thank all the replies. Because blogspot is blocked  in China (GFW reason) ,SO,  I can't find the answer.Now in here, I found a lot.
Title: Re: Can I use Syntax Highlighting for my Lisp code In my blog?
Post by: Lee Mac on December 23, 2010, 05:39:00 AM
Lee, I like your site, codes with picture or animation. ~ :-D

Lee,your attarctors  are very cute! fabulous!

Thanks guys!  8-)