/* * リファレンスサイトやヘルプファイルなどを開く秀丸マクロ * 設定次第でいろいろな URL を開くことが出来ます。 * * Ver.3.9 (2017-07-24) * * 機能 * - ファイルタイプに応じたリファレンスサイトやヘルプファイルを開きます。 * - マクロの先頭でファイルタイプとリファレンスの対応などを設定できます。 * - 1つのファイルタイプに複数のリファレンスが対応している場合は、メニューが表示され、開きたいものを選択できます。 * - リファレンスサイトを開くときは、カーソル位置の単語または選択中の文字列をURLのパラメータとして利用できます。 * - リファレンスサイト毎に検索用のURLとindexのURLを指定できます。検索ワードが無い場合はindexのURLを開きます。 * - マクロの先頭でRubyインタプリタを設定すると、マルチバイト文字列もURLのパラメータとして利用できるようになります。 * - このマクロが実行されたときに特定のキー(デフォルトでは Alt)が押されていた場合は、ファイルタイプとの関連付けを * 無視して、登録されているすべてのリファレンスをメニューに表示します。 * * - デフォルトで以下のリファレンスが設定してあります。 * - PHPマニュアル (.php) * - Rubyリファレンスマニュアル (.rb .rbw) * - とほほのWWW入門 (.html .css .js) * - Mozilla Developer Network (.html .css .js) * - Google * - 英辞郎 on the WEB * - 秀丸エディタヘルプ * - 秀丸マクロヘルプ (.mac) * * Yasunori Miyamoto * http://tipszone.jp/20121203_open_manual_mac/ * mailto: nori@tipszone.jp */ // Rubyインタプリタ $ruby = "ruby"; // このマクロが実行された時にここで設定したキーが押されていた場合、ファイルタイプとの関連付けを // 無視して、登録されているすべてのリファレンスをメニューに表示します。 // // Shift: 0x10 上: 0x26 下: 0x28 0〜9: 0x30〜0x39 // Ctrl : 0x11 左: 0x25 右: 0x27 A〜Z: 0x41〜0x5A // Alt : 0x12 ※詳しくは秀丸エディタマクロヘルプの iskeydown の項目を参照 // #code = 0x12; // ファイルタイプとリファレンスの関連付け // // ##id : リファレンスID // $name[##id] : リファレンスの名前 (必須) // "\x01"という文字列を指定すると、メニューにセパレータを表示できます。 // $index[##id] : 検索ワードが無い場合に開くURL (即ち、行末にカーソルを置いて実行した場合に開く URL) // $search[##id] : URL ("%s" が検索ワードに置換されます) // または、ヘルプファイルを開く秀丸マクロのコマンド (macrohelp, hidemaruhelp, help, help2, ...) // $shortcut[##id]: メニューからリファレンスを選択するときのショートカットキー // $charset[##id] : 検索ワードをこの文字コードに変換してから %s を置換します。 (デフォルトは UTF-8) // ※ただし、有効なRubyインタプリタが指定されている場合に限る。 // $filetype[##id]: 関連付けるファイルタイプを配列で指定 // ##id = 0; $name[##id] = "PHPマニュアル"; $index[##id] = "http://www.php.net/manual/ja/"; $search[##id] = "http://jp2.php.net/manual-lookup.php?lang=ja&function=%s"; $shortcut[##id] = "P"; $filetype[##id][0] = ".php"; ##id = ##id + 1; $name[##id] = "Rubyリファレンスマニュアル"; $index[##id] = "https://docs.ruby-lang.org/ja/latest/doc/"; $search[##id] = "https://docs.ruby-lang.org/ja/search/query:%s/"; $shortcut[##id] = "R"; $filetype[##id][0] = ".rb"; $filetype[##id][1] = ".rbw"; $filetype[##id][2] = ".rake"; ##id = ##id + 1; $name[##id] = "とほほのWWW入門"; $index[##id] = "http://www.tohoho-web.com/www.htm"; $search[##id] = "https://www.google.com/search?as_sitesearch=www.tohoho-web.com&q=%s"; $shortcut[##id] = "T"; $filetype[##id][0] = ".html"; $filetype[##id][1] = ".css"; $filetype[##id][2] = ".scss"; $filetype[##id][3] = ".js"; ##id = ##id + 1; $name[##id] = "Mozilla Developer Network"; $index[##id] = "https://developer.mozilla.org/ja/"; $search[##id] = "https://developer.mozilla.org/ja/search?q=%s"; $shortcut[##id] = "M"; $filetype[##id][0] = ".html"; $filetype[##id][1] = ".css"; $filetype[##id][2] = ".scss"; $filetype[##id][3] = ".js"; ##id = ##id + 1; $name[##id] = "Google"; $index[##id] = "https://www.google.co.jp/"; $search[##id] = "https://www.google.co.jp/search?q=%s"; $shortcut[##id] = "G"; ##id = ##id + 1; $name[##id] = "英辞郎 on the WEB"; $index[##id] = "http://www.alc.co.jp/"; $search[##id] = "http://eow.alc.co.jp/search?q=%s"; $shortcut[##id] = "D"; ##id = ##id + 1; $name[##id] = "\x01"; ##id = ##id + 1; $name[##id] = "秀丸エディタヘルプ"; $search[##id] = "hidemaruhelp"; $shortcut[##id] = "E"; ##id = ##id + 1; $name[##id] = "秀丸マクロヘルプ"; $search[##id] = "macrohelp"; $shortcut[##id] = "H"; $filetype[##id][0] = ".mac"; ##id = ##id + 1; //$name[##id] = ""; //$search[##id] = ""; //$shortcut[##id] = ""; //$charset[##id] = ""; //$filetype[##id][0] = ""; //##id = ##id + 1; // 範囲選択中でない場合はカーソル位置の単語を検索対象とする。 if (selecting == no) { // カーソルが単語の終端にあると思われる場合は、左に動かす call CURSOR_IS_ON_WORD_END; if (##return) left; selectword; } // 開くリファレンスを決める call GET_REFERENCE_ID; ##id = ##return; // index または search が http で始まっていたらリファレンスサイト、そうでなければヘルプファイルを開く if ($search[##id] != "") $$ref = $search[##id]; else $$ref = $index[##id]; if (leftstr($$ref, 4) == "http") { $$query = gettext2(seltopcolumn, seltoplineno, selendcolumn, selendlineno, 1); call OPEN_REFERENCE ##id, $$query; } else if ($$ref == "macrohelp") macrohelp; else if ($$ref == "hidemaruhelp") hidemaruhelp; else if ($$ref == "help") help; else if ($$ref == "help2") help2; else if ($$ref == "help3") help3; else if ($$ref == "help4") help4; else if ($$ref == "help5") help5; else if ($$ref == "help6") help6; else message "Invalid Address specified."; endmacro; // 開くリファレンスを決める // Return: integer リファレンスID GET_REFERENCE_ID: ##size = 0; if (!iskeydown(#code)) { // ファイルタイプの設定が一致するリファレンスを探す ##i = 0; while ($name[##i] != "") { ##j = 0; while ($filetype[##i][##j] != "") { if ($filetype[##i][##j] == filetype) { #reference_id[##size] = ##i; ##size = ##size + 1; } ##j = ##j + 1; } ##i = ##i + 1; } if (##size == 1) return #reference_id[0]; } call SHOW_MENU ##size; return ##return; // リファレンスを選択するためのメニューを表示する // Param: integer #reference_id 配列のサイズ // 0 の場合は設定にあるすべてのリファレンスを表示、そうでなければ // #reference_id 配列で指定された中から選択できるようにする // Return: integer リファレンスID SHOW_MENU: ##size = ##1; if (##size == 0) { // すべてのリファレンスのIDを配列化 while ($name[##size] != "") { #reference_id[##size] = ##size; ##size = ##size + 1; } } // メニューを表示 ##i = 0; while (##i < ##size) { ##id = #reference_id[##i]; $$list[##i] = $name[##id]; if ($shortcut[##id] != "") $$list[##i] = $$list[##i] + "\t&" + $shortcut[##id]; ##i = ##i + 1; } menuarray $$list, ##size; if (result == 0) endmacro; return #reference_id[result - 1]; // カーソルが単語の終端にあるか調べる。 // Return: boolean 単語の終端にあると思われる場合には true そうでなければ false CURSOR_IS_ON_WORD_END: // Before ##code = unicode(gettext2(column - 1, lineno, column, lineno, 1)); call IS_ASCII_CONTROL_OR_MARK ##code; if (##return) return false; // After ##code = unicode(gettext2(column, lineno, column + 2, lineno, 1)); call IS_ASCII_CONTROL_OR_MARK ##code; return ##return; // 文字コードがコントロールコードや記号か調べる。 // Param: Integer 文字コード // Return: boolean コントロールコードや記号であれば true, そうでなければ false IS_ASCII_CONTROL_OR_MARK: return (##1 <= 127 && (##1 <= 47 || (58 <= ##1 && ##1 <= 64) || (91 <= ##1 && ##1 <= 94) || ##1 == 96 || 123 <= ##1)); // リファレンスサイトを開く // Param: integer マクロの先頭で設定したリファレンスID // Param: string 検索ワード (SJIS) OPEN_REFERENCE: // $index と $search どちらの URL を開くか決める if (($$2 == "" && $index[##1] != "") || $search[##1] == "") $$url = $index[##1]; else $$url = $search[##1]; if ($ruby != "") { runex "\"" + $ruby + "\" -x -- \"" + currentmacrofilename + "\" \"" + $$url + "\" \"" + $$2 + "\" " + $charset[##1], 1, //sync 0:async 1:sync 0, "", //stdin 0:none 1:auto 2:file 3:(reserve) 4:all 5:select 0, "", //stdout 0:none 1:auto 2:file 3:add file 4:new 5:insert 6:replace 7:output frame 0, "", //stderr 0:none 1:=out 2:file 3:add file 4:new 5:insert 6:replace 7:output frame 0, "", //folder 0:none 1:current 2:specify 3:(reserve) 4:exe's folder 2, //show 0:auto 1:show 2:hide 1, //nodraw 0:draw 1:no draw 0; //unicode 0:ansi 2:unicode if (result && getresultex(9) == 0) return; } // マルチバイト文字での検索も有効にするためには、検索ワードを各リファレンスサイトが受け付ける // 文字コードに変換してからURLエンコードする必要がある。しかし、秀丸マクロでは困難と思われる。 call URL_ENCODE $$2; call REPLACE "%s", $$return, $$url; openbyshell $$return; return; // 引数として渡された文字列をURLエンコードして返す // Param: string URLエンコードする文字列 // Return: string エンコード後の文字列 URL_ENCODE: $$rslt = ""; ##strlen = strlen($$1); ##i = 0; while (##i < ##strlen) { $$rslt = $$rslt + "%" + hex(ascii(midstr($$1, ##i, 1))); ##i = ##i + 1; } return $$rslt; // 処理対象文字列に含まれる検索文字列を全て置換文字列に置換する // Param: 検索文字列 // Param: 置換文字列 // Param: 処理対象文字列 REPLACE: $$rslt = ""; while (true) { ##i = strstr($$3, $$1); if (##i == -1) { $$rslt = $$rslt + $$3; break; } $$rslt = $$rslt + leftstr($$3, ##i) + $$2; $$3 = rightstr($$3, strlen($$3) - ##i - strlen($$1)); } return $$rslt; /* #!ruby # coding: SJIS # ARGV[0] : アドレス # ARGV[1] : 検索ワード # ARGV[2] : 文字コード (デフォルト UTF-8) # [検索ワード] を [文字コード] に変換し、[アドレス] 内の %s をそれで置き換えた URL を開く require "cgi" address, query, charset = ARGV[0..2] charset ||= 'UTF-8' address = address.gsub(/%s/, CGI.escape(query.encode(charset))) `start "" "#{address}"` __END__ */