annotate runtime/indent/prolog.vim @ 32086:45142117e206 v9.0.1374

patch 9.0.1374: function for setting options not used consistently Commit: https://github.com/vim/vim/commit/c727b19e9f1df36e44321d933334c7b4961daa54 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Fri Mar 3 12:26:15 2023 +0000 patch 9.0.1374: function for setting options not used consistently Problem: Function for setting options not used consistently. Solution: Use a function for 'encoding' and terminal options. (Yegappan Lakshmanan, closes #12099)
author Bram Moolenaar <Bram@vim.org>
date Fri, 03 Mar 2023 13:30:03 +0100
parents 6dd88e45d47d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " vim: set sw=4 sts=4:
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14864
diff changeset
2 " Language: Prolog
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14864
diff changeset
3 " Maintainer: Gergely Kontra <kgergely@mcl.hu> (Invalid email address)
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14864
diff changeset
4 " Doug Kearns <dougkearns@gmail.com>
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14864
diff changeset
5 " Revised on: 2002.02.18. 23:34:05
14864
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
6 " Last change by: Takuya Fujiwara, 2018 Sep 23
28379
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25880
diff changeset
7 " 2022 April: b:undo_indent added by Doug Kearns
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 " TODO:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 " checking with respect to syntax highlighting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 " ignoring multiline comments
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 " detecting multiline strings
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 setlocal indentexpr=GetPrologIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 setlocal indentkeys-=:,0#
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 setlocal indentkeys+=0%,-,0;,>,0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24
28379
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25880
diff changeset
25 let b:undo_indent = "setl inde< indk<"
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25880
diff changeset
26
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 "if exists("*GetPrologIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 " finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 "endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 function! GetPrologIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 " Find a non-blank line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 let pnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 " Hit the start of the file, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 if pnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 let line = getline(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let pline = getline(pnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 let ind = indent(pnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 " Previous line was comment -> use previous line's indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 if pline =~ '^\s*%'
14864
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
45 return ind
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
46 endif
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
47 " Previous line was the start of block comment -> +1 after '/*' comment
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
48 if pline =~ '^\s*/\*'
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
49 return ind + 1
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
50 endif
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
51 " Previous line was the end of block comment -> -1 after '*/' comment
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
52 if pline =~ '^\s*\*/'
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
53 return ind - 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 " Check for clause head on previous line
14864
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
56 if pline =~ '\%(:-\|-->\)\s*\(%.*\)\?$'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
57 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 " Check for end of clause on previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 elseif pline =~ '\.\s*\(%.*\)\?$'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
60 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 " Check for opening conditional on previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 if pline =~ '^\s*\([(;]\|->\)'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
64 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 " Check for closing an unclosed paren, or middle ; or ->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 if line =~ '^\s*\([);]\|->\)'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
68 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 endfunction