From 5d7da9a94489da0db3b3c7b766606b80fc71becf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Sonderfeld?= Date: Thu, 14 Jun 2012 10:37:58 +0100 Subject: git-blame.el: Do not use goto-line in lisp code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit goto-line is a user-level command, instead use the lisp-level construct recommended in Emacs documentation. Signed-off-by: RĂ¼diger Sonderfeld Signed-off-by: Lawrence Mitchell Signed-off-by: Junio C Hamano diff --git a/contrib/emacs/git-blame.el b/contrib/emacs/git-blame.el index d351cfb..3b5d5af 100644 --- a/contrib/emacs/git-blame.el +++ b/contrib/emacs/git-blame.el @@ -389,7 +389,8 @@ See also function `git-blame-mode'." (set-buffer git-blame-file) (let ((inhibit-point-motion-hooks t) (inhibit-modification-hooks t)) - (goto-line start-line) + (goto-char (point-min)) + (forward-line (1- start-line)) (let* ((start (point)) (end (progn (forward-line num-lines) (point))) (ovl (make-overlay start end)) -- cgit v0.10.2-6-g49f6 From 0e59a6f6018182e6648789904672b738a944a524 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Thu, 14 Jun 2012 10:37:59 +0100 Subject: git-blame.el: Use with-current-buffer where appropriate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Lawrence Mitchell Signed-off-by: Junio C Hamano diff --git a/contrib/emacs/git-blame.el b/contrib/emacs/git-blame.el index 3b5d5af..8ebd985 100644 --- a/contrib/emacs/git-blame.el +++ b/contrib/emacs/git-blame.el @@ -337,16 +337,16 @@ See also function `git-blame-mode'." (defvar in-blame-filter nil) (defun git-blame-filter (proc str) - (save-excursion - (set-buffer (process-buffer proc)) - (goto-char (process-mark proc)) - (insert-before-markers str) - (goto-char 0) - (unless in-blame-filter - (let ((more t) - (in-blame-filter t)) - (while more - (setq more (git-blame-parse))))))) + (with-current-buffer (process-buffer proc) + (save-excursion + (goto-char (process-mark proc)) + (insert-before-markers str) + (goto-char 0) + (unless in-blame-filter + (let ((more t) + (in-blame-filter t)) + (while more + (setq more (git-blame-parse)))))))) (defun git-blame-parse () (cond ((looking-at "\\([0-9a-f]\\{40\\}\\) \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)\n") @@ -385,33 +385,33 @@ See also function `git-blame-mode'." info)))) (defun git-blame-create-overlay (info start-line num-lines) - (save-excursion - (set-buffer git-blame-file) - (let ((inhibit-point-motion-hooks t) - (inhibit-modification-hooks t)) - (goto-char (point-min)) - (forward-line (1- start-line)) - (let* ((start (point)) - (end (progn (forward-line num-lines) (point))) - (ovl (make-overlay start end)) - (hash (car info)) - (spec `((?h . ,(substring hash 0 6)) - (?H . ,hash) - (?a . ,(git-blame-get-info info 'author)) - (?A . ,(git-blame-get-info info 'author-mail)) - (?c . ,(git-blame-get-info info 'committer)) - (?C . ,(git-blame-get-info info 'committer-mail)) - (?s . ,(git-blame-get-info info 'summary))))) - (push ovl git-blame-overlays) - (overlay-put ovl 'git-blame info) - (overlay-put ovl 'help-echo - (format-spec git-blame-mouseover-format spec)) - (if git-blame-use-colors - (overlay-put ovl 'face (list :background - (cdr (assq 'color (cdr info)))))) - (overlay-put ovl 'line-prefix - (propertize (format-spec git-blame-prefix-format spec) - 'face 'git-blame-prefix-face)))))) + (with-current-buffer git-blame-file + (save-excursion + (let ((inhibit-point-motion-hooks t) + (inhibit-modification-hooks t)) + (goto-char (point-min)) + (forward-line (1- start-line)) + (let* ((start (point)) + (end (progn (forward-line num-lines) (point))) + (ovl (make-overlay start end)) + (hash (car info)) + (spec `((?h . ,(substring hash 0 6)) + (?H . ,hash) + (?a . ,(git-blame-get-info info 'author)) + (?A . ,(git-blame-get-info info 'author-mail)) + (?c . ,(git-blame-get-info info 'committer)) + (?C . ,(git-blame-get-info info 'committer-mail)) + (?s . ,(git-blame-get-info info 'summary))))) + (push ovl git-blame-overlays) + (overlay-put ovl 'git-blame info) + (overlay-put ovl 'help-echo + (format-spec git-blame-mouseover-format spec)) + (if git-blame-use-colors + (overlay-put ovl 'face (list :background + (cdr (assq 'color (cdr info)))))) + (overlay-put ovl 'line-prefix + (propertize (format-spec git-blame-prefix-format spec) + 'face 'git-blame-prefix-face))))))) (defun git-blame-add-info (info key value) (nconc info (list (cons (intern key) value)))) -- cgit v0.10.2-6-g49f6 From 32663b22418bb394d71012d17e4954217c02752f Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Thu, 14 Jun 2012 10:38:00 +0100 Subject: git-blame.el: Do not use bare 0 to mean (point-min) Signed-off-by: Lawrence Mitchell Signed-off-by: Junio C Hamano diff --git a/contrib/emacs/git-blame.el b/contrib/emacs/git-blame.el index 8ebd985..cf485a1 100644 --- a/contrib/emacs/git-blame.el +++ b/contrib/emacs/git-blame.el @@ -341,7 +341,7 @@ See also function `git-blame-mode'." (save-excursion (goto-char (process-mark proc)) (insert-before-markers str) - (goto-char 0) + (goto-char (point-min)) (unless in-blame-filter (let ((more t) (in-blame-filter t)) -- cgit v0.10.2-6-g49f6