Saturday, June 5, 2010

snippet의 실행을 간단하게. (부제:shebang의 확장으로 xml까지)

이 블로그는 도저히 길어져서 언어로 쓰기 어렵군요.
1시간짜리 경험의 이야기 일 듯 싶어서,
간단히 코드로 보여주고 줄거리는 상상에 맞기는 것이 좋겠습니다.

결론은 shebang의 방식을 xml로 까지 확장해서 사용하고 있으며,
이는 어느 언어든 적용할 수 있는 유연한 방식이었다. 라는 것입니다.

구현은 jscript로(emeditor에서 WSH를 사용할 수 있는 이유로) 되어 있으며
현재 매우 지저분해서 공개할 수 없지만,
이 아이디어는 약 4년전부터 구현하기 시작해 지금도 계속 확장중입니다.

snippet에 해당되는 파일은 물론 지금도 계속 늘려가는 중입니다만, 현재는 8만9천여개의 파일이 모아져 있는데, 꽤 유용하게 사용되고 있습니다.
비슷한 고민을 하신적이 있으시면, 자료와 아이디어를 공유하고 싶습니다. 트위터 @crowdy까지 연락 주시면 언제든 환영합니다.

우선 shebang의 사용

  1. #!/usr/bin/env perl  
  2.   
  3. print "hello";  


그리고 제가 중간정도에 사용하던 shebang의 확장
  1. /* 
  2.  
  3. #run:cscript c:\crowdy\emmacro\data\bin\runcrowdy.js {fullname} 
  4.  
  5. //SourceGUID:2877F00B-0CC4-4063-B5A6-D22D127DA319 
  6.  
  7. //ExecuteStart 
  8.  
  9. IF not exist c:\temp\2877F00B-0CC4-4063-B5A6-D22D127DA319 mkdir c:\temp\2877F00B-0CC4-4063-B5A6-D22D127DA319 
  10.  
  11. cd c:\temp\2877F00B-0CC4-4063-B5A6-D22D127DA319 
  12.  
  13. copy {fullname} . 
  14.  
  15. g++ -W -Wall -Werror {fullname} -o {filename.name}_gcc.exe 
  16.  
  17. strip {filename.name}_gcc.exe 
  18.  
  19. {filename.name}_gcc.exe 
  20.  
  21. //ExecuteEnd 
  22.  
  23. */  
  24.   
  25.   
  26.   
  27. #include <iostream>  
  28.   
  29.   
  30.   
  31. int main()  
  32.   
  33. {  
  34.   
  35.     std::cout << "This is a native C++ program." << std::endl;  
  36.   
  37.     return 0;  
  38.   
  39. }  
  40.   
  41. </iostream>  



그리고 이것은 제가 지금 사용하고 있는 snippet 파일
  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2.   
  3. <!--Use the axscript /info option to view this file-->  
  4.   
  5. <portablescriptfile product="crowdy Script .NET" productversion="1.1.97.0" <brbr="">    Schema="1.8" FileName="AddBeanFactoryPostProcessorToXmlBeanFactory.psf"  
  6.   
  7.     CommandLine=""  
  8.   
  9.     Generated="2010-05-31T01:46:35+10:00" xmlns="C:\Program Files\crowdy Script\psf.xsd">  
  10.   
  11.   <opt ion="">  
  12.   
  13.     <type>script</type>  
  14.   
  15.     <script>  
  16.   
  17.       <name>AddBeanFactoryPostProcessorToXmlBeanFactory.java</name>  
  18.   
  19.       <language>java</language>  
  20.   
  21.       <host>javac {references} {filename} && java {references} {filename.name}</host>  
  22.   
  23.       <timestamp>2010-05-31T01:46:35+10:00</timestamp>  
  24.   
  25.       <author>  
  26.   
  27.         <name>crowdy</name>  
  28.   
  29.         <description></description>  
  30.   
  31.         <copyright>  
  32.   
  33.         <signature>  
  34.   
  35.         <version>  
  36.   
  37.         <prerequisites></prerequisites>  
  38.   
  39.         <arguments></arguments>  
  40.   
  41.         <keywords></keywords>  
  42.   
  43.         <link></link>  
  44.   
  45.         <history><![CDATA[ ]]></history>  
  46.   
  47.         <comment><![CDATA[ ]]></comment>  
  48.   
  49.       </author>  
  50.   
  51.       <code><![CDATA[ 
  52.  
  53. import org.springframework.beans.BeansException; 
  54.  
  55. import org.springframework.beans.factory.config.BeanFactoryPostProcessor; 
  56.  
  57. import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 
  58.  
  59. import org.springframework.beans.factory.xml.XmlBeanFactory; 
  60.  
  61. import org.springframework.core.io.ClassPathResource; 
  62.  
  63.  
  64.  
  65. public class {filename.name} { 
  66.  
  67.   public static void main(String args[]) throws Exception { 
  68.  
  69.     XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("context.xml")); 
  70.  
  71.     factory.getBean("w"); 
  72.  
  73.     AllBeansLister lister = new AllBeansLister(); 
  74.  
  75.     lister.postProcessBeanFactory(factory); 
  76.  
  77.   } 
  78.  
  79. } 
  80.  
  81. class AllBeansLister implements BeanFactoryPostProcessor { 
  82.  
  83.   public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) 
  84.  
  85.       throws BeansException { 
  86.  
  87.  
  88.  
  89.     System.out.println("The factory contains the followig beans:"); 
  90.  
  91.     String[] beanNames = factory.getBeanDefinitionNames(); 
  92.  
  93.     for (int i = 0; i < beanNames.length; ++i) 
  94.  
  95.       System.out.println(beanNames[i]); 
  96.  
  97.   } 
  98.  
  99. }]]></code>  
  100.   
  101.     </script>  
  102.   
  103.   </opt>  
  104.   
  105.   <file>  
  106.   
  107.     <name>context.xml</name>  
  108.   
  109.     <content><!--[CDATA[<?xml version="1.0" encoding="UTF-8"?-->  
  110.   
  111. <!--DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"  
  112. <br /-->    "http://www.springframework.org/dtd/spring-beans.dtd">  
  113.   
  114. <beans>  
  115.   
  116.   <bean id="w" class="java.lang.String"></bean>  
  117.   
  118.    <bean id="allBeansLister" class="AllBeansLister">  
  119.   
  120. </bean></beans>  
  121.   
  122. ]]></content>  
  123.   
  124.   </file>  
  125.   
  126.   <opt ion="">  
  127.   
  128.    <name>references</name>  
  129.   
  130.    <value>.</value>  
  131.   
  132.    <value>e:\ineedcodesample\Language\Jar\STUVWXYZ\spring.jar</value>  
  133.   
  134.    <value>e:\ineedcodesample\Language\Jar\JKL\jakarta-commons\commons-logging.jar</value>  
  135.   
  136.   </opt>  
  137.   
  138.   <scriptapi></scriptapi>  
  139.   
  140. </portablescriptfile>  


그리고 다음은 에디터(emeditor)에서 단축키를 눌러 매크로로 실행한 화면