Docfix and remove one redundant LOC.
[planner-el.git] / planner-psvn.el
blob70948d8d9b7487a7eead52beb891cbacc82397cb
1 ;;; planner-psvn.el --- psvn.el integration for the Emacs Planner
3 ;; Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc.
5 ;; Author: Stefan Reichör <stefan@xsteve.at>
6 ;; Keywords: planner, psvn
8 ;; This file is part of Planner. It is not part of GNU Emacs.
10 ;; Planner is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; any later version.
15 ;; Planner is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with Planner; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
25 ;;;_ + Commentary:
27 ;; This file allows you to refer to your svn changesets easily from within
28 ;; a planner page.
30 ;; Example: the changeset
31 ;; [[psvn://http://my.svn-repos.at/svn/project1/trunk@39][project1#39]]
32 ;; can be shown easily via psvn.
34 ;; Additionally there is functionality to generate a note for your
35 ;; commits via subversion, just set
36 ;; `planner-psvn-log-edit-notice-commit-function' to t.
38 ;;; Contributors:
40 ;; Seth Falcon provided a patch to write the note to planner-today
41 ;; rather than *temp*.muse.
43 ;; Yann Hodique helped port this to Muse.
45 ;;; Code:
47 (require 'planner)
48 (require 'psvn)
50 (defgroup planner-psvn nil
51 "Planner options for the psvn integration."
52 :prefix "planner-psvn-"
53 :group 'planner)
55 (defcustom planner-psvn-log-edit-include-files-flag
57 "Non-nil means include a list of committed files in the note."
58 :type 'boolean
59 :group 'planner-psvn)
61 (defcustom planner-psvn-log-edit-notice-commit-function nil
62 "Function that should return non-nil if this commit should be noted.
63 The function will be run in the log buffer."
64 :type '(choice
65 (const :tag "Always note commits" t)
66 function)
67 :group 'planner-psvn)
70 ;; compatibility for older psvn.el revisions
71 (cond ((fboundp 'svn-run)
72 (defalias 'planner-svn-run 'svn-run))
73 ((fboundp 'svn-run-svn)
74 (defalias 'planner-svn-run 'svn-run-svn))
76 (error "No `svn-run' command found")))
78 (defun planner-psvn-generate-url (repo-path revision &optional link-prefix no-link-postfix)
79 (planner-make-link (concat "psvn://" repo-path "@" revision)
80 (if link-prefix
81 (if no-link-postfix
82 link-prefix
83 (concat link-prefix revision))
84 (concat "svn-rev#" revision))))
86 ;;;###autoload
87 (defun planner-annotation-from-psvn ()
88 "If called from a psvn *svn-log-view* buffer, return an annotation.
89 Suitable for use in `planner-annotation-functions'."
90 (when (eq major-mode 'svn-log-view-mode)
91 (svn-status-parse-info t)
92 (planner-psvn-generate-url (svn-status-base-info->url)
93 (svn-log-revision-at-point))))
95 ;;;###autoload
96 (defun planner-psvn-browse-url (url)
97 "If this is a psvn url, handle it."
98 (when (string-match "\\`psvn:/?/?\\(.+\\)@\\([0-9]+\\)" url)
99 (let ((repo-path (match-string 1 url))
100 (svn-rev (string-to-number (match-string 2 url)))
101 (cur-buf (current-buffer)))
102 (planner-svn-run nil t 'diff "diff"
103 (concat repo-path "@" (number-to-string (- svn-rev 1)))
104 (concat repo-path "@" (number-to-string svn-rev)))
105 (svn-status-activate-diff-mode))
108 (defun planner-psvn-log-edit-extract-file-name (file-info)
109 (svn-status-line-info->filename file-info))
111 ;;;###autoload
112 (defun planner-psvn-log-edit-add-note ()
113 "Add a note describing the commit via psvn to the current planner page."
114 (when (if (functionp planner-psvn-log-edit-notice-commit-function)
115 (funcall planner-psvn-log-edit-notice-commit-function)
116 planner-psvn-log-edit-notice-commit-function)
117 (svn-status-parse-info t)
118 (save-window-excursion
119 (planner-create-note nil)
120 (insert "Commit")
121 (insert (concat " " (planner-psvn-generate-url
122 (svn-status-base-info->url)
123 (number-to-string svn-status-commit-rev-number)
124 (when svn-status-module-name
125 (concat svn-status-module-name "#")))))
126 (newline)
127 (when (and planner-psvn-log-edit-include-files-flag
128 svn-status-files-to-commit)
129 (insert "Files: ")
130 (insert (mapconcat 'planner-psvn-log-edit-extract-file-name
131 svn-status-files-to-commit " "))
132 (newline)
133 (newline))
134 (insert-buffer-substring "*svn-log-edit*"))))
136 (add-hook 'svn-log-edit-done-hook 'planner-psvn-log-edit-add-note)
138 (planner-add-protocol "psvn:/?/?" 'planner-psvn-browse-url nil)
139 (add-hook 'planner-annotation-functions 'planner-annotation-from-psvn)
140 (custom-add-option 'planner-annotation-functions 'planner-annotation-from-psvn)
142 (provide 'planner-psvn)
144 ;;; planner-psvn.el ends here