Mercurial > vim
comparison src/option.c @ 31922:440256d03990 v9.0.1293
patch 9.0.1293: the set_num_option() is too long
Commit: https://github.com/vim/vim/commit/0caaf1e46511f7a92e036f05e6aa9d5992540117
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Feb 9 12:23:17 2023 +0000
patch 9.0.1293: the set_num_option() is too long
Problem: The set_num_option() is too long.
Solution: Move code to separate functions. (Yegappan Lakshmanan,
closes #11954)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 09 Feb 2023 13:30:04 +0100 |
parents | 1ae3ad2e3d03 |
children | 4789a9d20e7c |
comparison
equal
deleted
inserted
replaced
31921:f23a4fc4520e | 31922:440256d03990 |
---|---|
538 /* | 538 /* |
539 * Set the "fileencodings" option to the default value for when 'encoding' is | 539 * Set the "fileencodings" option to the default value for when 'encoding' is |
540 * utf-8. | 540 * utf-8. |
541 */ | 541 */ |
542 void | 542 void |
543 set_fencs_unicode() | 543 set_fencs_unicode(void) |
544 { | 544 { |
545 set_string_option_direct((char_u *)"fencs", -1, fencs_utf8_default, | 545 set_string_option_direct((char_u *)"fencs", -1, fencs_utf8_default, |
546 OPT_FREE, 0); | 546 OPT_FREE, 0); |
547 } | 547 } |
548 | 548 |
3477 | 3477 |
3478 return errmsg; | 3478 return errmsg; |
3479 } | 3479 } |
3480 | 3480 |
3481 /* | 3481 /* |
3482 * Process the new 'winheight' or the 'helpheight' option value. | |
3483 */ | |
3484 static char * | |
3485 did_set_winheight_helpheight(long *pp, char *errmsg) | |
3486 { | |
3487 if (p_wh < 1) | |
3488 { | |
3489 errmsg = e_argument_must_be_positive; | |
3490 p_wh = 1; | |
3491 } | |
3492 if (p_wmh > p_wh) | |
3493 { | |
3494 errmsg = e_winheight_cannot_be_smaller_than_winminheight; | |
3495 p_wh = p_wmh; | |
3496 } | |
3497 if (p_hh < 0) | |
3498 { | |
3499 errmsg = e_argument_must_be_positive; | |
3500 p_hh = 0; | |
3501 } | |
3502 | |
3503 // Change window height NOW | |
3504 if (!ONE_WINDOW) | |
3505 { | |
3506 if (pp == &p_wh && curwin->w_height < p_wh) | |
3507 win_setheight((int)p_wh); | |
3508 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh) | |
3509 win_setheight((int)p_hh); | |
3510 } | |
3511 | |
3512 return errmsg; | |
3513 } | |
3514 | |
3515 /* | |
3516 * Process the new 'winminheight' option value. | |
3517 */ | |
3518 static char * | |
3519 did_set_winminheight(char *errmsg) | |
3520 { | |
3521 if (p_wmh < 0) | |
3522 { | |
3523 errmsg = e_argument_must_be_positive; | |
3524 p_wmh = 0; | |
3525 } | |
3526 if (p_wmh > p_wh) | |
3527 { | |
3528 errmsg = e_winheight_cannot_be_smaller_than_winminheight; | |
3529 p_wmh = p_wh; | |
3530 } | |
3531 win_setminheight(); | |
3532 | |
3533 return errmsg; | |
3534 } | |
3535 | |
3536 /* | |
3537 * Process the new 'winwidth' option value. | |
3538 */ | |
3539 static char * | |
3540 did_set_winwidth(char *errmsg) | |
3541 { | |
3542 if (p_wiw < 1) | |
3543 { | |
3544 errmsg = e_argument_must_be_positive; | |
3545 p_wiw = 1; | |
3546 } | |
3547 if (p_wmw > p_wiw) | |
3548 { | |
3549 errmsg = e_winwidth_cannot_be_smaller_than_winminwidth; | |
3550 p_wiw = p_wmw; | |
3551 } | |
3552 | |
3553 // Change window width NOW | |
3554 if (!ONE_WINDOW && curwin->w_width < p_wiw) | |
3555 win_setwidth((int)p_wiw); | |
3556 | |
3557 return errmsg; | |
3558 } | |
3559 | |
3560 /* | |
3561 * Process the new 'winminwidth' option value. | |
3562 */ | |
3563 static char * | |
3564 did_set_winminwidth(char *errmsg) | |
3565 { | |
3566 if (p_wmw < 0) | |
3567 { | |
3568 errmsg = e_argument_must_be_positive; | |
3569 p_wmw = 0; | |
3570 } | |
3571 if (p_wmw > p_wiw) | |
3572 { | |
3573 errmsg = e_winwidth_cannot_be_smaller_than_winminwidth; | |
3574 p_wmw = p_wiw; | |
3575 } | |
3576 win_setminwidth(); | |
3577 | |
3578 return errmsg; | |
3579 } | |
3580 | |
3581 /* | |
3582 * Process the new 'laststatus' option value. | |
3583 */ | |
3584 static void | |
3585 did_set_laststatus(void) | |
3586 { | |
3587 last_status(FALSE); // (re)set last window status line | |
3588 } | |
3589 | |
3590 /* | |
3591 * Process the new 'showtabline' option value. | |
3592 */ | |
3593 static void | |
3594 did_set_showtabline(void) | |
3595 { | |
3596 shell_new_rows(); // recompute window positions and heights | |
3597 } | |
3598 | |
3599 #ifdef FEAT_GUI | |
3600 /* | |
3601 * Process the new 'linespace' option value. | |
3602 */ | |
3603 static void | |
3604 did_set_linespace(void) | |
3605 { | |
3606 // Recompute gui.char_height and resize the Vim window to keep the | |
3607 // same number of lines. | |
3608 if (gui.in_use && gui_mch_adjust_charheight() == OK) | |
3609 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); | |
3610 } | |
3611 #endif | |
3612 | |
3613 #ifdef FEAT_FOLDING | |
3614 /* | |
3615 * Process the new 'foldlevel' option value. | |
3616 */ | |
3617 static void | |
3618 did_set_foldlevel(void) | |
3619 { | |
3620 if (curwin->w_p_fdl < 0) | |
3621 curwin->w_p_fdl = 0; | |
3622 newFoldLevel(); | |
3623 } | |
3624 | |
3625 /* | |
3626 * Process the new 'foldminlines' option value. | |
3627 */ | |
3628 static void | |
3629 did_set_foldminlines(void) | |
3630 { | |
3631 foldUpdateAll(curwin); | |
3632 } | |
3633 | |
3634 /* | |
3635 * Process the new 'foldnestmax' option value. | |
3636 */ | |
3637 static void | |
3638 did_set_foldnestmax(void) | |
3639 { | |
3640 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) | |
3641 foldUpdateAll(curwin); | |
3642 } | |
3643 | |
3644 /* | |
3645 * Process the new 'foldcolumn' option value. | |
3646 */ | |
3647 static char * | |
3648 did_set_foldcolumn(char *errmsg) | |
3649 { | |
3650 if (curwin->w_p_fdc < 0) | |
3651 { | |
3652 errmsg = e_argument_must_be_positive; | |
3653 curwin->w_p_fdc = 0; | |
3654 } | |
3655 else if (curwin->w_p_fdc > 12) | |
3656 { | |
3657 errmsg = e_invalid_argument; | |
3658 curwin->w_p_fdc = 12; | |
3659 } | |
3660 | |
3661 return errmsg; | |
3662 } | |
3663 #endif | |
3664 | |
3665 /* | |
3666 * Process the new 'shiftwidth' or the 'tabstop' option value. | |
3667 */ | |
3668 static void | |
3669 did_set_shiftwidth_tabstop(long *pp) | |
3670 { | |
3671 #ifdef FEAT_FOLDING | |
3672 if (foldmethodIsIndent(curwin)) | |
3673 foldUpdateAll(curwin); | |
3674 #endif | |
3675 // When 'shiftwidth' changes, or it's zero and 'tabstop' changes: | |
3676 // parse 'cinoptions'. | |
3677 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) | |
3678 parse_cino(curbuf); | |
3679 } | |
3680 | |
3681 /* | |
3682 * Process the new 'maxcombine' option value. | |
3683 */ | |
3684 static void | |
3685 did_set_maxcombine(void) | |
3686 { | |
3687 if (p_mco > MAX_MCO) | |
3688 p_mco = MAX_MCO; | |
3689 else if (p_mco < 0) | |
3690 p_mco = 0; | |
3691 screenclear(); // will re-allocate the screen | |
3692 } | |
3693 | |
3694 /* | |
3695 * Process the new 'iminsert' option value. | |
3696 */ | |
3697 static char * | |
3698 did_set_iminsert(char *errmsg) | |
3699 { | |
3700 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) | |
3701 { | |
3702 errmsg = e_invalid_argument; | |
3703 curbuf->b_p_iminsert = B_IMODE_NONE; | |
3704 } | |
3705 p_iminsert = curbuf->b_p_iminsert; | |
3706 if (termcap_active) // don't do this in the alternate screen | |
3707 showmode(); | |
3708 #if defined(FEAT_KEYMAP) | |
3709 // Show/unshow value of 'keymap' in status lines. | |
3710 status_redraw_curbuf(); | |
3711 #endif | |
3712 | |
3713 return errmsg; | |
3714 } | |
3715 | |
3716 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
3717 /* | |
3718 * Process the new 'imstyle' option value. | |
3719 */ | |
3720 static char * | |
3721 did_set_imstyle(char *errmsg) | |
3722 { | |
3723 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT) | |
3724 errmsg = e_invalid_argument; | |
3725 | |
3726 return errmsg; | |
3727 } | |
3728 #endif | |
3729 | |
3730 /* | |
3731 * Process the new 'window' option value. | |
3732 */ | |
3733 static void | |
3734 did_set_window(void) | |
3735 { | |
3736 if (p_window < 1) | |
3737 p_window = 1; | |
3738 else if (p_window >= Rows) | |
3739 p_window = Rows - 1; | |
3740 } | |
3741 | |
3742 /* | |
3743 * Process the new 'imsearch' option value. | |
3744 */ | |
3745 static char * | |
3746 did_set_imsearch(char *errmsg) | |
3747 { | |
3748 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST) | |
3749 { | |
3750 errmsg = e_invalid_argument; | |
3751 curbuf->b_p_imsearch = B_IMODE_NONE; | |
3752 } | |
3753 p_imsearch = curbuf->b_p_imsearch; | |
3754 | |
3755 return errmsg; | |
3756 } | |
3757 | |
3758 /* | |
3759 * Process the new 'titlelen' option value. | |
3760 */ | |
3761 static char * | |
3762 did_set_titlelen(long old_value, char *errmsg) | |
3763 { | |
3764 // if 'titlelen' has changed, redraw the title | |
3765 if (p_titlelen < 0) | |
3766 { | |
3767 errmsg = e_argument_must_be_positive; | |
3768 p_titlelen = 85; | |
3769 } | |
3770 if (starting != NO_SCREEN && old_value != p_titlelen) | |
3771 need_maketitle = TRUE; | |
3772 | |
3773 return errmsg; | |
3774 } | |
3775 | |
3776 /* | |
3777 * Process the new 'cmdheight' option value. | |
3778 */ | |
3779 static char * | |
3780 did_set_cmdheight(long old_value, char *errmsg) | |
3781 { | |
3782 // if p_ch changed value, change the command line height | |
3783 if (p_ch < 1) | |
3784 { | |
3785 errmsg = e_argument_must_be_positive; | |
3786 p_ch = 1; | |
3787 } | |
3788 if (p_ch > Rows - min_rows() + 1) | |
3789 p_ch = Rows - min_rows() + 1; | |
3790 | |
3791 // Only compute the new window layout when startup has been | |
3792 // completed. Otherwise the frame sizes may be wrong. | |
3793 if ((p_ch != old_value | |
3794 || tabline_height() + topframe->fr_height != Rows - p_ch) | |
3795 && full_screen | |
3796 #ifdef FEAT_GUI | |
3797 && !gui.starting | |
3798 #endif | |
3799 ) | |
3800 command_height(); | |
3801 | |
3802 return errmsg; | |
3803 } | |
3804 | |
3805 /* | |
3806 * Process the new 'updatecount' option value. | |
3807 */ | |
3808 static char * | |
3809 did_set_updatecount(long old_value, char *errmsg) | |
3810 { | |
3811 // when 'updatecount' changes from zero to non-zero, open swap files | |
3812 if (p_uc < 0) | |
3813 { | |
3814 errmsg = e_argument_must_be_positive; | |
3815 p_uc = 100; | |
3816 } | |
3817 if (p_uc && !old_value) | |
3818 ml_open_files(); | |
3819 | |
3820 return errmsg; | |
3821 } | |
3822 | |
3823 #ifdef FEAT_CONCEAL | |
3824 /* | |
3825 * Process the new 'conceallevel' option value. | |
3826 */ | |
3827 static char * | |
3828 did_set_conceallevel(char *errmsg) | |
3829 { | |
3830 if (curwin->w_p_cole < 0) | |
3831 { | |
3832 errmsg = e_argument_must_be_positive; | |
3833 curwin->w_p_cole = 0; | |
3834 } | |
3835 else if (curwin->w_p_cole > 3) | |
3836 { | |
3837 errmsg = e_invalid_argument; | |
3838 curwin->w_p_cole = 3; | |
3839 } | |
3840 | |
3841 return errmsg; | |
3842 } | |
3843 #endif | |
3844 | |
3845 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) | |
3846 /* | |
3847 * Process the new 'pyxversion' option value. | |
3848 */ | |
3849 static char * | |
3850 did_set_pyxversion(char *errmsg) | |
3851 { | |
3852 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3) | |
3853 errmsg = e_invalid_argument; | |
3854 | |
3855 return errmsg; | |
3856 } | |
3857 #endif | |
3858 | |
3859 /* | |
3860 * Process the new global 'undolevels' option value. | |
3861 */ | |
3862 static void | |
3863 did_set_global_undolevels(long value, long old_value) | |
3864 { | |
3865 // sync undo before 'undolevels' changes | |
3866 | |
3867 // use the old value, otherwise u_sync() may not work properly | |
3868 p_ul = old_value; | |
3869 u_sync(TRUE); | |
3870 p_ul = value; | |
3871 } | |
3872 | |
3873 /* | |
3874 * Process the new buffer local 'undolevels' option value. | |
3875 */ | |
3876 static void | |
3877 did_set_buflocal_undolevels(long value, long old_value) | |
3878 { | |
3879 // use the old value, otherwise u_sync() may not work properly | |
3880 curbuf->b_p_ul = old_value; | |
3881 u_sync(TRUE); | |
3882 curbuf->b_p_ul = value; | |
3883 } | |
3884 | |
3885 #ifdef FEAT_LINEBREAK | |
3886 /* | |
3887 * Process the new 'numberwidth' option value. | |
3888 */ | |
3889 static char * | |
3890 did_set_numberwidth(char *errmsg) | |
3891 { | |
3892 // 'numberwidth' must be positive | |
3893 if (curwin->w_p_nuw < 1) | |
3894 { | |
3895 errmsg = e_argument_must_be_positive; | |
3896 curwin->w_p_nuw = 1; | |
3897 } | |
3898 if (curwin->w_p_nuw > 20) | |
3899 { | |
3900 errmsg = e_invalid_argument; | |
3901 curwin->w_p_nuw = 20; | |
3902 } | |
3903 curwin->w_nrwidth_line_count = 0; // trigger a redraw | |
3904 | |
3905 return errmsg; | |
3906 } | |
3907 #endif | |
3908 | |
3909 /* | |
3910 * Process the new 'textwidth' option value. | |
3911 */ | |
3912 static char * | |
3913 did_set_textwidth(char *errmsg) | |
3914 { | |
3915 if (curbuf->b_p_tw < 0) | |
3916 { | |
3917 errmsg = e_argument_must_be_positive; | |
3918 curbuf->b_p_tw = 0; | |
3919 } | |
3920 #ifdef FEAT_SYN_HL | |
3921 { | |
3922 win_T *wp; | |
3923 tabpage_T *tp; | |
3924 | |
3925 FOR_ALL_TAB_WINDOWS(tp, wp) | |
3926 check_colorcolumn(wp); | |
3927 } | |
3928 #endif | |
3929 | |
3930 return errmsg; | |
3931 } | |
3932 | |
3933 /* | |
3934 * When some number options are changed, need to take some action. | |
3935 */ | |
3936 static char * | |
3937 did_set_num_option(long *pp, long value, long old_value, char *errmsg) | |
3938 { | |
3939 if (pp == &p_wh // 'winheight' | |
3940 || pp == &p_hh) // 'helpheight' | |
3941 errmsg = did_set_winheight_helpheight(pp, errmsg); | |
3942 else if (pp == &p_wmh) // 'winminheight' | |
3943 errmsg = did_set_winminheight(errmsg); | |
3944 else if (pp == &p_wiw) // 'winwidth' | |
3945 errmsg = did_set_winwidth(errmsg); | |
3946 else if (pp == &p_wmw) // 'winminwidth' | |
3947 errmsg = did_set_winminwidth(errmsg); | |
3948 else if (pp == &p_ls) | |
3949 did_set_laststatus(); // 'laststatus' | |
3950 else if (pp == &p_stal) | |
3951 did_set_showtabline(); // 'showtabline' | |
3952 #ifdef FEAT_GUI | |
3953 else if (pp == &p_linespace) // 'linespace' | |
3954 did_set_linespace(); | |
3955 #endif | |
3956 #ifdef FEAT_FOLDING | |
3957 else if (pp == &curwin->w_p_fdl) // 'foldlevel' | |
3958 did_set_foldlevel(); | |
3959 else if (pp == &curwin->w_p_fml) // 'foldminlines' | |
3960 did_set_foldminlines(); | |
3961 else if (pp == &curwin->w_p_fdn) // 'foldnestmax' | |
3962 did_set_foldnestmax(); | |
3963 else if (pp == &curwin->w_p_fdc) // 'foldcolumn' | |
3964 errmsg = did_set_foldcolumn(errmsg); | |
3965 #endif // FEAT_FOLDING | |
3966 else if ( pp == &curbuf->b_p_sw // 'shiftwidth' | |
3967 || pp == &curbuf->b_p_ts) // 'tabstop' | |
3968 did_set_shiftwidth_tabstop(pp); | |
3969 else if (pp == &p_mco) // 'maxcombine' | |
3970 did_set_maxcombine(); | |
3971 else if (pp == &curbuf->b_p_iminsert) // 'iminsert' | |
3972 errmsg = did_set_iminsert(errmsg); | |
3973 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
3974 else if (pp == &p_imst) // 'imstyle' | |
3975 errmsg = did_set_imstyle(errmsg); | |
3976 #endif | |
3977 else if (pp == &p_window) // 'window' | |
3978 did_set_window(); | |
3979 else if (pp == &curbuf->b_p_imsearch) // 'imsearch' | |
3980 errmsg = did_set_imsearch(errmsg); | |
3981 else if (pp == &p_titlelen) // 'titlelen' | |
3982 errmsg = did_set_titlelen(old_value, errmsg); | |
3983 else if (pp == &p_ch) // 'cmdheight' | |
3984 errmsg = did_set_cmdheight(old_value, errmsg); | |
3985 else if (pp == &p_uc) // 'updatecount' | |
3986 errmsg = did_set_updatecount(old_value, errmsg); | |
3987 #ifdef FEAT_CONCEAL | |
3988 else if (pp == &curwin->w_p_cole) // 'conceallevel' | |
3989 errmsg = did_set_conceallevel(errmsg); | |
3990 #endif | |
3991 #ifdef MZSCHEME_GUI_THREADS | |
3992 else if (pp == &p_mzq) // 'mzquantum' | |
3993 mzvim_reset_timer(); | |
3994 #endif | |
3995 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) | |
3996 else if (pp == &p_pyx) // 'pyxversion' | |
3997 errmsg = did_set_pyxversion(errmsg); | |
3998 #endif | |
3999 else if (pp == &p_ul) // global 'undolevels' | |
4000 did_set_global_undolevels(value, old_value); | |
4001 else if (pp == &curbuf->b_p_ul) // buffer local 'undolevels' | |
4002 did_set_buflocal_undolevels(value, old_value); | |
4003 #ifdef FEAT_LINEBREAK | |
4004 else if (pp == &curwin->w_p_nuw) // 'numberwidth' | |
4005 errmsg = did_set_numberwidth(errmsg); | |
4006 #endif | |
4007 else if (pp == &curbuf->b_p_tw) // 'textwidth' | |
4008 errmsg = did_set_textwidth(errmsg); | |
4009 | |
4010 return errmsg; | |
4011 } | |
4012 | |
4013 /* | |
4014 * Check the bounds of numeric options. | |
4015 */ | |
4016 static char * | |
4017 check_num_option_bounds( | |
4018 long *pp, | |
4019 long old_value, | |
4020 long old_Rows, | |
4021 long old_Columns, | |
4022 char *errbuf, | |
4023 size_t errbuflen, | |
4024 char *errmsg) | |
4025 { | |
4026 if (Rows < min_rows() && full_screen) | |
4027 { | |
4028 if (errbuf != NULL) | |
4029 { | |
4030 vim_snprintf(errbuf, errbuflen, | |
4031 _(e_need_at_least_nr_lines), min_rows()); | |
4032 errmsg = errbuf; | |
4033 } | |
4034 Rows = min_rows(); | |
4035 } | |
4036 if (Columns < MIN_COLUMNS && full_screen) | |
4037 { | |
4038 if (errbuf != NULL) | |
4039 { | |
4040 vim_snprintf(errbuf, errbuflen, | |
4041 _(e_need_at_least_nr_columns), MIN_COLUMNS); | |
4042 errmsg = errbuf; | |
4043 } | |
4044 Columns = MIN_COLUMNS; | |
4045 } | |
4046 limit_screen_size(); | |
4047 | |
4048 /* | |
4049 * If the screen (shell) height has been changed, assume it is the | |
4050 * physical screenheight. | |
4051 */ | |
4052 if (old_Rows != Rows || old_Columns != Columns) | |
4053 { | |
4054 // Changing the screen size is not allowed while updating the screen. | |
4055 if (updating_screen) | |
4056 *pp = old_value; | |
4057 else if (full_screen | |
4058 #ifdef FEAT_GUI | |
4059 && !gui.starting | |
4060 #endif | |
4061 ) | |
4062 set_shellsize((int)Columns, (int)Rows, TRUE); | |
4063 else | |
4064 { | |
4065 // Postpone the resizing; check the size and cmdline position for | |
4066 // messages. | |
4067 check_shellsize(); | |
4068 if (cmdline_row > Rows - p_ch && Rows > p_ch) | |
4069 cmdline_row = Rows - p_ch; | |
4070 } | |
4071 if (p_window >= Rows || !option_was_set((char_u *)"window")) | |
4072 p_window = Rows - 1; | |
4073 } | |
4074 | |
4075 if (curbuf->b_p_ts <= 0) | |
4076 { | |
4077 errmsg = e_argument_must_be_positive; | |
4078 curbuf->b_p_ts = 8; | |
4079 } | |
4080 else if (curbuf->b_p_ts > TABSTOP_MAX) | |
4081 { | |
4082 errmsg = e_invalid_argument; | |
4083 curbuf->b_p_ts = 8; | |
4084 } | |
4085 if (p_tm < 0) | |
4086 { | |
4087 errmsg = e_argument_must_be_positive; | |
4088 p_tm = 0; | |
4089 } | |
4090 if ((curwin->w_p_scr <= 0 | |
4091 || (curwin->w_p_scr > curwin->w_height | |
4092 && curwin->w_height > 0)) | |
4093 && full_screen) | |
4094 { | |
4095 if (pp == &(curwin->w_p_scr)) | |
4096 { | |
4097 if (curwin->w_p_scr != 0) | |
4098 errmsg = e_invalid_scroll_size; | |
4099 win_comp_scroll(curwin); | |
4100 } | |
4101 // If 'scroll' became invalid because of a side effect silently adjust | |
4102 // it. | |
4103 else if (curwin->w_p_scr <= 0) | |
4104 curwin->w_p_scr = 1; | |
4105 else // curwin->w_p_scr > curwin->w_height | |
4106 curwin->w_p_scr = curwin->w_height; | |
4107 } | |
4108 if (p_hi < 0) | |
4109 { | |
4110 errmsg = e_argument_must_be_positive; | |
4111 p_hi = 0; | |
4112 } | |
4113 else if (p_hi > 10000) | |
4114 { | |
4115 errmsg = e_invalid_argument; | |
4116 p_hi = 10000; | |
4117 } | |
4118 if (p_re < 0 || p_re > 2) | |
4119 { | |
4120 errmsg = e_invalid_argument; | |
4121 p_re = 0; | |
4122 } | |
4123 if (p_report < 0) | |
4124 { | |
4125 errmsg = e_argument_must_be_positive; | |
4126 p_report = 1; | |
4127 } | |
4128 if ((p_sj < -100 || p_sj >= Rows) && full_screen) | |
4129 { | |
4130 if (Rows != old_Rows) // Rows changed, just adjust p_sj | |
4131 p_sj = Rows / 2; | |
4132 else | |
4133 { | |
4134 errmsg = e_invalid_scroll_size; | |
4135 p_sj = 1; | |
4136 } | |
4137 } | |
4138 if (p_so < 0 && full_screen) | |
4139 { | |
4140 errmsg = e_argument_must_be_positive; | |
4141 p_so = 0; | |
4142 } | |
4143 if (p_siso < 0 && full_screen) | |
4144 { | |
4145 errmsg = e_argument_must_be_positive; | |
4146 p_siso = 0; | |
4147 } | |
4148 if (p_cwh < 1) | |
4149 { | |
4150 errmsg = e_argument_must_be_positive; | |
4151 p_cwh = 1; | |
4152 } | |
4153 if (p_ut < 0) | |
4154 { | |
4155 errmsg = e_argument_must_be_positive; | |
4156 p_ut = 2000; | |
4157 } | |
4158 if (p_ss < 0) | |
4159 { | |
4160 errmsg = e_argument_must_be_positive; | |
4161 p_ss = 0; | |
4162 } | |
4163 | |
4164 return errmsg; | |
4165 } | |
4166 | |
4167 /* | |
3482 * Set the value of a number option, and take care of side effects. | 4168 * Set the value of a number option, and take care of side effects. |
3483 * Returns NULL for success, or an error message for an error. | 4169 * Returns NULL for success, or an error message for an error. |
3484 */ | 4170 */ |
3485 static char * | 4171 static char * |
3486 set_num_option( | 4172 set_num_option( |
3542 } | 4228 } |
3543 | 4229 |
3544 /* | 4230 /* |
3545 * Number options that need some action when changed | 4231 * Number options that need some action when changed |
3546 */ | 4232 */ |
3547 if (pp == &p_wh || pp == &p_hh) | 4233 errmsg = did_set_num_option(pp, value, old_value, errmsg); |
3548 { | |
3549 // 'winheight' and 'helpheight' | |
3550 if (p_wh < 1) | |
3551 { | |
3552 errmsg = e_argument_must_be_positive; | |
3553 p_wh = 1; | |
3554 } | |
3555 if (p_wmh > p_wh) | |
3556 { | |
3557 errmsg = e_winheight_cannot_be_smaller_than_winminheight; | |
3558 p_wh = p_wmh; | |
3559 } | |
3560 if (p_hh < 0) | |
3561 { | |
3562 errmsg = e_argument_must_be_positive; | |
3563 p_hh = 0; | |
3564 } | |
3565 | |
3566 // Change window height NOW | |
3567 if (!ONE_WINDOW) | |
3568 { | |
3569 if (pp == &p_wh && curwin->w_height < p_wh) | |
3570 win_setheight((int)p_wh); | |
3571 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh) | |
3572 win_setheight((int)p_hh); | |
3573 } | |
3574 } | |
3575 else if (pp == &p_wmh) | |
3576 { | |
3577 // 'winminheight' | |
3578 if (p_wmh < 0) | |
3579 { | |
3580 errmsg = e_argument_must_be_positive; | |
3581 p_wmh = 0; | |
3582 } | |
3583 if (p_wmh > p_wh) | |
3584 { | |
3585 errmsg = e_winheight_cannot_be_smaller_than_winminheight; | |
3586 p_wmh = p_wh; | |
3587 } | |
3588 win_setminheight(); | |
3589 } | |
3590 else if (pp == &p_wiw) | |
3591 { | |
3592 // 'winwidth' | |
3593 if (p_wiw < 1) | |
3594 { | |
3595 errmsg = e_argument_must_be_positive; | |
3596 p_wiw = 1; | |
3597 } | |
3598 if (p_wmw > p_wiw) | |
3599 { | |
3600 errmsg = e_winwidth_cannot_be_smaller_than_winminwidth; | |
3601 p_wiw = p_wmw; | |
3602 } | |
3603 | |
3604 // Change window width NOW | |
3605 if (!ONE_WINDOW && curwin->w_width < p_wiw) | |
3606 win_setwidth((int)p_wiw); | |
3607 } | |
3608 else if (pp == &p_wmw) | |
3609 { | |
3610 // 'winminwidth' | |
3611 if (p_wmw < 0) | |
3612 { | |
3613 errmsg = e_argument_must_be_positive; | |
3614 p_wmw = 0; | |
3615 } | |
3616 if (p_wmw > p_wiw) | |
3617 { | |
3618 errmsg = e_winwidth_cannot_be_smaller_than_winminwidth; | |
3619 p_wmw = p_wiw; | |
3620 } | |
3621 win_setminwidth(); | |
3622 } | |
3623 | |
3624 // (re)set last window status line | |
3625 else if (pp == &p_ls) | |
3626 { | |
3627 last_status(FALSE); | |
3628 } | |
3629 | |
3630 // (re)set tab page line | |
3631 else if (pp == &p_stal) | |
3632 { | |
3633 shell_new_rows(); // recompute window positions and heights | |
3634 } | |
3635 | |
3636 #ifdef FEAT_GUI | |
3637 else if (pp == &p_linespace) | |
3638 { | |
3639 // Recompute gui.char_height and resize the Vim window to keep the | |
3640 // same number of lines. | |
3641 if (gui.in_use && gui_mch_adjust_charheight() == OK) | |
3642 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); | |
3643 } | |
3644 #endif | |
3645 | |
3646 #ifdef FEAT_FOLDING | |
3647 // 'foldlevel' | |
3648 else if (pp == &curwin->w_p_fdl) | |
3649 { | |
3650 if (curwin->w_p_fdl < 0) | |
3651 curwin->w_p_fdl = 0; | |
3652 newFoldLevel(); | |
3653 } | |
3654 | |
3655 // 'foldminlines' | |
3656 else if (pp == &curwin->w_p_fml) | |
3657 { | |
3658 foldUpdateAll(curwin); | |
3659 } | |
3660 | |
3661 // 'foldnestmax' | |
3662 else if (pp == &curwin->w_p_fdn) | |
3663 { | |
3664 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) | |
3665 foldUpdateAll(curwin); | |
3666 } | |
3667 | |
3668 // 'foldcolumn' | |
3669 else if (pp == &curwin->w_p_fdc) | |
3670 { | |
3671 if (curwin->w_p_fdc < 0) | |
3672 { | |
3673 errmsg = e_argument_must_be_positive; | |
3674 curwin->w_p_fdc = 0; | |
3675 } | |
3676 else if (curwin->w_p_fdc > 12) | |
3677 { | |
3678 errmsg = e_invalid_argument; | |
3679 curwin->w_p_fdc = 12; | |
3680 } | |
3681 } | |
3682 #endif // FEAT_FOLDING | |
3683 | |
3684 // 'shiftwidth' or 'tabstop' | |
3685 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts) | |
3686 { | |
3687 #ifdef FEAT_FOLDING | |
3688 if (foldmethodIsIndent(curwin)) | |
3689 foldUpdateAll(curwin); | |
3690 #endif | |
3691 // When 'shiftwidth' changes, or it's zero and 'tabstop' changes: | |
3692 // parse 'cinoptions'. | |
3693 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) | |
3694 parse_cino(curbuf); | |
3695 } | |
3696 | |
3697 // 'maxcombine' | |
3698 else if (pp == &p_mco) | |
3699 { | |
3700 if (p_mco > MAX_MCO) | |
3701 p_mco = MAX_MCO; | |
3702 else if (p_mco < 0) | |
3703 p_mco = 0; | |
3704 screenclear(); // will re-allocate the screen | |
3705 } | |
3706 | |
3707 else if (pp == &curbuf->b_p_iminsert) | |
3708 { | |
3709 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) | |
3710 { | |
3711 errmsg = e_invalid_argument; | |
3712 curbuf->b_p_iminsert = B_IMODE_NONE; | |
3713 } | |
3714 p_iminsert = curbuf->b_p_iminsert; | |
3715 if (termcap_active) // don't do this in the alternate screen | |
3716 showmode(); | |
3717 #if defined(FEAT_KEYMAP) | |
3718 // Show/unshow value of 'keymap' in status lines. | |
3719 status_redraw_curbuf(); | |
3720 #endif | |
3721 } | |
3722 | |
3723 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
3724 // 'imstyle' | |
3725 else if (pp == &p_imst) | |
3726 { | |
3727 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT) | |
3728 errmsg = e_invalid_argument; | |
3729 } | |
3730 #endif | |
3731 | |
3732 else if (pp == &p_window) | |
3733 { | |
3734 if (p_window < 1) | |
3735 p_window = 1; | |
3736 else if (p_window >= Rows) | |
3737 p_window = Rows - 1; | |
3738 } | |
3739 | |
3740 else if (pp == &curbuf->b_p_imsearch) | |
3741 { | |
3742 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST) | |
3743 { | |
3744 errmsg = e_invalid_argument; | |
3745 curbuf->b_p_imsearch = B_IMODE_NONE; | |
3746 } | |
3747 p_imsearch = curbuf->b_p_imsearch; | |
3748 } | |
3749 | |
3750 // if 'titlelen' has changed, redraw the title | |
3751 else if (pp == &p_titlelen) | |
3752 { | |
3753 if (p_titlelen < 0) | |
3754 { | |
3755 errmsg = e_argument_must_be_positive; | |
3756 p_titlelen = 85; | |
3757 } | |
3758 if (starting != NO_SCREEN && old_value != p_titlelen) | |
3759 need_maketitle = TRUE; | |
3760 } | |
3761 | |
3762 // if p_ch changed value, change the command line height | |
3763 else if (pp == &p_ch) | |
3764 { | |
3765 if (p_ch < 1) | |
3766 { | |
3767 errmsg = e_argument_must_be_positive; | |
3768 p_ch = 1; | |
3769 } | |
3770 if (p_ch > Rows - min_rows() + 1) | |
3771 p_ch = Rows - min_rows() + 1; | |
3772 | |
3773 // Only compute the new window layout when startup has been | |
3774 // completed. Otherwise the frame sizes may be wrong. | |
3775 if ((p_ch != old_value | |
3776 || tabline_height() + topframe->fr_height != Rows - p_ch) | |
3777 && full_screen | |
3778 #ifdef FEAT_GUI | |
3779 && !gui.starting | |
3780 #endif | |
3781 ) | |
3782 command_height(); | |
3783 } | |
3784 | |
3785 // when 'updatecount' changes from zero to non-zero, open swap files | |
3786 else if (pp == &p_uc) | |
3787 { | |
3788 if (p_uc < 0) | |
3789 { | |
3790 errmsg = e_argument_must_be_positive; | |
3791 p_uc = 100; | |
3792 } | |
3793 if (p_uc && !old_value) | |
3794 ml_open_files(); | |
3795 } | |
3796 #ifdef FEAT_CONCEAL | |
3797 else if (pp == &curwin->w_p_cole) | |
3798 { | |
3799 if (curwin->w_p_cole < 0) | |
3800 { | |
3801 errmsg = e_argument_must_be_positive; | |
3802 curwin->w_p_cole = 0; | |
3803 } | |
3804 else if (curwin->w_p_cole > 3) | |
3805 { | |
3806 errmsg = e_invalid_argument; | |
3807 curwin->w_p_cole = 3; | |
3808 } | |
3809 } | |
3810 #endif | |
3811 #ifdef MZSCHEME_GUI_THREADS | |
3812 else if (pp == &p_mzq) | |
3813 mzvim_reset_timer(); | |
3814 #endif | |
3815 | |
3816 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) | |
3817 // 'pyxversion' | |
3818 else if (pp == &p_pyx) | |
3819 { | |
3820 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3) | |
3821 errmsg = e_invalid_argument; | |
3822 } | |
3823 #endif | |
3824 | |
3825 // sync undo before 'undolevels' changes | |
3826 else if (pp == &p_ul) | |
3827 { | |
3828 // use the old value, otherwise u_sync() may not work properly | |
3829 p_ul = old_value; | |
3830 u_sync(TRUE); | |
3831 p_ul = value; | |
3832 } | |
3833 else if (pp == &curbuf->b_p_ul) | |
3834 { | |
3835 // use the old value, otherwise u_sync() may not work properly | |
3836 curbuf->b_p_ul = old_value; | |
3837 u_sync(TRUE); | |
3838 curbuf->b_p_ul = value; | |
3839 } | |
3840 | |
3841 #ifdef FEAT_LINEBREAK | |
3842 // 'numberwidth' must be positive | |
3843 else if (pp == &curwin->w_p_nuw) | |
3844 { | |
3845 if (curwin->w_p_nuw < 1) | |
3846 { | |
3847 errmsg = e_argument_must_be_positive; | |
3848 curwin->w_p_nuw = 1; | |
3849 } | |
3850 if (curwin->w_p_nuw > 20) | |
3851 { | |
3852 errmsg = e_invalid_argument; | |
3853 curwin->w_p_nuw = 20; | |
3854 } | |
3855 curwin->w_nrwidth_line_count = 0; // trigger a redraw | |
3856 } | |
3857 #endif | |
3858 | |
3859 else if (pp == &curbuf->b_p_tw) | |
3860 { | |
3861 if (curbuf->b_p_tw < 0) | |
3862 { | |
3863 errmsg = e_argument_must_be_positive; | |
3864 curbuf->b_p_tw = 0; | |
3865 } | |
3866 #ifdef FEAT_SYN_HL | |
3867 { | |
3868 win_T *wp; | |
3869 tabpage_T *tp; | |
3870 | |
3871 FOR_ALL_TAB_WINDOWS(tp, wp) | |
3872 check_colorcolumn(wp); | |
3873 } | |
3874 #endif | |
3875 } | |
3876 | 4234 |
3877 /* | 4235 /* |
3878 * Check the bounds for numeric options here | 4236 * Check the bounds for numeric options here |
3879 */ | 4237 */ |
3880 if (Rows < min_rows() && full_screen) | 4238 errmsg = check_num_option_bounds(pp, old_value, old_Rows, old_Columns, |
3881 { | 4239 errbuf, errbuflen, errmsg); |
3882 if (errbuf != NULL) | |
3883 { | |
3884 vim_snprintf(errbuf, errbuflen, | |
3885 _(e_need_at_least_nr_lines), min_rows()); | |
3886 errmsg = errbuf; | |
3887 } | |
3888 Rows = min_rows(); | |
3889 } | |
3890 if (Columns < MIN_COLUMNS && full_screen) | |
3891 { | |
3892 if (errbuf != NULL) | |
3893 { | |
3894 vim_snprintf(errbuf, errbuflen, | |
3895 _(e_need_at_least_nr_columns), MIN_COLUMNS); | |
3896 errmsg = errbuf; | |
3897 } | |
3898 Columns = MIN_COLUMNS; | |
3899 } | |
3900 limit_screen_size(); | |
3901 | |
3902 /* | |
3903 * If the screen (shell) height has been changed, assume it is the | |
3904 * physical screenheight. | |
3905 */ | |
3906 if (old_Rows != Rows || old_Columns != Columns) | |
3907 { | |
3908 // Changing the screen size is not allowed while updating the screen. | |
3909 if (updating_screen) | |
3910 *pp = old_value; | |
3911 else if (full_screen | |
3912 #ifdef FEAT_GUI | |
3913 && !gui.starting | |
3914 #endif | |
3915 ) | |
3916 set_shellsize((int)Columns, (int)Rows, TRUE); | |
3917 else | |
3918 { | |
3919 // Postpone the resizing; check the size and cmdline position for | |
3920 // messages. | |
3921 check_shellsize(); | |
3922 if (cmdline_row > Rows - p_ch && Rows > p_ch) | |
3923 cmdline_row = Rows - p_ch; | |
3924 } | |
3925 if (p_window >= Rows || !option_was_set((char_u *)"window")) | |
3926 p_window = Rows - 1; | |
3927 } | |
3928 | |
3929 if (curbuf->b_p_ts <= 0) | |
3930 { | |
3931 errmsg = e_argument_must_be_positive; | |
3932 curbuf->b_p_ts = 8; | |
3933 } | |
3934 else if (curbuf->b_p_ts > TABSTOP_MAX) | |
3935 { | |
3936 errmsg = e_invalid_argument; | |
3937 curbuf->b_p_ts = 8; | |
3938 } | |
3939 if (p_tm < 0) | |
3940 { | |
3941 errmsg = e_argument_must_be_positive; | |
3942 p_tm = 0; | |
3943 } | |
3944 if ((curwin->w_p_scr <= 0 | |
3945 || (curwin->w_p_scr > curwin->w_height | |
3946 && curwin->w_height > 0)) | |
3947 && full_screen) | |
3948 { | |
3949 if (pp == &(curwin->w_p_scr)) | |
3950 { | |
3951 if (curwin->w_p_scr != 0) | |
3952 errmsg = e_invalid_scroll_size; | |
3953 win_comp_scroll(curwin); | |
3954 } | |
3955 // If 'scroll' became invalid because of a side effect silently adjust | |
3956 // it. | |
3957 else if (curwin->w_p_scr <= 0) | |
3958 curwin->w_p_scr = 1; | |
3959 else // curwin->w_p_scr > curwin->w_height | |
3960 curwin->w_p_scr = curwin->w_height; | |
3961 } | |
3962 if (p_hi < 0) | |
3963 { | |
3964 errmsg = e_argument_must_be_positive; | |
3965 p_hi = 0; | |
3966 } | |
3967 else if (p_hi > 10000) | |
3968 { | |
3969 errmsg = e_invalid_argument; | |
3970 p_hi = 10000; | |
3971 } | |
3972 if (p_re < 0 || p_re > 2) | |
3973 { | |
3974 errmsg = e_invalid_argument; | |
3975 p_re = 0; | |
3976 } | |
3977 if (p_report < 0) | |
3978 { | |
3979 errmsg = e_argument_must_be_positive; | |
3980 p_report = 1; | |
3981 } | |
3982 if ((p_sj < -100 || p_sj >= Rows) && full_screen) | |
3983 { | |
3984 if (Rows != old_Rows) // Rows changed, just adjust p_sj | |
3985 p_sj = Rows / 2; | |
3986 else | |
3987 { | |
3988 errmsg = e_invalid_scroll_size; | |
3989 p_sj = 1; | |
3990 } | |
3991 } | |
3992 if (p_so < 0 && full_screen) | |
3993 { | |
3994 errmsg = e_argument_must_be_positive; | |
3995 p_so = 0; | |
3996 } | |
3997 if (p_siso < 0 && full_screen) | |
3998 { | |
3999 errmsg = e_argument_must_be_positive; | |
4000 p_siso = 0; | |
4001 } | |
4002 if (p_cwh < 1) | |
4003 { | |
4004 errmsg = e_argument_must_be_positive; | |
4005 p_cwh = 1; | |
4006 } | |
4007 if (p_ut < 0) | |
4008 { | |
4009 errmsg = e_argument_must_be_positive; | |
4010 p_ut = 2000; | |
4011 } | |
4012 if (p_ss < 0) | |
4013 { | |
4014 errmsg = e_argument_must_be_positive; | |
4015 p_ss = 0; | |
4016 } | |
4017 | 4240 |
4018 // May set global value for local option. | 4241 // May set global value for local option. |
4019 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) | 4242 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
4020 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp; | 4243 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp; |
4021 | 4244 |