Last active
January 2, 2019 08:04
-
-
Save skymonsters-Ks/063c9af558871186bfd452a88f6d7786 to your computer and use it in GitHub Desktop.
Notepad++用ファイル実行補助ツール
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Notepad++用ファイル実行補助ツール | |
Notepad++で編集中の文書を保存し登録したファイルを実行します | |
主にコードのコンパイルに使用します | |
使い方 | |
1. このスクリプトをコンパイルして実行ファイル(nppcl.exe)作成 | |
2. nppcl.exe を notepad++.exe と同じフォルダにコピー | |
3. nppcl.ini を同じフォルダに新規作成 | |
内容は、1行目は 0 | |
2行目は 実行コマンド名 | |
3行目は "実行ファイルのフルパス" | |
複数登録する場合は 4行目以降は 2,3行目の繰り返し… | |
4. Notepad++ の「ファイル名を指定して実行」に登録 | |
"$(NPP_DIRECTORY)\nppcl.exe" "$(FULL_CURRENT_PATH)" | |
-pオプション付きも登録(前回のコマンドを実行する) | |
"$(NPP_DIRECTORY)\nppcl.exe" "$(FULL_CURRENT_PATH)" -p | |
license: NYSL 0.9982 ( http://www.kmonos.net/nysl/ ) | |
tested: HSP 3.5b5 | |
*/ | |
#define global SOFT_NAME "NPP cmpluncher" | |
#define global VERSION_S "0.1.1.0" | |
#define global VERSION_I 110 | |
#define global AUTHOR "K-s (@skymonsters_Ks)" | |
#define SAVE_FILE_NAME "nppcl.ini" | |
#const SAVE_TIMEOUT 500 ; (*10msec) | |
#packopt runtime "hsp3c.hrt" | |
#packopt name "nppcl" | |
#packopt xsize 1 | |
#packopt ysize 1 | |
#packopt hide 1 | |
#include "user32.as" | |
#module | |
/* | |
引用符つき文字列分割、取得モジュール | |
in 分割文字列、 _delim 分割文字、 _quot 引用符、 _esc エスケープ文字 | |
引用符で囲まれた文字列は分割文字があっても分割されない、分割後引用符は除かれる | |
引用符自体を文字列に用いる場合は直前にエスケープ文字を置く | |
splitString で分解、 stat に分割数が返る | |
getSplitString で分割した文字列が res に返る、 id は分割文字列のインデックス | |
*/ | |
#deffunc splitString var in, int _delim, int _quot, int _esc | |
sdim out, strlen(in) + 2 | |
dim p_src | |
p_dst = 1 | |
index = 1 | |
dim num | |
dim qf | |
if (peek(in) == _quot) { | |
qf = 1 | |
p_src++ | |
} | |
repeat | |
c = peek(in, p_src) | |
if (c == 0) { | |
num++ | |
break | |
} else : if (c == _delim) { | |
if (qf) { | |
poke out, p_dst, _delim | |
p_dst++ | |
} else { | |
if (peek(out, p_dst - 1)) { | |
poke out, p_dst | |
p_dst++ | |
num++ | |
index(num) = p_dst | |
} | |
} | |
} else : if (c == _quot) { | |
if (peek(in, p_src - 1) == _esc) { | |
poke out, p_dst - 1, _quot | |
} else { | |
qf ^= 1 | |
} | |
} else { | |
poke out, p_dst, c | |
p_dst++ | |
} | |
p_src++ | |
loop | |
if (peek(out, p_dst - 1)) : else { | |
if (num > 0) : num-- | |
} | |
return num | |
#deffunc getSplitString var res, int id | |
if (id < num) { | |
getstr res, out, index(id) | |
} | |
return | |
#global | |
ts = dir_cmdline | |
splitString ts, ' ', '"', '\\' | |
if (stat == 0) { | |
ts = strf("%s %s\n\nauthor: %s\nbuild: %s-%s-%x", SOFT_NAME, VERSION_S, AUTHOR, __date__, __time__, hspver) | |
s = "About" | |
mbp = 40, hwnd, hinstance, varptr(ts), varptr(s), $80, 128 | |
MessageBeep $40 | |
MessageBoxIndirect varptr(mbp) | |
end | |
} | |
cmdlineParamNum = stat | |
sdim buf, 512 | |
GetForegroundWindow | |
whdl = stat | |
sendmsg whdl, $000d, 512, varptr(buf) ; WM_GETTEXT | |
if (instr(buf, 0, " - Notepad++") < 0) { | |
dialog "Notepad++ is not active", , SOFT_NAME | |
end | |
} | |
if (peek(buf, 0) == '*') { | |
keybd_event $11, 0, 0, 0 | |
keybd_event 'S', 0, 0, 0 | |
keybd_event $11, 0, 2, 0 | |
keybd_event 'S', 0, 2, 0 | |
repeat SAVE_TIMEOUT, 1 | |
await 10 | |
sendmsg whdl, $000d, 512, varptr(buf) ; WM_GETTEXT | |
if (peek(buf, 0) != '*') { | |
break | |
} | |
if (cnt == SAVE_TIMEOUT) { | |
dialog "Save timed out", , SOFT_NAME | |
end | |
} | |
loop | |
} | |
fprecmd = 0 | |
sdim fpath | |
repeat cmdlineParamNum | |
getSplitString prm, cnt | |
if (prm == "-p") { | |
fprecmd = 1 | |
} else { | |
fpath = "\"" + prm + "\"" | |
} | |
loop | |
sdim buf | |
sdim cmdname | |
sdim cmdlist | |
notesel buf | |
noteload SAVE_FILE_NAME | |
noteget ts, 0 | |
precmd = int(ts) | |
i = 1 | |
repeat | |
noteget ts, i | |
if (ts == "") : break | |
cmdname += ts + "\n" | |
noteget ts, i + 1 | |
cmdlist(cnt) = ts | |
i += 2 | |
loop | |
if (fprecmd) { | |
goto *runcmd | |
} else { | |
screen 0, 260, 20, 2, ginfo_mx - 100, ginfo_my - 30 | |
title SOFT_NAME | |
objsize 200, 20 | |
combox cmdid, , cmdname | |
objsize 60, 20 | |
pos 200, 0 | |
button gosub "Run", *runcmd | |
onkey gosub *evkey | |
gsel 0, 2 | |
SetForegroundWindow hwnd | |
objsel 0 | |
} | |
stop | |
*evkey | |
if (lparam >> 30) : return | |
if (wparam == 13) : gosub *runcmd ; [enter] | |
return | |
*runcmd | |
if (fprecmd) { | |
i = precmd | |
} else { | |
i = cmdid | |
} | |
cmd = cmdlist(i) | |
strrep cmd, "%f", fpath | |
exec cmd | |
noteadd str(i), 0, 1 | |
notesave SAVE_FILE_NAME | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment