* lisp/vc/diff-mode.el (diff-file-kill): New optional DELETE
parameter.
(diff-kill-creations-deletions):
* lisp/vc/vc.el (vc--fileset-by-state): New functions.
(diff-kill-creations-deletions, diff-filename-drop-dir)
(diff-hunk-file-names, diff-file-next, diff-hunk-header-re)
(vc-dir-resynch-file): Declare.
(vc--apply-to-other-working-tree): Handle copying and moving
files in the added, removed, missing and unregistered states.
* test/lisp/vc/vc-tests/vc-tests.el
(vc-test--apply-to-other-working-tree): New test.
* lisp/vc/diff-mode.el (diff-revert-and-kill-hunk): When the
region is active, operate on all hunks it overlaps.
* doc/emacs/files.texi (Diff Mode):
* etc/NEWS: Document the change.
* lisp/vc/diff-mode.el (diff-apply-buffer): New 'no-save'
meaning for fourth optional argument. Reserve other non-nil
values for this argument. Use ngettext for one message.
(diff-apply-hunk): If the region is active, apply all hunks that
the region overlaps, like diff-apply-buffer.
* doc/emacs/files.texi (Diff Mode):
* etc/NEWS: Document the change to diff-apply-hunk.
Restore yellow colors previously used in the 'diff-changed' face.
Copy color values from 'smerge-base'. This will distinguish them
from grey 'diff-file-header' and 'diff-hunk-header' in context diffs.
Avoid getting stuck waiting for `diff` to refine big hunks.
* lisp/vc/diff-mode.el (diff-refine-threshold): New custom var.
(diff--refine-hunk): Add arg `skip-if-large` and use that new var if
the arg says so.
(diff-refine-hunk): Add arg `skip-if-large`.
(diff-auto-refine-mode, diff-next/prevhunk, diff--font-lock-refined):
Use it.
* lisp/vc/diff-mode.el (diff-find-matching-buffer): Rename ...
* lisp/progmodes/project.el
(project-change-to-matching-directory): ... to here. All uses
changed.
* lisp/vc/log-view.el (project-change-to-matching-directory):
Declare.
(log-view-mode): Use it.
* doc/emacs/vc1-xtra.texi (Other Working Trees): Document the
change.
* lisp/vc/diff-mode.el (project-root): Declare.
(diff-find-matching-buffer): New function.
(diff-mode): Use it.
* doc/emacs/vc1-xtra.texi (Other Working Trees): Document
'C-x v w w' in diff-mode buffers.
* lisp/vc/diff-mode.el (diff--font-lock-prettify):
Use 'window-fringes' instead of the 'left-fringe' frame parameter
since the former returns an integer on both GUI and TTY frames.
* lisp/vc/diff-mode.el (diff-read-only-map): New keymap,
factored out of code modifying minor-mode-map-alist.
(diff-mode): Include bindings from diff-read-only-map in
docstring (bug#34080).
* lisp/vc/diff-mode.el (diff-mode-shared-map): No longer inherit
from special-mode-map.
(diff-mode-map): Tidy up list of unbindings now that we no
longer need to override any bindings from special-mode-map.
(minor-mode-map-alist): <diff-mode-read-only>: Ensure that the
minor mode keymap continues to inherit from special-mode-map by
calling make-composed-keymap here.
Co-authored-by: Stefan Monnier <monnier@iro.umontreal.ca>
* lisp/vc/diff-mode.el (diff-outline-regexp): Change the default value
to match the diff command name in recursive diff. Move after
'diff-hunk-header-re' variable definition used in the new value.
(diff-setup-buffer-type): Change setq of 'diff-outline-regexp'
to buffer-local (bug#78269).
* lisp/nxml/nxml-mode.el (nxml-extend-region):
Protect against error "Invalid search bound (wrong side of point)".
* lisp/vc/diff-mode.el (diff-syntax-fontify-hunk):
Use 'with-demoted-errors' instead of 'ignore-errors'.
* lisp/vc/diff-mode.el (diff-find-source-location):
Consider the case when there is no diff context above or below
edited lines. (bug#72556)
* test/lisp/vc/diff-mode-tests.el: Add tests for undoing hunks
from diffs with addtions only in the beginning or end of the
source file.
* lisp/vc/diff-mode.el (diff-apply-buffer): Interactively,
operate on an active region. Reverse-apply hunks with a prefix
argument, like C-u C-c C-a already does.
* lisp/vc/diff-mode.el (diff-font-lock-keywords): Don't fontify lines in
Git patches starting with + or - as added/removed, if they are either
before the first hunk, or in the email signature. (Bug#75884)
(diff-buffer-type): Move definition up.
(diff--indicator-added-re, diff--indicator-removed-re): New variables.
(diff--git-preamble-end, diff--git-footer-start)
(diff--indicator-matcher-helper, diff--indicator-added-matcher)
(diff--indicator-removed-matcher): New functions.
* test/lisp/vc/diff-mode-tests.el (diff-mode-test-git-patch)
(diff-mode-test-git-patch/before-first-hunk)
(diff-mode-test-git-patch/signature): New tests.
* test/lisp/vc/diff-mode-resources/git.patch: New file.
* lisp/vc/diff-mode.el (diff-add-log-current-defuns): Don't run mode
hooks when enabling major mode hooks. That fails if, for example,
paredit-mode is on emacs-lisp-mode-hook and it signaled due to
unbalanced parens.
* lisp/vc/diff-mode.el (diff-syntax-fontify-props):
* lisp/vc/vc.el (vc-find-revision-no-save):
Use enable-local-variables as is only when it's one of these values:
:safe, :all, or nil. Otherwise, for all remaining values that query,
use :safe. Also use non-nil 'find-file' arg of 'normal-mode'.
https://lists.gnu.org/archive/html/emacs-devel/2025-02/msg00897.html
Put the property 'mode-class' with the value 'special' on the symbol
'diff-mode'. This fixes the case when 'view-read-only' is non-nil
by disabling activation of 'view-mode' that overrides single keys
from 'diff-mode-shared-map' (bug#75993).
* lisp/vc/diff-mode.el (diff-find-source-location): Undo part of
the previous change, so that 'reverse' does not affect whether the
"other file" is used (bug#62731).
(diff-apply-hunk): Make that choice here.
* lisp/vc/diff-mode.el (diff-find-file-name): Allow entering
non-existing file name when the corresponding hunk is of type
"create file" (bug#62731). Default to file name with deleted
prefix if diff-buffer-type is Git or Hg. Make sure not to add
such input to diff-remembered-files-alist, it would be hard to
change otherwise in case of typo.
(diff-setup-buffer-type):
Match against the diff header common to 'hg diff' output.
(diff-find-source-location): Look at the other source when the
buffer is applied in reverse.
(diff-apply-hunk): Delect file deletion and pass a different
argument to 'diff-find-source-location' in such case. Bind
diff-vc-backend to nil to avoid older revision buffer being
returned. In the end, offer to delete the file if the hunk was of
corresponding type and matched the existing contents.
* etc/NEWS: Mention the new capability.
* lisp/vc/diff-mode.el (diff-vc-deduce-fileset): Signal
user-error when the buffer is narrowed.
* lisp/vc/vc.el (vc-next-action): Remove code signalling a
user-error when the buffer is narrowed.
* lisp/vc/diff-mode.el (diff-delete-other-hunks): New
command (bug#73387).
(diff-mode-map): Bind the new command to C-c RET n.
(diff-mode-menu): New entry for the new command.
(vc-next-action): Stop, and warn, if the user attempts to commit
a patch from a narrowed buffer (bug#73387).
* doc/emacs/files.texi (Diff Mode):
* etc/NEWS: Document the new command.
* lisp/vc/diff-mode.el (diff-revert-and-kill-hunk): New
command (bug#73407).
(diff-ask-before-revert-and-kill-hunk): New user option.
(diff-apply-buffer): New optional BEG, END and REVERSE
arguments. Return nil if buffers were saved, or the number of
failed applications.
(diff-mode-map): Bind the new command to C-c M-r.
(diff-mode-menu): New entry for the new command.
* doc/emacs/files.texi (Diff Mode):
* etc/NEWS: Document the change.