1 ;;; patcher-cmtcmd.el --- Commit Command buffers
3 ;; Copyright (C) 2010, 2011 Didier Verna
5 ;; Author: Didier Verna <didier@lrde.epita.fr>
6 ;; Maintainer: Didier Verna <didier@lrde.epita.fr>
7 ;; Created: Sun Apr 4 18:44:08 2010
8 ;; Last Revision: Sun Dec 4 15:54:31 2011
12 ;; This file is part of Patcher.
14 ;; Patcher is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License version 3,
16 ;; as published by the Free Software Foundation.
18 ;; Patcher is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program; if not, write to the Free Software
25 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 ;; Contents management by FCM version 0.1.
37 (eval-when-compile (require 'patcher-cutil))
38 (require 'patcher-util)
39 (require 'patcher-face)
40 (require 'patcher-project)
41 (require 'patcher-instance)
44 (defgroup patcher-cmtcmd nil
45 "Patcher settings for commit command buffers."
50 ;; ==========================================================================
52 ;; ==========================================================================
54 (defun patcher-cmtcmd-init (command)
55 ;; Initialize the current commit command buffer with COMMAND.
57 (substitute-command-keys
59 # Edit / confirm the commit command below.\n\
60 # - `\\[patcher-cmtcmd-commit]' to commit the project,\n\
61 # - `\\[patcher-cmtcmd-cancel]' to cancel the commit,\n\
62 # - `\\[patcher-cmtcmd-kill]' to kill the project.\n\n"))
63 (insert-string command))
68 ;; ==========================================================================
69 ;; Patcher CmtCmd fontification
70 ;; ==========================================================================
72 (defcustom patcher-cmtcmd-font-lock-keywords
73 '(("^\\s-*#.*" . patcher-comment-face)
74 ("`\\([^'\n]+\\)'" (1 patcher-reference-face prepend)))
75 "*Font lock keywords for commit command buffers."
76 :group 'patcher-cmtcmd
82 ;; ==========================================================================
83 ;; Patcher CmtCmd mode
84 ;; ==========================================================================
86 (defun patcher-cmtcmd-kill ()
87 "Kill the project related to the current commit command buffer."
89 (patcher-kill-project patcher-project))
91 (defun patcher-cmtcmd-cancel ()
92 "Cancel the current commit command."
94 (pop-window-configuration))
96 (defun patcher-cmtcmd-commit ()
98 "Commit project with the command in current buffer.
99 Comment lines are skipped. Other lines are concatenated together."
100 (patcher-detect-committed-project patcher-project)
101 (goto-char (point-min))
104 (unless (looking-at "[ \t]*#")
105 (setq command (concat command
107 (buffer-substring (point) (point-at-eol)))))
109 (patcher-condition-case nil
110 (patcher-commit-project patcher-project command)
113 ;; we come from the CmtCmd buffer.
115 (display-buffer (patcher-project-process-buffer patcher-project)
119 Error during commit. Type \\[patcher-cmtcmd-commit] to try again."))
120 ;; Otherwise, propagate to the caller.
121 (patcher-error 'commit command))))))
123 (defcustom patcher-cmtcmd-mode-hook nil
124 "*Hook to run after setting up Patcher CmtCmd mode."
125 :group 'patcher-cmtcmd
128 (defvar patcher-cmtcmd-mode-map
129 (let ((map (make-sparse-keymap)))
130 (define-key map [(control c) (control p) c] 'patcher-cmtcmd-commit)
131 (define-key map [(control c) (control c)] 'patcher-cmtcmd-commit)
132 (define-key map [(control c) (control z)] 'patcher-cmtcmd-cancel)
133 (define-key map [(control c) (control k)] 'patcher-cmtcmd-kill)
136 (defun patcher-cmtcmd-mode ()
137 "Major mode for Patcher commit command management.
138 You're not supposed to use this mode manually, unless you know what you're
141 The following commands are available in a CmtCmd buffer:
142 \\{patcher-cmtcmd-mode-map}"
144 (kill-all-local-variables)
145 (setq major-mode 'patcher-cmtcmd)
146 (setq mode-name "Patcher-CmtCmd")
147 (use-local-map patcher-cmtcmd-mode-map)
148 (setq font-lock-keywords patcher-cmtcmd-font-lock-keywords)
149 (run-hooks 'patcher-cmtcmd-mode-hook))
152 (provide 'patcher-cmtcmd)
154 ;;; patcher-cmtcmd.el ends here