annotate runtime/ftplugin/erlang.vim @ 26644:2fc1e528e0e1 v8.2.3851

patch 8.2.3851: Vim9: overhead when comparing string, dict or function Commit: https://github.com/vim/vim/commit/265f811f5a2dac81d9698f5202a661a04ed095f1 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 19 12:33:05 2021 +0000 patch 8.2.3851: Vim9: overhead when comparing string, dict or function Problem: Vim9: overhead when comparing string, dict or function. Solution: Call the intented compare function directly. Refactor to avoid duplicated code.
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Dec 2021 13:45:03 +0100
parents e2e2cc5d0856
children f68f43043842
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 " Vim ftplugin file
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
2 " Language: Erlang (http://www.erlang.org)
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
3 " Maintainer: Csaba Hoch <csaba.hoch@gmail.com>
22723
5b7ea82bc18f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 3410
diff changeset
4 " Author: Oscar Hellström <oscar@oscarh.net>
5b7ea82bc18f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 3410
diff changeset
5 " Contributors: Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6 " Eduardo Lopez (http://github.com/tapichu)
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
7 " Arvid Bjurklint (http://github.com/slarwise)
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
8 " Last Update: 2021-Jan-08
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9 " License: Vim license
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
10 " URL: https://github.com/vim-erlang/vim-erlang-runtime
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12 if exists('b:did_ftplugin')
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
13 finish
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 endif
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
15 let b:did_ftplugin = 1
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16
3410
94601b379f38 Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents: 3356
diff changeset
17 let s:cpo_save = &cpo
94601b379f38 Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents: 3356
diff changeset
18 set cpo&vim
94601b379f38 Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents: 3356
diff changeset
19
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
20 let &l:keywordprg = get(g:, 'erlang_keywordprg', 'erl -man')
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
21
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
22 if get(g:, 'erlang_folding', 0)
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
23 setlocal foldmethod=expr
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
24 setlocal foldexpr=GetErlangFold(v:lnum)
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
25 setlocal foldtext=ErlangFoldText()
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26 endif
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
28 setlocal comments=:%%%,:%%,:%
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
29 setlocal commentstring=%%s
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
30
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
31 setlocal formatoptions+=ro
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
32
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
33 setlocal suffixesadd=.erl,.hrl
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
34
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
35 let &l:include = '^\s*-\%(include\|include_lib\)\s*("\zs\f*\ze")'
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
36 let &l:define = '^\s*-\%(define\|record\|type\|opaque\)'
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37
3356
b37888de599c Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
38 let s:erlang_fun_begin = '^\a\w*(.*$'
b37888de599c Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
39 let s:erlang_fun_end = '^[^%]*\.\s*\(%.*\)\?$'
b37888de599c Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
40
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
41 if !exists('*GetErlangFold')
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
42 function GetErlangFold(lnum)
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
43 let lnum = a:lnum
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
44 let line = getline(lnum)
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
46 if line =~ s:erlang_fun_end
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
47 return '<1'
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
48 endif
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
50 if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
51 return '1'
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
52 endif
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
54 if line =~ s:erlang_fun_begin
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
55 return '>1'
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
56 endif
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
58 return '='
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
59 endfunction
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
60 endif
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
62 if !exists('*ErlangFoldText')
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
63 function ErlangFoldText()
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
64 let line = getline(v:foldstart)
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
65 let foldlen = v:foldend - v:foldstart + 1
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
66 let lines = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '')
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
67 if foldlen < 10
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
68 let lines = ' ' . lines
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
69 endif
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
70 let retval = '+' . v:folddashes . lines
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
72 return retval
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
73 endfunction
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
74 endif
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
76 let b:undo_ftplugin = "setlocal keywordprg< foldmethod< foldexpr< foldtext<"
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
77 \ . " comments< commentstring< formatoptions< suffixesadd< include<"
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
78 \ . " define<"
3410
94601b379f38 Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents: 3356
diff changeset
79
94601b379f38 Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents: 3356
diff changeset
80 let &cpo = s:cpo_save
94601b379f38 Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents: 3356
diff changeset
81 unlet s:cpo_save
23573
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
82
e2e2cc5d0856 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 22723
diff changeset
83 " vim: sw=2 et