How can I display changed line in Emacs?

浪尽此生 提交于 2019-12-11 03:47:17

问题


Some text editors can display changed line by default. But in Emacs, how?


回答1:


The minor mode highlight-changes-mode displays text changes.

ADDITION: I wrote some code of fringe support for highlight-changes-mode.

(eval-after-load "hilit-chg"
  '(progn
     (defvar highlight-fringe-mark 'filled-square
       "The fringe bitmap name marked at changed line.
Should be selected from `fringe-bitmaps'.")

     (defadvice hilit-chg-make-ov (after hilit-chg-add-fringe activate)
       (mapc (lambda (ov)
           (if (overlay-get ov 'hilit-chg)
           (let ((fringe-anchor (make-string 1 ?x)))
             (put-text-property 0 1 'display
                    (list 'left-fringe highlight-fringe-mark)
                    fringe-anchor)
             (overlay-put ov 'before-string fringe-anchor))
         ))
         (overlays-at (ad-get-arg 1))))))


(source: gyazo.com)

ADDITION: To remove highlights on save time, try it:

(add-hook 'after-save-hook
          (lambda ()
            (when highlight-changes-mode
              (save-restriction
                (widen)
                (highlight-changes-remove-highlight (point-min) (point-max))))))



回答2:


I assume you're interested in changes between the buffer and the saved file. I usually use diff-buffer-with-file for that, because I don't need it too often.


I also use diff-hl mode, which shows changed lines of the saved file vs. the last commit in a version control system. It's available in Melpa.

Here's my config, which changes the indicators to '+', '-', and '!':

(setq diff-hl-fringe-bmp-function 'diff-hl-fringe-bmp-from-type)
(global-diff-hl-mode 1)

Though you didn't ask about it, I'll also mention that vc can easily diff files that are under version control with C-x v = (current file) or C-x v D (entire project).



来源:https://stackoverflow.com/questions/21084023/how-can-i-display-changed-line-in-emacs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!