Skip to content

Instantly share code, notes, and snippets.

@liuyinz
Last active October 19, 2021 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liuyinz/b30e967879da225d18ad57e5d87391ac to your computer and use it in GitHub Desktop.
Save liuyinz/b30e967879da225d18ad57e5d87391ac to your computer and use it in GitHub Desktop.
emacsclient as mergetool
[diff]
tool = edf
ignoreSubmodules = untracked
[difftool]
prompt = false
[difftool "edf"]
cmd = edf "$LOCAL" "$REMOTE"
[mergetool]
keepBackup = false
prompt = false
[merge]
tool = edf
conflictStyle = diff3
[mergetool "edf"]
cmd = edf "$MERGED"
#!/usr/bin/env bash
# SEE https://github.com/liuyinz/dotfile/tree/master/common/bin
# used for diff and merge tool
emacsclient -u -e '(server-running-p)' 2>/dev/null || emacs --daemon
case "${#}" in
1)
MERGED=${1}
EVAL="find-file \"${MERGED}\""
;;
2)
LOCAL=${1}
REMOTE=${2}
EVAL="ediff-files \"${LOCAL}\" \"${REMOTE}\""
;;
3)
LOCAL=${1}
REMOTE=${2}
MERGED=${3}
EVAL="ediff-merge-files \"${LOCAL}\" \"${REMOTE}\" nil \"${MERGED}\""
;;
4)
LOCAL=${1}
REMOTE=${2}
MERGED=${3}
BASE=${4}
EVAL="ediff-merge-files-with-ancestor \"${LOCAL}\" \"${REMOTE}\" \"${BASE}\" nil \"${MERGED}\""
;;
esac
emacsclient -q -t -e "(${EVAL})" 2>&1
;; Add code below in init.el to work with et,ec,ecc scripts
(add-hook 'after-init-hook (lambda ()
(require 'server)
(unless (or (daemonp) (server-running-p))
(server-start))))
;; smerge settings
(add-hook 'smerge-mode-hook #'smerge-first)
(setq smerge-command-prefix ""
smerge-change-buffer-confirm nil
smerge-refine-ignore-whitespace nil)
(defun smerge-first ()
"Jump to first conflict in the buffer."
(interactive)
(goto-char (point-min))
(unless (looking-at smerge-begin-re)
(smerge-next)))
(defun smerge-last ()
"Jump to first conflict in the buffer."
(interactive)
(goto-char (point-max))
(smerge-prev))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment