diff options
| author | Juri Linkov | 2019-02-02 23:23:16 +0200 |
|---|---|---|
| committer | Juri Linkov | 2019-02-02 23:23:16 +0200 |
| commit | 42c8399059bb311c8cfaf9428f0a29032d71011d (patch) | |
| tree | c6f6a6596fffe3339004294e63e309e4a57ab9c9 /lisp/vc/diff-mode.el | |
| parent | adc31c6bdcdb52c2bc0240982d3e8ce870af1fab (diff) | |
| download | emacs-42c8399059bb311c8cfaf9428f0a29032d71011d.tar.gz emacs-42c8399059bb311c8cfaf9428f0a29032d71011d.zip | |
* test/lisp/vc/diff-mode-tests.el (diff-mode-test-font-lock): New test.
(diff-mode-test-font-lock-syntax-one-line): New test for one line.
* test/data/vc/diff-mode/hello_world.c:
* test/data/vc/diff-mode/hello_world_1.c:
* test/data/vc/diff-mode/hello_emacs.c:
* test/data/vc/diff-mode/hello_emacs_1.c: New fixtures.
* lisp/vc/diff-mode.el (diff-syntax-fontify): Move remove-overlays
from diff-syntax-fontify-hunk. (Bug#33567)
(diff-syntax-fontify-hunk): Remove VISIT arg from insert-file-contents.
Diffstat (limited to 'lisp/vc/diff-mode.el')
| -rw-r--r-- | lisp/vc/diff-mode.el | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 158489c97fe..607c7b583ed 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el | |||
| @@ -2391,6 +2391,7 @@ and the position in MAX." | |||
| 2391 | 2391 | ||
| 2392 | (defun diff-syntax-fontify (beg end) | 2392 | (defun diff-syntax-fontify (beg end) |
| 2393 | "Highlight source language syntax in diff hunk between BEG and END." | 2393 | "Highlight source language syntax in diff hunk between BEG and END." |
| 2394 | (remove-overlays beg end 'diff-mode 'syntax) | ||
| 2394 | (save-excursion | 2395 | (save-excursion |
| 2395 | (diff-syntax-fontify-hunk beg end t) | 2396 | (diff-syntax-fontify-hunk beg end t) |
| 2396 | (diff-syntax-fontify-hunk beg end nil))) | 2397 | (diff-syntax-fontify-hunk beg end nil))) |
| @@ -2402,9 +2403,10 @@ and the position in MAX." | |||
| 2402 | (defun diff-syntax-fontify-hunk (beg end old) | 2403 | (defun diff-syntax-fontify-hunk (beg end old) |
| 2403 | "Highlight source language syntax in diff hunk between BEG and END. | 2404 | "Highlight source language syntax in diff hunk between BEG and END. |
| 2404 | When OLD is non-nil, highlight the hunk from the old source." | 2405 | When OLD is non-nil, highlight the hunk from the old source." |
| 2405 | (remove-overlays beg end 'diff-mode 'syntax) | ||
| 2406 | (goto-char beg) | 2406 | (goto-char beg) |
| 2407 | (let* ((hunk (buffer-substring-no-properties beg end)) | 2407 | (let* ((hunk (buffer-substring-no-properties beg end)) |
| 2408 | ;; Trim a trailing newline to find hunk in diff-syntax-fontify-props | ||
| 2409 | ;; in diffs that have no newline at end of diff file. | ||
| 2408 | (text (string-trim-right (or (ignore-errors (diff-hunk-text hunk (not old) nil)) ""))) | 2410 | (text (string-trim-right (or (ignore-errors (diff-hunk-text hunk (not old) nil)) ""))) |
| 2409 | (line (if (looking-at "\\(?:\\*\\{15\\}.*\n\\)?[-@* ]*\\([0-9,]+\\)\\([ acd+]+\\([0-9,]+\\)\\)?") | 2411 | (line (if (looking-at "\\(?:\\*\\{15\\}.*\n\\)?[-@* ]*\\([0-9,]+\\)\\([ acd+]+\\([0-9,]+\\)\\)?") |
| 2410 | (if old (match-string 1) | 2412 | (if old (match-string 1) |
| @@ -2431,7 +2433,7 @@ When OLD is non-nil, highlight the hunk from the old source." | |||
| 2431 | (setq props (diff-syntax-fontify-props nil text line-nb t))) | 2433 | (setq props (diff-syntax-fontify-props nil text line-nb t))) |
| 2432 | ;; Get properties from the file | 2434 | ;; Get properties from the file |
| 2433 | (with-temp-buffer | 2435 | (with-temp-buffer |
| 2434 | (insert-file-contents file t) | 2436 | (insert-file-contents file) |
| 2435 | (setq props (diff-syntax-fontify-props file text line-nb))))) | 2437 | (setq props (diff-syntax-fontify-props file text line-nb))))) |
| 2436 | ;; Get properties from a cached revision | 2438 | ;; Get properties from a cached revision |
| 2437 | (let* ((buffer-name (format " *diff-syntax:%s.~%s~*" | 2439 | (let* ((buffer-name (format " *diff-syntax:%s.~%s~*" |
| @@ -2459,7 +2461,7 @@ When OLD is non-nil, highlight the hunk from the old source." | |||
| 2459 | (if (and file (file-exists-p file) (file-regular-p file)) | 2461 | (if (and file (file-exists-p file) (file-regular-p file)) |
| 2460 | ;; Try to get full text from the file | 2462 | ;; Try to get full text from the file |
| 2461 | (with-temp-buffer | 2463 | (with-temp-buffer |
| 2462 | (insert-file-contents file t) | 2464 | (insert-file-contents file) |
| 2463 | (setq props (diff-syntax-fontify-props file text line-nb))) | 2465 | (setq props (diff-syntax-fontify-props file text line-nb))) |
| 2464 | ;; Otherwise, get properties from the hunk alone | 2466 | ;; Otherwise, get properties from the hunk alone |
| 2465 | (with-temp-buffer | 2467 | (with-temp-buffer |