comparison lisp/vc-hg.el @ 81566:0e2a83705e5f

(vc-hg-registered): Add an autoloaded version. (vc-hg-log-view-mode): Use log-view-font-lock-keywords.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 22 Jun 2007 18:37:16 +0000
parents 99961edaa9c1
children 0991efe3cafa
comparison
equal deleted inserted replaced
81565:17afe39dcfdb 81566:0e2a83705e5f
37 37
38 ;; Implement the rest of the vc interface: 38 ;; Implement the rest of the vc interface:
39 ;; - dired 39 ;; - dired
40 ;; - snapshot? 40 ;; - snapshot?
41 41
42 ;; Implement Stefan Monnier's advice: 42 ;; Implement Stefan Monnier's advice:
43 ;; vc-hg-registered and vc-hg-state 43 ;; vc-hg-registered and vc-hg-state
44 ;; Both of those functions should be super extra careful to fail gracefully in 44 ;; Both of those functions should be super extra careful to fail gracefully in
45 ;; unexpected circumstances. The most important such case is when the `hg' 45 ;; unexpected circumstances. The most important such case is when the `hg'
46 ;; executable is not available. The reason this is important is that any error 46 ;; executable is not available. The reason this is important is that any error
47 ;; there will prevent the user from even looking at the file :-( 47 ;; there will prevent the user from even looking at the file :-(
49 ;; mercurial's control and extracting the current revision should be done 49 ;; mercurial's control and extracting the current revision should be done
50 ;; without even using `hg' (this way even if you don't have `hg' installed, 50 ;; without even using `hg' (this way even if you don't have `hg' installed,
51 ;; Emacs is able to tell you this file is under mercurial's control). 51 ;; Emacs is able to tell you this file is under mercurial's control).
52 52
53 ;;; History: 53 ;;; History:
54 ;; 54 ;;
55 55
56 ;;; Code: 56 ;;; Code:
57 57
58 (eval-when-compile 58 (eval-when-compile
59 (require 'vc)) 59 (require 'vc))
60 60
61 ;; XXX This should be moved to vc-hooks when the full vc interface is 61 ;; XXX This should be moved to vc-hooks when we can be sure that vc-state
62 ;; implemented. 62 ;; and friends are always harmless.
63 (add-to-list 'vc-handled-backends 'HG) 63 (add-to-list 'vc-handled-backends 'HG)
64 64
65 ;;; Customization options 65 ;;; Customization options
66 66
67 (defcustom vc-hg-global-switches nil 67 (defcustom vc-hg-global-switches nil
74 ;; :version "22.2" 74 ;; :version "22.2"
75 :group 'vc) 75 :group 'vc)
76 76
77 ;;; State querying functions 77 ;;; State querying functions
78 78
79 ;;; Modelled after the similar function in vc-bzr.el 79 ;;;###autoload (defun vc-hg-registered (file)
80 ;;;###autoload "Return non-nil if FILE is registered with hg."
81 ;;;###autoload (if (vc-find-root file ".hg") ; short cut
82 ;;;###autoload (progn
83 ;;;###autoload (load "vc-hg")
84 ;;;###autoload (vc-hg-registered file))))
85
86 ;; Modelled after the similar function in vc-bzr.el
80 (defun vc-hg-registered (file) 87 (defun vc-hg-registered (file)
81 "Return non-nil if FILE is registered with hg." 88 "Return non-nil if FILE is registered with hg."
82 (if (vc-find-root file ".hg") ; short cut 89 (if (vc-find-root file ".hg") ; short cut
83 (vc-hg-state file))) ; expensive 90 (vc-hg-state file))) ; expensive
84 91
124 file "log")) 131 file "log"))
125 132
126 (defvar log-view-message-re) 133 (defvar log-view-message-re)
127 (defvar log-view-file-re) 134 (defvar log-view-file-re)
128 (defvar log-view-font-lock-keywords) 135 (defvar log-view-font-lock-keywords)
129 (defvar log-view-current-tag-function)
130 136
131 (define-derived-mode vc-hg-log-view-mode log-view-mode "HG-Log-View" 137 (define-derived-mode vc-hg-log-view-mode log-view-mode "HG-Log-View"
132 (require 'add-log) ;; we need the faces add-log 138 (require 'add-log) ;; we need the faces add-log
133 ;; Don't have file markers, so use impossible regexp. 139 ;; Don't have file markers, so use impossible regexp.
134 (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)") 140 (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)")
135 (set (make-local-variable 'log-view-message-re) 141 (set (make-local-variable 'log-view-message-re)
136 "^changeset:[ \t]*\\([0-9]+\\):\\(.+\\)") 142 "^changeset:[ \t]*\\([0-9]+\\):\\(.+\\)")
137 (set (make-local-variable 'log-view-font-lock-keywords) 143 (set (make-local-variable 'log-view-font-lock-keywords)
138 (append 144 (append
139 ;; XXX maybe use a different face for the version number 145 log-view-font-lock-keywords
140 `((,log-view-message-re (1 'change-log-acknowledgement))
141 (,log-view-file-re (1 'change-log-file-face)))
142 ;; Handle the case: 146 ;; Handle the case:
143 ;; user: foo@bar 147 ;; user: foo@bar
144 '(("^user:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)" 148 '(("^user:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)"
145 (1 'change-log-email)) 149 (1 'change-log-email))
146 ;; Handle the case: 150 ;; Handle the case:
157 (if (and (equal oldvers working) (not newvers)) 161 (if (and (equal oldvers working) (not newvers))
158 (setq oldvers nil)) 162 (setq oldvers nil))
159 (if (and (not oldvers) newvers) 163 (if (and (not oldvers) newvers)
160 (setq oldvers working)) 164 (setq oldvers working))
161 (apply 'call-process "hg" nil (or buffer "*vc-diff*") nil 165 (apply 'call-process "hg" nil (or buffer "*vc-diff*") nil
162 "--cwd" (file-name-directory file) "diff" 166 "--cwd" (file-name-directory file) "diff"
163 (append 167 (append
164 (if oldvers 168 (if oldvers
165 (if newvers 169 (if newvers
166 (list "-r" oldvers "-r" newvers) 170 (list "-r" oldvers "-r" newvers)
167 (list "-r" oldvers)) 171 (list "-r" oldvers))
168 (list "")) 172 (list ""))
169 (list (file-name-nondirectory file)))))) 173 (list (file-name-nondirectory file))))))
170 174
171 (defun vc-hg-annotate-command (file buffer &optional version) 175 (defun vc-hg-annotate-command (file buffer &optional version)
172 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER. 176 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER.
173 Optional arg VERSION is a version to annotate from." 177 Optional arg VERSION is a version to annotate from."
174 (vc-hg-command buffer 0 file "annotate" "-d" "-n" (if version (concat "-r" version))) 178 (vc-hg-command buffer 0 file "annotate" "-d" "-n" (if version (concat "-r" version)))
176 (goto-char (point-min)) 180 (goto-char (point-min))
177 (re-search-forward "^[0-9]") 181 (re-search-forward "^[0-9]")
178 (delete-region (point-min) (1- (point))))) 182 (delete-region (point-min) (1- (point)))))
179 183
180 184
181 ;;; The format for one line output by "hg annotate -d -n" looks like this: 185 ;; The format for one line output by "hg annotate -d -n" looks like this:
182 ;;;215 Wed Jun 20 21:22:58 2007 -0700: CONTENTS 186 ;;215 Wed Jun 20 21:22:58 2007 -0700: CONTENTS
183 ;;; i.e: VERSION_NUMBER DATE: CONTENTS 187 ;; i.e: VERSION_NUMBER DATE: CONTENTS
184 (defconst vc-hg-annotate-re "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\): ") 188 (defconst vc-hg-annotate-re "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\): ")
185 189
186 (defun vc-hg-annotate-time () 190 (defun vc-hg-annotate-time ()
187 (when (looking-at vc-hg-annotate-re) 191 (when (looking-at vc-hg-annotate-re)
188 (goto-char (match-end 0)) 192 (goto-char (match-end 0))
189 (vc-annotate-convert-time 193 (vc-annotate-convert-time
190 (date-to-time (match-string-no-properties 2))))) 194 (date-to-time (match-string-no-properties 2)))))
191 195
192 (defun vc-hg-annotate-extract-revision-at-line () 196 (defun vc-hg-annotate-extract-revision-at-line ()
193 (save-excursion 197 (save-excursion
194 (beginning-of-line) 198 (beginning-of-line)
208 (defun vc-hg-checkin (file rev comment) 212 (defun vc-hg-checkin (file rev comment)
209 "HG-specific version of `vc-backend-checkin'. 213 "HG-specific version of `vc-backend-checkin'.
210 REV is ignored." 214 REV is ignored."
211 (vc-hg-command nil nil file "commit" "-m" comment)) 215 (vc-hg-command nil nil file "commit" "-m" comment))
212 216
213 ;;; Modelled after the similar function in vc-bzr.el 217 ;; Modelled after the similar function in vc-bzr.el
214 (defun vc-hg-checkout (file &optional editable rev workfile) 218 (defun vc-hg-checkout (file &optional editable rev workfile)
215 "Retrieve a revision of FILE into a WORKFILE. 219 "Retrieve a revision of FILE into a WORKFILE.
216 EDITABLE is ignored. 220 EDITABLE is ignored.
217 REV is the revision to check out into WORKFILE." 221 REV is the revision to check out into WORKFILE."
218 (unless workfile 222 (unless workfile