From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/96760 Path: news.gmane.org!.POSTED!not-for-mail From: Nicola Newsgroups: gmane.comp.tex.context Subject: Re: Vim wiki page updated Date: Sat, 5 Nov 2016 15:53:16 +0100 Message-ID: References: <8e279755-0e50-233e-72ca-8b519cf30e6a@wxs.nl> <26fc952d-c0e9-93f3-122d-23b1b14e2fa0@wxs.nl> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------3ACBD3D558D4D2CD514F5F62" X-Trace: blaine.gmane.org 1478357719 17441 195.159.176.226 (5 Nov 2016 14:55:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 5 Nov 2016 14:55:19 +0000 (UTC) User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 To: ntg-context@ntg.nl Original-X-From: ntg-context-bounces@ntg.nl Sat Nov 05 15:55:14 2016 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c32Ms-0000lT-BI for gctc-ntg-context-518@m.gmane.org; Sat, 05 Nov 2016 15:54:50 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 2E7341D201; Sat, 5 Nov 2016 15:54:39 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rDNp2oWku3IR; Sat, 5 Nov 2016 15:54:38 +0100 (CET) Original-Received: from zapf.ntg.nl (localhost [IPv6:::1]) by zapf.ntg.nl (Postfix) with ESMTP id 69F7E1D232; Sat, 5 Nov 2016 15:54:38 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id C551F1D219 for ; Sat, 5 Nov 2016 15:54:37 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c9TfdRgHpkSm for ; Sat, 5 Nov 2016 15:54:36 +0100 (CET) Original-Received: from blaine.gmane.org (unknown [195.159.176.226]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id AF3A41D201 for ; Sat, 5 Nov 2016 15:54:26 +0100 (CET) Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1c32Lt-00025Z-SA for ntg-context@ntg.nl; Sat, 05 Nov 2016 15:53:49 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 261 Original-X-Complaints-To: usenet@blaine.gmane.org In-Reply-To: X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.16 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.org gmane.comp.tex.context:96760 Archived-At: This is a multi-part message in MIME format. --------------3ACBD3D558D4D2CD514F5F62 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 05/11/2016 15:45, Alan Braslau wrote: > Hans, Nicola, > > Being a vim user (and not presently taking much advantage of the syntax highlighting), and a MP fan, I will take care of this (in coordination with Hans, eventually). > > Alan For what is worth, I attach the Ruby script I am using. It outputs the keywords in a format that can be used directly in Vim. Nicola --------------3ACBD3D558D4D2CD514F5F62 Content-Type: text/x-ruby-script; name="extract_mp_keywords.rb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="extract_mp_keywords.rb" #!/usr/bin/env ruby # -*- coding: utf-8 -*- # Copyright (c) 2016 Lifepillar # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. VERSION = '1.0.0' def debug title, *info return unless $DEBUG puts "\033[1;35m[DEBUG]\033[1;39m #{title}\033[0m" info.each do |chunk| chunk.each_line do |l| puts "\033[1;35m[DEBUG]\033[0m #{l.chomp!}" end end end def help; <<-HELP Usage: parse_metafun [ ...] Options: -h, --help Show this help message and exit. --version Print version and exit. --debug Enable debugging. Example: parse_metafun mp-tool.mp mp-step.mp HELP end # Parse options paths = [] n = ARGV.length i = 0 while i < n case ARGV[i] when /^--version$/ puts VERSION exit(0) when /^--debug$/ $DEBUG = true when /^-h|--help$/ puts help exit(0) else # Assume it is a path paths << ARGV[i] end i += 1 end if paths.empty? paths << Dir.entries(".") end maxlinelen = 52 defs = {} saved_vars = {} known_commands = [ ] known_constants = [ ] known_defs = [ ] known_primary_defs = [ ] known_secondary_defs = [ ] known_tertiary_defs = [ ] known_vardefs = [ ] known_num_exps = [ ] known_types = [ ] false_positives = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', # just to be safe 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', # just to be safe 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', # just to be safe ] types = 'boolean|color|cmykcolor|numeric|pair|path|pen|picture|rgbcolor|string|transform' types += '|' + known_types.join('|') begin paths.each do |p| name = File.basename(p) defs[name] = { 'mpCommand' => [], 'mpDef' => [], 'mpVardef' => [], 'mpPrimaryDef' => [], 'mpSecondaryDef' => [], 'mpTertiaryDef' => [], 'mpNewInternal' => [], 'mpNumExp' => [], 'mpType' => [], 'mpVariable' => [], 'mpConstant' => [], 'LET' => [] } saved_vars[name] = [] File.open(p).each_line do |l| next if l =~ /^\s*%/ # skip comments /^[^%]*\bdef\s+(\w+)/.match(l) { |m| if m[1] !~ /^_|_$/ defs[name]['mpDef'] << m[1] end } /^[^%]*\bvardef\s+(\w+)/.match(l) { |m| if m[1] !~ /^_|_$/ defs[name]['mpVardef'] << m[1] end } /^[^%]*\bprimarydef\s+\w+\s+(\w+)/.match(l) { |m| if m[1] !~ /^_|_$/ defs[name]['mpPrimaryDef'] << m[1] end } /^[^%]*\bsecondarydef\s+\w+\s+(\w+)/.match(l) { |m| if m[1] !~ /^_|_$/ defs[name]['mpSecondaryDef'] << m[1] end } /^[^%]*\btertiarydef\s+\w+\s+(\w+)/.match(l) { |m| if m[1] !~ /^_|_$/ defs[name]['mpTertiaryDef'] << m[1] end } l.scan(/\bnewinternal\b\s+([^;]+);/).each { |m| m[0].split(/,/).each { |w| w.strip! if w !~ /^_|_$/ defs[name]['mpNewInternal'] << w end } } /^[^%]*\blet\s+(\w+)/.match(l) { |m| if m[1] !~ /^_|_$/ if !false_positives.include?(m[1]) if known_constants.include?(m[1]) defs[name]['mpConstant'] << m[1] elsif known_types.include?(m[1]) defs[name]['mpType'] << m[1] elsif known_defs.include?(m[1]) defs[name]['mpDef'] << m[1] elsif known_vardefs.include?(m[1]) defs[name]['mpVardef'] << m[1] elsif known_primary_defs.include?(m[1]) defs[name]['mpPrimaryDef'] << m[1] elsif known_secondary_defs.include?(m[1]) defs[name]['mpSecondaryDef'] << m[1] elsif known_tertiary_defs.include?(m[1]) defs[name]['mpTertiaryDef'] << m[1] elsif known_commands.include?(m[1]) defs[name]['mpCommand'] << m[1] elsif known_num_exps.include?(m[1]) defs[name]['mpNumExp'] << m[1] else defs[name]['LET'] << m[1] end end end } l.scan(/\bsave\b\s+([^;]+);/).each do |m| # This considers also save inside comments m[0].split(/,/).each do |w| saved_vars[name] << w.strip end end l.scan(/\b(#{types})\b\s+([^;]+);/).each { |m| m[1].split(/,/).each { |w| w.strip! w.gsub!(/[\[\]]/, '') next unless w =~ /^\w+$/ # Skip if it is not a single token next if false_positives.include?(w) unless saved_vars.has_key?(name) && saved_vars[name].include?(w) if w !~ /^_|_$/ if known_constants.include?(w) defs[name]['mpConstant'] << w else defs[name]['mpVariable'] << w end end end } } end end defs.each_key do |n| defs[n].each_key do |t| defs[n][t].sort!.uniq! end end defs.each_key do |n| print " \" #{n}" defs[n].each_pair do |t, l| pos = maxlinelen l.each do |w| if pos + w.length + 1 > maxlinelen puts print " syn keyword #{t}" print " " * (14 - t.length) pos = 0 end print " #{w}" pos += w.length + 1 end end puts end rescue Interrupt puts "parse_metafun interrupted" exit(1) rescue => ex puts debug 'Backtrace:', ex.backtrace.join("\n") "Unexpected exception raised:\n#{ex}" end --------------3ACBD3D558D4D2CD514F5F62 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f --------------3ACBD3D558D4D2CD514F5F62--