annotate runtime/indent/prolog.vim @ 34674:bfd2c0032686 v9.1.0218

patch 9.1.0218: Unnecessary multiplications in backspace code Commit: https://github.com/vim/vim/commit/8ede7a069419e0e01368c65a2d0c79d6332aa6cd Author: zeertzjq <zeertzjq@outlook.com> Date: Thu Mar 28 10:30:08 2024 +0100 patch 9.1.0218: Unnecessary multiplications in backspace code Problem: Unnecessary multiplications in backspace code, as "col / ts * ts" is the same as "col - col % ts". Solution: Change "col / ts * ts" to "col - col % ts". Adjust the loop and the comments ins_bs() to be easier to understand. Update tests to reset 'smarttab' properly. (zeertzjq) closes: #14308 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 28 Mar 2024 10:45:04 +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