ã«ã³ãã§ä½ç½®ãæããjEditãã¯ã
ã«ã³ãã§åºåã£ã¦ããã¹ãã®ä½ç½®ãæããjEditãã¯ããæ¸ãã¦ã¿ã¾ããã
使ç¨å
[ {'name':'ã°ã¬ã¼ã', 'text':'ãã¿ã¯ç©¶æ¥µã®ã²ã¼ãã¼ã ', 'score':100}, {'name':'ã°ãã', 'text':'ããã¾ã§ããã¤ãã¯ãªããªãããªãã', 'score':80}, {'name':'ãã§ã¢', 'text':'ã¾ã並ã¿ã®åæ ¼ç¹ã ã', 'score':50} ]
使ç¨å¾
[ {'name':'ã°ã¬ã¼ã', 'text':'ãã¿ã¯ç©¶æ¥µã®ã²ã¼ãã¼ã ', 'score':100}, {'name':'ã°ãã', 'text':'ããã¾ã§ããã¤ãã¯ãªããªãããªãã', 'score':80}, {'name':'ãã§ã¢', 'text':'ã¾ã並ã¿ã®åæ ¼ç¹ã ã', 'score':50} ]
ã¤ã³ãã³ãããªããªã£ã¦ãã¾ãã®ã¯ãç©å½¢é¸æã¢ã¼ã(Alt+\)ã§å調æ´ãã¦ãã ãããªã
ã«ã³ãã§ä½ç½®ãæãã.bsh
//text width based on CJK letter width int widthOf(text) { int w = 0; for(i = 0; i < text.length(); i++) { c = text.charAt(i); w += (0x2000 <= c && c < 0xff61) ? 2 : 1; //Fuzzy Zenkaku range } return w; } //replacement for String.split(",") String[] spritByCommaExactly(text) { int numTokens = 1; for(i = 0; i < text.length(); i++) { if(text.charAt(i) == ',') numTokens++; } tokens = new String[numTokens]; c = 0; p = 0; for(i = 0; i < text.length(); i++) { if(text.charAt(i) == ',') { tokens[c++] = text.substring(p, i).trim(); p = i + 1; } } tokens[c++] = text.substring(p, i).trim(); return tokens; } String formatTextAlignmentByComma(text) { lines = text.split("\n"); //expand text to table form. //...and get the max number of columns in table table = new String[lines.length][]; maxTokens = 0; for(i = 0; i < lines.length; i++) { tokens = spritByCommaExactly(lines[i]); table[i] = tokens; if(tokens.length > maxTokens) { maxTokens = tokens.length; } } //calc width for each columns. widthArray = new int[maxTokens]; for(i = 0; i < table.length; i++) { tokens = table[i]; for(j = 0; j < tokens.length; j++) { w = widthOf(tokens[j]); if(w > widthArray[j]) { widthArray[j] = w; } } } //generate output. sb = new StringBuffer(); for(i = 0; i < table.length; i++) { tokens = table[i]; for(j = 0; j < tokens.length; j++) { sb.append(tokens[j]); if(j < tokens.length - 1) { sb.append(","); //padding for the next token //it's skipped if the next token is the last and the last token is empty. if(!(j == tokens.length - 2 && tokens[tokens.length - 1].equals(""))){ pad = widthArray[j] - widthOf(tokens[j]) + 1; for(k = 0; k < pad; k++) { sb.append(" "); } } } } sb.append("\n"); } return sb.toString(); } if(buffer.isReadOnly()) Macros.error(view, "Buffer is read-only."); else textArea.setSelectedText(formatTextAlignmentByComma(textArea.getSelectedText()));
jEditãã¯ãã¯æ¥æ¬èªãã¡ã¤ã«åã§ãå¹³æ°ã§ããã~/.jedit/macros ã«ãã«ã³ãã§ä½ç½®ãæãã.bshããä¿åããã°ããã¯ãã¡ãã¥ã¼ã«æ¥æ¬èªã®é ç®ãå¢ãã¾ãã
åèªã®åãæ¹ãã«ã¹ã¿ãã¤ãºããã°ãããè¨èªã«ç¹åãããã®ãã§ããããã
ããã«ãã¦ããhttp://d.hatena.ne.jp/tanakahisateru/20080925/1222336816 ã§æ¸ãããjEditã«JRubyãçµã¿è¾¼ãããããã£ã¨æ¥½ã§ãæ¥æ¬ã§ãã¦ã±ãã®ããªããã£ã¦åè«ã®ã¤ããã§è¨ã£ããã©ãã©ãããåè«ãããªãã£ã½ããä»åã®ã¹ã¯ãªããã§ãã»ãã¨ã«Groovyã¨ãJRubyã¨ã使ãããã¨æãã¾ããã