Mercurial > vim
comparison src/option.c @ 4350:7eaccdaa5304 v7.3.924
updated for version 7.3.924
Problem: Python interface can't easily access options.
Solution: Add vim.options, vim.window.options and vim.buffer.options. (ZyX)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Mon, 06 May 2013 03:52:55 +0200 |
parents | edd0bc1f26bd |
children | 94aa0d30a3ea |
comparison
equal
deleted
inserted
replaced
4349:9e3cdd762964 | 4350:7eaccdaa5304 |
---|---|
8818 } | 8818 } |
8819 return 1; | 8819 return 1; |
8820 } | 8820 } |
8821 #endif | 8821 #endif |
8822 | 8822 |
8823 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) | |
8824 /* | |
8825 * Returns the option attributes and its value. Unlike the above function it | |
8826 * will return either global value or local value of the option depending on | |
8827 * what was requested, but it will never return global value if it was | |
8828 * requested to return local one and vice versa. Neither it will return | |
8829 * buffer-local value if it was requested to return window-local one. | |
8830 * | |
8831 * Pretends that option is absent if it is not present in the requested scope | |
8832 * (i.e. has no global, window-local or buffer-local value depending on | |
8833 * opt_type). Uses | |
8834 * | |
8835 * Returned flags: | |
8836 * 0 hidden or unknown option | |
8837 * see SOPT_* in vim.h for other flags | |
8838 * | |
8839 * Possible opt_type values: see SREQ_* in vim.h | |
8840 */ | |
8841 int | |
8842 get_option_value_strict(name, numval, stringval, opt_type, from) | |
8843 char_u *name; | |
8844 long *numval; | |
8845 char_u **stringval; /* NULL when only obtaining attributes */ | |
8846 int opt_type; | |
8847 void *from; | |
8848 { | |
8849 int opt_idx; | |
8850 char_u *varp; | |
8851 struct vimoption *p; | |
8852 int r = 0; | |
8853 | |
8854 opt_idx = findoption(name); | |
8855 if (opt_idx < 0) | |
8856 return 0; | |
8857 | |
8858 p = &(options[opt_idx]); | |
8859 | |
8860 /* Hidden option */ | |
8861 if (p->var == NULL) | |
8862 return 0; | |
8863 | |
8864 if (p->flags & P_BOOL) | |
8865 r |= SOPT_BOOL; | |
8866 else if (p->flags & P_NUM) | |
8867 r |= SOPT_NUM; | |
8868 else if (p->flags & P_STRING) | |
8869 r |= SOPT_STRING; | |
8870 | |
8871 if (p->indir == PV_NONE) | |
8872 { | |
8873 if (opt_type == SREQ_GLOBAL) | |
8874 r |= SOPT_GLOBAL; | |
8875 else | |
8876 return 0; /* Did not request global-only option */ | |
8877 } | |
8878 else | |
8879 { | |
8880 if (p->indir & PV_BOTH) | |
8881 r |= SOPT_GLOBAL; | |
8882 else if (opt_type == SREQ_GLOBAL) | |
8883 return 0; /* Requested global option */ | |
8884 | |
8885 if (p->indir & PV_WIN) | |
8886 { | |
8887 if (opt_type == SREQ_BUF) | |
8888 return 0; /* Did not request window-local option */ | |
8889 else | |
8890 r |= SOPT_WIN; | |
8891 } | |
8892 else if (p->indir & PV_BUF) | |
8893 { | |
8894 if (opt_type == SREQ_WIN) | |
8895 return 0; /* Did not request buffer-local option */ | |
8896 else | |
8897 r |= SOPT_BUF; | |
8898 } | |
8899 } | |
8900 | |
8901 if (stringval == NULL) | |
8902 return r; | |
8903 | |
8904 if (opt_type == SREQ_GLOBAL) | |
8905 varp = p->var; | |
8906 else | |
8907 { | |
8908 if (opt_type == SREQ_BUF) | |
8909 { | |
8910 /* Special case: 'modified' is b_changed, but we also want to | |
8911 * consider it set when 'ff' or 'fenc' changed. */ | |
8912 if (p->indir == PV_MOD) | |
8913 { | |
8914 *numval = bufIsChanged((buf_T *) from); | |
8915 varp = NULL; | |
8916 } | |
8917 #ifdef FEAT_CRYPT | |
8918 else if (p->indir == PV_KEY) | |
8919 { | |
8920 /* never return the value of the crypt key */ | |
8921 *stringval = NULL; | |
8922 varp = NULL; | |
8923 } | |
8924 #endif | |
8925 else | |
8926 { | |
8927 aco_save_T aco; | |
8928 aucmd_prepbuf(&aco, (buf_T *) from); | |
8929 varp = get_varp(p); | |
8930 aucmd_restbuf(&aco); | |
8931 } | |
8932 } | |
8933 else if (opt_type == SREQ_WIN) | |
8934 { | |
8935 win_T *save_curwin; | |
8936 save_curwin = curwin; | |
8937 curwin = (win_T *) from; | |
8938 curbuf = curwin->w_buffer; | |
8939 varp = get_varp(p); | |
8940 curwin = save_curwin; | |
8941 curbuf = curwin->w_buffer; | |
8942 } | |
8943 if (varp == p->var) | |
8944 return (r | SOPT_UNSET); | |
8945 } | |
8946 | |
8947 if (varp != NULL) | |
8948 { | |
8949 if (p->flags & P_STRING) | |
8950 *stringval = vim_strsave(*(char_u **)(varp)); | |
8951 else if (p->flags & P_NUM) | |
8952 *numval = *(long *) varp; | |
8953 else | |
8954 *numval = *(int *)varp; | |
8955 } | |
8956 | |
8957 return r; | |
8958 } | |
8959 #endif | |
8960 | |
8823 /* | 8961 /* |
8824 * Set the value of option "name". | 8962 * Set the value of option "name". |
8825 * Use "string" for string options, use "number" for other options. | 8963 * Use "string" for string options, use "number" for other options. |
8826 */ | 8964 */ |
8827 void | 8965 void |
9552 ru_col = 1; | 9690 ru_col = 1; |
9553 #else | 9691 #else |
9554 sc_col = Columns; | 9692 sc_col = Columns; |
9555 ru_col = Columns; | 9693 ru_col = Columns; |
9556 #endif | 9694 #endif |
9695 } | |
9696 | |
9697 /* | |
9698 * Unset local option value, similar to ":set opt<". | |
9699 */ | |
9700 | |
9701 void | |
9702 unset_global_local_option(name, from) | |
9703 char_u *name; | |
9704 void *from; | |
9705 { | |
9706 struct vimoption *p; | |
9707 int opt_idx; | |
9708 | |
9709 buf_T *buf = (buf_T *) from; | |
9710 win_T *win = (win_T *) from; | |
9711 | |
9712 opt_idx = findoption(name); | |
9713 p = &(options[opt_idx]); | |
9714 | |
9715 switch ((int)p->indir) | |
9716 { | |
9717 /* global option with local value: use local value if it's been set */ | |
9718 case PV_EP: | |
9719 *buf->b_p_ep = NUL; | |
9720 break; | |
9721 case PV_KP: | |
9722 *buf->b_p_kp = NUL; | |
9723 break; | |
9724 case PV_PATH: | |
9725 *buf->b_p_path = NUL; | |
9726 break; | |
9727 case PV_AR: | |
9728 buf->b_p_ar = -1; | |
9729 break; | |
9730 case PV_TAGS: | |
9731 *buf->b_p_tags = NUL; | |
9732 break; | |
9733 #ifdef FEAT_FIND_ID | |
9734 case PV_DEF: | |
9735 *buf->b_p_def = NUL; | |
9736 break; | |
9737 case PV_INC: | |
9738 *buf->b_p_inc = NUL; | |
9739 break; | |
9740 #endif | |
9741 #ifdef FEAT_INS_EXPAND | |
9742 case PV_DICT: | |
9743 *buf->b_p_dict = NUL; | |
9744 break; | |
9745 case PV_TSR: | |
9746 *buf->b_p_tsr = NUL; | |
9747 break; | |
9748 #endif | |
9749 #ifdef FEAT_QUICKFIX | |
9750 case PV_EFM: | |
9751 *buf->b_p_efm = NUL; | |
9752 break; | |
9753 case PV_GP: | |
9754 *buf->b_p_gp = NUL; | |
9755 break; | |
9756 case PV_MP: | |
9757 *buf->b_p_mp = NUL; | |
9758 break; | |
9759 #endif | |
9760 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) | |
9761 case PV_BEXPR: | |
9762 *buf->b_p_bexpr = NUL; | |
9763 break; | |
9764 #endif | |
9765 #if defined(FEAT_CRYPT) | |
9766 case PV_CM: | |
9767 *buf->b_p_cm = NUL; | |
9768 break; | |
9769 #endif | |
9770 #ifdef FEAT_STL_OPT | |
9771 case PV_STL: | |
9772 *win->w_p_stl = NUL; | |
9773 break; | |
9774 #endif | |
9775 } | |
9557 } | 9776 } |
9558 | 9777 |
9559 /* | 9778 /* |
9560 * Get pointer to option variable, depending on local or global scope. | 9779 * Get pointer to option variable, depending on local or global scope. |
9561 */ | 9780 */ |