-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsqitch-plan-mode.el
113 lines (89 loc) · 4 KB
/
sqitch-plan-mode.el
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
;;; sqitch-plan-mode.el --- Major mode for interacting with Sqitch plan files
;; Copyright (C) 2014 Christopher Maier
;; Author: Christopher Maier <[email protected]>
;; Maintainer: Christopher Maier <[email protected]>
;; Version: 0.0.1
;; Keywords: sql, sqitch
;; URL: https://github.com/christophermaier/sqitch-for-emacs
;; This file is NOT part of GNU Emacs.
;;; License:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; Provides basic navigation across files of a Sqitch project from a
;; 'sqitch.plan' file. See http://www.sqitch.org for details.
;;
;; To use this file, make sure that the following code (or its
;; equivalent) is in your Emacs configuration:
;;
;; (add-to-list 'load-path "/path/to/sqitch-for-emacs")
;; (require 'sqitch-plan-mode)
;;
;; Files named 'sqitch.plan' are automatically opened in this mode.
;;; Code:
(require 'derived)
(require 'thingatpt)
(defun sqitch-plan-maybe-changeset-at-point ()
"Crude way of (maybe) getting the changeset at point. Not at
all guaranteed to actually *be* a changeset, absent a more robust
implementation."
(thing-at-point 'symbol))
(defun sqitch-plan-find-script (script-type)
"Opens the SCRIPT-TYPE Sqitch script for the changeset
described by the current line of a Sqitch plan file.
SCRIPT-TYPE should be one of \"deploy\", \"verify\", or
\"revert\"."
(let ((changeset (sqitch-plan-maybe-changeset-at-point)))
(if changeset
(let* ((script-dir (concat (file-name-directory (buffer-file-name)) script-type))
(script (concat changeset ".sql"))
(script-file (concat (file-name-as-directory script-dir)
script)))
(if (file-exists-p script-file)
(find-file script-file)
(message "'%s' is not a sqitch changeset" changeset))))))
(defun sqitch-plan-find-deploy-script ()
"Open the deploy script for the changeset described by the
current line of a Sqitch plan file."
(interactive)
(sqitch-plan-find-script "deploy"))
(defun sqitch-plan-find-verify-script ()
"Open the verify script for the changeset described by the
current line of a Sqitch plan file."
(interactive)
(sqitch-plan-find-script "verify"))
(defun sqitch-plan-find-revert-script ()
"Open the revert script for the changeset described by the
current line of a Sqitch plan file."
(interactive)
(sqitch-plan-find-script "revert"))
(defvar sqitch-plan-mode-map nil "sqitch-plan-mode keymap")
(if sqitch-plan-mode-map
nil
(setq sqitch-plan-mode-map (make-sparse-keymap))
(define-key sqitch-plan-mode-map (kbd "C-c d") 'sqitch-plan-find-deploy-script)
(define-key sqitch-plan-mode-map (kbd "C-c C-d") 'sqitch-plan-find-deploy-script)
(define-key sqitch-plan-mode-map (kbd "C-c v") 'sqitch-plan-find-verify-script)
(define-key sqitch-plan-mode-map (kbd "C-c C-v") 'sqitch-plan-find-verify-script)
(define-key sqitch-plan-mode-map (kbd "C-c r") 'sqitch-plan-find-revert-script)
(define-key sqitch-plan-mode-map (kbd "C-c C-r") 'sqitch-plan-find-revert-script))
;;;###autoload
(define-derived-mode sqitch-plan-mode text-mode "sqitch-plan"
"Major mode for interacting with Sqitch plan files.
\\{sqitch-plan-mode-map}")
;;;###autoload
(add-to-list 'auto-mode-alist '("sqitch\.plan$" . sqitch-plan-mode))
(provide 'sqitch-plan-mode)
;;; sqitch-plan-mode.el ends here