//--------------------------------------------------------------------// // 秀丸用 howmマクロ Ver. 0.5   2005/12/01 M.MORIO -- 2006/11/26 by i16 //speedup with perl PAR 2006/06/09 -- by i16 //orikaeshi set & debugs 2006/11/26 -- by i16 //{cond} 2007/01/04 -- by i16 //ホームフォルダを共有フォルダ以外にする場合は$dir_homeを変更します。 // $dir_homr="u:"; になってたらi16設定が残ってるのでその行消してね -- i16 //howmフォルダ$dir_howmを作るなら作ります //howmx.exe を $dir_howm に置きます。。。 //-- by i16 // //  使い方 //  このマクロを適当なキーに割り当てて、実行してください。 //  実行するとメニューが表示されます。 //  使う前に、下のパラメータを適切に設定してください。 //--------------------------------------------------------------------// //-----------パラメータ----------------- //ホームフォルダ $dir_home = "C:\\Documents and Settings\\All Users\\Documents"; $dir_home="u:"; //howmメモが溜まっているフォルダ。 $dir_howm = $dir_home + "\\howm"; //一時ファイル生成場所 $dir_tmp = "C:\\windows\\temp"; //メニューショートカットキー $str_menu = ","; //新規ショートカットキー $str_new = "C"; //一覧表示ショートカットーキー $str_alllist = "A"; //検索ショートカットキー $str_search = "S"; //ジャンプショートカットキー $str_jump = "J"; //その他機能ショートカットキー $str_other = "X"; //検索結果結合ショートカットキー $str_append = "P"; //日付挿入ショートカットキー $str_insert_date = "D"; //ComeFrom解析ショートカットキー $str_comefrom = "F"; $str_quick = "Q"; //---------------------------------------- //----------------------マクロ開始-------------------------------- //メニュー項目 $MENU[0] = "メニュー(&" + $str_menu + ")"; $MENU[1] = "新規(&" + $str_new + ")"; $MENU[2] = "一覧(&" + $str_alllist + ")"; $MENU[3] = "検索(&" + $str_search + ")"; $MENU[4] = "ジャンプ(&" + $str_jump + ")"; $MENU[5] = "その他(&" + $str_other + ")"; //その他メニュー項目 $MENU_other[0] = "検索結果結合(&" + $str_append + ")"; $MENU_other[1] = "日付挿入(&" + $str_insert_date + ")"; $MENU_other[2] = "ComeFrom解析(&" + $str_comefrom + ")"; $MENU_other[3] = "quick menu (&" + $str_quick + ")"; $MENU_other[4] = "未設定"; main://---------メイン------------ //メニュー作成 menuarray $MENU, 6; //各機能処理 if( result == 0 ) endmacro; else if( result == 1 ) { //メニュー生成 goto make_menu; }else if( result == 2 ) { //新規作成 goto new; } else if( result == 3 ) { //一覧表示 goto alllist; } else if( result == 4 ) { //検索 goto search; } else if( result == 5) { //ジャンプ goto jump; } else if( result == 6) { goto other; } endmacro; make_menu://---------メニュー画面生成------------ if(basename == "howm_menu.howm"){ //自分がメニューだったら閉じちゃう closenew; } if( findhidemaru( $dir_tmp + "\\howm_menu.howm" ) != -1 ) { //どっかにメニューが居たらそれも閉じちゃう closehidemaruforced findhidemaru( $dir_tmp + "\\howm_menu.howm" ); } runsync2 $dir_howm + "\\howmx.exe -m \"" + $dir_howm + "\" \"" + $dir_tmp + "\\howm_menu.howm\""; openfile $dir_tmp + "\\howm_menu.howm"; config "xAutoAdjustOrikaeshi:2"; gofiletop; readonlyswitch; endmacro; new://---------新規メモ作成------------ $org_file = filename; $dir_year = $dir_howm + "\\" + year; $dir_month = $dir_year + "\\" + month; if(! existfile($dir_year)){ runsync2 "cmd.exe /C mkdir \"" + $dir_year + "\""; } if(! existfile($dir_month)){ runsync2 "cmd.exe /C mkdir \"" + $dir_month + "\""; } if(! existfile($dir_month)){ message "保存フォルダの作成に失敗しました"; endmacro; } $create_year = year; $create_month = month; $create_day = day; $create_hour = hour; $create_minute = minute; $create_second = second; openfile $dir_month + "\\" + $create_year + "-" + $create_month + "-" + $create_day + "-" + $create_hour + $create_minute + $create_second + ".howm"; insert "= \n"; insert "[" + $create_year + "-" + $create_month + "-" + $create_day + " " + $create_hour + ":" + $create_minute + "] "; if (rightstr($org_file,5) == "\.howm" && rightstr($org_file,14) != "howm_menu\.howm"){ // ~/に変換 openfile "/h " + $dir_tmp + "\\scratch"; gofiletop; deleteafter; insert $org_file; #h = hidemaruhandle(0); replaceallfast $dir_home , "~" ,noregular; replaceallfast "\\" , "/" ,noregular; gofiletop; beginsel; golineend; endsel; $org_file = gettext(seltopx,seltopy,selendx,selendy); //prevhidemaru; setactivehidemaru findhidemaru($create_year + "-" + $create_month + "-" + $create_day + "-" + $create_hour + $create_minute + $create_second + ".howm"); closehidemaruforced #h; insert ">>> " + $org_file; } insert "\n\n"; gofiletop; golineend; endmacro; alllist://---------一覧表示------------ grep "^=","*.howm",$dir_howm,nocasesense,regular,subdir,icon,nohilight; gofileend; up; endmacro; search://---------検索------------ $str_search = input("検索文字列(正規表現)"); grep $str_search,"*.howm",$dir_howm,nocasesense,regular,subdir,hilight; endmacro; jump://---------ジャンプ------------ //config "xHilightTitle:howm.hilght"; //config "y+"; //saveconfig; //endmacro; config "xAutoAdjustOrikaeshi:2"; if(filetype == "grep"){//grep結果だった場合、普通にタグジャンプ tagjump; endmacro; }else if(colorcode == 7){//リンク while(colorcode == 7){ left; } right; beginsel; while(colorcode == 7){ right; } endsel; } //GOTOリンクかどうかのチェック // if文の中で実行できないので予めチェック #org_x = x; #org_y = y; $lnk_goto = ""; golinetop; beginsel; golineend; endsel; $str_target = gettext(seltopx,seltopy,selendx,selendy); openfile "/h " + $dir_tmp + "\\scratch"; config "xAutoAdjustOrikaeshi:2"; gofiletop; deleteafter; insert $str_target; gofiletop; #h = hidemaruhandle(0); searchdown2 ">>>",noregular; if(result){ right 3; searchdown2 "[^\\s]",regular; beginsel; golineend; endsel; $lnk_goto = gettext(seltopx,seltopy,selendx,selendy); } prevhidemaru; closehidemaruforced #h; moveto #org_x ,#org_y; if(gettext(0,y,1,y) == ">" && gettext(8,y,9,y) == "[" && rightstr(filename,14) == "howm_menu\.howm"){ //TODOリストからジャンプ moveto 0,y; right 8; beginsel; golineend; endsel; $str_search = gettext(seltopx,seltopy,selendx,selendy); openfile "/h " + $dir_tmp + "\\scratch"; config "xAutoAdjustOrikaeshi:2"; gofiletop; deleteafter; insert $str_search; #h = hidemaruhandle(0); replaceallfast "\\" , "\\\\" ,noregular; replaceallfast "[" , "\\[" ,noregular; replaceallfast "]" , "\\]" ,noregular; replaceallfast "(" , "\\(" ,noregular; replaceallfast ")" , "\\)" ,noregular; replaceallfast "^" , "\\^" ,noregular; replaceallfast "$" , "\\$" ,noregular; replaceallfast "." , "\\." ,noregular; replaceallfast "*" , "\\*" ,noregular; replaceallfast "+" , "\\+" ,noregular; replaceallfast "?" , "\\?" ,noregular; replaceallfast "|" , "\\|" ,noregular; gofiletop; beginsel; golineend; endsel; $str_search = gettext(seltopx,seltopy,selendx,selendy); prevhidemaru; closehidemaruforced #h; //grep $str_search,"*.howm",$dir_howm,nocasesense,regular,subdir,hilight; }else if($lnk_goto != ""){ //GOTOリンク if(rightstr($lnk_goto,5) ==".howm"){ //ファイルパスでジャンプ // ~/などを戻す openfile "/h " + $dir_tmp + "\\scratch"; config "xAutoAdjustOrikaeshi:2"; gofiletop; deleteafter; insert $lnk_goto; #h = hidemaruhandle(0); replaceallfast "~" , $dir_home ,noregular; replaceallfast "/" , "\\" ,noregular; gofiletop; beginsel; golineend; endsel; $lnk_goto = gettext(seltopx,seltopy,selendx,selendy); prevhidemaru; closehidemaruforced #h; openfile $lnk_goto; config "xAutoAdjustOrikaeshi:2"; endmacro; }else{ //GrepによるGOTOリンク $str_search = $lnk_goto; } }else if(selecting == 0){ //選択文字列で検索 selectword; $str_search = gettext(seltopx,seltopy,selendx,selendy); }else{ //秀丸の単語判定で検索 $str_search = gettext(seltopx,seltopy,selendx,selendy); } grep $str_search,"*.howm",$dir_howm,nocasesense,regular,subdir,hilight; config "xAutoAdjustOrikaeshi:2"; if (result > 0){ #h = hidemaruhandle(0); goscreenend; if (lineno <= 1){ prevhidemaru; closehidemaruforced #h; } if (lineno > 2){ goscreentop; endmacro; } up; golinetop; tagjump; if (result == yes){ closehidemaruforced #h; endmacro; } } endmacro; other://---------その他------------ //メニュー作成 menuarray $MENU_other, 4; //各機能処理 if( result == 0 ) endmacro; else if( result == 1 ) { //結合 goto append; }else if( result == 2){ goto insert_date; }else{ goto comefrom; //call keywdHilight "hoge"; } endmacro; append://---------結合------------ if(filetype == "grep"){//grep結果だった場合、結合処理 setclipboard ""; gofiletop; //#h = hidemaruhandle(0); #oldy = -1; #newy = y; $str_delimit = "================================================================>"; $str_tmp = ""; $old_filename = ""; $org_searchbuf = searchbuffer; #org_searchop = searchoption; while( #oldy != #newy ) { golinetop; beginsel; golineend; endsel; $new_filename = gettext(seltopx,seltopy,selendx,selendy); // ファイル名を取得 openfile "/h " + $dir_tmp + "\\scratch"; gofiletop; deleteafter; insert $new_filename; #h = hidemaruhandle(0); golinetop; beginsel; searchdown2 "(",noregular; endsel; $new_filename = gettext(seltopx,seltopy,selendx,selendy); prevhidemaru; closehidemaruforced #h; if($old_filename != $new_filename){ golinetop; tagjump; if (result == yes){ #h = hidemaruhandle(0); addclipboard "\x0D\x0A" + $str_delimit + "\x0D\x0A\x0D\x0A"; selectall; appendcopy; prevhidemaru; closehidemaru #h; } } #oldy = y; golineend2; down; #newy = y; $old_filename = $new_filename; } //newfile; //ハイライトさせるためにhowm_append.howmとして開く if( findhidemaru( $dir_tmp + "\\howm_append.howm" ) != -1 ) { closehidemaruforced findhidemaru( $dir_tmp + "\\howm_append.howm" ); } openfile $dir_tmp + "\\howm_append.howm"; selectall; delete; paste; gofiletop; //browsemodeswitch; setsearch $org_searchbuf,#org_searchop; hilightfound 1; setclipboard ""; save; readonlyswitch; endmacro; } endmacro; insert_date://---------日付挿入------------ $str_date_change = input("Enter,+数値,-数値,数値,etc."); if (leftstr($str_date_change,1) == "+" || leftstr($str_date_change,1) == "-"){ call calcDate "D", year + month + day,val($str_date_change); insert "[" + leftstr($$return,4) + "-" + midstr($$return,4,2) + "-" + rightstr($$return,2) + "]"; }else if ($str_date_change != ""){ if (strlen($str_date_change) == 1){ $input_date = year + month + "0" + $str_date_change; }else if (strlen($str_date_change) == 2){ $input_date = year + month + $str_date_change; }else if (strlen($str_date_change) == 3){ $input_date = year + "0" + $str_date_change; }else if (strlen($str_date_change) == 4){ $input_date = year + $str_date_change; }else if (strlen($str_date_change) == 5){ $input_date = "200" + $str_date_change; }else if (strlen($str_date_change) == 6){ $input_date = "20" + $str_date_change; }else if (strlen($str_date_change) == 7){ $input_date = "2" + $str_date_change; }else if (strlen($str_date_change) == 8){ $input_date = $str_date_change; } call date2count $input_date; call count2date ##return; insert "[" + leftstr($$return,4) + "-" + midstr($$return,4,2) + "-" + rightstr($$return,2) + "]"; } else{ insert "[" + year + "-" + month + "-" + day + "]"; } endmacro; comefrom://---------ComeFromリンク解析------------ gofiletop; #r = 1; while(#r){ //searchdown2 "<<<\s*[^\s].*\n",regular; searchdown2 "<<<.*\n",regular; #r = result; if(#r){ right 3; searchdown2 "[^ ]",regular; beginsel; searchdown2 "\n",regular; endsel; $str_keyword = gettext(seltopx,seltopy,selendx,selendy); call keywdHilight $str_keyword; } } config "xHilight:1"; loadhilight "howm.hilight",1; saveconfig; gofiletop; endmacro; // ============================================================================== // // キーワードハイライトサブルーチン // // ------------------------------------------------------------------------------ // // 使い方 // // call keywdHilight "hoge"; // "hoge"をハイライト // // ============================================================================== // keywdHilight: { #h_org = hidemaruhandle(0); openfile "/h " + hidemarudir + "\\howm.hilight"; //openfile hidemarudir + "\\howm.hilight"; gofileend; insert "97," + $$1 + "\x0D\x0A"; call uniq; save; setactivehidemaru #h_org; closehidemaru findhidemaru(hidemarudir + "\\howm.hilight"); // config "xHilight:1"; // loadhilight "howm.hilight",1; // saveconfig; return 1; } // ============================================================================== // // 重複行削除用サブルーチン // // ------------------------------------------------------------------------------ // // 使い方 // // call uniq; // ============================================================================== // // 重複行を除去 // by Sconcho, 2004.03.04 v1.0 uniq: { call sort; #y = linecount - 1; moveto 0, #y; $line1 = gettext(0, #y, linelen, #y); #y = #y - 1; while (#y >= 0) { moveto 0, #y; $line2 = gettext(0, #y, linelen, #y); if ($line2 == $line1) { moveto 0, #y; deleteline; } $line1 = $line2; #y = #y - 1; } return 1; } sort: { title "ソート中"; selectall; if( existfile( hidemarudir + "\\Sort.hmf " ) ) filter "Sort.hmf", "sort", "0000"; else run "sort /rec 8200 < con > con"; gofiletop; while ( code == 0x0d ) down; while( code != eof ) { call GetLine; $s1 = $$return; movetolineno 1, lineno + 1; while( 1 ) { call GetLine; $s2 = $$return; if( $s1 == $s2 ) { selectline; delete; #count = #count + 1; } else break; } #i = #i + 1; if( #i % 20 == 0 ) title "削除中 " + str( #i ); } return; } GetLine: { golinetop2; ##topy = y; golineend2; $$s = gettext( 0, ##topy, x, y ); return $$s; } // ============================================================================== // // 旬度桁数揃え用サブルーチン // // ------------------------------------------------------------------------------ // // 使い方 // // call formatShun "-3"; // $$return = " -3" // ============================================================================== // formatShun: { if($$1 == ""){ return " "; }else if(strlen($$1) == 1){ return " " + $$1; }else if(strlen($$1) == 2){ return " " + $$1; }else if(strlen($$1) == 3){ return " " + $$1; }else if(strlen($$1) == 4){ return " " + $$1; }else if(strlen($$1) == 5){ return $$1; }else{ return " "; } } // ============================================================================== // // 日付計算用サブルーチン // // ------------------------------------------------------------------------------ // // 使い方 // // call calcDate "D", "20020801", 20; // 2002年8月1日の20日後を算出 // // ============================================================================== // calcDate: { // パラメータチェック if($$1 != "D" && $$1 != "M" && $$1 != "Y" && $$1 != "W"){ message "日付演算ルーチンエラー:第1パラメータが不正です"; return ""; } // 年月日の取り出し ##y = val( $$2 ) / 10000; ##m = val( $$2 ) / 100 % 100; ##d = val( $$2 ) % 100; // 日付形式チェック =============================================================== ##endDay[1] = 31; ##endDay[2] = 28; ##endDay[3] = 31; ##endDay[4] = 30; ##endDay[5] = 31; ##endDay[6] = 30; ##endDay[7] = 31; ##endDay[8] = 31; ##endDay[9] = 30; ##endDay[10] = 31; ##endDay[11] = 30; ##endDay[12] = 31; // たけのこさんのアイデアを頂戴しました。 ##endDay[2] = ##endDay[2] + (##y % 4 == 0) - (##y % 100 == 0) + (##y % 400 == 0); if( ##m < 1 || ##m > 12 || ##d < 1 || ##d > ##endDay[##m] || val( $$2 ) < 19000101 ){ message "日付演算ルーチンエラー:第2パラメータが日付ではありません"; return ""; } // 日付形式チェック終了 =========================================================== // 曜日計算 ======================================================================= if( $$1 == "W" ){ ##YY_W = ##y; ##MM_W = ##m; ##DD_W = ##d; if( ##MM_W < 3 ) { ##YY_W = ##YY_W - 1; ##MM_W = ##MM_W + 12; } ##Y1_W = ##YY_W / 100; ##Cal1_W = ##Y1_W / 4; ##Y2_W = ##YY_W - (##YY_W / 100) * 100; ##Cal2_W = ##Y2_W / 4; ##Cal3_W = 26 * (##MM_W + 1) / 10; ##Cal9_W = ##Cal1_W - ##Y1_W * 2 + ##Y2_W + ##Cal2_W + ##Cal3_W + ##DD_W - 1; while( ##Cal9_W < 0 ) { ##Cal9_W = ##Cal9_W + 7; } ##Date_WeekDay = ##Cal9_W - (##Cal9_W / 7) * 7; if( ##3 == 1 ){ $$YOUBI[0] = "日"; $$YOUBI[1] = "月"; $$YOUBI[2] = "火"; $$YOUBI[3] = "水"; $$YOUBI[4] = "木"; $$YOUBI[5] = "金"; $$YOUBI[6] = "土"; $$ret = $$YOUBI[##Date_WeekDay]; } else { $$ret = str( ##Date_WeekDay + 1 ); } return $$ret; } // 曜日計算終了 ================================================================= // 日単位の演算 =================================================================== else if( $$1 == "D" ) { // 日付を通算日付に変換 call date2count $$2; ##Nissu = ##return + ##3; // 加算結果を日付に変換 call count2date ##Nissu; return $$return; } // 日単位の演算終了 =============================================================== // 年・月単位の演算 =============================================================== else{ if( $$1 == "M" ){ ##ret_mm = ##m + ##3; ##ret_yy = ##y; }else{ ##ret_yy = ##y + ##3; ##ret_mm = ##m; } ##ret_dd = ##d; while( ##ret_mm > 12 ){ ##ret_yy = ##ret_yy + 1; ##ret_mm = ##ret_mm - 12; } while( ##ret_mm < 0 ){ ##ret_yy = ##ret_yy - 1; ##ret_mm = ##ret_mm + 12; } // 2月末日のリセット ##endDay[2] = 28; ##endDay[2] = ##endDay[2] + (##ret_yy % 4 == 0) - (##ret_yy % 100 == 0) + (##ret_yy % 400 == 0); if( ##ret_dd > ##endDay[##ret_mm] ) { ##ret_dd = ##endDay[##ret_mm]; } $$y = str(##ret_yy); $$m = rightstr( "0" + str(##ret_mm), 2 ); $$d = rightstr( "0" + str(##ret_dd), 2 ); return $$y + $$m + $$d; } // 年・月単位の演算終了 =========================================================== } // 日付を1900年1月1日からの通算日数に変換する // 1900年1月1日を1とする date2count: { ##y = val( $$1 ) / 10000; ##m = val( $$1 ) / 100 % 100; ##d = val( $$1 ) % 100; // 前年までのうるう年の回数 call countURUU ##y - 1; // 前年12月31日までの通算日付 ##lastMISOKA = 365 * (##y - 1900) + ##return; ##endDay[1] = 31; ##endDay[2] = 28; ##endDay[3] = 31; ##endDay[4] = 30; ##endDay[5] = 31; ##endDay[6] = 30; ##endDay[7] = 31; ##endDay[8] = 31; ##endDay[9] = 30; ##endDay[10] = 31; ##endDay[11] = 30; ##endDay[12] = 31; // たけのこさんのアイデアを頂戴しました。 ##endDay[2] = ##endDay[2] + (##y % 4 == 0) - (##y % 100 == 0) + (##y % 400 == 0); ##idx = 1; ##thisYEAR = 0; while( ##idx < ##m ){ ##thisYEAR = ##thisYEAR + ##endDay[##idx]; ##idx = ##idx + 1; } ##thisYEAR = ##thisYEAR + ##d; return ##lastMISOKA + ##thisYEAR; } // 通算日数を日付に変換する // 1900年1月1日を1とする count2date: { // およその年数 ##tmpYEAR = ##1 / 365 + 1900; // message str(##1); // 前年末までの日数 if( 1900 == ##tmpYEAR ) { ##std = 0; }else{ while(1){ call date2count str( ##tmpYEAR - 1 ) + "1231"; ##std = ##return; // message str(##std); if( ##std < ##1 ){ break; } else{ ##tmpYEAR = ##tmpYEAR - 1; } } } // 前年末からの日数 ##tmpDAY = ##1 - ##std; ##endDay[1] = 31; ##endDay[2] = 28; ##endDay[3] = 31; ##endDay[4] = 30; ##endDay[5] = 31; ##endDay[6] = 30; ##endDay[7] = 31; ##endDay[8] = 31; ##endDay[9] = 30; ##endDay[10] = 31; ##endDay[11] = 30; ##endDay[12] = 31; ##endDay[2] = ##endDay[2] + (##tmpYEAR % 4 == 0) - (##tmpYEAR % 100 == 0) + (##tmpYEAR % 400 == 0); ##idx = 0; while( 0 < ##tmpDAY ){ ##tmpDAY = ##tmpDAY - ##endDay[##idx+1]; ##idx = ##idx + 1; } ##tmpMONTH = ##idx; $$ret = str(##tmpYEAR) + rightstr( "0" + str(##tmpMONTH), 2 ) + rightstr( "0" + str(##tmpDAY + ##endDay[##idx]), 2 ); return $$ret; } countURUU: { ##idx = 1900; ##uruuCount = 0; // その年までのうるう年の回数を数える while( ##idx <= ##1 ){ ##uruuCount = ##uruuCount + (##idx % 4 == 0) - (##idx % 100 == 0) + (##idx % 400 == 0); ##idx = ##idx + 1; } return ##uruuCount; }