Function: majutsu-diff--update-hunk-syntax

majutsu-diff--update-hunk-syntax is a natively compiled function defined in majutsu-diff.el.

Signature

(majutsu-diff--update-hunk-syntax &optional SECTION)

Documentation

Apply syntax highlighting overlays to hunk SECTION.

When SECTION is nil, walk all hunk sections.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-diff.el
;;; Syntax highlighting

(defun majutsu-diff--update-hunk-syntax (&optional section)
  "Apply syntax highlighting overlays to hunk SECTION.
When SECTION is nil, walk all hunk sections."
  (if section
      (when (and (not (oref section hidden))
                 (not (oref section fontified))
                 (fboundp 'diff-syntax-fontify-props)
                 (fboundp 'diff-hunk-text)
                 (not (eq majutsu-diff-backend 'color-words)))
        (oset section fontified t)
        (save-excursion
          (goto-char (oref section content))
          (let* ((file (magit-section-parent-value section))
                 (revs (majutsu-diff--revisions))
                 (old (majutsu-diff--get-hunk-syntax section (car revs) file t))
                 (new (majutsu-diff--get-hunk-syntax
                       section
                       (if (majutsu-diff--visit-workspace-p) nil (cdr revs))
                       file nil)))
            (while (< (point) (oref section end))
              (pcase-dolist (`(,beg ,end ,face)
                             (pcase (char-after)
                               (?- (pop old))
                               (?+ (pop new))
                               (?\s (pop old)
                                    (pop new))))
                (let ((ov (make-overlay (+ (point) 1 beg)
                                        (+ (point) 1 end)
                                        nil t)))
                  (overlay-put ov 'evaporate t)
                  (overlay-put ov 'face face)
                  (overlay-put ov 'majutsu-diff-syntax t)))
              (forward-line 1)))))
    (cl-labels ((walk (node)
                  (if (magit-section-match 'jj-hunk node)
                      (majutsu-diff--update-hunk-syntax node)
                    (dolist (child (oref node children))
                      (walk child)))))
      (walk magit-root-section))))