annotate runtime/indent/hamster.vim @ 31890:2d96d7f9da7e v9.0.1277

patch 9.0.1277: cursor may move with autocmd in Visual mode Commit: https://github.com/vim/vim/commit/49f0524fb575bb1cf4881e472afab7d37c579440 Author: zeertzjq <zeertzjq@outlook.com> Date: Sat Feb 4 10:58:34 2023 +0000 patch 9.0.1277: cursor may move with autocmd in Visual mode Problem: Cursor may move with autocmd in Visual mode. Solution: Restore "VIsual_active" before calling check_cursor(). (closes #11939)
author Bram Moolenaar <Bram@vim.org>
date Sat, 04 Feb 2023 12:00:05 +0100
parents 3b34837f4538
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
1 " Vim indent file
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
2 " Language: Hamster Script
25973
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
3 " Version: 2.0.6.1
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
4 " Last Change: 2021 Oct 11
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
5 " Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
6 " Download: https://www.vim.org/scripts/script.php?script_id=1099
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
7 "
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
8 " 2.0.6.1 (Oct 2021)
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
9 " Added b:undo_indent
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
10 " Added cpo check
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
11 "
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
12
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
13 " Only load this indent file when no other was loaded.
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
14 if exists("b:did_indent")
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
15 finish
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
16 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
17 let b:did_indent = 1
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
18
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
19 setlocal indentkeys+==~if,=~else,=~endif,=~endfor,=~endwhile
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
20 setlocal indentkeys+==~do,=~until,=~while,=~repeat,=~for,=~loop
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
21 setlocal indentkeys+==~sub,=~endsub
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
22
25973
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
23 let b:undo_indent = "setl indentkeys<"
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
24
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
25 " Define the appropriate indent function but only once
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
26 setlocal indentexpr=HamGetFreeIndent()
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
27 if exists("*HamGetFreeIndent")
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
28 finish
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
29 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
30
25973
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
31 let s:keepcpo = &cpo
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
32 set cpo&vim
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
33
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
34 function HamGetIndent(lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
35 let ind = indent(a:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
36 let prevline=getline(a:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
37
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
38 " Add a shiftwidth to statements following if, else, elseif,
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
39 " case, select, default, do, until, while, for, start
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
40 if prevline =~? '^\s*\<\(if\|else\%(if\)\?\|for\|repeat\|do\|while\|sub\)\>'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 1125
diff changeset
41 let ind = ind + shiftwidth()
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
42 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
43
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
44 " Subtract a shiftwidth from else, elseif, end(if|while|for), until
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
45 let line = getline(v:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
46 if line =~? '^\s*\(else\|elseif\|loop\|until\|end\%(if\|while\|for\|sub\)\)\>'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 1125
diff changeset
47 let ind = ind - shiftwidth()
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
48 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
49
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
50 return ind
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
51 endfunction
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
52
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
53 function HamGetFreeIndent()
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
54 " Find the previous non-blank line
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
55 let lnum = prevnonblank(v:lnum - 1)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
56
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
57 " Use zero indent at the top of the file
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
58 if lnum == 0
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
59 return 0
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
60 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
61
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
62 let ind=HamGetIndent(lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
63 return ind
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
64 endfunction
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
65
25973
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
66 " Restore:
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
67 let &cpo = s:keepcpo
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
68 unlet s:keepcpo
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
69
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
70 " vim:sw=2 tw=80