(planner-create-note): Fix for #10196, make sure that newly created notes get the...
[planner-el.git] / planner-log-edit.el
blob2e11b94d45ca59ea54449dba166ca874854a6de5
1 ;;; planner-log-edit.el --- Record VC commits as a note in todays planner file
3 ;; Copyright (C) 2004, 2008 Simon Winwood (sjw AT cse.unsw.edu.au)
4 ;; Parts copyright (C) 2004, 2008 Free Software Foundation, Inc.
5 ;; Parts copyright (C) 2004, 2008 Dryice Dong Liu (dryice AT liu.com.cn)
6 ;; Parts copyright (C) 2005, 2008 Yann Hodique (yann.hodique AT gmail.com)
8 ;; Author: Simon Winwood <sjw@cse.unsw.edu.au>
9 ;; Version: 0.1
10 ;; Keywords: planner, vc, pcl-cvs, log-edit
12 ;; This file is part of Planner. It is not part of GNU Emacs.
14 ;; Planner is free software; you can redistribute it and/or modify it
15 ;; under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; any later version.
19 ;; Planner is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with Planner; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
29 ;;; Commentary:
31 ;; This file records cvs (and VC) commits into todays planner file.
33 ;;; Contributors:
35 ;; Dryice Dong Liu (dryice AT liu.com.cn) provided the
36 ;; `planner-log-edit-quote-filenames-flag' option and patched the code
37 ;; to use it.
39 ;; Yann Hodique added the possibility to ignore patterns before
40 ;; inserting commit messages as notes (useful for psvn) via the new
41 ;; `planner-log-edit-flush-regexp-list' option.
43 ;;; Code:
45 (require 'planner)
46 (require 'log-edit)
48 (defgroup planner-log-edit nil
49 "Planner options for log-edit."
50 :prefix "planner-log-edit-"
51 :group 'planner)
53 (defcustom planner-log-edit-include-files-flag
55 "Non-nil means include a list of committed files in the note."
56 :type 'boolean
57 :group 'planner-log-edit)
59 (defcustom planner-log-edit-quote-filenames-flag
60 nil
61 "Non-nil means quote the file names with \"=\"."
62 :type 'boolean
63 :group 'planner-log-edit)
65 (defcustom planner-log-edit-notice-commit-function t
66 "Function that should return non-nil if this commit should be noted.
67 The function will be run in the log buffer."
68 :type '(choice
69 (const :tag "Always note commits" t)
70 function)
71 :group 'planner-log-edit)
73 (defcustom planner-log-edit-flush-regexp-list
74 nil
75 "List of regexps to flush before inserting note"
76 :type '(repeat regexp)
77 :group 'planner-log-edit)
79 (defcustom planner-log-edit-module-name-function 'planner-log-edit-cvs-module
80 "Function that should return a name for the current module."
81 :type 'function
82 :group 'planner-log-edit)
84 (defun planner-log-edit-quote-file-maybe (arg)
85 "Quote ARG if `planner-log-edit-quote-filenames-flag is non-nil."
86 (if planner-log-edit-quote-filenames-flag
87 (concat "=" arg "=")
88 arg))
90 (defun planner-log-edit-cvs-module ()
91 (condition-case nil
92 (when (fboundp 'cvs-get-module) (cvs-get-module))))
94 ;;;###autoload
95 (defun planner-log-edit-add-note ()
96 "Add a note describing the commit to the current planner page."
97 (let* ((buffer (current-buffer))
98 (files (log-edit-files))
99 ;; This should be a function call into log-edit, but until it
100 ;; exists ...
101 (module-name (funcall planner-log-edit-module-name-function)))
102 (if (if (functionp planner-log-edit-notice-commit-function)
103 (funcall planner-log-edit-notice-commit-function)
104 planner-log-edit-notice-commit-function)
105 (save-excursion
106 (save-window-excursion
107 (planner-create-note nil)
108 (insert "Commit"
109 (if module-name
110 (concat " in "
111 (planner-log-edit-quote-file-maybe
112 module-name))
113 ""))
114 (newline)
115 (when planner-log-edit-include-files-flag
116 (insert "Files: ")
117 (insert (mapconcat 'planner-log-edit-quote-file-maybe files " "))
118 (newline)
119 (newline))
120 (insert
121 (with-temp-buffer
122 (insert-buffer-substring buffer)
123 (goto-char (point-min))
124 (mapc (lambda (regexp)
125 (flush-lines regexp))
126 planner-log-edit-flush-regexp-list)
127 (buffer-string)))
128 ;(insert-buffer-substring buffer)
129 )))))
131 (add-hook 'log-edit-done-hook 'planner-log-edit-add-note)
133 (provide 'planner-log-edit)
135 ;;; planner-log-edit.el ends here