Function: diff--font-lock-prettify

diff--font-lock-prettify is a byte-compiled function defined in diff-mode.el.gz.

Signature

(diff--font-lock-prettify LIMIT)

Source Code

;; Defined in /usr/src/emacs/lisp/vc/diff-mode.el.gz
(defun diff--font-lock-prettify (limit)
  (when diff-font-lock-prettify
    (save-excursion
      ;; FIXME: Include the first space for context-style hunks!
      (while (re-search-forward "^[-+! ]" limit t)
        (let ((spec (alist-get (char-before)
                               '((?+ . (left-fringe diff-fringe-add diff-indicator-added))
                                 (?- . (left-fringe diff-fringe-del diff-indicator-removed))
                                 (?! . (left-fringe diff-fringe-rep diff-indicator-changed))
                                 (?\s . (left-fringe diff-fringe-nul fringe))))))
          (put-text-property (match-beginning 0) (match-end 0) 'display spec))))
    ;; Mimicks the output of Magit's diff.
    ;; FIXME: This has only been tested with Git's diff output.
    (while (re-search-forward "^diff " limit t)
      ;; FIXME: Switching between context<->unified leads to messed up
      ;; file headers by cutting the `display' property in chunks!
      (when (save-excursion
              (forward-line 0)
              (looking-at
               (eval-when-compile
                 (concat "diff.*\n"
                         "\\(?:\\(?:new file\\|deleted\\).*\n\\)?"
                         "\\(?:index.*\n\\)?"
                         "--- \\(?:" null-device "\\|a/\\(.*\\)\\)\n"
                         "\\+\\+\\+ \\(?:" null-device "\\|b/\\(.*\\)\\)\n"))))
        (put-text-property (match-beginning 0)
                           (or (match-beginning 2) (match-beginning 1))
                           'display (propertize
                                     (cond
                                      ((null (match-beginning 1)) "new file  ")
                                      ((null (match-beginning 2)) "deleted   ")
                                      (t                          "modified  "))
                                     'face '(diff-file-header diff-header)))
        (unless (match-beginning 2)
          (put-text-property (match-end 1) (1- (match-end 0))
                             'display "")))))
  nil)