More git commands.
[mp-5.x.git] / mp_vcs.mpsl
blobc2447f31bd57bb17e590e6ca85a20ca0e292bccf
1 /*
3     Minimum Profit 5.x
4     A Programmer's Text Editor
6     Version Control System support
8     Copyright (C) 1991-2011 Angel Ortega <angel@triptico.com>
10     This program is free software; you can redistribute it and/or
11     modify it under the terms of the GNU General Public License
12     as published by the Free Software Foundation; either version 2
13     of the License, or (at your option) any later version.
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
20     You should have received a copy of the GNU General Public License
21     along with this program; if not, write to the Free Software
22     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24     http://www.triptico.com
28 /** data **/
30 mp.vcs = [
31     {
32         id:     'git',
33         check:  [ '.git', '../.git', '../../.git' ],
34         opts:   [
35             'git diff',
36             'git status',
37             'git log',
38             "git diff '%s'",
39             "git log '%s'",
40             "git add '%s'",
41             "git blame '%s'",
42             "git checkout '%s'",
43             "git stash",
44             "git stash apply"
45         ]
46     },
47     {
48         id:     'SVN',
49         check:  [ '.svn' ],
50         opts:   [
51             'svn diff',
52             'svn status',
53             'svn log',
54             "svn diff '%s'",
55             "svn log '%s'",
56             "svn add '%s'",
57             "svn annotate '%s'"
58         ]
59     }
62 /** editor actions **/
64 mp.actions['vcs'] = sub (d) {
65     local v = NULL;
67     foreach (n, mp.vcs) {
68         foreach (d, n.check) {
69             if (stat(d) != NULL) {
70                 v = n;
71                 break;
72             }
73         }
75         if (v != NULL)
76             break;
77     }
79     if (v == NULL)
80         mp.alert(L("This directory is not under a supported version control system"));
81     else {
82         local l = v.opts;
84         local t = mp.form(
85             [
86                 {
87                     label:  sprintf(L("Available %s commands"), v.id),
88                     type:   'list',
89                     list:   l,
90                     value:  mp.vcs_target
91                 }
92             ]
93         );
95         if (t != NULL) {
96             mp.vcs_target = t[0];
98             local cmd = sprintf(l[mp.vcs_target], d.name);
100             local log = mp.open(sprintf(L("<%s output>"), cmd));
102             log.txt.lines   = [ '' ];
103             log.txt.y       = 0;
105             mp.actions.exec_command(log, cmd);
106             mp.detect_syntax(log);
108             mp.move_bof(log);
109             log.txt.mod     = 0;
110             log.undo        = [];
111             log.read_only   = 1;
112         }
113     }
116 /** default key bindings **/
118 mp.keycodes['ctrl-p'] = 'vcs';
120 /** action descriptions **/
122 mp.keycodes['vcs'] = LL("Version Control...");
124 /** code **/