/
commands.c
1575 lines (1388 loc) · 30.9 KB
/
commands.c
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
#include "editor.h"
#include "edit.h"
#include "move.h"
#include "window.h"
#include "view.h"
#include "change.h"
#include "term.h"
#include "search.h"
#include "cmdline.h"
#include "history.h"
#include "spawn.h"
#include "filetype.h"
#include "color.h"
#include "state.h"
#include "syntax.h"
#include "lock.h"
#include "ptr-array.h"
#include "bind.h"
#include "alias.h"
#include "tag.h"
#include "config.h"
#include "command.h"
#include "parse-args.h"
#include "file-option.h"
#include "msg.h"
#include "frame.h"
#include "load-save.h"
#include "selection.h"
#include "encoding.h"
#include "path.h"
#include "error.h"
#include "input-special.h"
#include "git-open.h"
// go to compiler error saving position if file changed or cursor moved
static void activate_current_message_save(void)
{
struct file_location *loc = create_file_location(view);
struct block_iter save = view->cursor;
activate_current_message();
if (view->cursor.blk != save.blk || view->cursor.offset != save.offset) {
push_file_location(loc);
} else {
file_location_free(loc);
}
}
static void cmd_alias(const char *pf, char **args)
{
add_alias(args[0], args[1]);
}
static void cmd_bind(const char *pf, char **args)
{
if (args[1])
add_binding(args[0], args[1]);
else
remove_binding(args[0]);
}
static void cmd_bof(const char *pf, char **args)
{
move_bof();
}
static void cmd_bol(const char *pf, char **args)
{
move_bol();
}
static void cmd_case(const char *pf, char **args)
{
int mode = 't';
while (*pf) {
switch (*pf) {
case 'l':
case 'u':
mode = *pf;
break;
}
pf++;
}
change_case(mode);
}
static void cmd_cd(const char *pf, char **args)
{
char *dir = args[0];
char cwd[8192];
char *cwdp = NULL;
bool got_cwd = !!getcwd(cwd, sizeof(cwd));
int i;
if (streq(dir, "-")) {
dir = getenv("OLDPWD");
if (dir == NULL || dir[0] == 0) {
error_msg("cd: OLDPWD not set");
return;
}
}
if (chdir(dir)) {
error_msg("cd: %s", strerror(errno));
return;
}
if (got_cwd)
setenv("OLDPWD", cwd, 1);
got_cwd = !!getcwd(cwd, sizeof(cwd));
if (got_cwd) {
setenv("PWD", cwd, 1);
cwdp = cwd;
}
for (i = 0; i < buffers.count; i++) {
struct buffer *b = buffers.ptrs[i];
update_short_filename_cwd(b, cwdp);
}
// need to update all tabbars
mark_everything_changed();
}
static void cmd_center_view(const char *pf, char **args)
{
view->force_center = true;
}
static void cmd_clear(const char *pf, char **args)
{
clear_lines();
}
static void cmd_close(const char *pf, char **args)
{
bool force = false;
bool allow_quit = false;
bool allow_wclose = false;
while (*pf) {
switch (*pf) {
case 'f':
force = true;
break;
case 'q':
allow_quit = true;
break;
case 'w':
allow_wclose = true;
break;
}
pf++;
}
if (!view_can_close(view) && !force) {
error_msg("The buffer is modified. Save or run 'close -f' to close without saving.");
return;
}
if (allow_quit && windows.count == 1 && buffers.count == 1) {
editor_status = EDITOR_EXITING;
return;
}
if (allow_wclose && window->views.count <= 1) {
window_close_current();
return;
}
window_close_current_view(window);
set_view(window->view);
}
static void cmd_command(const char *pf, char **args)
{
set_input_mode(INPUT_COMMAND);
if (args[0])
cmdline_set_text(&cmdline, args[0]);
}
static void cmd_compile(const char *pf, char **args)
{
struct compiler *c;
unsigned int flags = 0;
const char *name;
while (*pf) {
switch (*pf) {
case '1':
flags |= SPAWN_READ_STDOUT;
break;
case 'p':
flags |= SPAWN_PROMPT;
break;
case 's':
flags |= SPAWN_QUIET;
break;
}
pf++;
}
name= *args++;
c = find_compiler(name);
if (!c) {
error_msg("No such error parser %s", name);
return;
}
clear_messages();
spawn_compiler(args, flags, c);
if (message_count())
activate_current_message_save();
}
static void cmd_copy(const char *pf, char **args)
{
struct block_iter save = view->cursor;
if (view->selection) {
copy(prepare_selection(view), view->selection == SELECT_LINES);
unselect();
} else {
struct block_iter tmp;
block_iter_bol(&view->cursor);
tmp = view->cursor;
copy(block_iter_eat_line(&tmp), 1);
}
view->cursor = save;
}
static void cmd_cut(const char *pf, char **args)
{
int x = view_get_preferred_x(view);
if (view->selection) {
cut(prepare_selection(view), view->selection == SELECT_LINES);
if (view->selection == SELECT_LINES) {
move_to_preferred_x(x);
}
unselect();
} else {
struct block_iter tmp;
block_iter_bol(&view->cursor);
tmp = view->cursor;
cut(block_iter_eat_line(&tmp), 1);
move_to_preferred_x(x);
}
}
static void cmd_delete(const char *pf, char **args)
{
delete_ch();
}
static void cmd_delete_eol(const char *pf, char **args)
{
struct block_iter bi = view->cursor;
buffer_delete_bytes(block_iter_eol(&bi));
}
static void cmd_delete_word(const char *pf, char **args)
{
bool skip_non_word = *pf == 's';
struct block_iter bi = view->cursor;
buffer_delete_bytes(word_fwd(&bi, skip_non_word));
}
static void cmd_down(const char *pf, char **args)
{
move_down(1);
}
static void cmd_eof(const char *pf, char **args)
{
move_eof();
}
static void cmd_eol(const char *pf, char **args)
{
move_eol();
}
static void cmd_erase(const char *pf, char **args)
{
erase();
}
static void cmd_erase_bol(const char *pf, char **args)
{
buffer_erase_bytes(block_iter_bol(&view->cursor));
}
static void cmd_erase_word(const char *pf, char **args)
{
bool skip_non_word = *pf == 's';
buffer_erase_bytes(word_bwd(&view->cursor, skip_non_word));
}
static void cmd_errorfmt(const char *pf, char **args)
{
bool ignore = false;
while (*pf) {
switch (*pf) {
case 'i':
ignore = true;
break;
}
pf++;
}
add_error_fmt(args[0], ignore, args[1], args + 2);
}
static void cmd_ft(const char *pf, char **args)
{
enum detect_type dt = FT_EXTENSION;
int i;
while (*pf) {
switch (*pf) {
case 'c':
dt = FT_CONTENT;
break;
case 'f':
dt = FT_FILENAME;
break;
case 'i':
dt = FT_INTERPRETER;
break;
}
pf++;
}
for (i = 1; args[i]; i++)
add_filetype(args[0], args[i], dt);
}
static void cmd_filter(const char *pf, char **args)
{
struct filter_data data;
struct block_iter save = view->cursor;
if (view->selection) {
data.in_len = prepare_selection(view);
} else {
struct block *blk;
data.in_len = 0;
list_for_each_entry(blk, &buffer->blocks, node)
data.in_len += blk->size;
move_bof();
}
data.in = block_iter_get_bytes(&view->cursor, data.in_len);
if (spawn_filter(args, &data)) {
free(data.in);
view->cursor = save;
return;
}
free(data.in);
buffer_replace_bytes(data.in_len, data.out, data.out_len);
free(data.out);
unselect();
}
static void cmd_format_paragraph(const char *pf, char **args)
{
int text_width = buffer->options.text_width;
if (args[0])
text_width = atoi(args[0]);
if (text_width <= 0) {
error_msg("Paragraph width must be positive.");
return;
}
format_paragraph(text_width);
}
static void cmd_git_open(const char *pf, char **args)
{
set_input_mode(INPUT_GIT_OPEN);
git_open_reload();
}
static void cmd_hi(const char *pf, char **args)
{
struct term_color color;
if (args[0] == NULL) {
exec_builtin_rc(reset_colors_rc);
remove_extra_colors();
} else if (parse_term_color(&color, args + 1)) {
set_highlight_color(args[0], &color);
}
// Don't call update_all_syntax_colors() needlessly.
// It is called right after config has been loaded.
if (editor_status != EDITOR_INITIALIZING) {
update_all_syntax_colors();
mark_everything_changed();
}
}
static void cmd_include(const char *pf, char **args)
{
read_config(commands, args[0], true);
}
static void cmd_insert(const char *pf, char **args)
{
const char *str = args[0];
if (strchr(pf, 'k')) {
int i;
for (i = 0; str[i]; i++)
insert_ch(str[i]);
} else {
long del_len = 0;
long ins_len = strlen(str);
if (view->selection) {
del_len = prepare_selection(view);
unselect();
}
buffer_replace_bytes(del_len, str, ins_len);
if (strchr(pf, 'm'))
block_iter_skip_bytes(&view->cursor, ins_len);
}
}
static void cmd_insert_special(const char *pf, char **args)
{
special_input_activate();
}
static void cmd_join(const char *pf, char **args)
{
join_lines();
}
static void cmd_left(const char *pf, char **args)
{
move_cursor_left();
}
static void cmd_line(const char *pf, char **args)
{
int x = view_get_preferred_x(view);
int line;
line = atoi(args[0]);
if (line > 0) {
move_to_line(view, line);
move_to_preferred_x(x);
}
}
static void cmd_load_syntax(const char *pf, char **args)
{
const char *filename = args[0];
const char *filetype = path_basename(filename);
int err;
if (filename != filetype) {
if (find_syntax(filetype)) {
error_msg("Syntax for filetype %s already loaded", filetype);
} else {
load_syntax_file(filename, true, &err);
}
} else {
if (!find_syntax(filetype))
load_syntax_by_filetype(filetype);
}
}
static void cmd_move_tab(const char *pf, char **args)
{
long j, i = ptr_array_idx(&window->views, view);
char *str = args[0];
if (streq(str, "left")) {
j = i - 1;
} else if (streq(str, "right")) {
j = i + 1;
} else {
long num;
if (!str_to_long(str, &num) || num < 1) {
error_msg("Invalid tab position %s", str);
return;
}
j = num - 1;
if (j >= window->views.count)
j = window->views.count - 1;
}
j = (window->views.count + j) % window->views.count;
ptr_array_insert(&window->views, ptr_array_remove_idx(&window->views, i), j);
window->update_tabbar = true;
}
static void cmd_msg(const char *pf, char **args)
{
char dir = 0;
while (*pf) {
switch (*pf) {
case 'n':
case 'p':
dir = *pf;
break;
}
pf++;
}
if (dir == 'n') {
activate_next_message();
} else if (dir == 'p') {
activate_prev_message();
} else {
activate_current_message();
}
}
static void cmd_new_line(const char *pf, char **args)
{
new_line();
}
static void cmd_next(const char *pf, char **args)
{
set_view(ptr_array_next(&window->views, view));
}
static void cmd_open(const char *pf, char **args)
{
const char *enc = NULL;
char *encoding = NULL;
while (*pf) {
switch (*pf) {
case 'e':
enc = *args++;
break;
}
pf++;
}
if (enc) {
encoding = normalize_encoding(enc);
if (encoding == NULL) {
error_msg("Unsupported encoding %s", enc);
return;
}
}
if (!args[0]) {
window_open_new_file(window);
if (encoding) {
free(buffer->encoding);
buffer->encoding = encoding;
}
return;
}
if (!args[1]) {
// previous view is remembered when opening single file
window_open_file(window, args[0], encoding);
} else {
// it makes no sense to remember previous view when opening multiple files
window_open_files(window, args, encoding);
}
free(encoding);
}
static void cmd_option(const char *pf, char **args)
{
int argc = count_strings(args);
char *list, *comma;
char **strs;
if (argc % 2 == 0) {
error_msg("Missing option value");
return;
}
if (!validate_local_options(args + 1)) {
return;
}
// NOTE: options and values are shared
strs = copy_string_array(args + 1, argc - 1);
if (*pf) {
add_file_options(FILE_OPTIONS_FILENAME, xstrdup(args[0]), strs);
return;
}
list = args[0];
do {
int len;
comma = strchr(list, ',');
len = comma ? comma - list : strlen(list);
add_file_options(FILE_OPTIONS_FILETYPE, xstrslice(list, 0, len), strs);
list = comma + 1;
} while (comma);
}
static void cmd_pass_through(const char *pf, char **args)
{
struct filter_data data;
long del_len = 0;
bool strip_nl = false;
bool move = false;
while (*pf) {
switch (*pf++) {
case 'm':
move = true;
break;
case 's':
strip_nl = true;
break;
}
}
data.in = NULL;
data.in_len = 0;
if (spawn_filter(args, &data))
return;
if (view->selection) {
del_len = prepare_selection(view);
unselect();
}
if (strip_nl && data.out_len > 0 && data.out[data.out_len - 1] == '\n') {
if (--data.out_len > 0 && data.out[data.out_len - 1] == '\r')
data.out_len--;
}
buffer_replace_bytes(del_len, data.out, data.out_len);
free(data.out);
if (move) {
block_iter_skip_bytes(&view->cursor, data.out_len);
}
}
static void cmd_paste(const char *pf, char **args)
{
paste();
}
static void cmd_pgdown(const char *pf, char **args)
{
long margin = window_get_scroll_margin(window);
long bottom = view->vy + window->edit_h - 1 - margin;
long count;
if (view->cy < bottom) {
count = bottom - view->cy;
} else {
count = window->edit_h - 1 - margin * 2;
}
move_down(count);
}
static void cmd_pgup(const char *pf, char **args)
{
long margin = window_get_scroll_margin(window);
long top = view->vy + margin;
long count;
if (view->cy > top) {
count = view->cy - top;
} else {
count = window->edit_h - 1 - margin * 2;
}
move_up(count);
}
static void cmd_prev(const char *pf, char **args)
{
set_view(ptr_array_prev(&window->views, view));
}
static void cmd_quit(const char *pf, char **args)
{
int i;
if (pf[0]) {
editor_status = EDITOR_EXITING;
return;
}
for (i = 0; i < buffers.count; i++) {
struct buffer *b = buffers.ptrs[i];
if (buffer_modified(b)) {
// activate modified buffer
struct view *v = window_find_view(window, b);
if (v == NULL) {
// buffer isn't open in current window
// activate first window of the buffer
v = b->views.ptrs[0];
window = v->window;
mark_everything_changed();
}
set_view(v);
error_msg("Save modified files or run 'quit -f' to quit without saving.");
return;
}
}
editor_status = EDITOR_EXITING;
}
static void cmd_redo(const char *pf, char **args)
{
int change_id = 0;
if (args[0]) {
change_id = atoi(args[0]);
if (change_id <= 0) {
error_msg("Invalid change id: %s", args[0]);
return;
}
}
if (redo(change_id)) {
unselect();
}
}
static void cmd_repeat(const char *pf, char **args)
{
const struct command *cmd;
int count;
count = atoi(args[0]);
cmd = find_command(commands, args[1]);
if (!cmd) {
error_msg("No such command: %s", args[1]);
return;
}
args += 2;
pf = parse_args(args, cmd->flags, cmd->min_args, cmd->max_args);
if (pf) {
while (count-- > 0)
cmd->cmd(pf, args);
}
}
static void cmd_replace(const char *pf, char **args)
{
unsigned int flags = 0;
int i;
for (i = 0; pf[i]; i++) {
switch (pf[i]) {
case 'b':
flags |= REPLACE_BASIC;
break;
case 'c':
flags |= REPLACE_CONFIRM;
break;
case 'g':
flags |= REPLACE_GLOBAL;
break;
case 'i':
flags |= REPLACE_IGNORE_CASE;
break;
}
}
reg_replace(args[0], args[1], flags);
}
static void cmd_right(const char *pf, char **args)
{
move_cursor_right();
}
static void cmd_run(const char *pf, char **args)
{
int fd[3] = { 0, 1, 2 };
bool prompt = false;
while (*pf) {
switch (*pf) {
case 'p':
prompt = true;
break;
case 's':
fd[0] = -1;
fd[1] = -1;
fd[2] = -1;
break;
}
pf++;
}
spawn(args, fd, prompt);
}
static int stat_changed(const struct stat *a, const struct stat *b)
{
/* don't compare st_mode because we allow chmod 755 etc. */
return a->st_mtime != b->st_mtime ||
a->st_dev != b->st_dev ||
a->st_ino != b->st_ino;
}
static void cmd_save(const char *pf, char **args)
{
char *absolute = buffer->abs_filename;
char *encoding = buffer->encoding;
const char *enc = NULL;
bool force = false;
enum newline_sequence newline = buffer->newline;
mode_t old_mode = buffer->st.st_mode;
struct stat st;
bool new_locked = false;
while (*pf) {
switch (*pf) {
case 'd':
newline = NEWLINE_DOS;
break;
case 'e':
enc = *args++;
break;
case 'f':
force = true;
break;
case 'u':
newline = NEWLINE_UNIX;
break;
}
pf++;
}
if (enc) {
encoding = normalize_encoding(enc);
if (encoding == NULL) {
error_msg("Unsupported encoding %s", enc);
return;
}
}
if (args[0]) {
char *tmp;
if (args[0][0] == 0) {
error_msg("Empty filename not allowed");
return;
}
tmp = path_absolute(args[0]);
if (!tmp) {
error_msg("Failed to make absolute path: %s", strerror(errno));
return;
}
if (absolute && streq(tmp, absolute)) {
free(tmp);
} else {
absolute = tmp;
}
} else {
if (!absolute) {
error_msg("No filename.");
return;
}
if (buffer->ro && !force) {
error_msg("Use -f to force saving read-only file.");
return;
}
}
if (stat(absolute, &st)) {
if (errno != ENOENT) {
error_msg("stat failed for %s: %s", absolute, strerror(errno));
goto error;
}
if (options.lock_files) {
if (absolute == buffer->abs_filename) {
if (!buffer->locked) {
if (lock_file(absolute)) {
if (!force) {
error_msg("Can't lock file %s", absolute);
goto error;
}
} else {
buffer->locked = true;
}
}
} else {
if (lock_file(absolute)) {
if (!force) {
error_msg("Can't lock file %s", absolute);
goto error;
}
} else {
new_locked = true;
}
}
}
} else {
if (absolute == buffer->abs_filename && !force && stat_changed(&buffer->st, &st)) {
error_msg("File has been modified by someone else. Use -f to force overwrite.");
goto error;
}
if (S_ISDIR(st.st_mode)) {
error_msg("Will not overwrite directory %s", absolute);
goto error;
}
if (options.lock_files) {
if (absolute == buffer->abs_filename) {
if (!buffer->locked) {
if (lock_file(absolute)) {
if (!force) {
error_msg("Can't lock file %s", absolute);
goto error;
}
} else {
buffer->locked = true;
}
}
} else {
if (lock_file(absolute)) {
if (!force) {
error_msg("Can't lock file %s", absolute);
goto error;
}
} else {
new_locked = true;
}
}
}
if (absolute != buffer->abs_filename && !force) {
error_msg("Use -f to overwrite %s.", absolute);
goto error;
}
/* allow chmod 755 etc. */
buffer->st.st_mode = st.st_mode;
}
if (save_buffer(buffer, absolute, encoding, newline))
goto error;
buffer->saved_change = buffer->cur_change;
buffer->ro = false;
buffer->newline = newline;
if (encoding != buffer->encoding) {
free(buffer->encoding);
buffer->encoding = encoding;
}
if (absolute != buffer->abs_filename) {
if (buffer->locked) {
// filename changes, relase old file lock
unlock_file(buffer->abs_filename);
}
buffer->locked = new_locked;
free(buffer->abs_filename);
buffer->abs_filename = absolute;
update_short_filename(buffer);
// filename change is not detected (only buffer_modified() change)
mark_buffer_tabbars_changed(buffer);
}
if (!old_mode && streq(buffer->options.filetype, "none")) {
/* new file and most likely user has not changed the filetype */
if (buffer_detect_filetype(buffer)) {
set_file_options(buffer);
buffer_update_syntax(buffer);
}
}
return;
error:
if (new_locked)
unlock_file(absolute);
if (absolute != buffer->abs_filename)
free(absolute);
if (encoding != buffer->encoding)
free(encoding);
}
static void cmd_scroll_down(const char *pf, char **args)
{
view->vy++;
if (view->cy < view->vy)
move_down(1);
}
static void cmd_scroll_pgdown(const char *pf, char **args)
{
int max = buffer->nl - window->edit_h + 1;
if (view->vy < max && max > 0) {
int count = window->edit_h - 1;
if (view->vy + count > max)
count = max - view->vy;