forked from MarcSaenz/NotepadSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PluginDefinition.cpp
2219 lines (1722 loc) · 64.3 KB
/
PluginDefinition.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//this file is part of notepad++
//Copyright (C)2003 Don HO <donho@altern.org>
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "stdio.h"
#include "tchar.h"
#include "PluginDefinition.h"
#include "menuCmdID.h"
#include "Version.h"
// The plugin data that Notepad++ needs
//
FuncItem funcItem[nbFunc];
//
// The data of Notepad++ that you can use in your plugin commands
//
NppData nppData;
//
// Initialize your plugin data here
// It will be called while plugin loading
void pluginInit(HANDLE hModule)
{
}
//
// Here you can do the clean up, save the parameters (if any) for the next session
//
void pluginCleanUp()
{
}
//
// Initialization of your plugin commands
// You should fill your plugins commands here
void commandMenuInit()
{
//--------------------------------------------//
//-- STEP 3. CUSTOMIZE YOUR PLUGIN COMMANDS --//
//--------------------------------------------//
// with function :
// setCommand(int index, // zero based number to indicate the order of command
// TCHAR *commandName, // the command name that you want to see in plugin menu
// PFUNCPLUGINCMD functionPointer, // the symbol of function (function pointer) associated with this command. The body should be defined below. See Step 4.
// ShortcutKey *shortcut, // optional. Define a shortcut to trigger this command
// bool check0nInit // optional. Make this menu item be checked visually
// );
/**
* Delete current line on CTRL+SHIFT+D
*/
ShortcutKey *D_key = new ShortcutKey;
D_key->_isAlt = false;
D_key->_isCtrl = true;
D_key->_isShift = true;
D_key->_key = 0x44; // D
setCommand(0, TEXT("Delete current line"), delete_current_line, D_key, false);
ShortcutKey *ctrlv = new ShortcutKey;
ctrlv->_isAlt = false;
ctrlv->_isCtrl = true;
ctrlv->_isShift = false;
ctrlv->_key = 0x56; // V
setCommand(1, TEXT("Paste indented"), paste_indented, ctrlv, false);
ShortcutKey *T_key = new ShortcutKey;
T_key->_isAlt = false;
T_key->_isCtrl = true;
T_key->_isShift = true;
T_key->_key = 0x54; // T
setCommand(2, TEXT("Undo close tab"), undo_closed_tab, T_key, false);
ShortcutKey *I_key = new ShortcutKey;
I_key->_isAlt = false;
I_key->_isCtrl = true;
I_key->_isShift = true;
I_key->_key = 0x49 ; // I
//setCommand(2, TEXT("INSERT ALL FILES LIST"), closed_file_list, I_key, false);
ShortcutKey *LEFT_key = new ShortcutKey;
LEFT_key->_isAlt = true;
LEFT_key->_isCtrl = false;
LEFT_key->_isShift = false;
LEFT_key->_key = VK_LEFT ; // LEFT
setCommand(4, TEXT("Tab left"), buffer_left, LEFT_key, false);
ShortcutKey *RIGHT_key = new ShortcutKey;
RIGHT_key->_isAlt = true;
RIGHT_key->_isCtrl = false;
RIGHT_key->_isShift = false;
RIGHT_key->_key = VK_RIGHT ; // RIGHT
setCommand(5, TEXT("Tab right"), buffer_right, RIGHT_key, false);
ShortcutKey *W_key = new ShortcutKey;
W_key->_isAlt = true;
W_key->_isCtrl = true;
W_key->_isShift = false;
W_key->_key = 0x57; // W
setCommand(7, TEXT("Wrap selection with tag"), wrap_with_tag, W_key, false);
ShortcutKey *period = new ShortcutKey;
period->_isAlt = false;
period->_isCtrl = true;
period->_isShift = false;
period->_key = 0xBE;// VK_OEM_PERIOD 0xBE "." any country/region
setCommand(8, TEXT("Close last open tag"), end_tag, period, false);
setCommand(10, TEXT("URL encode selection"), url_encode_selection, NULL, false);
setCommand(11, TEXT("URL decode selection"), url_decode_selection, NULL, false);
ShortcutKey *C_key = new ShortcutKey;
C_key->_isAlt = false;
C_key->_isCtrl = true;
C_key->_isShift = true;
C_key->_key = 0x43; // C
setCommand(13, TEXT("Column ruler"), ruler, C_key, false);
setCommand(15, TEXT("Leading TABS to Spaces"), tabs_to_spaces, NULL, false);
setCommand(16, TEXT("Leading Spaces to TABS"), spaces_to_tabs, NULL, false);
setCommand(18, TEXT("Features"), show_features, NULL, false);
setCommand(19, TEXT("About"), show_about, NULL, false);
ShortcutKey *L_key = new ShortcutKey;
L_key->_isAlt = true;
L_key->_isCtrl = false;
L_key->_isShift = false;
L_key->_key = 0x49; // L
setCommand(20, TEXT("Select string"), select_string, L_key, false);
::SendMessage(getCurrentScintilla(), SCI_SETENDATLASTLINE , (WPARAM)false, (LPARAM)false);
}
//
// Here you can do the clean up (especially for the shortcut)
//
void commandMenuCleanUp()
{
// Don't forget to deallocate your shortcut here
}
//
// This function help you to initialize your plugin commands
//
bool setCommand(size_t index, TCHAR *cmdName, PFUNCPLUGINCMD pFunc, ShortcutKey *sk, bool check0nInit)
{
if (index >= nbFunc)
return false;
if (!pFunc)
return false;
lstrcpy(funcItem[index]._itemName, cmdName);
funcItem[index]._pFunc = pFunc;
funcItem[index]._init2Check = check0nInit;
funcItem[index]._pShKey = sk;
return true;
}
//----------------------------------------------//
//-- STEP 4. DEFINE YOUR ASSOCIATED FUNCTIONS --//
//----------------------------------------------//
void show_features()
{
::MessageBox(nppData._nppHandle, FEATURES, TEXT("Notepad#"), MB_OK);
}
void show_about()
{
HWND curScintilla = getCurrentScintilla();
char about[9999];
strcpy(about, "");
strcat(about , "Notepad#\r\n\
Version: ");
strcat(about , VERSION_TEXT);
strcat(about, "\
\r\nSource code: https://github.com/jvdanilo/NotepadSharp \r\n\
\r\n\
This plugin implements all the features I wanted to see in Notepad++ for years, plus some more\r\n\
\r\n\
jvdanilo");
TCHAR about_wide[MAX_PATH];
int len = MultiByteToWideChar ((int)::SendMessage(curScintilla, SCI_GETCODEPAGE, 0, 0), 0, about, -1, NULL, 0);
MultiByteToWideChar ((int)::SendMessage(curScintilla, SCI_GETCODEPAGE, 0, 0), 0, about, -1, about_wide, len);
::MessageBox(nppData._nppHandle, about_wide, TEXT("Notepad#"), MB_OK);
}
void Newline()
{
HWND curScintilla = getCurrentScintilla();
int lang = -100;
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTLANGTYPE, 0, (LPARAM)&lang);
int position = ::SendMessage(curScintilla, SCI_GETCURRENTPOS, 0, 0);
int line_number = ::SendMessage(curScintilla, SCI_LINEFROMPOSITION, position, 0);
position = ::SendMessage(curScintilla, SCI_GETCURRENTPOS, 0, 0);
line_number = ::SendMessage(curScintilla, SCI_LINEFROMPOSITION, position, 0);
char line[9999];
::SendMessage(curScintilla, SCI_GETLINE, line_number - 1 , (LPARAM)line);
trim_left(line);
switch (lang)
{
case L_C:
case L_CPP:
case L_CS:
case L_JAVA:
case L_USER:
case 53: // PowerShell
cStyleComment(curScintilla, line, line_number);
indentAfterCurlyBrace(curScintilla, line_number - 1);
break;
case L_CSS:
if (cStyleComment(curScintilla, line, line_number) == 0
&& indentAfterCurlyBrace(curScintilla, line_number - 1) == 0)
{
}
break;
case L_JS:
if (cStyleComment(curScintilla, line, line_number) == 0
&& indentAfterCurlyBrace(curScintilla, line_number - 1) == 0)
{
}
break;
case L_PHP:
if ( cStyleComment(curScintilla, line, line_number) == 0
&& poundComment(curScintilla, line) == 0
&& indentAfterCurlyBrace(curScintilla, line_number - 1) == 0)
{
XHTMLindent(curScintilla, position, line_number - 1);
}
break;
case L_HTML:
case L_XML:
XHTMLindent(curScintilla, position, line_number - 1);
break;
case L_RUBY:
if (poundComment(curScintilla, line) == 0)
{
Ruby_Newline(curScintilla);
}
break;
case L_TXT:
auto_numbering();
break;
}
}
int indentAfterCurlyBrace(HWND &curScintilla, int line_number)
{
::SendMessage(curScintilla, SCI_BEGINUNDOACTION, 0, 0);
int ret = 0;
int save_position = ::SendMessage(curScintilla, SCI_GETCURRENTPOS, 0, 0);
char selection[9999];
int line_start = ::SendMessage(curScintilla, SCI_POSITIONFROMLINE, line_number, 0);
int line_end = ::SendMessage(curScintilla, SCI_GETLINEENDPOSITION, line_number, 0);
::SendMessage(curScintilla, SCI_SETSEL, line_start, line_end);
::SendMessage(curScintilla, SCI_GETSELTEXT, 0, (LPARAM)&selection);
char *lastchar;
lastchar = substr(selection, strlen(selection) - 1, strlen(selection));
char nextchar[1];
::SendMessage(curScintilla, SCI_SETSEL, save_position, save_position + 1);
::SendMessage(curScintilla, SCI_GETSELTEXT, 0, (LPARAM)&nextchar);
::SendMessage(curScintilla, SCI_SETSEL, save_position, save_position);
if (strstr(lastchar, "{"))
{
ret = 1;
if (strstr(nextchar, "}"))
{
::SendMessage(curScintilla, SCI_NEWLINE , 0, 0 );
::SendMessage(curScintilla, SCI_SETSEL, save_position, save_position);
}
::SendMessage(curScintilla, SCI_TAB , 0, 0 );
}
::SendMessage(curScintilla, SCI_ENDUNDOACTION, 0, 0);
return ret;
}
void indentEndingCurlyBrace()
{
int lang = -100;
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTLANGTYPE, 0, (LPARAM)&lang);
if (!( lang == L_C
|| lang == L_CPP
|| lang == L_CS
|| lang == L_JAVA
|| lang == L_JS
|| lang == L_PHP
|| lang == L_CSS
|| lang == 53 // PowerShell
|| lang == L_USER))
{
return;
}
HWND curScintilla = getCurrentScintilla();
int save_position = ::SendMessage(curScintilla, SCI_GETCURRENTPOS, 0, 0);
int save_line = ::SendMessage(curScintilla, SCI_LINEFROMPOSITION, save_position, 0);
int line_start = ::SendMessage(curScintilla, SCI_POSITIONFROMLINE, save_line, 0);
int line_end = ::SendMessage(curScintilla, SCI_GETLINEENDPOSITION, save_line, 0);
char line_contents[9999];
::SendMessage(curScintilla, SCI_SETSEL, line_start, line_end);
::SendMessage(curScintilla, SCI_GETSELTEXT, 0, (LPARAM)&line_contents);
::SendMessage(curScintilla, SCI_SETSEL, save_position, save_position);
// IF THERE ARE OTHER CHARACTERS
if (strlen(trim(line_contents)) > 1)
{
return;
}
// FIND MATCHING BRACE INDENTATION
int opening_brace_position = ::SendMessage(curScintilla, SCI_BRACEMATCH, save_position - 1, 0);
if (opening_brace_position == -1)
{
return;
}
::SendMessage(curScintilla, SCI_BEGINUNDOACTION, 0, 0);
int opening_brace_line = ::SendMessage(curScintilla, SCI_LINEFROMPOSITION, opening_brace_position, 0);
int brace_indent = ::SendMessage(curScintilla, SCI_GETLINEINDENTATION, opening_brace_line, 0);
// RETURN TO SAVED POSITION
::SendMessage(curScintilla, SCI_SETSEL, save_position, save_position);
// SET THE MATCHING BRACE INDENTATION
::SendMessage(curScintilla, SCI_SETLINEINDENTATION, save_line, brace_indent);
::SendMessage(curScintilla, SCI_ENDUNDOACTION, 0, 0);
}
int poundComment(HWND &curScintilla, char *line)
{
int ret = 0;
char comment[2];
strncpy(comment, line, 2);
if (strstr(comment, "# "))
{
::SendMessage(curScintilla, SCI_BEGINUNDOACTION, 0, 0);
ret = 1;
int pos = ::SendMessage(curScintilla, SCI_GETCURRENTPOS, 0, 0);
::SendMessage(curScintilla, SCI_INSERTTEXT, pos, (LPARAM)"# " );
int next = pos + 2;
::SendMessage(curScintilla, SCI_SETSEL, next, next);
::SendMessage(curScintilla, SCI_ENDUNDOACTION, 0, 0);
auto_numbering();
}
return ret;
}
int cStyleComment(HWND &curScintilla, char *line, int line_number)
{
int ret = 0;
char comment[2];
strncpy(comment, line, 2);
comment[2] = '\0';
if (strstr(comment,"* ") && ! strstr(line, "*/") )
{
::SendMessage(curScintilla, SCI_BEGINUNDOACTION, 0, 0);
ret = 1;
int pos = ::SendMessage(curScintilla, SCI_GETCURRENTPOS, 0, 0);
::SendMessage(curScintilla, SCI_INSERTTEXT, pos, (LPARAM)"* " );
int next = pos + 2;
::SendMessage(curScintilla, SCI_SETSEL, next, next);
::SendMessage(curScintilla, SCI_ENDUNDOACTION, 0, 0);
auto_numbering();
}
else if (strstr(comment, "/*") && ! strstr(line, "*/") )
{
::SendMessage(curScintilla, SCI_BEGINUNDOACTION, 0, 0);
ret = 2;
int pos = ::SendMessage(curScintilla, SCI_GETCURRENTPOS, 0, 0);
::SendMessage(curScintilla, SCI_INSERTTEXT, pos, (LPARAM)" * " );
int next = pos + 3;
::SendMessage(curScintilla, SCI_SETSEL, next, next);
::SendMessage(curScintilla, SCI_ENDUNDOACTION, 0, 0);
auto_numbering();
}
else
{
char check_line[9999];
::SendMessage(curScintilla, SCI_GETLINE, line_number - 1, (LPARAM)check_line);
int check_line_end = ::SendMessage(curScintilla, SCI_LINELENGTH, line_number - 1, 0);
check_line[check_line_end] = '\0';
if (check_line[0] != '*' && strlen(trim(check_line)) == 2)
{
ret = 3;
strncpy(comment, trim(check_line), 2);
if (comment[0] == '*' && comment[1] == '/') {
ret = 4;
::SendMessage(curScintilla, SCI_DELETEBACK, 0, 0);
}
}
}
return ret;
}
void XHTMLindent(HWND &curScintilla, int position, int line_number)
{
::SendMessage(curScintilla, SCI_SEARCHANCHOR, 0, 0);
//::SendMessage(curScintilla, SCI_SEARCHPREV, SCFIND_REGEXP, (LPARAM)"<[^?][^\\/]+>$");
::SendMessage(curScintilla, SCI_SEARCHPREV, SCFIND_REGEXP, (LPARAM)"<[\\w\\/]+[\\w\\W\\b\\B]*?>\\s*$");
char selection[9999];
::SendMessage(curScintilla, SCI_GETSELTEXT, 0, (LPARAM)&selection);
int selection_end = ::SendMessage(curScintilla, SCI_GETSELECTIONEND, 0, 0);
int line_end = ::SendMessage(curScintilla, SCI_GETLINEENDPOSITION, line_number, 0);
// FALLBACK TO SIMPLE REGEX
//if (selection_end != line_end)
//{
// ::SendMessage(curScintilla, SCI_SETSEL, position, position);
// ::SendMessage(curScintilla, SCI_SEARCHANCHOR, 0, 0);
// ::SendMessage(curScintilla, SCI_SEARCHPREV, SCFIND_REGEXP, (LPARAM)"<[\\w\\W\\b\\B]+?>");
// ::SendMessage(curScintilla, SCI_GETSELTEXT, 0, (LPARAM)&selection);
// selection_end = ::SendMessage(curScintilla, SCI_GETSELECTIONEND, 0, 0);
//}
char not_allowed[] = "!?%/";
if (strstr(not_allowed, substr(selection, 1,1)))
{
::SendMessage(curScintilla, SCI_SETSEL, position, position);
return;
}
else if (selection[strlen(selection) - 2] == '/')
{
::SendMessage(curScintilla, SCI_SETSEL, position, position);
return;
}
::SendMessage(curScintilla, SCI_BEGINUNDOACTION, 0, 0);
char tag[30];
create_ending_tag(tag);
if (selection_end == line_end)
{
::SendMessage(curScintilla, SCI_SEARCHANCHOR, 0, 0);
::SendMessage(curScintilla, SCI_SEARCHNEXT, 0, (LPARAM)tag);
int selection_start = ::SendMessage(curScintilla, SCI_GETSELECTIONSTART, 0, 0);
::SendMessage(curScintilla, SCI_SETSEL, position, position);
if (selection_start == position)
{
::SendMessage(curScintilla, SCI_NEWLINE , 0, 0 );
::SendMessage(curScintilla, SCI_SETSEL, position, position);
}
::SendMessage(curScintilla, SCI_TAB , 0, 0 );
}
else {
::SendMessage(curScintilla, SCI_SETSEL, position, position);
}
::SendMessage(curScintilla, SCI_ENDUNDOACTION, 0, 0);
}
char* create_ending_tag(char *tag)
{
HWND curScintilla = getCurrentScintilla();
char selection[9999];
::SendMessage(curScintilla, SCI_GETSELTEXT, 0, (LPARAM)&selection);
int tag_i = 2;
int selection_i = 1;
tag[0] = '<';
tag[1] = '/';
while (tag_i < 30) {
if (selection[selection_i] == ' ' || selection[selection_i] == '>') {
break;
} else {
tag[tag_i] = selection[selection_i];
tag_i++;
selection_i++;
}
}
tag[tag_i] = '>';
tag[tag_i+1] = '\0';
return tag;
}
void end_tag()
{
HWND curScintilla = getCurrentScintilla();
::SendMessage(curScintilla, SCI_BEGINUNDOACTION, 0, 0);
int save_position = ::SendMessage(curScintilla, SCI_GETCURRENTPOS, 0, 0);
int save_line = ::SendMessage(curScintilla, SCI_LINEFROMPOSITION, save_position, 0);
int html_comment = 9;
char line[9999];
::SendMessage(curScintilla, SCI_GETCURLINE, 9999, (LPARAM)&line);
int trim_line = strlen(trim(line));
int matching_tag_indentation;
int tag_line;
int end = 0;
char selection[9999];
int last_search = 0;
int i = 1;
char not_allowed[] = "!?%/";
do {
::SendMessage(curScintilla, SCI_SEARCHANCHOR, 0, 0);
//::SendMessage(curScintilla, SCI_SEARCHPREV, SCFIND_REGEXP, (LPARAM)"<[\\w\\W\\b\\B]+?>");
/**
* Scintillas regex engine is not very friendly
*/
::SendMessage(curScintilla, SCI_SEARCHPREV, SCFIND_REGEXP, (LPARAM)"<[\\w\\/][\\w\\W\\b\\B]*?>");
end = ::SendMessage(curScintilla, SCI_GETSELECTIONEND, 0, 0);
::SendMessage(curScintilla, SCI_GETSELTEXT, 0, (LPARAM)&selection);
if (
::SendMessage(curScintilla, SCI_GETSTYLEAT, ::SendMessage(curScintilla, SCI_GETSELECTIONSTART, 0, 0) + 1, 0) == html_comment
) {
continue;
}
else if (end == last_search)
{
::SendMessage(curScintilla, SCI_SETSEL, end, end);
break;
}
last_search = end;
if (selection[1] == '/')
{
i++;
}
else if (strstr(not_allowed, substr(selection, 1,1)))
{
continue;
}
else if (selection[strlen(selection) - 2] == '/')
{
continue;
}
else {
i--;
}
}
while (i);
// FIXES PROBLEM WITH LAST TAG REPEATION
int tag_selection_start = ::SendMessage(curScintilla, SCI_GETSELECTIONNSTART, 0, 0);
int tag_selection_end = ::SendMessage(curScintilla, SCI_GETSELECTIONEND, 0, 0);
if ( tag_selection_start != tag_selection_end )
{
char tag[30];
create_ending_tag(tag);
int taglen = strlen(tag);
if (trim_line < 1)
{
tag_line = ::SendMessage(curScintilla, SCI_LINEFROMPOSITION, tag_selection_start, 0);
matching_tag_indentation = ::SendMessage(curScintilla, SCI_GETLINEINDENTATION, tag_line, 0);
}
::SendMessage(curScintilla, SCI_INSERTTEXT, save_position, (LPARAM)tag );
::SendMessage(curScintilla, SCI_SETSEL, save_position + taglen, save_position + taglen);
if (trim_line < 1)
{
::SendMessage(curScintilla, SCI_SETLINEINDENTATION, save_line, matching_tag_indentation);
}
}
else
{
::SendMessage(curScintilla, SCI_SETSEL, save_position , save_position );
}
::SendMessage(curScintilla, SCI_ENDUNDOACTION, 0, 0);
}
void delete_current_line()
{
HWND curScintilla = getCurrentScintilla();
int position = ::SendMessage(curScintilla, SCI_GETCURRENTPOS, 0, 0);
int line = ::SendMessage(curScintilla, SCI_LINEFROMPOSITION, position, 0);
int column = ::SendMessage(curScintilla, SCI_GETCOLUMN, position, 0);
int lines = ::SendMessage(curScintilla, SCI_GETLINECOUNT, 0, 0);
if (line == (lines - 1)) {
//SCI_GETLINEENDPOSITION(int line)
int line_start = ::SendMessage(curScintilla, SCI_POSITIONFROMLINE, line, 0);
int line_end = ::SendMessage(curScintilla, SCI_GETLINEENDPOSITION, line, 0);
if (line_start != line_end)
{
::SendMessage(curScintilla, SCI_SETSELECTIONSTART, line_start, 0);
::SendMessage(curScintilla, SCI_SETSELECTIONEND, line_end, 0);
::SendMessage(curScintilla, SCI_DELETEBACK, 0, 0);
}
return;
}
::SendMessage(curScintilla, SCI_BEGINUNDOACTION, 0, 0);
int line_start = ::SendMessage(curScintilla, SCI_POSITIONFROMLINE, line, 0);
int line_length = ::SendMessage(curScintilla, SCI_LINELENGTH, line, 0);
::SendMessage(curScintilla, SCI_SETSEL, line_start, line_start + line_length);
::SendMessage(curScintilla, SCI_DELETEBACK, 0, 0);
int restore_column = ::SendMessage(curScintilla, SCI_FINDCOLUMN, line, column);
::SendMessage(curScintilla, SCI_SETSEL, restore_column, restore_column);
::SendMessage(curScintilla, SCI_ENDUNDOACTION, 0, 0);
}
char closed_files[300][MAX_PATH] = {};
int closed_files_index = 0;
void undo_closed_tab()
{
int i = closed_files_index - 1;
if (strlen(closed_files[i]))
{
HWND curScintilla = getCurrentScintilla();
TCHAR path[MAX_PATH];
int len = MultiByteToWideChar ((int)::SendMessage(curScintilla, SCI_GETCODEPAGE, 0, 0), 0, closed_files[i], -1, NULL, 0);
MultiByteToWideChar ((int)::SendMessage(curScintilla, SCI_GETCODEPAGE, 0, 0), 0, closed_files[i], -1, path, len);
::SendMessage(nppData._nppHandle, NPPM_DOOPEN, 0, (LPARAM)path);
closed_files[i][0] = '\0';
}
closed_files_index--;
if (closed_files_index < 1)
{
closed_files_index = 0;
}
}
char all_files[300][MAX_PATH] = {};
int all_files_index = 0;
void get_all_files()
{
HWND curScintilla = getCurrentScintilla();
int position = 0;
int buffer;
TCHAR full_file_path[MAX_PATH];
char path_text[MAX_PATH];
int loop = 30;
while (loop)
{
buffer = ::SendMessage(nppData._nppHandle, NPPM_GETBUFFERIDFROMPOS, position, (LPARAM)MAIN_VIEW);
::SendMessage(nppData._nppHandle, NPPM_GETFULLPATHFROMBUFFERID, buffer, (LPARAM)full_file_path);
WideCharToMultiByte((int)::SendMessage(curScintilla, SCI_GETCODEPAGE, 0, 0), 0, full_file_path, -1, path_text, MAX_PATH, NULL, NULL);
if (strstr(all_files[all_files_index - 1], path_text))
{
all_files[all_files_index][0] = '\0';
break;
}
//::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)getEOL());
//::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)path_text );
strcpy(all_files[all_files_index], path_text);
position++;
loop--;
all_files_index++;
}
}
char now_files[300][MAX_PATH] = {};
int now_files_index = 0;
void get_files_now()
{
HWND curScintilla = getCurrentScintilla();
int position = 0;
int buffer;
TCHAR full_file_path[MAX_PATH];
char path_text[MAX_PATH];
int loop = 30;
while (loop)
{
buffer = ::SendMessage(nppData._nppHandle, NPPM_GETBUFFERIDFROMPOS, position, (LPARAM)MAIN_VIEW);
::SendMessage(nppData._nppHandle, NPPM_GETFULLPATHFROMBUFFERID, buffer, (LPARAM)full_file_path);
WideCharToMultiByte((int)::SendMessage(curScintilla, SCI_GETCODEPAGE, 0, 0), 0, full_file_path, -1, path_text, MAX_PATH, NULL, NULL);
if (strstr(now_files[now_files_index - 1], path_text))
{
now_files[now_files_index][0] = '\0';
break;
}
strcpy(now_files[now_files_index], path_text);
position++;
loop--;
now_files_index++;
}
}
void find_missing()
{
HWND curScintilla = getCurrentScintilla();
get_files_now();
int has = 0;
int i;
int j;
int all_files_loop = all_files_index + 1;
int now_files_loop = now_files_index + 1;
now_files_index = 0;
for(i = 0; i < all_files_loop; i++)
{
if (strlen(all_files[i]) < 1)
{
break;
}
has = 0;
for (j = 0; j < now_files_loop; j++)
{
if (strlen(now_files[j]) < 1)
{
break;
}
if (strstr(all_files[i], now_files[j]))
{
has = 1;
}
}
if (has == 0)
{
strcpy(closed_files[closed_files_index], all_files[i]);
closed_files_index++;
}
}
//insertList();
//::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)getEOL());
//closed_file_list();
all_files_index = 0;
}
void closed_file_list()
{
HWND curScintilla = getCurrentScintilla();
for (int i = 0; i < 30; i++)
{
if (strlen(closed_files[i]) < 1)
{
break;
}
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)getEOL());
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)closed_files[i]);
}
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)getEOL());
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)"CLOSED FILES LIST");
}
void insertList()
{
HWND curScintilla = getCurrentScintilla();
for (int i = 0; i < 30; i++)
{
if (strlen(all_files[i]))
{
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)getEOL());
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)all_files[i]);
}
else {
break;
}
}
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)getEOL());
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)"FILES BEFORE CLOSE");
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)getEOL());
for (int i = 0; i < 30; i++)
{
if (strlen(now_files[i]))
{
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)getEOL());
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)now_files[i]);
}
else {
break;
}
}
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)getEOL());
::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)"FILES AFTER CLOSE");
}
/*
void buffer_left()
{
HWND curScintilla = getCurrentScintilla();
int buffer;
int pos;
buffer = ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);
pos = ::SendMessage(nppData._nppHandle, NPPM_GETPOSFROMBUFFERID , buffer, 0);
pos--;
int left_buffer = ::SendMessage(nppData._nppHandle, NPPM_GETBUFFERIDFROMPOS , pos, 0);
TCHAR full_file_path[MAX_PATH];
char path_text[MAX_PATH];
::SendMessage(nppData._nppHandle, NPPM_GETFULLPATHFROMBUFFERID, left_buffer, (LPARAM)full_file_path);
WideCharToMultiByte((int)::SendMessage(curScintilla, SCI_GETCODEPAGE, 0, 0), 0, full_file_path, -1, path_text, MAX_PATH, NULL, NULL);
::SendMessage(nppData._nppHandle, NPPM_SWITCHTOFILE , 0, (LPARAM)full_file_path);
}
*/
void buffer_left()
{
HWND curScintilla = getCurrentScintilla();
int buffer;
int pos;
buffer = ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);
pos = ::SendMessage(nppData._nppHandle, NPPM_GETPOSFROMBUFFERID , buffer, 0);
int which;
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&which);
pos--;
if (which == 1) {
pos = pos - 1073741823 - 1;
}
int left_buffer = ::SendMessage(nppData._nppHandle, NPPM_GETBUFFERIDFROMPOS , pos, which );
//if (left_buffer == 0)
//{
// ::SendMessage(curScintilla, SCI_INSERTTEXT, 0, (LPARAM)"INVALID");
//}
TCHAR full_file_path[MAX_PATH];
char path_text[MAX_PATH];
::SendMessage(nppData._nppHandle, NPPM_GETFULLPATHFROMBUFFERID, left_buffer, (LPARAM)full_file_path);
WideCharToMultiByte((int)::SendMessage(curScintilla, SCI_GETCODEPAGE, 0, 0), 0, full_file_path, -1, path_text, MAX_PATH, NULL, NULL);
::SendMessage(nppData._nppHandle, NPPM_SWITCHTOFILE , 0, (LPARAM)full_file_path);
}
/*
void buffer_right()
{
HWND curScintilla = getCurrentScintilla();
int buffer;
int pos;
buffer = ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);
pos = ::SendMessage(nppData._nppHandle, NPPM_GETPOSFROMBUFFERID , buffer, 0);
pos++;
int left_buffer = ::SendMessage(nppData._nppHandle, NPPM_GETBUFFERIDFROMPOS , pos, 0);
TCHAR full_file_path[MAX_PATH];
char path_text[MAX_PATH];
::SendMessage(nppData._nppHandle, NPPM_GETFULLPATHFROMBUFFERID, left_buffer, (LPARAM)full_file_path);
WideCharToMultiByte((int)::SendMessage(curScintilla, SCI_GETCODEPAGE, 0, 0), 0, full_file_path, -1, path_text, MAX_PATH, NULL, NULL);
::SendMessage(nppData._nppHandle, NPPM_SWITCHTOFILE , 0, (LPARAM)full_file_path);
}
*/
void buffer_right()
{
HWND curScintilla = getCurrentScintilla();
int buffer;
int pos;
buffer = ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);
pos = ::SendMessage(nppData._nppHandle, NPPM_GETPOSFROMBUFFERID , buffer, 0);
pos++;
int which;
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&which);
if (which == 1) {
pos = pos - 1073741823 - 1;
}