一、全域變數
$(FULL_CURRENT_PATH) : E:\my Web\main\welcome.html$(CURRENT_DIRECTORY) : E:\my Web\main$(FILE_NAME) : welcome.html$(NAME_PART) : welcome$(EXT_PART) : html$(NPP_DIRECTORY) : the full path of notepad++'s directory$(CURRENT_WORD) : word(s) you selected in Notepad++$(CURRENT_LINE) : current line number$(CURRENT_COLUMN) : current column number
二、配置運行宏("運行"菜單的"運行"子功能表)
1. 編譯當前開啟的java源檔案
cmd /K cd /D $(CURRENT_DIRECTORY) && javac $(FILE_NAME)
2. 執行當前開啟的java源檔案對應的class檔案
cmd /K cd /D $(CURRENT_DIRECTORY) && java $(NAME_PART)
3. 編譯並運行當前開啟的java源檔案
cmd /K cd /D $(CURRENT_DIRECTORY) && javac $(FILE_NAME) && java $(NAME_PART)
三、瘋狂改造
1. 將編譯下邊的C源碼編譯成exec_head.exe,放到notepad++的安裝目錄
#include <stdio.h>#include <stdlib.h>#include <string.h>static int buf_i = 0;static int buf_size = 0;static char *buf = NULL;static void _buf_add(char c) {if (c == -1) {if (buf_i > 0) buf_i--;return;}if (buf == NULL || buf_i == buf_size) {buf_size += 1024;buf = (char *)realloc(buf, buf_size);if (buf == NULL) exit(1);}buf[buf_i++] = c;}static int _fgetc(FILE *file){char c = fgetc(file);if (c == '\n') {if (fgetc(file) != '/' || fgetc(file) != '/')return EOF;else c = fgetc(file);}if (c == '\n' || c == '#') {return EOF;}return c;}int main(int argc, char *argv[]){if (argc < 2) return 1;FILE *file = fopen(argv[1], "r");if (!file) return 1;if (fgetc(file) != '/' || fgetc(file) != '/' || fgetc(file) != '#') return 1;char c = _fgetc(file);while (c == ' ' || c == '\t') c = _fgetc(file);while (c != EOF) {if (c == ' ' || c == '\t') {do { c = _fgetc(file); } while (c == ' ' || c == '\t');if (c != ';') _buf_add(' ');} else if (c == ';') {do { c = _fgetc(file); } while (c == ' ' || c == '\t');if (c != EOF) _buf_add(';');} else {_buf_add(c);c = _fgetc(file);}}fclose(file);_buf_add('\0');char *cmd = strtok(buf, ";");while (cmd) {printf("#exec:%s\n", cmd);system(cmd);cmd = strtok(NULL, ";");}free(buf);buf = NULL;return 0;}
2. 配置運行宏,並設定快速鍵Ctrl + Shift + H
cmd /K cd /D $(CURRENT_DIRECTORY) && $(NPP_DIRECTORY)/exec_head.exe $(FILE_NAME)
3. 若當前開啟的檔案以"//#"開頭的話,程式會將"//#"至"#"之間的文本解釋成命令並執行,命令間可用";"分割,如
//#//javac Test.java; //java Test//#public class Test {public static void main(String[] args) {System.out.println("Hello");}}
4. 按下快速鍵Ctrl + Shift + H,將彈出一個CMD視窗:
#exec:javac Test.java#exec:java TestHello