Skip to content

Commit 520e1e4

Browse files
committed
patch 7.4.1154
Problem: No support for JSON. Solution: Add jsonencode() and jsondecode(). Also add v:false, v:true, v:null and v:none.
1 parent 6920c72 commit 520e1e4

28 files changed

+863
-34
lines changed

Filelist

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ SRC_ALL = \
4040
src/hardcopy.c \
4141
src/hashtab.c \
4242
src/keymap.h \
43+
src/json.c \
4344
src/macros.h \
4445
src/main.c \
4546
src/mark.c \
@@ -132,6 +133,7 @@ SRC_ALL = \
132133
src/proto/gui_beval.pro \
133134
src/proto/hardcopy.pro \
134135
src/proto/hashtab.pro \
136+
src/proto/json.pro \
135137
src/proto/main.pro \
136138
src/proto/mark.pro \
137139
src/proto/mbyte.pro \

runtime/doc/eval.txt

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 7.4. Last change: 2016 Jan 21
1+
*eval.txt* For Vim version 7.4. Last change: 2016 Jan 23
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1409,6 +1409,10 @@ v:exception The value of the exception most recently caught and not
14091409
:endtry
14101410
< Output: "caught oops".
14111411

1412+
*v:false* *false-variable*
1413+
v:false A Number with value zero. Used to put "false" in JSON. See
1414+
|jsonencode()|.
1415+
14121416
*v:fcs_reason* *fcs_reason-variable*
14131417
v:fcs_reason The reason why the |FileChangedShell| event was triggered.
14141418
Can be used in an autocommand to decide what to do and/or what
@@ -1542,6 +1546,14 @@ v:mouse_col Column number for a mouse click obtained with |getchar()|.
15421546
This is the screen column number, like with |virtcol()|. The
15431547
value is zero when there was no mouse button click.
15441548

1549+
*v:none* *none-variable*
1550+
v:none An empty String. Used to put an empty item in JSON. See
1551+
|jsonencode()|.
1552+
1553+
*v:null* *null-variable*
1554+
v:null An empty String. Used to put "null" in JSON. See
1555+
|jsonencode()|.
1556+
15451557
*v:oldfiles* *oldfiles-variable*
15461558
v:oldfiles List of file names that is loaded from the |viminfo| file on
15471559
startup. These are the files that Vim remembers marks for.
@@ -1707,6 +1719,10 @@ v:throwpoint The point where the exception most recently caught and not
17071719
:endtry
17081720
< Output: "Exception from test.vim, line 2"
17091721

