开发者

P4CONFIG with emacs

I would like to see examples of how to setup perforce, using the config file functionality where emacs is used as the diff and merge programs (P4DIFF and P4MERGE settings). Even better if this is on Windows.

I'm also struggling with getting the P4EDITOR to work correctly whe开发者_运维技巧n using emacsclientw, specifically specifying the alternate-editor functionality.

Any tips, suggestions, example configs are very welcome.


Here's a different trick I used to use. It adds a few command line options to emacs so that you can do diffs and merges in a new emacs instance (again using ediff).

;; -diff
(defun command-line-diff (switch)
  (let ((file1 (pop command-line-args-left))
        (file2 (pop command-line-args-left)))
    (ediff file1 file2)))
(add-to-list 'command-switch-alist '("-diff" . command-line-diff))

;; -merge
(defun command-line-merge (switch)
  (let ((base (pop command-line-args-left))
        (sccs (pop command-line-args-left))
        (mine (pop command-line-args-left))
        (merg (pop command-line-args-left)))
   (ediff-merge-with-ancestor sccs mine base () merg)))
(add-to-list 'command-switch-alist '("-merge" . command-line-merge))

Just put that in your .emacs file. Then you can set your P4DIFF program to be emacs -diff and your P4MERGE program to be emacs -merge.


I'm assuming you're already using p4.el.

Here's a function that will allow you to set your p4-client-config easily:

(defun p4-go (config)
  (interactive
   (list (read-file-name "P4 Config file: "
                         (concat (getenv "HOME") "/etc/perforce/")
                         ""
                         t)))
  (p4-set-client-config (expand-file-name config))
  t)

Then I just run M-x p4-go <RET> conf <RET>.

My ~/etc/perforce/conf file looks like:

P4CLIENT=ewarmenhoven-ppd
P4PORT=perforce.netflix.com:1666
P4USER=ewarmenhoven

P4EDITOR=emacsclient
P4DIFF=diff -dupU8
P4MERGE=~/bin/emerge

The emerge merge program is just a short little shell script that calls emacsclient appropriately:

#!/bin/bash

base=$1 sccs=$2 mine=$3 merg=$4

emacsclient -e "(ediff-merge-files-with-ancestor \"$base\" \"$sccs\" \"$mine\" () \"$merg\")" emacsclient "$merg"

If you're using cygwin it should work just fine.

For doing diffs, if it's running from the shell then I want the output in the shell, hence just using normal diff. If it's not, I use p4-ediff, which is bound to C-x p - by default.


The awesome answer by Eric doesn't work properly in latest emacs because of welcome screen. In order to hide the welcome screen (so that you may get the diff properly) please refer Unable to hide welcome screen in Emacs.

Another nifty setting which opens the diff in regular vertical mode is setting the below config variable

(custom-set-variables
  ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 '(ediff-split-window-function (quote split-window-horizontally)))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