* lisp/vc/smerge-mode.el (smerge-change-buffer-confirm): New var

(smerge-vc-next-conflict): Obey it.  Save buffer before going to
the next.  Don't emit message when vc-find-conflicted-file can't find
other conflicted file.

* lisp/vc/vc-hooks.el: Use lexical-binding.

* lisp/vc/vc.el: Remove redundant :groups.
(vc-find-conflicted-file): Autoload.
This commit is contained in:
Stefan Monnier 2019-02-18 09:43:59 -05:00
parent 2eecaa2897
commit 2ede38ce4b
3 changed files with 55 additions and 48 deletions

View file

@ -1432,19 +1432,39 @@ If no conflict maker is found, turn off `smerge-mode'."
(smerge-next))
(error (smerge-auto-leave))))
(require 'vc)
(defcustom smerge-change-buffer-confirm t
"If non-nil, request confirmation before moving to another buffer."
:type 'boolean)
(defun smerge-vc-next-conflict ()
"Tries to go to next conflict in current file, otherwise tries
to open next conflicted file version-control-system wise"
"Go to next conflict, possibly in another file.
First tries to go to the next conflict in the current buffer, and if not
found, uses VC to try and find the next file with conflict."
(interactive)
(let ((buffer (current-buffer)))
(when (not (smerge-goto-next-conflict))
(vc-find-conflicted-file)
(if (eq buffer (current-buffer))
(message "No conflicts found")
(goto-char 0)
(smerge-goto-next-conflict)))))
(condition-case nil
;; FIXME: Try again from BOB before moving to the next file.
(smerge-next)
(error
(if (and (or smerge-change-buffer-confirm
(and (buffer-modified-p) buffer-file-name))
(not (or (eq last-command this-command)
(eq ?\r last-command-event)))) ;Called via M-x!?
;; FIXME: Don't emit this message if `vc-find-conflicted-file' won't
;; go to another file anyway (because there are no more conflicted
;; files).
(message (if (buffer-modified-p)
"No more conflicts here. Repeat to save and go to next buffer"
"No more conflicts here. Repeat to go to next buffer"))
(if (and (buffer-modified-p) buffer-file-name)
(save-buffer))
(vc-find-conflicted-file)
(if (eq buffer (current-buffer))
;; Do nothing: presumably `vc-find-conflicted-file' already
;; emitted a message explaining there aren't any more conflicts.
nil
(goto-char (point-min))
(smerge-next)))))))
(provide 'smerge-mode)

View file

@ -1,4 +1,4 @@
;;; vc-hooks.el --- resident support for version-control
;;; vc-hooks.el --- resident support for version-control -*- lexical-binding:t -*-
;; Copyright (C) 1992-1996, 1998-2019 Free Software Foundation, Inc.
@ -173,9 +173,9 @@ Otherwise, not displayed."
(make-variable-buffer-local 'vc-mode)
(put 'vc-mode 'permanent-local t)
;;; We signal this error when we try to do something a VC backend
;;; doesn't support. Two arguments: the method that's not supported
;;; and the backend
;; We signal this error when we try to do something a VC backend
;; doesn't support. Two arguments: the method that's not supported
;; and the backend
(define-error 'vc-not-supported "VC method not implemented for backend")
(defun vc-mode (&optional _arg)
@ -243,12 +243,12 @@ if that doesn't exist either, return nil."
"Call for BACKEND the implementation of FUNCTION-NAME with the given ARGS.
Calls
(apply \\='vc-BACKEND-FUN ARGS)
(apply #\\='vc-BACKEND-FUN ARGS)
if vc-BACKEND-FUN exists (after trying to find it in vc-BACKEND.el)
and else calls
(apply \\='vc-default-FUN BACKEND ARGS)
(apply #\\='vc-default-FUN BACKEND ARGS)
It is usually called via the `vc-call' macro."
(let ((f (assoc function-name (get backend 'vc-functions))))
@ -603,7 +603,7 @@ a regexp for matching all such backup files, regardless of the version."
"Delete all existing automatic version backups for FILE."
(condition-case nil
(mapc
'delete-file
#'delete-file
(directory-files (or (file-name-directory file) default-directory) t
(vc-version-backup-file-name file nil nil t)))
;; Don't fail when the directory doesn't exist.
@ -811,7 +811,7 @@ In the latter case, VC mode is deactivated for this buffer."
(when buffer-file-name
(vc-file-clearprops buffer-file-name)
;; FIXME: Why use a hook? Why pass it buffer-file-name?
(add-hook 'vc-mode-line-hook 'vc-mode-line nil t)
(add-hook 'vc-mode-line-hook #'vc-mode-line nil t)
(let (backend)
(cond
((setq backend (with-demoted-errors (vc-backend buffer-file-name)))
@ -862,13 +862,13 @@ In the latter case, VC mode is deactivated for this buffer."
)))))))))
(add-hook 'find-file-hook #'vc-refresh-state)
(define-obsolete-function-alias 'vc-find-file-hook 'vc-refresh-state "25.1")
(define-obsolete-function-alias 'vc-find-file-hook #'vc-refresh-state "25.1")
(defun vc-kill-buffer-hook ()
"Discard VC info about a file when we kill its buffer."
(when buffer-file-name (vc-file-clearprops buffer-file-name)))
(add-hook 'kill-buffer-hook 'vc-kill-buffer-hook)
(add-hook 'kill-buffer-hook #'vc-kill-buffer-hook)
;; Now arrange for (autoloaded) bindings of the main package.
;; Bindings for this have to go in the global map, as we'll often

View file

@ -736,8 +736,7 @@ These are passed to the checkin program by \\[vc-checkin]."
(string :tag "Argument String")
(repeat :tag "Argument List"
:value ("")
string))
:group 'vc)
string)))
(defcustom vc-checkout-switches nil
"A string or list of strings specifying extra switches for checkout.
@ -746,8 +745,7 @@ These are passed to the checkout program by \\[vc-checkout]."
(string :tag "Argument String")
(repeat :tag "Argument List"
:value ("")
string))
:group 'vc)
string)))
(defcustom vc-register-switches nil
"A string or list of strings; extra switches for registering a file.
@ -756,8 +754,7 @@ These are passed to the checkin program by \\[vc-register]."
(string :tag "Argument String")
(repeat :tag "Argument List"
:value ("")
string))
:group 'vc)
string)))
(defcustom vc-diff-switches nil
"A string or list of strings specifying switches for diff under VC.
@ -772,7 +769,6 @@ not specific to any particular backend."
(const :tag "None" t)
(string :tag "Argument String")
(repeat :tag "Argument List" :value ("") string))
:group 'vc
:version "21.1")
(defcustom vc-annotate-switches nil
@ -792,15 +788,13 @@ for the backend you use."
(const :tag "None" t)
(string :tag "Argument String")
(repeat :tag "Argument List" :value ("") string))
:group 'vc
:version "25.1")
(defcustom vc-log-show-limit 2000
"Limit the number of items shown by the VC log commands.
Zero means unlimited.
Not all VC backends are able to support this feature."
:type 'integer
:group 'vc)
:type 'integer)
(defcustom vc-allow-async-revert nil
"Specifies whether the diff during \\[vc-revert] may be asynchronous.
@ -808,7 +802,6 @@ Enabling this option means that you can confirm a revert operation even
if the local changes in the file have not been found and displayed yet."
:type '(choice (const :tag "No" nil)
(const :tag "Yes" t))
:group 'vc
:version "22.1")
;;;###autoload
@ -816,7 +809,6 @@ if the local changes in the file have not been found and displayed yet."
"Normal hook (list of functions) run after checking out a file.
See `run-hooks'."
:type 'hook
:group 'vc
:version "21.1")
;;;###autoload
@ -824,26 +816,22 @@ See `run-hooks'."
"Normal hook (list of functions) run after commit or file checkin.
See also `log-edit-done-hook'."
:type 'hook
:options '(log-edit-comment-to-change-log)
:group 'vc)
:options '(log-edit-comment-to-change-log))
;;;###autoload
(defcustom vc-before-checkin-hook nil
"Normal hook (list of functions) run before a commit or a file checkin.
See `run-hooks'."
:type 'hook
:group 'vc)
:type 'hook)
(defcustom vc-retrieve-tag-hook nil
"Normal hook (list of functions) run after retrieving a tag."
:type 'hook
:group 'vc
:version "27.1")
(defcustom vc-revert-show-diff t
"If non-nil, `vc-revert' shows a `vc-diff' buffer before querying."
:type 'boolean
:group 'vc
:version "24.1")
;; Header-insertion hair
@ -856,8 +844,7 @@ A %s in the template is replaced with the first string associated with
the file's version control type in `vc-BACKEND-header'."
:type '(repeat (cons :format "%v"
(regexp :tag "File Type")
(string :tag "Header String")))
:group 'vc)
(string :tag "Header String"))))
(defcustom vc-comment-alist
'((nroff-mode ".\\\"" ""))
@ -868,13 +855,11 @@ is sensitive to blank lines."
:type '(repeat (list :format "%v"
(symbol :tag "Mode")
(string :tag "Comment Start")
(string :tag "Comment End")))
:group 'vc)
(string :tag "Comment End"))))
(defcustom vc-find-revision-no-save nil
"If non-nil, `vc-find-revision' doesn't write the created buffer to file."
:type 'boolean
:group 'vc
:version "27.1")
@ -940,7 +925,7 @@ use."
;; 'create-repo method.
(completing-read
(format "%s is not in a version controlled directory.\nUse VC backend: " file)
(mapcar 'symbol-name possible-backends) nil t)))
(mapcar #'symbol-name possible-backends) nil t)))
(repo-dir
(let ((def-dir (file-name-directory file)))
;; read the directory where to create the
@ -1109,7 +1094,7 @@ BEWARE: this function may change the current buffer."
(defun vc-read-backend (prompt)
(intern
(completing-read prompt (mapcar 'symbol-name vc-handled-backends)
(completing-read prompt (mapcar #'symbol-name vc-handled-backends)
nil 'require-match)))
;; Here's the major entry point.
@ -1367,7 +1352,7 @@ first backend that could register the file is used."
(set-buffer-modified-p t))
(vc-buffer-sync)))))
(message "Registering %s... " files)
(mapc 'vc-file-clearprops files)
(mapc #'vc-file-clearprops files)
(vc-call-backend backend 'register files comment)
(mapc
(lambda (file)
@ -1569,7 +1554,7 @@ Runs the normal hooks `vc-before-checkin-hook' and `vc-checkin-hook'."
;; not a well-defined concept for filesets.
(progn
(vc-call-backend backend 'checkin files comment rev)
(mapc 'vc-delete-automatic-version-backups files))
(mapc #'vc-delete-automatic-version-backups files))
`((vc-state . up-to-date)
(vc-checkout-time . ,(file-attribute-modification-time
(file-attributes file)))
@ -1727,7 +1712,7 @@ Return t if the buffer had changes, nil otherwise."
(error "No revisions of %s exist" file)
;; We regard this as "changed".
;; Diff it against /dev/null.
(apply 'vc-do-command buffer
(apply #'vc-do-command buffer
(if async 'async 1) "diff" file
(append (vc-switches nil 'diff) '("/dev/null"))))))
(setq files (nreverse filtered))))
@ -2172,6 +2157,7 @@ changes from the current branch."
;; `default-next-file' variable for its default file (M-n), and
;; we could then set it upon mark-resolve, so C-x C-s C-x C-f M-n would
;; automatically offer the next conflicted file.
;;;###autoload
(defun vc-find-conflicted-file ()
"Visit the next conflicted file in the current project."
(interactive)
@ -2772,7 +2758,8 @@ If called interactively, read FILE, defaulting to the current
buffer's file name if it's under version control."
(interactive (list (read-file-name "VC delete file: " nil
(when (vc-backend buffer-file-name)
buffer-file-name) t)))
buffer-file-name)
t)))
(setq file (expand-file-name file))
(let ((buf (get-file-buffer file))
(backend (vc-backend file)))