diff options
| author | Stefan Monnier | 2007-09-15 22:25:55 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2007-09-15 22:25:55 +0000 |
| commit | 86e80023f4df1f8abbff5295d17aab68d8e0e19c (patch) | |
| tree | f71a7deb1c3ddb9406fb4c1c41528cc4d68fb03a | |
| parent | 0f71f9da9cd21af7838ed063c2af44f5ea4e9a02 (diff) | |
| download | emacs-86e80023f4df1f8abbff5295d17aab68d8e0e19c.tar.gz emacs-86e80023f4df1f8abbff5295d17aab68d8e0e19c.zip | |
(vc-process-sentinel): New function.
(vc-exec-after): Use it instead of using ugly hackish analysis and
construction of Elisp code.
(vc-sentinel-movepoint): New dynamically scoped var.
(vc-print-log, vc-annotate): Set it to move the user's point.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/vc.el | 54 |
2 files changed, 44 insertions, 16 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9f195dfe7b6..6dcd86c9f55 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,11 @@ | |||
| 1 | 2007-09-15 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2007-09-15 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * vc.el (vc-process-sentinel): New function. | ||
| 4 | (vc-exec-after): Use it instead of using ugly hackish analysis and | ||
| 5 | construction of Elisp code. | ||
| 6 | (vc-sentinel-movepoint): New dynamically scoped var. | ||
| 7 | (vc-print-log, vc-annotate): Set it to move the user's point. | ||
| 8 | |||
| 3 | * vc-cvs.el (vc-cvs-annotate-time): Use inhibit-read-only and | 9 | * vc-cvs.el (vc-cvs-annotate-time): Use inhibit-read-only and |
| 4 | inhibit-modification-hooks. | 10 | inhibit-modification-hooks. |
| 5 | 11 | ||
diff --git a/lisp/vc.el b/lisp/vc.el index 222825b054f..6c06f9a9032 100644 --- a/lisp/vc.el +++ b/lisp/vc.el | |||
| @@ -975,6 +975,33 @@ BUF defaults to \"*vc*\", can be a string and will be created if necessary." | |||
| 975 | (inhibit-read-only t)) | 975 | (inhibit-read-only t)) |
| 976 | (erase-buffer)))) | 976 | (erase-buffer)))) |
| 977 | 977 | ||
| 978 | (defvar vc-sentinel-movepoint) ;Dynamically scoped. | ||
| 979 | |||
| 980 | (defun vc-process-sentinel (p s) | ||
| 981 | (let ((previous (process-get p 'vc-previous-sentinel))) | ||
| 982 | (if previous (funcall previous p s)) | ||
| 983 | (with-current-buffer (process-buffer p) | ||
| 984 | (let (vc-sentinel-movepoint) | ||
| 985 | ;; Normally, we want async code such as sentinels to not move point. | ||
| 986 | (save-excursion | ||
| 987 | (goto-char (process-mark p)) | ||
| 988 | (let ((cmds (process-get p 'vc-sentinel-commands))) | ||
| 989 | (process-put p 'vc-postprocess nil) | ||
| 990 | (dolist (cmd cmds) | ||
| 991 | ;; Each sentinel may move point and the next one should be run | ||
| 992 | ;; at that new point. We could get the same result by having | ||
| 993 | ;; each sentinel read&set process-mark, but since `cmd' needs | ||
| 994 | ;; to work both for async and sync processes, this would be | ||
| 995 | ;; difficult to achieve. | ||
| 996 | (vc-exec-after cmd)))) | ||
| 997 | ;; But sometimes the sentinels really want to move point. | ||
| 998 | (if vc-sentinel-movepoint | ||
| 999 | (let ((win (get-buffer-window (current-buffer) 0))) | ||
| 1000 | (if (not win) | ||
| 1001 | (goto-char vc-sentinel-movepoint) | ||
| 1002 | (with-selected-window win | ||
| 1003 | (goto-char vc-sentinel-movepoint))))))))) | ||
| 1004 | |||
| 978 | (defun vc-exec-after (code) | 1005 | (defun vc-exec-after (code) |
| 979 | "Eval CODE when the current buffer's process is done. | 1006 | "Eval CODE when the current buffer's process is done. |
| 980 | If the current buffer has no process, just evaluate CODE. | 1007 | If the current buffer has no process, just evaluate CODE. |
| @@ -992,17 +1019,12 @@ Else, add CODE to the process' sentinel." | |||
| 992 | (eval code)) | 1019 | (eval code)) |
| 993 | ;; If a process is running, add CODE to the sentinel | 1020 | ;; If a process is running, add CODE to the sentinel |
| 994 | ((eq (process-status proc) 'run) | 1021 | ((eq (process-status proc) 'run) |
| 995 | (let ((sentinel (process-sentinel proc))) | 1022 | (let ((previous (process-sentinel proc))) |
| 996 | (set-process-sentinel proc | 1023 | (unless (eq previous 'vc-process-sentinel) |
| 997 | `(lambda (p s) | 1024 | (process-put proc 'vc-previous-sentinel previous)) |
| 998 | (with-current-buffer ',(current-buffer) | 1025 | (set-process-sentinel proc 'vc-process-sentinel)) |
| 999 | (save-excursion | 1026 | (process-put proc 'vc-sentinel-commands |
| 1000 | (goto-char (process-mark p)) | 1027 | (cons code (process-get proc 'vc-sentinel-commands)))) |
| 1001 | ,@(append (cdr (cdr (car ;Strip off (save-exc (goto-char...) | ||
| 1002 | (cdr (cdr ;Strip off (with-current-buffer buf | ||
| 1003 | (car (cdr (cdr ;Strip off (lambda (p s) | ||
| 1004 | sentinel)))))))) | ||
| 1005 | (list `(vc-exec-after ',code))))))))) | ||
| 1006 | (t (error "Unexpected process state")))) | 1028 | (t (error "Unexpected process state")))) |
| 1007 | nil) | 1029 | nil) |
| 1008 | 1030 | ||
| @@ -1087,7 +1109,8 @@ that is inserted into the command line before the filename." | |||
| 1087 | (if vc-command-messages | 1109 | (if vc-command-messages |
| 1088 | (message "Running %s...OK" full-command))) | 1110 | (message "Running %s...OK" full-command))) |
| 1089 | (vc-exec-after | 1111 | (vc-exec-after |
| 1090 | `(run-hook-with-args 'vc-post-command-functions ',command ',file-or-list ',flags)) | 1112 | `(run-hook-with-args 'vc-post-command-functions |
| 1113 | ',command ',file-or-list ',flags)) | ||
| 1091 | status)))) | 1114 | status)))) |
| 1092 | 1115 | ||
| 1093 | (defun vc-position-context (posn) | 1116 | (defun vc-position-context (posn) |
| @@ -2557,6 +2580,7 @@ If FOCUS-REV is non-nil, leave the point at that revision." | |||
| 2557 | (vc-call-backend ',(vc-backend file) | 2580 | (vc-call-backend ',(vc-backend file) |
| 2558 | 'show-log-entry | 2581 | 'show-log-entry |
| 2559 | ',focus-rev) | 2582 | ',focus-rev) |
| 2583 | (setq vc-sentinel-movepoint (point)) | ||
| 2560 | (set-buffer-modified-p nil))))) | 2584 | (set-buffer-modified-p nil))))) |
| 2561 | 2585 | ||
| 2562 | (defun vc-default-log-view-mode (backend) (log-view-mode)) | 2586 | (defun vc-default-log-view-mode (backend) (log-view-mode)) |
| @@ -3279,10 +3303,8 @@ colors. `vc-annotate-background' specifies the background color." | |||
| 3279 | ;; moved it elsewhere, but really point here is not the position | 3303 | ;; moved it elsewhere, but really point here is not the position |
| 3280 | ;; of the user's cursor :-( | 3304 | ;; of the user's cursor :-( |
| 3281 | (when ,current-line ;(and (bobp)) | 3305 | (when ,current-line ;(and (bobp)) |
| 3282 | (let ((win (get-buffer-window (current-buffer) 0))) | 3306 | (goto-line ,current-line) |
| 3283 | (when win | 3307 | (setq vc-sentinel-movepoint)) |
| 3284 | (with-selected-window win | ||
| 3285 | (goto-line ,current-line))))) | ||
| 3286 | (unless (active-minibuffer-window) | 3308 | (unless (active-minibuffer-window) |
| 3287 | (message "Annotating... done"))))))) | 3309 | (message "Annotating... done"))))))) |
| 3288 | 3310 | ||