Wednesday, June 25, 2014

Perforce Edit and Revert in Emacs

I found this snippet of Elisp to be helpful for the most basic of Perforce operations:

(defun p4-edit ()
  "Open the file for edit"
  (interactive)
  (let ((retval (call-process "p4" nil nil nil "edit" buffer-file-name)))
    (if (eql 0 retval)
    (setq buffer-read-only nil)
      (error "Perforce edit failed"))))

(defun p4-revert ()
  "Revert the file"
  (interactive)
  (let ((retval (call-process "p4" nil nil nil "revert" buffer-file-name)))
    (if (eql 0 retval)
    (revert-buffer t t)
      (error "Perforce revert failed"))))