git-blame.el: Use with-current-buffer where appropriate

In git-blame-filter and git-blame-create-overlay we want to save (along with the values of point and mark) the current-buffer in scope when calling the functions. The idiom (save-excursion (set-buffer buf) ...) will correctly restore the correct buffer, but will not save the values of point and mark in buf (only in the buffer current when the save-excursion call is executed). The intention of these functions is to save the current buffer from the calling scope and the values of point and mark in the buffer they are modifying. The correct idiom for this is (with-current-buffer buf (save-excursion ...)) Signed-off-by: Rüdiger Sonderfeld <ruediger@c-plusplus.de> Signed-off-by: Lawrence Mitchell <wence@gmx.li> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lawrence Mitchell committed Jun 14, 2012 at 10:37 UTC 0e59a6f6018182e6648789904672b738a944a524
1 file changed +37 -37
contrib/emacs/git-blame.el
+37 -37
@@ -337,16 +337,16 @@ See also function `git-blame-mode'."
337 (defvar in-blame-filter nil)
338
339 (defun git-blame-filter (proc str)
340 - (save-excursion
341 - (set-buffer (process-buffer proc))
342 - (goto-char (process-mark proc))
343 - (insert-before-markers str)
344 - (goto-char 0)
345 - (unless in-blame-filter
346 - (let ((more t)
347 - (in-blame-filter t))
348 - (while more
349 - (setq more (git-blame-parse)))))))
340 + (with-current-buffer (process-buffer proc)
341 + (save-excursion
342 + (goto-char (process-mark proc))
343 + (insert-before-markers str)
344 + (goto-char 0)
345 + (unless in-blame-filter
346 + (let ((more t)
347 + (in-blame-filter t))
348 + (while more
349 + (setq more (git-blame-parse))))))))
350
351 (defun git-blame-parse ()
352 (cond ((looking-at "\\([0-9a-f]\\{40\\}\\) \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)\n")
@@ -385,33 +385,33 @@ See also function `git-blame-mode'."
385 info))))
386
387 (defun git-blame-create-overlay (info start-line num-lines)
388 - (save-excursion
389 - (set-buffer git-blame-file)
390 - (let ((inhibit-point-motion-hooks t)
391 - (inhibit-modification-hooks t))
392 - (goto-char (point-min))
393 - (forward-line (1- start-line))
394 - (let* ((start (point))
395 - (end (progn (forward-line num-lines) (point)))
396 - (ovl (make-overlay start end))
397 - (hash (car info))
398 - (spec `((?h . ,(substring hash 0 6))
399 - (?H . ,hash)
400 - (?a . ,(git-blame-get-info info 'author))
401 - (?A . ,(git-blame-get-info info 'author-mail))
402 - (?c . ,(git-blame-get-info info 'committer))
403 - (?C . ,(git-blame-get-info info 'committer-mail))
404 - (?s . ,(git-blame-get-info info 'summary)))))
405 - (push ovl git-blame-overlays)
406 - (overlay-put ovl 'git-blame info)
407 - (overlay-put ovl 'help-echo
408 - (format-spec git-blame-mouseover-format spec))
409 - (if git-blame-use-colors
410 - (overlay-put ovl 'face (list :background
411 - (cdr (assq 'color (cdr info))))))
412 - (overlay-put ovl 'line-prefix
413 - (propertize (format-spec git-blame-prefix-format spec)
414 - 'face 'git-blame-prefix-face))))))
388 + (with-current-buffer git-blame-file
389 + (save-excursion
390 + (let ((inhibit-point-motion-hooks t)
391 + (inhibit-modification-hooks t))
392 + (goto-char (point-min))
393 + (forward-line (1- start-line))
394 + (let* ((start (point))
395 + (end (progn (forward-line num-lines) (point)))
396 + (ovl (make-overlay start end))
397 + (hash (car info))
398 + (spec `((?h . ,(substring hash 0 6))
399 + (?H . ,hash)
400 + (?a . ,(git-blame-get-info info 'author))
401 + (?A . ,(git-blame-get-info info 'author-mail))
402 + (?c . ,(git-blame-get-info info 'committer))
403 + (?C . ,(git-blame-get-info info 'committer-mail))
404 + (?s . ,(git-blame-get-info info 'summary)))))
405 + (push ovl git-blame-overlays)
406 + (overlay-put ovl 'git-blame info)
407 + (overlay-put ovl 'help-echo
408 + (format-spec git-blame-mouseover-format spec))
409 + (if git-blame-use-colors
410 + (overlay-put ovl 'face (list :background
411 + (cdr (assq 'color (cdr info))))))
412 + (overlay-put ovl 'line-prefix
413 + (propertize (format-spec git-blame-prefix-format spec)
414 + 'face 'git-blame-prefix-face)))))))
415
416 (defun git-blame-add-info (info key value)
417 (nconc info (list (cons (intern key) value))))