1722+
*v:true* *true-variable*
1723+
v:true A Number with value one. Used to put "true" in JSON. See
1724+
|jsonencode()|.
1725+
17101726
*v:val* *val-variable*
17111727
v:val Value of the current item of a |List| or |Dictionary|. Only
17121728
valid while evaluating the expression used with |map()| and
@@ -1913,6 +1929,8 @@ isdirectory( {directory}) Number TRUE if {directory} is a directory
19131929
islocked( {expr}) Number TRUE if {expr} is locked
19141930
items( {dict}) List key-value pairs in {dict}
19151931
join( {list} [, {sep}]) String join {list} items into one String
1932+
jsondecode( {string}) any decode JSON
1933+
jsonencode( {expr}) String encode JSON
19161934
keys( {dict}) List keys in {dict}
19171935
len( {expr}) Number the length of {expr}
19181936
libcall( {lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
@@ -4215,6 +4233,27 @@ join({list} [, {sep}]) *join()*
42154233
converted into a string like with |string()|.
42164234
The opposite function is |split()|.
42174235

4236+
jsondecode({string}) *jsondecode()*
4237+
TODO
4238+
4239+
jsonencode({expr}) *jsonencode()*
4240+
Encodode {expr} as JSON and return this as a string.
4241+
The encoding is specified in:
4242+
http://www.ietf.org/rfc/rfc4627.txt
4243+
Vim values are converted as follows:
4244+
Number decimal number
4245+
Float floating point number
4246+
String in double quotes (possibly null)
4247+
Funcref nothing
4248+
List as an array (possibly null); when
4249+
used recursively: []
4250+
Dict as an object (possibly null); when
4251+
used recursively: {}
4252+
v:false "false"
4253+
v:true "true"
4254+
v:none nothing
4255+
v:null "null"
4256+
42184257
keys({dict}) *keys()*
42194258
Return a |List| with all the keys of {dict}. The |List| is in
42204259
arbitrary order.

src/Make_bc3.mak

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ EXE_dependencies = \
7272
getchar.obj \
7373
hardcopy.obj \
7474
hashtab.obj \
75+
json.obj \
7576
main.obj \
7677
mark.obj \
7778
memfile.obj \

src/Make_bc5.mak

+1
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ vimobj = \
598598
$(OBJDIR)\getchar.obj \
599599
$(OBJDIR)\hardcopy.obj \
600600
$(OBJDIR)\hashtab.obj \
601+
$(OBJDIR)\json.obj \
601602
$(OBJDIR)\main.obj \
602603
$(OBJDIR)\mark.obj \
603604
$(OBJDIR)\memfile.obj \

src/Make_cyg_ming.mak

+1
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ OBJ = \
601601
$(OUTDIR)/getchar.o \
602602
$(OUTDIR)/hardcopy.o \
603603
$(OUTDIR)/hashtab.o \
604+
$(OUTDIR)/json.o \
604605
$(OUTDIR)/main.o \
605606
$(OUTDIR)/mark.o \
606607
$(OUTDIR)/memfile.o \

src/Make_dice.mak

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ SRC = \
4545
getchar.c \
4646
hardcopy.c \
4747
hashtab.c \
48+
json.c \
4849
main.c \
4950
mark.c \
5051
memfile.c \
@@ -93,6 +94,7 @@ OBJ = o/blowfish.o \
9394
o/getchar.o \
9495
o/hardcopy.o \
9596
o/hashtab.o \
97+
o/json.o \
9698
o/main.o \
9799
o/mark.o \
98100
o/memfile.o \
@@ -179,6 +181,8 @@ o/hardcopy.o: hardcopy.c $(SYMS)
179181

180182
o/hashtab.o: hashtab.c $(SYMS)
181183

184+
o/json.o: json.c $(SYMS)
185+
182186
o/main.o: main.c $(SYMS)
183187

184188
o/mark.o: mark.c $(SYMS)

src/Make_ivc.mak

+5
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ LINK32_OBJS= \
229229
"$(INTDIR)/getchar.obj" \
230230
"$(INTDIR)/hardcopy.obj" \
231231
"$(INTDIR)/hashtab.obj" \
232+
"$(INTDIR)/json.obj" \
232233
"$(INTDIR)/main.obj" \
233234
"$(INTDIR)/mark.obj" \
234235
"$(INTDIR)/mbyte.obj" \
@@ -555,6 +556,10 @@ SOURCE=.\if_ole.idl
555556
# End Source File
556557
# Begin Source File
557558

559+
SOURCE=.\json.c
560+
# End Source File
561+
# Begin Source File
562+
558563
SOURCE=.\main.c
559564
# End Source File
560565
# Begin Source File

src/Make_manx.mak

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ SRC = blowfish.c \
5555
getchar.c \
5656
hardcopy.c \
5757
hashtab.c \
58+
json.c \
5859
main.c \
5960
mark.c \
6061
memfile.c \
@@ -105,6 +106,7 @@ OBJ = obj/blowfish.o \
105106
obj/getchar.o \
106107
obj/hardcopy.o \
107108
obj/hashtab.o \
109+
obj/json.o \
108110
obj/main.o \
109111
obj/mark.o \
110112
obj/memfile.o \
@@ -153,6 +155,7 @@ PRO = proto/blowfish.pro \
153155
proto/getchar.pro \
154156
proto/hardcopy.pro \
155157
proto/hashtab.pro \
158+
proto/json.pro \
156159
proto/main.pro \
157160
proto/mark.pro \
158161
proto/memfile.pro \
@@ -284,6 +287,9 @@ obj/hardcopy.o: hardcopy.c
284287
obj/hashtab.o: hashtab.c
285288
$(CCSYM) $@ hashtab.c
286289

290+
obj/json.o: json.c
291+
$(CCSYM) $@ json.c
292+
287293
# Don't use $(SYMS) here, because main.c defines EXTERN
288294
obj/main.o: main.c option.h globals.h
289295
$(CCNOSYM) $@ main.c

src/Make_morph.mak

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ SRC = blowfish.c \
4343
getchar.c \
4444
hardcopy.c \
4545
hashtab.c \
46+
json.c \
4647
main.c \
4748
mark.c \
4849
mbyte.c \

src/Make_mvc.mak

+4
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ OBJ = \
536536
$(OUTDIR)\getchar.obj \
537537
$(OUTDIR)\hardcopy.obj \
538538
$(OUTDIR)\hashtab.obj \
539+
$(OUTDIR)\json.obj \
539540
$(OUTDIR)\main.obj \
540541
$(OUTDIR)\mark.obj \
541542
$(OUTDIR)\mbyte.obj \
@@ -1202,6 +1203,8 @@ $(OUTDIR)/if_sniff.obj: $(OUTDIR) if_sniff.c $(INCL)
12021203
$(OUTDIR)/if_tcl.obj: $(OUTDIR) if_tcl.c $(INCL)
12031204
$(CC) $(CFLAGS) $(TCL_INC) if_tcl.c
12041205

1206+
$(OUTDIR)/json.obj: $(OUTDIR) json.c $(INCL)
1207+
12051208
$(OUTDIR)/main.obj: $(OUTDIR) main.c $(INCL)
12061209

12071210
$(OUTDIR)/mark.obj: $(OUTDIR) mark.c $(INCL)
@@ -1329,6 +1332,7 @@ proto.h: \
13291332
proto/getchar.pro \
13301333
proto/hardcopy.pro \
13311334
proto/hashtab.pro \
1335+
proto/json.pro \
13321336
proto/main.pro \
13331337
proto/mark.pro \
13341338
proto/memfile.pro \

src/Make_sas.mak

+5
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ SRC = \
108108
getchar.c \
109109
hardcopy.c \
110110
hashtab.c \
111+
json.c \
111112
main.c \
112113
mark.c \
113114
memfile.c \
@@ -157,6 +158,7 @@ OBJ = \
157158
getchar.o \
158159
hardcopy.o \
159160
hashtab.o \
161+
json.o \
160162
main.o \
161163
mark.o \
162164
memfile.o \
@@ -206,6 +208,7 @@ PRO = \
206208
proto/getchar.pro \
207209
proto/hardcopy.pro \
208210
proto/hashtab.pro \
211+
proto/json.pro \
209212
proto/main.pro \
210213
proto/mark.pro \
211214
proto/memfile.pro \
@@ -328,6 +331,8 @@ hardcopy.o: hardcopy.c
328331
proto/hardcopy.pro: hardcopy.c
329332
hashtab.o: hashtab.c
330333
proto/hashtab.pro: hashtab.c
334+
json.o: json.c
335+
proto/json.pro: json.c
331336
main.o: main.c
332337
proto/main.pro: main.c
333338
mark.o: mark.c

src/Make_vms.mms

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Makefile for Vim on OpenVMS
33
#
44
# Maintainer: Zoltan Arpadffy <arpadffy@polarhome.com>
5-
# Last change: 2014 Aug 10
5+
# Last change: 2016 Jan 22
66
#
77
# This has script been tested on VMS 6.2 to 8.2 on DEC Alpha, VAX and IA64
88
# with MMS and MMK
@@ -311,7 +311,7 @@ ALL_LIBS = $(LIBS) $(GUI_LIB_DIR) $(GUI_LIB) \
311311

312312
SRC = blowfish.c buffer.c charset.c crypt.c, crypt_zip.c diff.c digraph.c edit.c eval.c ex_cmds.c ex_cmds2.c \
313313
ex_docmd.c ex_eval.c ex_getln.c if_xcmdsrv.c fileio.c fold.c getchar.c \
314-
hardcopy.c hashtab.c main.c mark.c menu.c mbyte.c memfile.c memline.c message.c misc1.c \
314+
hardcopy.c hashtab.c json.c main.c mark.c menu.c mbyte.c memfile.c memline.c message.c misc1.c \
315315
misc2.c move.c normal.c ops.c option.c popupmnu.c quickfix.c regexp.c search.c sha256.c\
316316
spell.c syntax.c tag.c term.c termlib.c ui.c undo.c version.c screen.c \
317317
window.c os_unix.c os_vms.c pathdef.c \
@@ -320,7 +320,7 @@ SRC = blowfish.c buffer.c charset.c crypt.c, crypt_zip.c diff.c digraph.c edit.c
320320

321321
OBJ = blowfish.obj buffer.obj charset.obj crypt.obj, crypt_zip.obj diff.obj digraph.obj edit.obj eval.obj \
322322
ex_cmds.obj ex_cmds2.obj ex_docmd.obj ex_eval.obj ex_getln.obj \
323-
if_xcmdsrv.obj fileio.obj fold.obj getchar.obj hardcopy.obj hashtab.obj main.obj mark.obj \
323+
if_xcmdsrv.obj fileio.obj fold.obj getchar.obj hardcopy.obj hashtab.obj json.obj main.obj mark.obj \
324324
menu.obj memfile.obj memline.obj message.obj misc1.obj misc2.obj \
325325
move.obj mbyte.obj normal.obj ops.obj option.obj popupmnu.obj quickfix.obj \
326326
regexp.obj search.obj sha256.obj spell.obj syntax.obj tag.obj term.obj termlib.obj \
@@ -572,6 +572,10 @@ if_mzsch.obj : if_mzsch.c vim.h [.auto]config.h feature.h os_unix.h \
572572
ascii.h keymap.h term.h macros.h option.h structs.h \
573573
regexp.h gui.h gui_beval.h [.proto]gui_beval.pro ex_cmds.h proto.h \
574574
globals.h farsi.h arabic.h if_mzsch.h
575+
json.obj : json.c vim.h [.auto]config.h feature.h os_unix.h \
576+
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
577+
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \
578+
arabic.h version.h
575579
main.obj : main.c vim.h [.auto]config.h feature.h os_unix.h \
576580
ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h gui_beval.h \
577581
[.proto]gui_beval.pro option.h ex_cmds.h proto.h globals.h farsi.h \

0 commit comments

Comments
 (0)