### SQL Mode Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/sql/index.html An example of SQL syntax highlighting provided by the SQL mode. This includes various data types, keywords, and comments. ```sql -- SQL Mode for CodeMirror SELECT SQL_NO_CACHE DISTINCT @var1 AS `val1`, @'val2', @global.`sql_mode`, 1.1 AS `float_val`, .14 AS `another_float`, 0.09e3 AS `int_with_esp`, 0xFA5 AS `hex`, x'fa5' AS `hex2`, 0b101 AS `bin`, b'101' AS `bin2`, DATE '1994-01-01' AS `sql_date`, { T "1994-01-01" } AS `odbc_date`, 'my string', _utf8'your string', N'her string', TRUE, FALSE, UNKNOWN FROM DUAL -- space needed after '--' # 1 line comment /* multiline comment! */ LIMIT 1 OFFSET 0; ``` -------------------------------- ### Stylus Syntax Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/stylus/index.html Demonstrates basic Stylus syntax including comments, selectors, properties, and variables. ```stylus /* Stylus mode */ #id .class article font-family Arial, sans-serif #id, .class, article { font-family: Arial, sans-serif; } // Variables font-size-base = 16px line-height-base = 1.5 font-family-base = "Helvetica Neue", Helvetica, Arial, sans-serif text-color = lighten(#000, 20%) body { font: font-size-base/line-height-base font-family-base color text-color; } // Variables link-color = darken(#428bca, 6.5%) link-hover-color = darken(link-color, 15%) link-decoration = none link-hover-decoration = false // Mixin tab-focus() { outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } a { color: link-color; if link-decoration { text-decoration: link-decoration; } &:hover, &:focus { color: link-hover-color; } &:focus { tab-focus(); } } a:hover, a:focus { color: #2f6ea7; } a:focus { outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } ``` -------------------------------- ### Puppet Code Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/puppet/index.html This is an example of Puppet code demonstrating class definition, parameter inheritance, and resource declaration for managing files and packages. It's useful for understanding Puppet's declarative syntax for system configuration. ```puppet # == Class: automysqlbackup # # Puppet module to install AutoMySQLBackup for periodic MySQL backups. # # class { # 'automysqlbackup': # backup_dir => '/mnt/backups', # } class automysqlbackup ( $bin_dir = $automysqlbackup::params::bin_dir, $etc_dir = $automysqlbackup::params::etc_dir, $backup_dir = $automysqlbackup::params::backup_dir, $install_multicore = undef, $config = {}, $config_defaults = {}, ) inherits automysqlbackup::params { # Ensure valid paths are assigned validate_absolute_path($bin_dir) validate_absolute_path($etc_dir) validate_absolute_path($backup_dir) # Create a subdirectory in /etc for config files file { $etc_dir: ensure => directory, owner => 'root', group => 'root', mode => '0750', } # Create an example backup file, useful for reference file { "${etc_dir}/automysqlbackup.conf.example": ensure => file, owner => 'root', group => 'root', mode => '0660', source => 'puppet:///modules/automysqlbackup/automysqlbackup.conf', } # Add files from the developer file { "${etc_dir}/AMB_README": ensure => file, source => 'puppet:///modules/automysqlbackup/AMB_README', } file { "${etc_dir}/AMB_LICENSE": ensure => file, source => 'puppet:///modules/automysqlbackup/AMB_LICENSE', } # Install the actual binary file file { "${bin_dir}/automysqlbackup": ensure => file, owner => 'root', group => 'root', mode => '0755', source => 'puppet:///modules/automysqlbackup/automysqlbackup', } # Create the base backup directory file { $backup_dir: ensure => directory, owner => 'root', group => 'root', mode => '0755', } # If you'd like to keep your config in hiera and pass it to this class if !empty($config) { create_resources('automysqlbackup::backup', $config, $config_defaults) } # If using RedHat family, must have the RPMforge repo's enabled if $install_multicore { package { ['pigz', 'pbzip2']: ensure => installed } } } ``` -------------------------------- ### Basic CodeMirror Initialization Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/diff/index.html A minimal example of initializing CodeMirror from a textarea element. This serves as a starting point for more complex configurations. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); ``` -------------------------------- ### Asterisk Dialplan Configuration Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/asterisk/index.html This is an example of an Asterisk extensions.conf file, demonstrating various dialplan contexts, extensions, and commands. It covers general settings, international dialing, local calls, voicemail, and demo features. ```asterisk ; extensions.conf - the Asterisk dial plan ; [general] ; ; If static is set to no, or omitted, then the pbx_config will rewrite ; this file when extensions are modified. Remember that all comments ; made in the file will be lost when that happens. static=yes #include "/etc/asterisk/additional_general.conf" [iaxprovider] switch => IAX2/user:[key]@myserver/mycontext [dynamic] #exec /usr/bin/dynamic-peers.pl [trunkint] ; ; International long distance through trunk ; exten => _9011.,1,Macro(dundi-e164,${EXTEN:4}) exten => _9011.,n,Dial(${GLOBAL(TRUNK)}/${FILTER(0-9,${EXTEN:${GLOBAL(TRUNKMSD)}})}) [local] ; ; Master context for local, toll-free, and iaxtel calls only ; ignorepat => 9 include => default [demo] include => stdexten ; ; We start with what to do when a call first comes in. ; exten => s,1,Wait(1) ; Wait a second, just for fun same => n,Answer ; Answer the line same => n,Set(TIMEOUT(digit)=5) ; Set Digit Timeout to 5 seconds same => n,Set(TIMEOUT(response)=10) ; Set Response Timeout to 10 seconds same => n(restart),BackGround(demo-congrats) ; Play a congratulatory message same => n(instruct),BackGround(demo-instruct) ; Play some instructions same => n,WaitExten ; Wait for an extension to be dialed. exten => 2,1,BackGround(demo-moreinfo) ; Give some more information. exten => 2,n,Goto(s,instruct) exten => 3,1,Set(LANGUAGE()=fr) ; Set language to french exten => 3,n,Goto(s,restart) ; Start with the congratulations exten => 1000,1,Goto(default,s,1) ; ; We also create an example user, 1234, who is on the console and has ; voicemail, etc. ; exten => 1234,1,Playback(transfer,skip) ; "Please hold while..." ; (but skip if channel is not up) exten => 1234,n,Gosub(${EXTEN},stdexten(${GLOBAL(CONSOLE)})) exten => 1234,n,Goto(default,s,1) ; exited Voicemail exten => 1235,1,Voicemail(1234,u) ; Right to voicemail exten => 1236,1,Dial(Console/dsp) ; Ring forever exten => 1236,n,Voicemail(1234,b) ; Unless busy ; ; # for when they're done with the demo exten => #,1,Playback(demo-thanks) ; "Thanks for trying the demo" exten => #,n,Hangup ; Hang them up. ; ; A timeout and "invalid extension rule" exten => t,1,Goto(#,1) ; If they take too long, give up exten => i,1,Playback(invalid) ; "That's not valid, try again" ; ; Create an extension, 500, for dialing the ; Asterisk demo. ; exten => 500,1,Playback(demo-abouttotry); Let them know what's going on exten => 500,n,Dial(IAX2/guest@pbx.digium.com/s@default) ; Call the Asterisk demo exten => 500,n,Playback(demo-nogo) ; Couldn't connect to the demo site exten => 500,n,Goto(s,6) ; Return to the start over message. ; ; Create an extension, 600, for evaluating echo latency. ; exten => 600,1,Playback(demo-echotest) ; Let them know what's going on exten => 600,n,Echo ; Do the echo test exten => 600,n,Playback(demo-echodone) ; Let them know it's over exten => 600,n,Goto(s,6) ; Start over ; ; You can use the Macro Page to intercom a individual user exten => 76245,1,Macro(page,SIP/Grandstream1) ; or if your peernames are the same as extensions exten => _7XXX,1,Macro(page,SIP/${EXTEN}) ; ; System Wide Page at extension 7999 exten => 7999,1,Set(TIMEOUT(absolute)=60) exten => 7999,2,Page(Local/Grandstream1@page&Local/Xlite1@page&Local/1234@page/n) ; Give voicemail at extension 8500 ; exten => 8500,1,VoicemailMain exten => 8500,n,Goto(s,6) ``` -------------------------------- ### Verilog/SystemVerilog Syntax Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/verilog/index.html Demonstrates various Verilog/SystemVerilog syntax elements including literals, macro definitions, module definitions, class definitions, and comments. ```verilog // Literals 1'b0 1'bx 1'bz 16'hDC78 'hdeadbeef 'b0011xxzz 1234 32'd5678 3.4e6 -128.7 // Macro definition `define BUS_WIDTH = 8; // Module definition module block( input clk, input rst_n, input [`BUS_WIDTH-1:0] data_in, output [`BUS_WIDTH-1:0] data_out ); always @(posedge clk or negedge rst_n) begin if (~rst_n) begin data_out <= 8'b0; end else begin data_out <= data_in; end if (~rst_n) data_out <= 8'b0; else data_out <= data_in; if (~rst_n) begin data_out <= 8'b0; end else begin data_out <= data_in; end end endmodule // Class definition class test; /** * Sum two integers */ function int sum(int a, int b); int result = a + b; string msg = $sformatf("%d + %d = %d", a, b, result); $display(msg); return result; endfunction task delay(int num_cycles); repeat(num_cycles) #1; endtask endclass ``` -------------------------------- ### Dylan Language Syntax Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/dylan/index.html This snippet demonstrates Dylan syntax for defining methods and protocols. It includes examples of locator merging and checking for openable locators. ```dylan locator.locator-base, extension: locator.locator-extension) else locator end end method merge-locators; define method merge-locators (locator :: , from-locator :: ) => (merged-locator :: ) let from-directory = from-locator.locator-directory; if (from-directory) merge-locators(locator, from-directory) else locator end end method merge-locators; /// Locator protocols define sideways method supports-open-locator? (locator :: ) => (openable? :: ) ~locator.locator-relative? end method supports-open-locator?; define sideways method open-locator (locator :: , #rest keywords, #key, #all-keys) => (stream :: ) apply(open-file-stream, locator, keywords) end method open-locator; ``` -------------------------------- ### Go Prime Sieve Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/go/index.html Demonstrates a prime sieve algorithm implemented in Go, as taken from the Go specification. This code showcases concurrency patterns using channels. ```go package main import "fmt" // Send the sequence 2, 3, 4, ... to channel 'ch'. func generate(ch chan<- int) { for i := 2; ; i++ { ch <- i // Send 'i' to channel 'ch' } } // Copy the values from channel 'src' to channel 'dst', // removing those divisible by 'prime'. func filter(src <-chan int, dst chan<- int, prime int) { for i := range src { // Loop over values received from 'src'. if i%prime != 0 { dst <- i // Send 'i' to channel 'dst'. } } } // The prime sieve: Daisy-chain filter processes together. func sieve() { ch := make(chan int) // Create a new channel. go generate(ch) // Start generate() as a subprocess. for { prime := <-ch fmt.Print(prime, "\n") ch1 := make(chan int) go filter(ch, ch1, prime) ch = ch1 } } func main() { sieve() } ``` -------------------------------- ### Erlang Mode Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/erlang/index.html Demonstrates how to print a record in Erlang. This code defines a module with a record and functions to process it. ```erlang %% - -*- mode: erlang; erlang-indent-level: 2 - *- %%% Created : 7 May 2012 by mats cronqvist %% @doc %% Demonstrates how to print a record. %% @end -module('ex'). -author('mats cronqvist'). -export( [demo/0, rec_info/1] ). -record(demo,{a="One",b="Two",c="Three",d="Four"}). rec_info(demo) -> record_info(fields,demo). demo() -> expand_recs(?MODULE,#demo{a="A",b="BB"}). expand_recs(M,List) when is_list(List) -> [expand_recs(M,L)||L<-List] ; expand_recs(M,Tup) when is_tuple(Tup) -> case tuple_size(Tup) of L when L < 1 -> Tup ; L -> try Fields = M:rec_info(element(1,Tup)), L = length(Fields)+1, lists:zip(Fields,expand_recs(M,tl(tuple_to_list(Tup)))) catch _:_ -> list_to_tuple(expand_recs(M,tuple_to_list(Tup))) end end ; expand_recs(_,Term) -> Term. ``` -------------------------------- ### Objective-C Example with Comments and C-style Array Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/clike/index.html This Objective-C code demonstrates Objective-C syntax, including multi-line and single-line comments, class implementation, and the use of a C-style character array. ```objectivec /* This is a longer comment That spans two lines */ #import @implementation YourAppDelegate // This is a one-line comment - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ char myString[] = "This is a C character array"; int test = 5; return YES; } ``` -------------------------------- ### Initialize CodeMirror for Erlang Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/erlang/index.html Configures a CodeMirror editor instance for Erlang code. This setup enables line numbers, bracket matching, and applies the 'erlang-dark' theme. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, matchBrackets: true, extraKeys: {"Tab": "indentAuto"}, theme: "erlang-dark" }); ``` -------------------------------- ### Lua Syntax Highlighting Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/lua/index.html Demonstrates basic Lua syntax, including multi-line and single-line comments, function definitions, local variables, tables, conditional statements, and function calls. This is useful for showcasing the mode's ability to highlight standard Lua code structures. ```lua --[[ example useless code to show lua syntax highlighting this is multiline comment ]] function blahblahblah(x) local table = { "asd" = 123, "x" = 0.34, } if x ~= 3 then print( x ) elseif x == "string" my_custom_function( 0x34 ) else unknown_function( "some string" ) end --single line comment end function blablabla3() for k,v in ipairs( table ) do --abcde.. y=[[ x=[[ x is a multi line string ]] but its definition is iside a highest level string! ]=] print(" \"\" ") s = math.sin( x ) end end ``` -------------------------------- ### Initialize CodeMirror with Diff Mode Options Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/diff/index.html Example of initializing CodeMirror from a textarea, enabling line numbers, auto-matching brackets, and adding a gutter click handler. This is useful for interactive diff views. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, autoMatchBrackets: true, onGutterClick: function(x){console.log(x);} }); ``` -------------------------------- ### TOML Document Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/toml/index.html This is an example of a TOML document showcasing various data types and structures, including strings, integers, dates, arrays, and nested tables. ```toml # This is a TOML document. Boom. title = "TOML Example" [owner] name = "Tom Preston-Werner" organization = "GitHub" bio = "GitHub Cofounder & CEO\nLikes tater tots and beer." dob = 1979-05-27T07:32:00Z # First class dates? Why not? [database] server = "192.168.1.1" ports = [ 8001, 8001, 8002 ] connection_max = 5000 enabled = true [servers] # You can indent as you please. Tabs or spaces. TOML don't care. [servers.alpha] ip = "10.0.0.1" dc = "eqdc10" [servers.beta] ip = "10.0.0.2" dc = "eqdc10" [clients] data = [ ["gamma", "delta"], [1, 2] ] # Line breaks are OK when inside arrays hosts = [ "alpha", "omega" ] ``` -------------------------------- ### Modelica Code Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/modelica/index.html A sample Modelica model demonstrating basic syntax for a bouncing ball simulation. ```modelica model BouncingBall parameter Real e = 0.7; parameter Real g = 9.81; Real h(start=1); Real v; Boolean flying(start=true); Boolean impact; Real v_new; equation impact = h <= 0.0; der(v) = if flying then -g else 0; der(h) = v; when {h <= 0.0 and v <= 0.0, impact} then v_new = if edge(impact) then -e*pre(v) else 0; flying = v_new > 0; reinit(v, v_new); end when; annotation (uses(Modelica(version="3.2"))); end BouncingBall; ``` -------------------------------- ### Fortran Program Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/fortran/index.html A sample Fortran program that reads numbers, calculates their average, and separates averages for positive and negative numbers. This code is intended for demonstration purposes. ```fortran program average ! Read in some numbers and take the average ! As written, if there are no data points, an average of zero is returned ! While this may not be desired behavior, it keeps this example simple implicit none real, dimension(:), allocatable :: points integer :: number_of_points real :: average_points=0., positive_average=0., negative_average=0. write (*,*) "Input number of points to average:" read (*,*) number_of_points allocate (points(number_of_points)) write (*,*) "Enter the points to average:" read (*,*) points ! Take the average by summing points and dividing by number_of_points if (number_of_points > 0) average_points = sum(points) / number_of_points ! Now form average over positive and negative points only if (count(points > 0.) > 0) then positive_average = sum(points, points > 0.) / count(points > 0.) end if if (count(points < 0.) > 0) then negative_average = sum(points, points < 0.) / count(points < 0.) end if deallocate (points) ! Print result to terminal write (*,'(a,g12.4)') 'Average = ', average_points write (*,'(a,g12.4)') 'Average of positive points = ', positive_average write (*,'(a,g12.4)') 'Average of negative points = ', negative_average end program average ``` -------------------------------- ### C++ Example with Unicode and Raw Strings Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/clike/index.html This C++ code snippet showcases advanced features like namespaces, enums, Unicode string literals, raw string literals, and class templates with inheritance and method definitions. ```cpp #include #include "mystuff/util.h" namespace { enum Enum { VAL1, VAL2, VAL3 }; char32_t unicode_string = U"\U0010FFFF"; string raw_string = R"delim(anything you want)delim"; int Helper(const MyType& param) { return 0; } } // namespace class ForwardDec; template class Class : public BaseClass { const MyType member_; public: const MyType& Method() const { return member_; } void Method2(MyType* value); } template void Class::Method2(MyType* value) { std::out << 1 >> method(); value->Method3(member_); member_ = value; } ``` -------------------------------- ### GFM Fenced Code Block Example Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/gfm/index.html Demonstrates a fenced code block within GFM, which supports syntax highlighting for various languages. ```javascript for (var i = 0; i < items.length; i++) { console.log(items[i], i); // log them } ``` -------------------------------- ### Initialize CodeMirror with Lua Mode Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/lua/index.html Initializes a CodeMirror editor instance with Lua mode enabled. This example shows how to attach CodeMirror to a textarea element and configure specific editor options like bracket matching and theme. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { matchBrackets: true, theme: "neat" }); ``` -------------------------------- ### Scala Example with List Processing Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/clike/index.html This Scala code defines an object with an `App` trait and a `filter` function that recursively processes a list of integers based on a threshold. ```scala object FilterTest extends App { def filter(xs: List[Int], threshold: Int) = { def process(ys: List[Int]): List[Int] = if (ys.isEmpty) ys else if (ys.head < threshold) ys.head :: process(ys.tail) else process(ys.tail) process(xs) } println(filter(List(1, 9, 2, 8, 3, 7, 4), 5)) } ``` -------------------------------- ### mIRC Script Setup for AKA Nick Tracker Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/mirc/index.html Configuration section for the AKA Nick Tracker script. Adjust JoinDisplay, MaxNicks, and AKALogo to customize the display and storage of nickname information. ```mirc ;AKA Nick Tracker by Ford_Lawnmower irc.GeekShed.net #Script-Help ;***********************************************************************; ;**Start Setup ;Change JoinDisplay, below, for On Join AKA Display. On = 1 - Off = 0 alias -l JoinDisplay { return 1 }\n;Change MaxNicks, below, to the number of nicknames you want to store for each hostmask. I wouldn't go over 400 with this ;/ alias -l MaxNicks { return 20 }\n;Change AKALogo, below, To the text you want displayed before each AKA result. alias -l AKALogo { return 06 05A06K07A 06 }\n;**End Setup *********************************************************************** ``` -------------------------------- ### Eggdrop Tcl Whois Script Setup Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/tcl/index.html Configuration variables for the Tcl whois script. Adjust these to customize trigger characters, command names, colors, and output format. ```tcl namespace eval whois { ## change cmdchar to the trigger you want to use ## ## variable cmdchar "!" ## change command to the word trigger you would like to use. ## ## ## Keep in mind, This will also change the .chanset +/-command ## ## variable command "whois" ## change textf to the colors you want for the text. ## ## variable textf "\017\00304" ## change tagf to the colors you want for tags: ## ## variable tagf "\017\002" ## Change logo to the logo you want at the start of the line. ## ## variable logo "\017\00304\002\[\00306W\003hois\00304\]\017" ## Change lineout to the results you want. Valid results are channel users modes topic ## ## variable lineout "channel users modes topic" ############################################################################################## ## ## End Setup. ## ## ############################################################################################## variable channel "" setudef flag $whois::command bind pub -|- \[string trimleft $whois::cmdchar]\]${whois::command} whois::list bind raw -|- "311" whois::311 bind raw -|- "312" whois::312 bind raw -|- "319" whois::319 bind raw -|- "317" whois::317 bind raw -|- "313" whois::multi bind raw -|- "310" whois::multi bind raw -|- "335" whois::multi bind raw -|- "301" whois::301 bind raw -|- "671" whois::multi bind raw -|- "320" whois::multi bind raw -|- "401" whois::multi bind raw -|- "318" whois::318 bind raw -|- "307" whois::307 } ``` -------------------------------- ### mIRC Script: On Start, Exit, Disconnect, Unload Events Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/mirc/index.html Handles the loading and saving of the NickNames hash table. It loads from 'NickNames.hsh' on startup and saves on exit, disconnect, or unload to persist nickname data. ```mirc On *:Start: {\n if (!$hget(NickNames)) {\n hmake NickNames 10\n }\n if ($isfile(NickNames.hsh)) {\n hload NickNames NickNames.hsh\n }\n}\nOn *:Exit: {\n if ($hget(NickNames)) {\n hsave NickNames NickNames.hsh\n }\n}\nOn *:Disconnect: {\n if ($hget(NickNames)) {\n hsave NickNames NickNames.hsh\n }\n}\nOn *:Unload: {\n hfree NickNames\n} ``` -------------------------------- ### Java Example with Generics and Enum Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/clike/index.html This Java code snippet defines a generic enum and class, implementing an interface and demonstrating static final members, inner classes, and method overrides. ```java import com.demo.util.MyType; import com.demo.util.MyInterface; public enum Enum { VAL1, VAL2, VAL3 } public class Class implements MyInterface { public static final MyType member; private class InnerClass { public int zero() { return 0; } } @Override public MyType method() { return member; } public void method2(MyType value) { method(); value.method3(); member = value; } } ``` -------------------------------- ### C-like Mode Demo Code Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/clike/index.html This C code demonstrates the usage of zmq and pthread for asynchronous operations within a context structure. It includes initialization and thread management functions. ```c /* C demo code */ #include #include #include #include #include #include #include typedef struct { void* arg_socket; zmq_msg_t* arg_msg; char* arg_string; unsigned long arg_len; int arg_int, arg_command; int signal_fd; int pad; void* context; sem_t sem; } acl_zmq_context; #define p(X) (context->arg_##X) void* zmq_thread(void* context_pointer) { acl_zmq_context* context = (acl_zmq_context*)context_pointer; char ok = 'K', err = 'X'; int res; while (1) { while ((res = sem_wait(&context->sem)) == EINTR); if (res) {write(context->signal_fd, &err, 1); goto cleanup;} switch(p(command)) { case 0: goto cleanup; case 1: p(socket) = zmq_socket(context->context, p(int)); break; case 2: p(int) = zmq_close(p(socket)); break; case 3: p(int) = zmq_bind(p(socket), p(string)); break; case 4: p(int) = zmq_connect(p(socket), p(string)); break; case 5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string), &p(len)); break; case 6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break; case 7: p(int) = zmq_send(p(socket), p(msg), p(int)); break; case 8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break; case 9: p(int) = zmq_poll(p(socket), p(int), p(len)); break; } p(command) = errno; write(context->signal_fd, &ok, 1); } cleanup: close(context->signal_fd); free(context_pointer); return 0; } void* zmq_thread_init(void* zmq_context, int signal_fd) { acl_zmq_context* context = malloc(sizeof(acl_zmq_context)); pthread_t thread; context->context = zmq_context; context->signal_fd = signal_fd; sem_init(&context->sem, 1, 0); pthread_create(&thread, 0, &zmq_thread, context); pthread_detach(thread); return context; } ``` -------------------------------- ### Initialize CodeMirror with EBNF Mode Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/ebnf/index.html Demonstrates how to initialize a CodeMirror editor to use the EBNF mode. Ensure the 'ebnf' mode is loaded before using this configuration. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: {name: "ebnf"}, lineNumbers: true, bracesMode: 'javascript' }); ``` -------------------------------- ### Initialize CodeMirror for Go Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/go/index.html Initializes a CodeMirror editor instance for Go code. This configuration sets the theme, bracket matching, and indentation properties. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { theme: "elegant", matchBrackets: true, indentUnit: 8, tabSize: 8, indentWithTabs: true, mode: "text/x-go" }); ``` -------------------------------- ### Initialize CodeMirror with LiveScript Mode Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/livescript/index.html Demonstrates how to initialize a CodeMirror editor instance from a textarea element, applying the LiveScript mode with specific theme and line numbering options. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { theme: "solarized light", lineNumbers: true }); ``` -------------------------------- ### Sample COBOL Program Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/cobol/index.html A sample COBOL program demonstrating the syntax and structure recognized by the COBOL mode. ```cobol 000010 IDENTIFICATION DIVISION. MODTGHERE 000020 PROGRAM-ID. SAMPLE. 000030 AUTHOR. TEST SAM. 000040 DATE-WRITTEN. 5 February 2013 000041 000042* A sample program just to show the form. 000043* The program copies its input to the output, 000044* and counts the number of records. 000045* At the end this number is printed. 000046 000050 ENVIRONMENT DIVISION. 000060 INPUT-OUTPUT SECTION. 000070 FILE-CONTROL. 000080 SELECT STUDENT-FILE ASSIGN TO SYSIN 000090 ORGANIZATION IS LINE SEQUENTIAL. 000100 SELECT PRINT-FILE ASSIGN TO SYSOUT 000110 ORGANIZATION IS LINE SEQUENTIAL. 000120 000130 DATA DIVISION. 000140 FILE SECTION. 000150 FD STUDENT-FILE 000160 RECORD CONTAINS 43 CHARACTERS 000170 DATA RECORD IS STUDENT-IN. 000180 01 STUDENT-IN PIC X(43). 000190 000200 FD PRINT-FILE 000210 RECORD CONTAINS 80 CHARACTERS 000220 DATA RECORD IS PRINT-LINE. 000230 01 PRINT-LINE PIC X(80). 000240 000250 WORKING-STORAGE SECTION. 000260 01 DATA-REMAINS-SWITCH PIC X(2) VALUE SPACES. 000261 01 RECORDS-WRITTEN PIC 99. 000270 000280 01 DETAIL-LINE. 000290 05 FILLER PIC X(7) VALUE SPACES. 000300 05 RECORD-IMAGE PIC X(43). 000310 05 FILLER PIC X(30) VALUE SPACES. 000311 000312 01 SUMMARY-LINE. 000313 05 FILLER PIC X(7) VALUE SPACES. 000314 05 TOTAL-READ PIC 99. 000315 05 FILLER PIC X VALUE SPACE. 000316 05 FILLER PIC X(17) 000317 VALUE 'Records were read'. 000318 05 FILLER PIC X(53) VALUE SPACES. 000319 000320 PROCEDURE DIVISION. 000321 000330 PREPARE-SENIOR-REPORT. 000340 OPEN INPUT STUDENT-FILE 000350 OUTPUT PRINT-FILE. 000351 MOVE ZERO TO RECORDS-WRITTEN. 000360 READ STUDENT-FILE 000370 AT END MOVE 'NO' TO DATA-REMAINS-SWITCH 000380 END-READ. 000390 PERFORM PROCESS-RECORDS 000410 UNTIL DATA-REMAINS-SWITCH = 'NO'. 000411 PERFORM PRINT-SUMMARY. 000420 CLOSE STUDENT-FILE 000430 PRINT-FILE. 000440 STOP RUN. 000450 000460 PROCESS-RECORDS. 000470 MOVE STUDENT-IN TO RECORD-IMAGE. 000480 MOVE DETAIL-LINE TO PRINT-LINE. 000490 WRITE PRINT-LINE. 000500 ADD 1 TO RECORDS-WRITTEN. 000510 READ STUDENT-FILE 000520 AT END MOVE 'NO' TO DATA-REMAINS-SWITCH 000530 END-READ. 000540 000550 PRINT-SUMMARY. 000560 MOVE RECORDS-WRITTEN TO TOTAL-READ. 000570 MOVE SUMMARY-LINE TO PRINT-LINE. 000571 WRITE PRINT-LINE. 000572 ``` -------------------------------- ### Functional Composition and Currying in LiveScript Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/livescript/index.html Demonstrates functional programming utilities: `compose` for chaining functions, `curry` for partial application, `id` for identity, and `flip` for argument reordering. ```livescript compose = (...funcs) -> -> args = arguments for f in funcs args = [f.apply this, args] args.0 ``` ```livescript curry = (f) -> curry$ f # using util method curry$ from livescript ``` ```livescript id = (x) -> x ``` ```livescript flip = (f, x, y) --> f y, x ``` -------------------------------- ### Initialize CodeMirror with TiddlyWiki Mode Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/tiddlywiki/index.html Use this code to initialize a CodeMirror editor instance for TiddlyWiki syntax. Ensure the target element has the ID 'code'. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: 'tiddlywiki', lineNumbers: true, matchBrackets: true }); ``` -------------------------------- ### Sample XQuery Usage Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/xquery/index.html Demonstrates basic usage of the json:serialize function in XQuery to convert an XML element to a JSON string. Requires importing the json module. ```xquery xquery version "1.0-ml"; import module namespace json="http://marklogic.com/json" at "json.xqy"; json:serialize(kid) ``` -------------------------------- ### Initialize CodeMirror for Modelica Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/modelica/index.html Initializes a CodeMirror editor instance for Modelica code using the 'text/x-modelica' mode. Includes enabling line numbers, bracket matching, and setting up a custom key binding for autocompletion. ```javascript var modelicaEditor = CodeMirror.fromTextArea(document.getElementById("modelica"), { lineNumbers: true, matchBrackets: true, mode: "text/x-modelica" }); var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault; CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Space"] = "autocomplete"; ``` -------------------------------- ### CodeMirror Initialization for Various Modes Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/clike/index.html These JavaScript snippets demonstrate how to initialize CodeMirror editors for different programming languages (C, C++, Java, Objective-C, Scala) using `CodeMirror.fromTextArea` with specific mode configurations. ```javascript var cEditor = CodeMirror.fromTextArea(document.getElementById("c-code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-csrc" }); var cppEditor = CodeMirror.fromTextArea(document.getElementById("cpp-code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-c++src" }); var javaEditor = CodeMirror.fromTextArea(document.getElementById("java-code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-java" }); var objectivecEditor = CodeMirror.fromTextArea(document.getElementById("objectivec-code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-objectivec" }); var scalaEditor = CodeMirror.fromTextArea(document.getElementById("scala-code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-scala" }); ``` ```javascript var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault; CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Space"] = "autocomplete"; ``` -------------------------------- ### Initialize GFM Mode Editor Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/gfm/index.html Use this to create a CodeMirror editor instance configured for GitHub Flavored Markdown. It supports line numbers and a default theme. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: 'gfm', lineNumbers: true, theme: "default" }); ``` -------------------------------- ### Initialize Dylan Mode in CodeMirror Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/dylan/index.html Use this to initialize CodeMirror with the Dylan mode. Ensure the element with id 'code' exists and the CodeMirror library is loaded. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: "text/x-dylan", lineNumbers: true, matchBrackets: true, continueComments: "Enter", extraKeys: {"Ctrl-Q": "toggleComment"}, tabMode: "indent", indentUnit: 2 }); ``` -------------------------------- ### R Function Definition with Return Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/r/index.html Shows how to define a simple R function that returns a value. Useful for encapsulating reusable logic. ```r # FUNCTIONS -- square <- function(x) { return(x*x) } cat("The square of 3 is ", square(3), "\n") ``` -------------------------------- ### Run VB.NET Mode Tests and Initialize Text Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/vb/index.html Executes all defined VB.NET mode tests and then sets the initial text content for the editor. ```javascript function runTest() { document.getElementById('testresult').innerHTML = testAll(); initText(editor); } ``` -------------------------------- ### Initialize Verilog Mode in CodeMirror Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/verilog/index.html Initializes the Verilog mode for a CodeMirror editor instance, enabling line numbers and bracket matching. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, matchBrackets: true, mode: { name: "verilog", noIndentKeywords: ["package"] } }); ``` -------------------------------- ### Initialize CodeMirror for Fortran Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/fortran/index.html Initializes a CodeMirror editor instance for a textarea element, configuring it to use the Fortran mode. This is used to enable syntax highlighting and editing features for Fortran code. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, mode: "text/x-fortran" }); ``` -------------------------------- ### Least Common Multiple and Meta Functions in LiveScript Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/livescript/index.html Provides `lcm` for least common multiple and `installPrelude` for managing prelude functionality, along with `prelude` export. ```livescript lcm = (x, y) --> Math.abs Math.floor (x / (gcd x, y) * y) ``` ```livescript installPrelude = !(target) -> unless target.prelude?isInstalled target <<< out$ # using out$ generated by livescript target <<< target.prelude.isInstalled = true ``` ```livescript prelude = out$ ``` -------------------------------- ### CodeMirror Initialization Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/xquery/index.html Initializes a CodeMirror editor instance for a textarea element with specific configurations for line numbers, bracket matching, and theme. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, matchBrackets: true, theme: "xq-dark" }); ``` -------------------------------- ### Initialize CodeMirror for Ruby Mode Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/ruby/index.html Initializes a CodeMirror editor for a textarea element, enabling Ruby syntax highlighting and bracket matching. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: "text/x-ruby", matchBrackets: true, indentUnit: 4 }); ``` -------------------------------- ### Initialize CodeMirror Editor Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/haskell/index.html This JavaScript code initializes a CodeMirror editor instance from a textarea element. It enables line numbers, bracket matching, and applies the 'elegant' theme. Ensure the target textarea exists in the HTML. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, matchBrackets: true, theme: "elegant" }); ``` -------------------------------- ### Markdown Inline Link Syntax Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/markdown/index.html Demonstrates the syntax for creating inline links in Markdown, including optional title attributes. ```markdown This is an [example link](http://example.com/). ``` ```markdown This is an [example link](http://example.com/ "With a Title"). ``` -------------------------------- ### Initialize Markdown Mode in CodeMirror Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/markdown/index.html Configures a CodeMirror editor instance to use the Markdown mode. Includes line numbers and a specific key mapping for Markdown lists. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: 'markdown', lineNumbers: true, theme: "default", extraKeys: {"Enter": "newlineAndIndentContinueMarkdownList"} }); ``` -------------------------------- ### Initialize CodeMirror with COBOL Mode Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/cobol/index.html Initializes a CodeMirror editor instance from a textarea element, enabling COBOL syntax highlighting and various editor features. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-cobol", theme : "twilight", styleActiveLine: true, showCursorWhenSelecting : true, }); ``` -------------------------------- ### Markdown Image Syntax Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/markdown/index.html Illustrates the syntax for including images in Markdown, covering both inline and reference-style formats. ```markdown ![alt text](/path/to/img.jpg "Title") ``` ```markdown ![alt text][id] [id]: /path/to/img.jpg "Title" ``` -------------------------------- ### Initialize TOML Mode in CodeMirror Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/toml/index.html Integrate the TOML mode into a CodeMirror editor initialized from a textarea. Ensure the textarea element exists with the ID 'code'. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: {name: "toml"}, lineNumbers: true }); ``` -------------------------------- ### Initialize Asterisk Mode in CodeMirror Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/asterisk/index.html Initializes CodeMirror with the Asterisk dialplan mode. Ensure the target textarea has the ID 'code'. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: "text/x-asterisk", matchBrackets: true, lineNumber: true }); ``` -------------------------------- ### Initialize CodeMirror Editor (JavaScript) Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/commonlisp/index.html Initializes a CodeMirror editor instance from a textarea element. Enables line numbers for better code navigation. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), {lineNumbers: true}); ``` -------------------------------- ### mIRC Dialog Event: Aka_Search Init Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/mirc/index.html Initializes the AKA_Search dialog by clearing the list control (control ID 6). ```mirc On *:Dialog:Aka_Search:init:*: {\n did -c $dname 5\n} ``` -------------------------------- ### Markdown Block Code Syntax Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/markdown/index.html Demonstrates how to format entire blocks of pre-formatted code in Markdown by indenting each line with 4 spaces or 1 tab. Special characters are automatically escaped. ```markdown If you want your page to validate under XHTML 1.0 Strict, you've got to put paragraph tags in your blockquotes:

For example.

``` -------------------------------- ### Initialize VB.NET Editor Content Source: https://github.com/tommylemon/cvauto/blob/main/md/lib/codemirror/mode/vb/index.html Sets the initial content for a CodeMirror editor instance in VB.NET mode and indents each line. ```javascript function initText(editor) { var content = 'Class rocket\nPrivate quality as Double\nPublic Sub launch() as String\nif quality > 0.8\nlaunch = "Successful"\nElse\nlaunch = "Failed"\nEnd If\nEnd sub\nEnd class\n'; editor.setValue(content); for (var i = 0; i < editor.lineCount(); i++) editor.indentLine(i); } ```