Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support encodings incompatible with emacs default #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 44 additions & 31 deletions git-gutter.el
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,12 @@ Argument TEST is the case before BODY execution."
"bzr" "diff" "--context=0" args)))

(defun git-gutter:start-diff-process1 (file proc-buf)
(cl-case git-gutter:vcs-type
(git (git-gutter:start-git-diff-process file proc-buf))
(svn (git-gutter:start-svn-diff-process file proc-buf))
(hg (git-gutter:start-hg-diff-process file proc-buf))
(bzr (git-gutter:start-bzr-diff-process file proc-buf))))
(let ((coding-system-for-read buffer-file-coding-system))
(cl-case git-gutter:vcs-type
(git (git-gutter:start-git-diff-process file proc-buf))
(svn (git-gutter:start-svn-diff-process file proc-buf))
(hg (git-gutter:start-hg-diff-process file proc-buf))
(bzr (git-gutter:start-bzr-diff-process file proc-buf)))))

(defun git-gutter:start-diff-process (curfile proc-buf)
(let ((file (git-gutter:base-file)) ;; for tramp
Expand Down Expand Up @@ -833,9 +834,13 @@ Argument TEST is the case before BODY execution."
(let ((content (git-gutter-hunk-content diff-info))
(type (git-gutter-hunk-type diff-info))
(header (git-gutter:extract-hunk-header))
(patch (make-temp-name "git-gutter")))
(patch (make-temp-name "git-gutter"))
(coding buffer-file-coding-system))
(when header
(with-temp-file patch
;; patch must match target file encoding, but unix eols are mandatory
(setq buffer-file-coding-system
(coding-system-change-eol-conversion coding 'unix))
(insert header)
(git-gutter:insert-staging-hunk content type))
(let ((dir-option (git-gutter:apply-directory-option))
Expand Down Expand Up @@ -868,16 +873,18 @@ Argument TEST is the case before BODY execution."
(push-mark end nil t))))

(defun git-gutter:update-popuped-buffer (diffinfo)
(with-current-buffer (get-buffer-create git-gutter:popup-buffer)
(view-mode -1)
(setq buffer-read-only nil)
(erase-buffer)
(insert (git-gutter-hunk-content diffinfo))
(insert "\n")
(goto-char (point-min))
(diff-mode)
(view-mode +1)
(current-buffer)))
(let ((coding buffer-file-coding-system))
(with-current-buffer (get-buffer-create git-gutter:popup-buffer)
(setq buffer-file-coding-system (coding-system-base coding))
(view-mode -1)
(setq buffer-read-only nil)
(erase-buffer)
(insert (git-gutter-hunk-content diffinfo))
(insert "\n")
(goto-char (point-min))
(diff-mode)
(view-mode +1)
(current-buffer))))

(defun git-gutter:popup-hunk (&optional diffinfo)
"Popup current diff hunk."
Expand Down Expand Up @@ -1043,30 +1050,36 @@ start revision."
(setq git-gutter:update-timer nil))

(defsubst git-gutter:write-current-content (tmpfile)
(let ((content (buffer-substring-no-properties (point-min) (point-max))))
(let ((content (buffer-substring-no-properties (point-min) (point-max)))
(coding buffer-file-coding-system))
(with-temp-file tmpfile
(setq buffer-file-coding-system coding)
(insert content))))

(defun git-gutter:original-file-content (file vcs)
(with-temp-buffer
(cl-case vcs
(git
(when (zerop (process-file "git" nil t nil "show" (concat ":" file)))
(buffer-substring-no-properties (point-min) (point-max))))
((svn hg bzr)
(let ((command (symbol-name vcs)))
(when (zerop (process-file command nil t nil "cat" file))
(buffer-substring-no-properties (point-min) (point-max))))))))
(let ((coding-system-for-read (coding-system-base buffer-file-coding-system)))
(with-temp-buffer
(cl-case vcs
(git
(when (zerop (process-file "git" nil t nil "show" (concat ":" file)))
(buffer-substring-no-properties (point-min) (point-max))))
((svn hg bzr)
(let ((command (symbol-name vcs)))
(when (zerop (process-file command nil t nil "cat" file))
(buffer-substring-no-properties (point-min) (point-max)))))))))

(defun git-gutter:write-original-content (tmpfile filename)
(git-gutter:awhen (git-gutter:original-file-content filename git-gutter:vcs-type)
(with-temp-file tmpfile
(insert it)
t)))
(let ((coding buffer-file-coding-system))
(with-temp-file tmpfile
(setq buffer-file-coding-system coding)
(insert it)
t))))

(defsubst git-gutter:start-raw-diff-process (proc-buf original now)
(start-file-process "git-gutter:update-timer" proc-buf
"diff" "-U0" original now))
(let ((coding-system-for-read buffer-file-coding-system))
(start-file-process "git-gutter:update-timer" proc-buf
"diff" "-U0" original now)))

(defun git-gutter:start-live-update (file original now)
(let ((proc-bufname (git-gutter:diff-process-buffer file)))
Expand Down