aboutsummaryrefslogtreecommitdiff
path: root/plugins/language_diff.lua
blob: 46a6af40c1d3057a604585a767635a321ed4648d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- mod-version:2 -- lite-xl 2.0
local syntax = require "core.syntax"
local style = require "core.style"
local common = require "core.common"

-- we need these symbol types to have uniform colors
style.syntax["diff_add"] = { common.color "#72b886" }
style.syntax["diff_del"] = { common.color "#F36161" }

syntax.add {
  name = "Diff",
  files = { "%.diff$", "%.patch$", "%.rej$" },
  headers = "^diff ",
  patterns = {
    -- Method the patch was generated with and source/target files
    { regex = "^diff .+\n$",       type = "function" },
    -- Seen for changing the file permissions
    { regex = "^new .+\n$",        type = "comment"  },
    -- Usually holds starting and ending commit
    { regex = "^index .+\n$",      type = "comment"  },
    -- Position to patch
    {
      pattern = "@@.-@@ ().+\n",            --with heading
      type = { "number", "string" }
    },
    {
      regex = "^@@ [\\d,\\-\\+ ]+ @@\n$",   --wihtout heading
      type = "number"
    },
    -- Other position to patch formats
    {
      regex = "^\\-{3} [\\d]+,[\\d]+ \\-{4}\n$",
      type = "number"
    },
    {
      regex = "^\\*{3} [\\d]+,[\\d]+ \\*{4}\n$",
      type = "number"
    },
    -- Source and target file
    { regex = "^-{3} .+\n$",                 type = "keyword"  },
    { regex = "^\\+{3} .+\n$",               type = "keyword"  },
    -- Rarely used source file indicator
    { regex = "^\\*{3} .+\n$",               type = "keyword"  },
    -- git patches seem to add 3 dashes to separate message from changed files
    { regex = "^\\-{3}\n$",                  type = "normal"   },
    -- Addition and deletion of lines
    { regex = "^\\-.*\n$",                   type = "diff_del" },
    { regex = "^\\+.*\n$",                   type = "diff_add" },
    { regex = "^<.*\n$",                     type = "diff_del" },
    { regex = "^>.*\n$",                     type = "diff_add" },
    -- Change between two lines
    { regex = "^!.*\n$",                     type = "number"   },
    -- Stuff usually found on a authored patch heading
    {
      pattern = "From ()[a-fA-F0-9]+ ().+\n",
      type = { "keyword", "number", "string" }
    },
    { regex = "^[a-zA-Z\\-]+: ",             type = "keyword" },
    -- Diff stats
    { regex = "^ [\\d]+ files? changed",     type = "function" },
    { regex = "[\\d]+ insertions?\\(\\+\\)", type = "diff_add" },
    { regex = "[\\d]+ deletions?\\(\\-\\)",  type = "diff_del" },
    -- Match e-mail
    {
      regex = "<[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+>\n",
      type = "keyword2"
    },
    -- Everything else is normal text
    { pattern = "[%a_][%w_]*",               type = "normal"   },
  },
  symbols = {}
}