Skip to content

Commit ea0bac6

Browse files
committed
updated for version 7.3.694
Problem: Now that 'shiftwidth' may use the value of 'tabstop' it is not so easy to use in indent files. Solution: Add the shiftwidth() function. (so8res)
1 parent 6becf03 commit ea0bac6

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

runtime/doc/eval.txt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,7 @@ setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} to {val}
19321932
shellescape( {string} [, {special}])
19331933
String escape {string} for use as shell
19341934
command argument
1935+
shiftwidth() Number effective value of 'shiftwidth'
19351936
simplify( {filename}) String simplify filename as much as possible
19361937
sin( {expr}) Float sine of {expr}
19371938
sinh( {expr}) Float hyperbolic sine of {expr}
@@ -3754,10 +3755,10 @@ inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
37543755
Like |input()|, but when the GUI is running and text dialogs
37553756
are supported, a dialog window pops up to input the text.
37563757
Example: >
3757-
:let n = inputdialog("value for shiftwidth", &sw)
3758-
:if n != ""
3759-
: let &sw = n
3760-
:endif
3758+
:let n = inputdialog("value for shiftwidth", shiftwidth())
3759+
:if n != ""
3760+
: let &sw = n
3761+
:endif
37613762
< When the dialog is cancelled {cancelreturn} is returned. When
37623763
omitted an empty string is returned.
37633764
Hitting <Enter> works like pressing the OK button. Hitting
@@ -5331,6 +5332,23 @@ shellescape({string} [, {special}]) *shellescape()*
53315332
:call system("chmod +w -- " . shellescape(expand("%")))
53325333
53335334
5335+
shiftwidth() *shiftwidth()*
5336+
Returns the effective value of 'shiftwidth'. This is the
5337+
'shiftwidth' value unless it is zero, in which case it is the
5338+
'tabstop' value. To be backwards compatible in indent
5339+
plugins, use this: >
5340+
if exists('*shiftwidth')
5341+
func s:sw()
5342+
return shiftwidth()
5343+
endfunc
5344+
else
5345+
func s:sw()
5346+
return &sw
5347+
endfunc
5348+
endif
5349+
< And then use s:sw() instead of &sw.
5350+
5351+
53345352
simplify({filename}) *simplify()*
53355353
Simplify the file name as much as possible without changing
53365354
the meaning. Shortcuts (on MS-Windows) or symbolic links (on

src/eval.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ static void f_settabvar __ARGS((typval_T *argvars, typval_T *rettv));
687687
static void f_settabwinvar __ARGS((typval_T *argvars, typval_T *rettv));
688688
static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv));
689689
static void f_shellescape __ARGS((typval_T *argvars, typval_T *rettv));
690+
static void f_shiftwidth __ARGS((typval_T *argvars, typval_T *rettv));
690691
static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv));
691692
#ifdef FEAT_FLOAT
692693
static void f_sin __ARGS((typval_T *argvars, typval_T *rettv));
@@ -8051,6 +8052,7 @@ static struct fst
80518052
{"settabwinvar", 4, 4, f_settabwinvar},
80528053
{"setwinvar", 3, 3, f_setwinvar},
80538054
{"shellescape", 1, 2, f_shellescape},
8055+
{"shiftwidth", 0, 0, f_shiftwidth},
80548056
{"simplify", 1, 1, f_simplify},
80558057
#ifdef FEAT_FLOAT
80568058
{"sin", 1, 1, f_sin},
@@ -16651,6 +16653,17 @@ f_shellescape(argvars, rettv)
1665116653
rettv->v_type = VAR_STRING;
1665216654
}
1665316655

16656+
/*
16657+
* shiftwidth() function
16658+
*/
16659+
static void
16660+
f_shiftwidth(argvars, rettv)
16661+
typval_T *argvars;
16662+
typval_T *rettv;
16663+
{
16664+
rettv->vval.v_number = get_sw_value();
16665+
}
16666+
1665416667
/*
1665516668
* "simplify()" function
1665616669
*/

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ static char *(features[]) =
719719

720720
static int included_patches[] =
721721
{ /* Add new patch number below this line */
722+
/**/
723+
694,
722724
/**/
723725
693,
724726
/**/

0 commit comments

Comments
 (0)