updated for version 7.3.694 v7.3.694
authorBram Moolenaar <Bram@vim.org>
Sat, 20 Oct 2012 22:45:18 +0000 (00:45 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 20 Oct 2012 22:45:18 +0000 (00:45 +0200)
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)

runtime/doc/eval.txt
src/eval.c
src/version.c

index 12ea9c897ef8c77de0bb4b661332823638af2a49..8934215eb7e3bd3e3f184972bfdba72fdecd1956 100644 (file)
@@ -1932,6 +1932,7 @@ setwinvar( {nr}, {varname}, {val})        set {varname} in window {nr} to {val}
 shellescape( {string} [, {special}])
                                String  escape {string} for use as shell
                                        command argument
+shiftwidth()                   Number  effective value of 'shiftwidth'
 simplify( {filename})          String  simplify filename as much as possible
 sin( {expr})                   Float   sine of {expr}
 sinh( {expr})                  Float   hyperbolic sine of {expr}
@@ -3754,10 +3755,10 @@ inputdialog({prompt} [, {text} [, {cancelreturn}]])             *inputdialog()*
                Like |input()|, but when the GUI is running and text dialogs
                are supported, a dialog window pops up to input the text.
                Example: >
-                       :let n = inputdialog("value for shiftwidth", &sw)
-                       :if n != ""
-                       :  let &sw = n
-                       :endif
+                  :let n = inputdialog("value for shiftwidth", shiftwidth())
+                  :if n != ""
+                  :  let &sw = n
+                  :endif
 <              When the dialog is cancelled {cancelreturn} is returned.  When
                omitted an empty string is returned.
                Hitting <Enter> works like pressing the OK button.  Hitting
@@ -5331,6 +5332,23 @@ shellescape({string} [, {special}])                      *shellescape()*
                    :call system("chmod +w -- " . shellescape(expand("%")))
 
 
+shiftwidth()                                           *shiftwidth()*
+               Returns the effective value of 'shiftwidth'. This is the
+               'shiftwidth' value unless it is zero, in which case it is the
+               'tabstop' value.  To be backwards compatible in indent
+               plugins, use this: >
+                       if exists('*shiftwidth')
+                         func s:sw()
+                           return shiftwidth()
+                         endfunc
+                       else
+                         func s:sw()
+                           return &sw
+                         endfunc
+                       endif
+<              And then use s:sw() instead of &sw.
+
+
 simplify({filename})                                   *simplify()*
                Simplify the file name as much as possible without changing
                the meaning.  Shortcuts (on MS-Windows) or symbolic links (on
index 98b2a3367a5bb56173a67b538e7edf7b51c4ff5d..66b8606e050de3806b7dfbbb1d8b81ac3e9e89b1 100644 (file)
@@ -687,6 +687,7 @@ static void f_settabvar __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_settabwinvar __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_shellescape __ARGS((typval_T *argvars, typval_T *rettv));
+static void f_shiftwidth __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv));
 #ifdef FEAT_FLOAT
 static void f_sin __ARGS((typval_T *argvars, typval_T *rettv));
@@ -8051,6 +8052,7 @@ static struct fst
     {"settabwinvar",   4, 4, f_settabwinvar},
     {"setwinvar",      3, 3, f_setwinvar},
     {"shellescape",    1, 2, f_shellescape},
+    {"shiftwidth",     0, 0, f_shiftwidth},
     {"simplify",       1, 1, f_simplify},
 #ifdef FEAT_FLOAT
     {"sin",            1, 1, f_sin},
@@ -16651,6 +16653,17 @@ f_shellescape(argvars, rettv)
     rettv->v_type = VAR_STRING;
 }
 
+/*
+ * shiftwidth() function
+ */
+    static void
+f_shiftwidth(argvars, rettv)
+    typval_T   *argvars;
+    typval_T   *rettv;
+{
+    rettv->vval.v_number = get_sw_value();
+}
+
 /*
  * "simplify()" function
  */
index 0a39edeeb606d3c2377be97473dc37eafc400c46..f28590b9d1fd7de9872041ac46ddd88097fc8e0c 100644 (file)
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    694,
 /**/
     693,
 /**/