TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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!
-
:-D
you can get something from this page:
http://ivox-tech.blogspot.com/2006/10/autolisp-highlighter.html
-
my variant... (http://elpanov.com/index.php?id=22)
-
Just add some definitions to your site's css style sheet:
/* ...*/
/******************** 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:
(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):
<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 (< 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->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->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.
-
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:
-
I use quite a few more colours than Michael however :lol:
Nothing readability (http://lab.arc90.com/experiments/readability) can't fix. :evil:
-
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-)
-
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!
-
I use my editor.
( (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)
)
)
-
That works pretty well John. If only I didn't hate vim. :/
-
Hey, don't take it out on Vim; Its not Vim's fault that you like to use inferior tools.
[poke-poke]
:)
-
:lmao:
-
I wrote a lsp2htm converter a long time ago. There were a few others out there if I remember correctly. -David
-
@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!
-
Sister Thread
http://www.theswamp.org/index.php?topic=27946.msg335202#msg335202
-
Nothing readability (http://lab.arc90.com/experiments/readability) can't fix. :evil:
Or perhaps Readable (http://readable-app.appspot.com/setup.html).
-
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
-
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.
-
Lee, I like your site, codes with picture or animation. ~ :-D
Lee,your attarctors are very cute! fabulous!
Thanks guys! 8-)