[Upgrade to newest darcsum clinton@unknownlamer.org**20080707182325] { hunk ./site-lisp/darcsum.el 50 -;; Changes can be removed with "r". Move changes between buffers with -;; "M", which prompts for a darcsum buffer to move to (creating one if -;; the buffer doesn't exist). +;; Move changes between buffers with "M", which prompts for a darcsum +;; buffer to move to (creating one if the buffer doesn't exist). hunk ./site-lisp/darcsum.el 65 -;; - Warn users of empty changesets before darcs does hunk ./site-lisp/darcsum.el 66 -;; - Interface to darcs changes -;; - Changes from "replace" aren't shown hunk ./site-lisp/darcsum.el 88 +(defvar darcsum-show-context nil) +(defvar darcsum-pre-ediff-window-configuration nil) +(defvar darcsum-subdirectory ".") + +;; Make buffer-local variable storing old window configuration, +;; since "let" bindings die before ediff buffers are killed +(make-variable-buffer-local 'darcsum-pre-ediff-window-configuration) hunk ./site-lisp/darcsum.el 146 +(defface darcsum-whitespace-ateol-face + '((((class color) (background dark)) + (:background "red4")) + (((class color) (background light)) + (:background "red1"))) + "Face used to highlight whitespace at end of line." + :group 'darcsum) + hunk ./site-lisp/darcsum.el 170 -;; ((DIR (FILE (LINE CHANGE...)))) +;; ((PATH (TYPE SELECTED CONTENT...)))) hunk ./site-lisp/darcsum.el 172 -;; Where DIR and FILE are plain strings, but LINE is of the following +;; where PATH is plain string, but TYPE is of the following hunk ./site-lisp/darcsum.el 176 -;; -LINE Integer line of hunk, but hunk is not "visible" -;; (LINE) Integer line of hunk, but hunk is "marked" hunk ./site-lisp/darcsum.el 177 -;; -SYMBOL Non-hunk change, but change is not "visible" -;; (SYMBOL) Non-hunk change, but change is "marked" hunk ./site-lisp/darcsum.el 178 -;; Each CHANGE is a string which represents a modification to make to -;; the file after the starting LINE. It begins with either a "+" or -;; "-" to indicate if the line should be removed or added to the file. +;; SELECTED is a list of flags, 'mark or 'hide symbols. +;; +;; Each CONTENT is a string which represents a modification to make to the +;; file after the starting line. For hunks, each change begins with either a +;; "+" or "-" to indicate if the line should be removed or added to the +;; file. hunk ./site-lisp/darcsum.el 185 -;; So, for example, in a buffer with no changes visible or marked yet: +;; So, for example, in a buffer with changes visible in report.cc visible +;; and changes in report.h marked: +;; +;; (("./TODO" (addfile (hide))) +;; ("./report.cc" +;; (replace nil "[A-Za-z_0-9] indented intended") +;; (606 nil "- blah" "+ blah" "+ blah") +;; (620 nil "- blah" "+ blah" "+ blah") +;; (629 nil "- blah" "+ blah" "+ blah") +;; (634 nil "- blah" "+ blah" "+ blah") +;; (641 nil "- blah" "+ blah" "+ blah") +;; (652 nil "- blah" "+ blah" "+ blah") +;; (664 nil "- blah" "+ blah" "+ blah")) +;; ("./report.h" +;; (115 (mark) "- blah" "+ blah" "+ blah") +;; (126 (mark) "+")))) hunk ./site-lisp/darcsum.el 202 -;; (("." -;; ("TODO" (addfile)) -;; ("report.cc" (-replace "[A-Za-z_0-9] indented intended")) -;; ("report.cc" -;; (-606 "- blah" "+ blah" "+ blah") -;; (-620 "- blah" "+ blah" "+ blah") -;; (-629 "- blah" "+ blah" "+ blah") -;; (-634 "- blah" "+ blah" "+ blah") -;; (-641 "- blah" "+ blah" "+ blah") -;; (-652 "- blah" "+ blah" "+ blah") -;; (-664 "- blah" "+ blah" "+ blah")) -;; ("report.h" -;; (-115 "- blah" "+ blah" "+ blah") -;; (-126 "+")))) hunk ./site-lisp/darcsum.el 203 -(defconst darcsum-invisible-item-alist - '((-replace . replace) - (-addfile . addfile) - (-newfile . newfile) - (-rmfile . rmfile) - (-binary . binary))) +(defun darcsum-change-add-flag (change flag) + "Add FLAG on CHANGE." + (if (not (memq flag (cadr change))) + (setcar (cdr change) (cons flag (cadr change))))) hunk ./site-lisp/darcsum.el 208 -(defun darcsum-item-visible-p (item) - "Is ITEM visible? -Everything but negative numbers and invisible symbols are visible." - (if (numberp item) (<= 0 item) - (not (assq item darcsum-invisible-item-alist)))) +(defun darcsum-change-remove-flag (change flag) + "Remove FLAG on CHANGE." + (if (memq flag (cadr change)) + (setcar (cdr change) (delq flag (cadr change))))) hunk ./site-lisp/darcsum.el 213 -(defun darcsum-visible-item (item) - "Convert ITEM to visible." - (let (a) - (cond - ((numberp item) (abs item)) - ((setq a (assq item darcsum-invisible-item-alist)) (cdr a)) - (t item)))) +(defun darcsum-change-remove-all-flags (change) + "Remove all flags on CHANGE." + (setcar (cdr change) nil)) hunk ./site-lisp/darcsum.el 217 -(defun darcsum-invisible-item (item) - "Convert ITEM to invisible." - (let (a) - (cond - ((numberp item) (- (abs item))) - ((setq a (rassq item darcsum-invisible-item-alist)) (car a)) - (t item)))) +(defun darcsum-change-toggle-flag (change flag) + "Toggle FLAG on CHANGE." + (if (memq flag (cadr change)) + (setcar (cdr change) (delq flag (cadr change))) + (setcar (cdr change) (cons flag (cadr change))))) hunk ./site-lisp/darcsum.el 223 -(defun darcsum-toggle-item (item) - "Mark visible change ITEM as invisible and vice versa." - (let (a) - (cond - ((numberp item) (- item)) - ((setq a (assq item darcsum-invisible-item-alist)) (cdr a)) - ((setq a (rassq item darcsum-invisible-item-alist)) (car a)) - (t item)))) +(defun darcsum-change-mark-p (change) + "Return mark if CHANGE is marked." + (not (null (memq 'mark (cadr change))))) hunk ./site-lisp/darcsum.el 227 -(defconst darcsum-item-status-alist - '((addfile . "Added") - (newfile . "New") - (rmfile . "Removed") - (binary . "Modified binary"))) +(defun darcsum-change-unmark-p (change) + "Return mark if CHANGE is not marked." + (null (memq 'mark (cadr change)))) hunk ./site-lisp/darcsum.el 231 -(defun darcsum-item-status (item) - "Return file-status displayed with ITEM." - (cdr (assq (darcsum-visible-item item) darcsum-item-status-alist))) +(defun darcsum-change-toggle-mark (change) + "Toggle mark flag on CHANGE." + (darcsum-change-toggle-flag change 'mark)) hunk ./site-lisp/darcsum.el 235 -(eval-and-compile - (if (fboundp 'make-temp-file) - (defalias 'darcsum-make-temp-file 'make-temp-file) - ;; make-temp-name generates a unique name when it is called, but - ;; takes no provisions to ensure that it will remain unique. Thus, - ;; there is a race condition before we use the name. This is - ;; probably a bad thing. - (defalias 'darcsum-make-temp-file 'make-temp-name))) +(defun darcsum-change-add-mark (change) + "Add mark flag on CHANGE." + (darcsum-change-add-flag change 'mark)) hunk ./site-lisp/darcsum.el 239 -(defsubst darcsum-change-item (change) - (if (listp (car change)) - (caar change) - (car change))) +(defun darcsum-change-remove-mark (change) + "Remove mark flag on CHANGE." + (darcsum-change-remove-flag change 'mark)) hunk ./site-lisp/darcsum.el 243 -(defsubst darcsum-change-line (change) - (let ((ch (darcsum-change-item change))) - (if (symbolp ch) - 1 - ch))) +(defun darcsum-change-visible-p (change) + "Return t if CHANGE is visible." + (not (memq 'hide (cadr change)))) hunk ./site-lisp/darcsum.el 247 -(defun darcsum-applicable-p (data predicate) - (catch 'exit - (ignore - (let (dir file change) - (dolist (dir data) - (dolist (file (cdr dir)) - (dolist (change (cdr file)) - (if (funcall predicate (car dir) (car file) change) - (throw 'exit t))))))))) +(defun darcsum-change-toggle-hide (change) + "Toggle hide flag on CHANGE." + (darcsum-change-toggle-flag change 'hide)) hunk ./site-lisp/darcsum.el 251 -(defsubst darcsum-marked-p (data) - (darcsum-applicable-p data (function - (lambda (dir file change) - (listp (car change)))))) +(defun darcsum-change-add-hide (change) + "Add hide flag on CHANGE." + (darcsum-change-add-flag change 'hide)) hunk ./site-lisp/darcsum.el 255 -(defsubst darcsum-changeset-has-change-p (data odir ofile start-line replace) - (darcsum-applicable-p - data (function - (lambda (d f change) - (and (equal odir d) - (equal ofile f) - (eq start-line (darcsum-change-item change)) - (darcsum-item-visible-p (darcsum-change-item change)) - (or (not (eq start-line 'replace)) - (equal (cadr change) replace))))))) +(defun darcsum-change-remove-hide (change) + "Add hide flag on CHANGE." + (darcsum-change-remove-flag change 'hide)) hunk ./site-lisp/darcsum.el 259 -(defun darcsum-changeset-has-directory-p (changeset name) +(defun darcsum-changeset-any-p (changeset predicate) + "Return t if PREDICATE is true for any change in CHANGESET." hunk ./site-lisp/darcsum.el 263 - (let (dir) - (dolist (dir changeset) - (if (string= name (car dir)) - (throw 'exit t))))))) + (let (file change) + (dolist (file changeset) + (dolist (change (cdr file)) + (if (funcall predicate change) + (throw 'exit t)))))))) hunk ./site-lisp/darcsum.el 269 -(defun darcsum-find-changeset (data predicate) - (let (dir file change changeset) - (dolist (dir data) - (dolist (file (cdr dir)) - (dolist (change (cdr file)) - (if (funcall predicate (car dir) (car file) change) - (setq changeset - (darcsum-add-changeset - changeset - (list (list (car dir) (list (car file) change))))))))) - changeset)) +(defsubst darcsum-changeset-any-marked-p (changeset) + "Return t if CHANGESET has change(s) which have been marked." + (darcsum-changeset-any-p changeset (function darcsum-change-mark-p))) hunk ./site-lisp/darcsum.el 273 -(defun darcsum-apply-to-changeset (data func) - (let (dir file change) - (dolist (dir data) - (dolist (file (cdr dir)) +(defsubst darcsum-changeset-any-unmarked-p (changeset) + "Return t if CHANGESET has change(s) which have not been marked." + (darcsum-changeset-any-p changeset (function darcsum-change-unmark-p))) + +(defsubst darcsum-changeset-any-visible-p (changeset) + "Return t if CHANGESET has change(s) which are visible." + (darcsum-changeset-any-p changeset (function darcsum-change-visible-p))) + +(defun darcsum-changeset-all-p (changeset predicate) + "Return t if PREDICATE is true for all change in CHANGESET." + (not (catch 'exit + (ignore + (let (file change) + (dolist (file changeset) + (dolist (change (cdr file)) + (if (not (funcall predicate change)) + (throw 'exit t))))))))) + +(defsubst darcsum-changeset-all-marked-p (changeset) + "Return t if all changes in CHANGESET have been marked." + (darcsum-changeset-all-p changeset (function darcsum-change-mark-p))) + +(defsubst darcsum-changeset-all-visible-p (changeset) + "Return t if all changes in CHANGESET are visible." + (darcsum-changeset-all-p changeset (function darcsum-change-visible-p))) + +(defun darcsum-changeset-find (changeset predicate) + "Return changes selected by PREDICATE from CHANGESET." + (let (file change found) + (dolist (file changeset) + (let (changes) hunk ./site-lisp/darcsum.el 305 - (funcall func (car dir) (car file) change)))))) + (if (funcall predicate change) + (setq changes (cons change changes)))) + (if changes + (setq changes (cons (car file) (nreverse changes)) + found (cons changes found))))) + (nreverse found))) + +(defun darcsum-changeset-find-visible (changeset) + "Return visible changes from CHANGESET." + (darcsum-changeset-find changeset (function darcsum-change-visible-p))) + +(defun darcsum-changeset-find-marked (changeset) + "Return marked changes from CHANGESET." + (darcsum-changeset-find changeset (function darcsum-change-mark-p))) + +(defsubst darcsum-find-change (changeset file line content) + ;; Return change in CHANGESET with matching FILE, LINE and CONTENT. + ;; If CONTENT is 'any, it is ignored. + (let ((change (assoc line (assoc file changeset)))) + (if (or (eq content 'any) + (equal (caddr change) content)) + change))) + +(defconst darcsum-file-change-status-alist + '((addfile . "Added") + (adddir . "Added directory") + (newfile . "New") + (newdir . "New directory") + (rmfile . "Removed") + (rmdir . "Removed directory") + (binary . "Modified binary"))) + +(defun darcsum-file-change-status (change) + "Return file-change-status displayed with CHANGE." + (cdr (assq (car change) darcsum-file-change-status-alist))) + +(defun darcsum-make-temp-file (&optional template) + "Create temporary file. Optional argument TEMPLATE sets the base name. + +The template, if present, is passed to `expand-file-name' to construct a +fully qualified base name. If absent, the string \"_darcs\" is used. + +The function `make-temp-file' is preferred, but if it is not available, +`make-temp-name' is used as a fallback." + (unless template + (setq template "darcsum")) + (unless (file-name-absolute-p template) + (setq template (expand-file-name template "_darcs"))) + (if (fboundp 'make-temp-file) + (make-temp-file template) + ;; make-temp-name generates a unique name when it is called, but + ;; takes no provisions to ensure that it will remain unique. Thus, + ;; there is a race condition before we use the name. This is + ;; probably a bad thing. + (make-temp-name template))) + +(defun darcsum-changeset-has-directory-p (changeset dir) + (and (assoc dir changeset) t)) + +(defun darcsum-apply-to-changes (data func) + (let (file change) + (dolist (file data) + (dolist (change (cdr file)) + (funcall func change))))) hunk ./site-lisp/darcsum.el 370 -(defun darcsum-remove-changeset (data changeset) - "Remove DATA from the current CHANGESET." - (let (dir file change) - (dolist (dir changeset) - (dolist (file (cdr dir)) +(defun darcsum-remove-changeset (changeset remove) + "Remove REMOVE from the CHANGESET." + (let (file change) + (dolist (file remove) + (let ((fentry (assoc (car file) changeset))) hunk ./site-lisp/darcsum.el 376 - (let* ((dentry (assoc (car dir) data)) - (fentry (assoc (car file) (cdr dentry)))) - (setcdr fentry (delete (assoc (car change) (cdr fentry)) - (cdr fentry))) - (unless (cdr fentry) - (setcdr dentry (delete fentry (cdr dentry)))) - (unless (cdr dentry) - (setq data (delete dentry data)))))))) - data) + (setcdr fentry (delete (assoc (car change) (cdr fentry)) + (cdr fentry)))) + (unless (cdr fentry) + (setq changeset (delete fentry changeset)))))) + changeset) hunk ./site-lisp/darcsum.el 383 - '((addfile . 0) - (newfile . 0) - (rmfile . 0) + '((move . -2) + (addfile . -1) + (adddir . -1) + (newfile . -1) + (newdir . -1) + (rmfile . -1) + (rmdir . -1) hunk ./site-lisp/darcsum.el 391 - (replace . 999999))) + (replace . 0))) hunk ./site-lisp/darcsum.el 395 - l (if (listp l) (car l) l) - l (darcsum-visible-item l) - l (or (cdr (assq l darcsum-item-numeric-alist)) l)) - (setq r (car r) - r (if (listp r) (car r) r) - r (darcsum-visible-item r) - r (or (cdr (assq r darcsum-item-numeric-alist)) r)) - (< l r)) + r (car r)) + (< (if (numberp l) l (or (cdr (assq l darcsum-item-numeric-alist)) 0)) + (if (numberp r) r (or (cdr (assq r darcsum-item-numeric-alist)) 0)))) hunk ./site-lisp/darcsum.el 399 -(defun darcsum-add-changeset (data changeset) - "Add DATA to the current CHANGESET." - (let (dir file change) - (dolist (dir changeset) - (dolist (file (cdr dir)) - (dolist (change (cdr file)) - (let ((dentry (assoc (car dir) data))) - (if dentry - (let ((fentry (assoc (car file) dentry))) - (if fentry - (unless (member change (cdr fentry)) - (nconc fentry (list change)) - (setcdr fentry - (sort (cdr fentry) - (function darcsum-change-<)))) - (nconc dentry (list (list (car file) change))))) - (setq data (cons (list (car dir) - (list (car file) change)) - data)))))))) - data) +(defun darcsum-add-changeset (changeset add) + "Add ADD to CHANGESET." + (let (file fentry change) + (dolist (file add) + (if (setq fentry (assoc (car file) changeset)) + (progn + (dolist (change (cdr file)) + (unless (member change (cdr fentry)) + (nconc fentry (list change)))) + (setcdr fentry (sort (cdr fentry) (function darcsum-change-<)))) + (setq changeset (cons file changeset))))) + (sort changeset)) hunk ./site-lisp/darcsum.el 413 - "Merge DATA into the current CHANGESET." - (let (dir file change final-data) - (dolist (dir changeset) - (dolist (file (cdr dir)) - (dolist (change (cdr file)) - (let ((dentry (assoc (car dir) data))) - (if dentry - (let ((fentry (assoc (car file) dentry)) - (item (darcsum-change-item change))) - (if fentry - (unless - (or (assoc item (cdr fentry)) - (assoc (darcsum-toggle-item item) (cdr fentry)) - (assoc (list item) (cdr fentry))) - (nconc fentry (list change)) - (setcdr fentry - (sort (cdr fentry) - (function darcsum-change-<)))) - (nconc dentry (list (list (car file) change))))) - (setq data (cons (list (car dir) - (list (car file) change)) - data))))))) - (dolist (dir data) - (dolist (file (cdr dir)) - (dolist (change (cdr file)) - (let* ((dentry (assoc (car dir) changeset)) - (fentry (assoc (car file) dentry)) - (item (darcsum-change-item change)) - final-dentry final-fentry) - (when (and dentry fentry - (or (assoc item (cdr fentry)) - (assoc (darcsum-toggle-item item) (cdr fentry)) - (assoc (list item) (cdr fentry)))) - (unless (setq final-dentry (assoc (car dir) final-data)) - (setq final-data (cons (list (car dir)) final-data) - final-dentry (assoc (car dir) final-data))) - (unless (setq final-fentry (assoc (car file) final-dentry)) - (nconc final-dentry (list (list (car file)))) - (setq final-fentry (assoc (car file) final-dentry))) - (nconc final-fentry (list change))))))) - (nreverse final-data))) + "Merge CHANGESET into the DATA. + +Currently this simply moves 'mark and 'hide from DATA to CHANGESET." + ;;;;;;; TODO: commute new patches + ;;;;;;; (iow, behave properly if lines are added or deleted) + (let (file data-file change data-change) + (dolist (file changeset) + (if (setq data-file (assoc (car file) data)) + (dolist (change (cdr file)) + (let ((data-change (assoc (car change) data-file)) + (item (car data-change))) + (if (cond + ((null item)) + ((eq item 'replace) (equal (cddr change) (cddr data-change))) + ((numberp item) (darcsum-hunk-match (cddr change) (cddr data-change))) + (t t)) + (setcar (cdr change) (car (cdr data-change))))))))) + changeset) + +(defun darcsum-hunk-match (a b) + "Return t if hunks in A and B match (modify same lines)." + (if (equal a b) + t + (while (string-match "^ " (car a)) (setq a (cdr a))) + (while (string-match "^ " (car b)) (setq b (cdr b))) + (while (and a b (string= (car a) (car b))) + (setq a (cdr a) b (cdr b))) + (if (or (null a) (null b) + (string-match "^[+]" (car a)) + (string-match "^[+]" (car b))) + t))) hunk ./site-lisp/darcsum.el 447 - (forward-line) + (when (looking-at "^{") + (forward-line)) hunk ./site-lisp/darcsum.el 450 - data entries) + data change entry) hunk ./site-lisp/darcsum.el 452 - (> limit 0)) + (> limit 0)) hunk ./site-lisp/darcsum.el 455 - ((looking-at "^adddir\\s-+\\(.+?\\)$") - (forward-line)) - ((looking-at "^rmdir\\s-+\\(.+?\\)$") - (forward-line)) - ((looking-at "^move\\s-+\\(.+?\\)$") - (forward-line)) - ((looking-at "^\\(old\\|new\\)hex$") - (forward-line) - (while (looking-at "^\\*") - (forward-line))) - ((looking-at "^\\(addfile\\|binary\\|rmfile\\|hunk\\|replace\\)\\s-+\\(.+?\\)\\(\\s-+\\([0-9]+\\|.+\\)\\)?$") - (forward-line) - (let* ((kind (match-string 1)) - (file (match-string 2)) - (dir (directory-file-name (file-name-directory file))) - (base (file-name-nondirectory file)) - (start-line (match-string 4)) - (add-dir dir) - item lines) - (cond - ((string= kind "hunk") - (when start-line - (while (looking-at "^\\([+ -].*\\)") - (setq lines (cons (match-string 1) lines)) - (forward-line))) - (setq item (string-to-number start-line)) - (setq entries - (cons (if visible item (- item)) - (nreverse lines)))) - (t - (setq item (intern kind) - item (if (and - (eq item 'addfile) - (not (or (eq pending t) - (darcsum-changeset-has-directory-p - pending dir)))) - 'newfile - item) - entries (list (if visible item (darcsum-toggle-item item)) - (if (eq item 'replace) start-line))))) - (let ((entry (assoc dir data))) - (if (null entry) - (setq data - (cons (cons dir (list (cons base - (list entries)))) data)) - (if entry - (let ((item (assoc base entry))) - (if item - (nconc item (list entries)) - (nconc entry - (list (cons base (list entries))))))))))) -; ((looking-at "^replace\\s-+\\(.+?\\)\\s-+\\(.*\\)+$") -; (forward-line)) + ((looking-at "^\\(addfile\\|adddir\\|rmdir\\|move\\|binary\\|rmfile\\|hunk\\|replace\\)\\s-+\\(.+?\\)\\(\\s-+\\([0-9]+\\|.+\\)\\)?$") + (forward-line) + (let* ((item (intern (match-string 1))) + (path (match-string 2)) + (extra (match-string 4)) + lines) + ;; (message (concat "Looking at " (match-string 1))) + (case item + ('hunk + (while (looking-at "^\\([+ -].*\\)") + (setq lines (cons (match-string 1) lines)) + (forward-line)) + (setq item (string-to-number extra) + lines (nreverse lines))) + ('binary + (while (looking-at "^\\(old\\|new\\)hex$") + (forward-line) + (while (looking-at "^\\*") + (forward-line)))) + ('addfile + (if (and (not (eq pending t)) + (null (assoc path pending))) + (setq item 'newfile))) + ('adddir + (if (and (not (eq pending t)) + (null (assoc path pending))) + (setq item 'newdir))) + ('move + (setq lines (list extra))) + ('replace + (setq lines (list extra)))) + (setq change (cons item (cons (if visible nil (list 'hide)) lines)) + fentry (assoc path data)) + (if (null fentry) + (setq data (cons (cons path (list change)) data)) + ;; (message path) + (setcdr fentry (cons change (cdr fentry)))))) hunk ./site-lisp/darcsum.el 494 + (dolist (entry data) + (setcdr entry (sort (cdr entry) (function darcsum-change-<)))) hunk ./site-lisp/darcsum.el 500 - (if (file-readable-p "_darcs/patches/pending") - (with-temp-buffer - (insert-file-contents "_darcs/patches/pending") - (darcsum-parse-changeset t))))) + (if (file-readable-p "_darcs/patches/pending") + (with-temp-buffer + (insert-file-contents "_darcs/patches/pending") + (darcsum-parse-changeset t visible))))) hunk ./site-lisp/darcsum.el 507 - (if (looking-at "^{") - (darcsum-parse-changeset pending visible)))) - + (unless (looking-at "^$") + (darcsum-parse-changeset pending visible)))) hunk ./site-lisp/darcsum.el 512 + ;; Lines starting with number indicates start of hunk + ;; Lines starting with "in directory" indicate directory + ;; Lines starting with \t indicate non-line change hunk ./site-lisp/darcsum.el 523 - (let (dir file change line beg) - (dolist (dir data) - (insert - (darcsum-add-props - (concat "in directory " - (darcsum-add-face (concat (car dir)) - 'darcsum-header-face t) - ":\n") - 'darcsum-line-type 'dir - 'darcsum-dir (car dir))) - (dolist (file (cdr dir)) - (let* ((all-marked (listp (car (cadr file)))) - (action (darcsum-change-item (cadr file))) - (status (darcsum-item-status action))) - (when (not status) - (setq all-marked t) - (dolist (change (cdr file)) - (if (and all-marked - (not (listp (car change)))) - (setq all-marked nil)))) - (insert - (darcsum-add-props - (concat " " - (if (and status (darcsum-item-visible-p action)) - (darcsum-add-face " * " 'darcsum-change-line-face t) - " ") - " " - (darcsum-add-face (format "%-24s" - (if status status "Modified")) - (if all-marked - 'darcsum-need-action-marked-face - 'darcsum-need-action-face) t) - (darcsum-add-face (concat (car file)) - 'darcsum-filename-face t) "\n") - 'darcsum-line-type 'file - 'darcsum-dir (car dir) - 'darcsum-file (car file))) - (dolist (change (if status nil (cdr file))) - (let ((item (darcsum-change-item change))) - (setq beg (point)) - (cond - ((eq 'replace item) - (insert (darcsum-add-face - "replace " - 'darcsum-change-line-face t) - (format " %s" (cadr change)) - ?\n) - (add-text-properties beg (point) - (list 'darcsum-line-type 'change - 'darcsum-dir (car dir) - 'darcsum-file (car file) - 'darcsum-change change))) - ((symbolp item) - ;; 'addfile 'newfile 'rmfile 'binary or '-replace - ;; xyzzy - ) - ((> item 0) + (let (dir sorted dentry file path status change changes line beg) + (dolist (file data) + (setq path (car file) + dir (if (memq (caadr file) '(adddir rmdir newdir)) path + (directory-file-name (file-name-directory path))) + dentry (assoc dir sorted)) + (if dentry + (setcdr dentry (cons file (cdr dentry))) + (setq sorted (cons (cons dir (list file)) sorted)))) + (setq sorted (sort sorted (function (lambda (a b) + (string-lessp (car a) (car b)))))) + (dolist (dentry sorted) + (setq dir (car dentry) + data (nreverse (cdr dentry)) + beg (point)) + (insert "in directory " + (darcsum-add-face dir 'darcsum-header-face t) + ":\n") + (add-text-properties beg (point) + (list + 'darcsum-line-type 'dir + 'darcsum-line-path dir + 'darcsum-line-change data)) + (dolist (file data) + (setq path (car file) + changes (cdr file) + status nil) + (while changes + (setq change (car changes) + item (car change) + marked (darcsum-change-mark-p change) + visible (darcsum-change-visible-p change) + beg (point)) + (cond + ((eq item 'move) + (darcsum-insert-file-line "Moved" path " -> " visible marked) + (insert (darcsum-add-face (caddr change) 'darcsum-filename-face t) + ?\n)) + ((memq item '(addfile adddir rmfile rmdir newfile newdir binary)) + (setq status (darcsum-file-change-status change)) + (darcsum-insert-file-line status path "\n" + visible marked 'file changes) + (setq changes nil ; don't show other changes + beg (point))) + ((eq item 'replace) + (unless status + (setq status (darcsum-insert-file-line "Modified" path "\n" + nil marked 'file changes) + beg (point))) + (if visible + (insert "\t " + (if marked + (darcsum-add-face + (format "%24s %s" "replace " (caddr change)) + 'darcsum-marked-face t) + (format "%24s %s" "replace " (caddr change))) + ?\n))) + ((numberp item) + (unless status + (setq status (darcsum-insert-file-line "Modified" path "\n" + nil marked 'file changes) + beg (point))) + (unless (not visible) hunk ./site-lisp/darcsum.el 588 - (format "%-10d" item) - 'darcsum-change-line-face t)) - ;; Avoid trailing whitespace here, so that we could use - ;; `show-trailing-whitespace' in Emacs, but make it - ;; display as space. \000 is unlikely to be searched - ;; for. NB "" as display property loses. - (if (boundp 'show-trailing-whitespace) - (if (fboundp 'propertize) - (insert (propertize "\000" 'display " ")))) - (insert ?\n) - (dolist (line (cdr change)) - (insert (if (not (listp (car change))) - line - (darcsum-add-face (concat line) - 'darcsum-marked-face t)) - ?\n)) + (format "%-10d" (car change)) 'darcsum-change-line-face t) + ?\n) + (dolist (line (cddr change)) + (string-match "[ \t]*$" line 1) + (let ((nws (substring line 0 (match-beginning 0))) + (ws (substring line (match-beginning 0)))) + (insert + (if marked + (darcsum-add-face nws 'darcsum-marked-face t) + nws) + (darcsum-add-face ws 'darcsum-whitespace-ateol-face t) + ?\n)))))) + (if (/= beg (point)) hunk ./site-lisp/darcsum.el 603 - 'darcsum-dir (car dir) - 'darcsum-file (car file) - 'darcsum-change change)))))))))) + 'darcsum-line-path path + 'darcsum-line-change + (list (list path change))))) + (setq changes (cdr changes)))))) hunk ./site-lisp/darcsum.el 610 +(defun darcsum-insert-file-line (title path end visible marked + &optional line-type changes) + "Insert per-file line into buffer" + (let ((begin (point))) + (if (and marked changes) + (setq marked (darcsum-changeset-all-marked-p + (list (cons path changes))))) + (insert + "\t " + (if visible + (darcsum-add-face " * " 'darcsum-change-line-face t) + " ") + " " + (darcsum-add-face (format "%-24s" title) + (if marked + 'darcsum-need-action-marked-face + 'darcsum-need-action-face) t) + (darcsum-add-face (file-name-nondirectory path) 'darcsum-filename-face t) + end) + (if line-type + (add-text-properties beg (point) + (list 'darcsum-line-type 'file + 'darcsum-line-path path + 'darcsum-line-change + (list (cons path changes)))))) + title) + +(defsubst darcsum-get-line-type (&optional position) + "Get darcsum line type at point or at the given POSITION." + (get-text-property (or position (point)) 'darcsum-line-type)) + hunk ./site-lisp/darcsum.el 644 - (let* ((type (get-text-property (point) 'darcsum-line-type)) - (dir (get-text-property (point) 'darcsum-dir)) - (dentry (and dir (assoc dir darcsum-data))) - data) - (cond - ((eq type 'dir) - (setq data (list dentry))) - ((eq type 'file) - (let* ((file (get-text-property (point) 'darcsum-file)) - (fentry (assoc file dentry))) - (setq data (list (list (car dentry) fentry))))) - ((eq type 'change) - (let* ((file (get-text-property (point) 'darcsum-file)) - (fentry (assoc file dentry))) - (setq data (list - (list (car dentry) - (list (car fentry) - (get-text-property (point) - 'darcsum-change)))))))) + "Return changeset at current point" + (let ((data (get-text-property (point) 'darcsum-line-change))) hunk ./site-lisp/darcsum.el 647 - data - (darcsum-find-changeset data - (function - (lambda (dir file change) - (setq change (darcsum-change-item change)) - (or (symbolp change) (>= change 0)))))))) + data + (darcsum-changeset-find-visible data)))) hunk ./site-lisp/darcsum.el 657 - ((darcsum-marked-p darcsum-data) - (darcsum-find-changeset darcsum-data - (function - (lambda (dir file change) - (listp (car change)))))) + ((darcsum-changeset-any-marked-p darcsum-data) + (darcsum-changeset-find-marked darcsum-data)) hunk ./site-lisp/darcsum.el 660 - (darcsum-find-changeset darcsum-data - (function - (lambda (dir file change) - (equal (darcsum-visible-item (car change)) - (car change)))))) + (darcsum-changeset-find-visible darcsum-data)) hunk ./site-lisp/darcsum.el 662 - (darcsum-changeset-at-point)))) + (darcsum-changeset-at-point 'invisible-too)))) hunk ./site-lisp/darcsum.el 679 +(defvar darcsum-output-environment + (list + "DARCS_DONT_ESCAPE_TRAILING_SPACES=1" + "DARCS_DONT_COLOR=1" + "DARCS_DONT_ESCAPE_TRAILING_CR=1") + "The environment variables to turn off highlighting.") + +(defvar darcsum-environment + nil + "*The extra environment variables for darcs.") + hunk ./site-lisp/darcsum.el 699 - (point-marker)))) + (point-marker)))) hunk ./site-lisp/darcsum.el 703 - (set-window-configuration (car darcsum-window-configuration-temp)) - (goto-char (cadr darcsum-window-configuration-temp))) + (set-window-configuration (car darcsum-window-configuration-temp)) + (goto-char (cadr darcsum-window-configuration-temp))) hunk ./site-lisp/darcsum.el 710 - (with-current-buffer darcsum-parent-buffer - (setq darcsum-data - (darcsum-remove-changeset darcsum-data changeset)) - (darcsum-refresh))))) + (with-current-buffer darcsum-parent-buffer + (setq darcsum-data + (darcsum-remove-changeset darcsum-data changeset)) + (darcsum-refresh))))) + +(defvar darcsum-darcs-2-options 'not-set) hunk ./site-lisp/darcsum.el 718 - &optional name value &rest localize) + &optional name value &rest localize) hunk ./site-lisp/darcsum.el 720 + (if (eq darcsum-darcs-2-options 'not-set) + ;; Check version and set proper darcsum-darcs-2-options + (with-temp-buffer + (call-process darcsum-program nil t nil "--version") + (goto-char (point-min)) + (setq darcsum-darcs-2-options + (if (looking-at "2[.]") (list "--quiet"))))) hunk ./site-lisp/darcsum.el 728 - ((buf (generate-new-buffer (format " *darcs %s*" subcommand))) - (process-environment - ;; Use the environment variables to turn off highlighting. (You - ;; could use `show-trailing-whitespace' in the buffer to highlight - ;; trailing space in the diffs.) - (append (list "DARCS_DONT_ESCAPE_TRAILING_SPACES=1" - "DARCS_DONT_COLOR=1" - "DARCS_DONT_ESCAPE_TRAILING_CR=1") - process-environment)) - (process-connection-type nil) - (proc (apply 'start-process "darcs" - buf darcsum-program subcommand args))) + ((buf (generate-new-buffer (format " *darcs %s*" subcommand))) + (process-environment + (append darcsum-environment + darcsum-output-environment + process-environment)) + (process-connection-type nil) + (proc (apply 'start-process "darcs" + buf darcsum-program subcommand + (append darcsum-darcs-2-options args)))) hunk ./site-lisp/darcsum.el 740 - (while name - (set (make-local-variable name) value) - (setq name (car localize) - value (cadr localize) - localize (cddr localize)))) + (while name + (set (make-local-variable name) value) + (setq name (car localize) + value (cadr localize) + localize (cddr localize)))) hunk ./site-lisp/darcsum.el 748 - (cond - ((and (string-match "^exited abnormally" string) (process-buffer proc)) - (message string)))) + (if (buffer-live-p (process-buffer proc)) + (with-current-buffer (process-buffer proc) + (save-excursion + (goto-char (point-min)) + (cond + ((looking-at "\n*\\(Couldn't get lock [^\n]*\\)") + (let ((waiting (match-string 1))) + (message waiting) + (kill-buffer (current-buffer)))) + ((string-match "^exited abnormally" string) + (message string))))))) hunk ./site-lisp/darcsum.el 764 - ;; Insert the text, advancing the process marker. - (goto-char (process-mark proc)) - (insert string) - (set-marker (process-mark proc) (point))) + ;; Insert the text, advancing the process marker. + (goto-char (process-mark proc)) + (insert string) + (set-marker (process-mark proc) (point))) hunk ./site-lisp/darcsum.el 771 + + (if (looking-at "\n*Skipped \\(record\\|add\\|revert\\) of [0-9]+ patch\\(es\\)?\\.\n") + (delete-region (point-min) (match-end 0))) + hunk ./site-lisp/darcsum.el 777 - (message "Changes recorded.") - (darcsum-changes-handled) + (message "Changes recorded.") + (darcsum-changes-handled) hunk ./site-lisp/darcsum.el 780 - (kill-buffer (current-buffer))) + (kill-buffer (current-buffer))) hunk ./site-lisp/darcsum.el 782 - (message "No changes recorded.") + (message "No changes recorded.") hunk ./site-lisp/darcsum.el 784 - (kill-buffer (current-buffer))) + (kill-buffer (current-buffer))) hunk ./site-lisp/darcsum.el 787 - (process-send-string proc darcsum-process-arg) - (delete-region (point-min) (point-max))) + (process-send-string proc darcsum-process-arg) + (delete-region (point-min) (point-max))) hunk ./site-lisp/darcsum.el 790 - (message "Changes sent to `%s'." darcsum-process-arg) - (kill-buffer (current-buffer))) + (message "Changes sent to `%s'." darcsum-process-arg) + (kill-buffer (current-buffer))) hunk ./site-lisp/darcsum.el 793 - (message "No changes sent.") - (kill-buffer (current-buffer))) + (message "No changes sent.") + (kill-buffer (current-buffer))) hunk ./site-lisp/darcsum.el 797 - (process-send-string proc "y\n") - (delete-region (point-min) (point-max))) + (process-send-string proc "y\n") + (delete-region (point-min) (point-max))) hunk ./site-lisp/darcsum.el 800 - (message "Changes reverted.") - (darcsum-changes-handled) - (kill-buffer (current-buffer))) + (message "Changes reverted.") + (darcsum-changes-handled) + (kill-buffer (current-buffer))) hunk ./site-lisp/darcsum.el 804 - (message "No changes reverted.") - (kill-buffer (current-buffer))) + (message "No changes reverted.") + (kill-buffer (current-buffer))) hunk ./site-lisp/darcsum.el 808 - (let ((waiting (match-string 1))) - (message waiting) - (delete-region (point-min) (match-end 0)))) + (let ((waiting (match-string 1))) + (message waiting) + (delete-region (point-min) (match-end 0)))) hunk ./site-lisp/darcsum.el 813 - (let ((waiting (match-string 1))) - (message waiting) - (kill-buffer (current-buffer)))) + (let ((waiting (match-string 1))) + (message waiting) + (kill-buffer (current-buffer)))) hunk ./site-lisp/darcsum.el 822 - (let* ((default-mail (concat user-full-name - " <" user-mail-address ">")) - (enable-recursive-minibuffers t) - (mail-address (read-string - (format - "What is your email address? (default %s) " - default-mail) - nil nil default-mail))) - (process-send-string proc mail-address) - (process-send-string proc "\n")) - (re-search-forward "What is your email address\\?.*") - (delete-region (point-min) (point))) + (let* ((default-mail (concat user-full-name + " <" user-mail-address ">")) + (enable-recursive-minibuffers t) + (mail-address (read-string + (format + "What is your email address? (default %s) " + default-mail) + nil nil default-mail))) + (process-send-string proc mail-address) + (process-send-string proc "\n")) + (re-search-forward "What is your email address\\?.*") + (delete-region (point-min) (point))) hunk ./site-lisp/darcsum.el 835 - ((looking-at "\n*\\(addfile\\|adddir\\|binary\\|rmfile\\|hunk\\|replace\\)\\s-+\\(.+?\\)\\(\\s-+\\([0-9]+\\)?\\)?\\( \\(.+\\)\\)?$") - (let* ((kind (intern (match-string 1))) - (file (match-string 2)) - (dir (directory-file-name - (file-name-directory file))) - (base (file-name-nondirectory file)) - (start-line (match-string 4)) - (replace (match-string 6))) - (goto-char (match-end 0)) - (forward-line) - (while (looking-at "^\\([+-].*\\)") - (forward-line)) - (when (looking-at - "^Shall I \\(record\\|send\\|revert\\|add\\) this \\(patch\\|change\\)\\?.+[]:] ") - (if (eq kind 'hunk) (setq kind (string-to-number start-line))) - (let ((end (match-end 0)) - (record (darcsum-changeset-has-change-p - darcsum-changeset-to-record - dir base kind replace))) - (process-send-string proc (if record "y" "n")) - (delete-region (point-min) end))))) + ((looking-at "\n*\\(move\\|addfile\\|adddir\\|binary\\|rmfile\\|rmdir\\|hunk\\|replace\\)\\s-+\\(.+?\\)\\(\\s-+\\([0-9]+\\)?\\)?\\( \\(.+\\)\\)?$") + (let* ((kind (intern (match-string 1))) + (path (match-string 2)) + (start-line (match-string 4)) + (extra (match-string 6)) + (content 'any)) + (goto-char (match-end 0)) + (forward-line) + (case kind + ('hunk (setq kind (string-to-number start-line))) + ('move (setq content extra)) + ('replace (setq content extra))) + (while (looking-at "^\\([+-].*\\)") + (forward-line)) + (when (looking-at + "^Shall I \\(record\\|send\\|revert\\|add\\) this \\(patch\\|change\\)\\?.+[]:] ") + (let ((end (match-end 0)) + (reply (darcsum-find-change + darcsum-changeset-to-record + path kind content))) + ;; (message (concat (if reply "Do " "Skip ") (match-string 1) " to " path)) + (process-send-string proc (if reply "y" "n")) + (delete-region (point-min) end))))) hunk ./site-lisp/darcsum.el 860 - (goto-char (match-end 0)) - (forward-line) - (when (looking-at - "^Shall I \\(record\\|send\\|revert\\|add\\) this \\(patch\\|change\\)\\?.+[]:] ") - (let ((end (match-end 0))) - (process-send-string proc "n") - (delete-region (point-min) end)))))))) + (goto-char (match-end 0)) + (forward-line) + (when (looking-at + "^Shall I \\(record\\|send\\|revert\\|add\\) this \\(patch\\|change\\)\\?.+[]:] ") + (let ((end (match-end 0))) + (process-send-string proc "n") + (delete-region (point-min) end)))))))) hunk ./site-lisp/darcsum.el 871 - (parent-buf darcsum-parent-buffer) - (changeset darcsum-changeset-to-record)) + (parent-buf darcsum-parent-buffer) + (changeset darcsum-changeset-to-record)) hunk ./site-lisp/darcsum.el 876 - (insert ?\n)) + (insert ?\n)) hunk ./site-lisp/darcsum.el 879 - (error "No record description entered"))) + (error "No record description entered"))) hunk ./site-lisp/darcsum.el 902 - (changeset (darcsum-selected-changeset t)) - (buf (get-buffer-create "*darcs comment*"))) - (switch-to-buffer-other-window buf) - (darcsum-comment-mode) + (changeset (darcsum-selected-changeset t)) + (buf)) + (if (null changeset) + (error "No changes are selected")) + (if (darcsum-changeset-any-p changeset + (function + (lambda (change) + (memq (car change) '(newdir newfile))))) + (error "You have to add new directories and files first.")) + (switch-to-buffer-other-window (setq buf (get-buffer-create "*darcs comment*"))) + (if (fboundp 'log-edit) + ;; TODO: add SETUP (nil?) and LISTFUN arguments? See also `vc-log-edit' + (log-edit #'darcsum-really-record) + (darcsum-comment-mode) ) hunk ./site-lisp/darcsum.el 934 - "Show the changes in another buffer" + "Show the changes in another buffer. Optional argument HOW-MANY limits +the number of changes shown, counting from the most recent changes." hunk ./site-lisp/darcsum.el 938 - "changes" (if how-many + "changes" (if how-many hunk ./site-lisp/darcsum.el 941 - 'darcsum-parent-buffer (current-buffer)))) + 'darcsum-parent-buffer (current-buffer)))) hunk ./site-lisp/darcsum.el 947 -(defun darcsum-changes-sentinel(process event) +(defun darcsum-changes-sentinel (process event) hunk ./site-lisp/darcsum.el 949 + (darcsum-changes-mode) hunk ./site-lisp/darcsum.el 952 +(defun darcsum-query-manifest () + "List the version-controlled files in the working copy." + (interactive) + (let ((proc (darcsum-start-process + "query" '("manifest") + 'darcsum-parent-buffer (current-buffer)))) + (set-process-filter proc nil) + (set-process-sentinel proc 'darcsum-query-manifest-sentinel) + (switch-to-buffer-other-window (process-buffer proc)) + (process-buffer proc))) + +(defun darcsum-query-manifest-sentinel (process event) + (with-current-buffer (process-buffer process) + (setq buffer-read-only t) + (darcsum-query-mode) + (goto-char (point-min)))) + +(defcustom darcsum-amend-confirmation-function #'darcsum-amend-confirmation + "*Function to invoke for confirming an amend operation. + +The function receives a prompt string as its sole argument; the expectation +is that it would display this string to the user, and prompt for a response. + +When the function is invoked, the current buffer is a temporary history +buffer displaying information about the patch which is about to be amended, +and a warning about the possible problems committing this change could cause. + +If the function returns nil, `darcsum-amend' will not carry out the +amend operation. + +Setting this function to nil will disable the confirmation logic altogether; +however, this is strongly discouraged. + +Amending a shared repository can be dangerous; see the Darcs manual +for details." + :type '(choice (const :tag "darcsum-amend-confirmation (default)" + #'darcsum-amend-confirmation) + (const :tag "Off (strongly discouraged)" nil) + function) + :group 'darcsum) + +(defun darcsum-amend-confirmation (prompt) + "The default confirmation function for `darcsum-amend-confirmation-function'; +pauses for two seconds, then invokes `yes-or-no-p'." + (sit-for 2) + (yes-or-no-p prompt) ) + hunk ./site-lisp/darcsum.el 1005 - (let ((history-buffer (darcsum-changes 1))) - (with-current-buffer history-buffer - (save-excursion - (goto-char (point-max)) - (insert " -WARNINGS: You should ONLY use amend-record on patches which only exist in a single repository! -Also, running amend-record while another user is pulling from the same repository may cause repository corruption.")) - (sleep-for 2) - (goto-char (point-min))) - (setq amend (yes-or-no-p "Amend this latest changeset? (see WARNINGS) ")) - (kill-buffer history-buffer) - (when amend + (let ((history-buffer (darcsum-changes 1)) + amend point) + (unwind-protect + (with-current-buffer history-buffer + (setq point (point-max)) + (goto-char point) + (insert " +WARNINGS: You should ONLY use amend-record on patches which only exist in +a single repository! Also, running amend-record while another user is +pulling from the same repository may cause repository corruption.\n") + (goto-char point) + (setq + amend + ;; If darcsum-amend-confirmation-function is nil, don't prompt + (or + (not (functionp darcsum-amend-confirmation-function)) + (funcall darcsum-amend-confirmation-function + "Amend this latest changeset? (see WARNINGS) ") )) ) + (kill-buffer history-buffer)) + (when amend hunk ./site-lisp/darcsum.el 1026 - "amend" (list) - 'darcsum-logfile nil - 'darcsum-changeset-to-record changeset - 'darcsum-parent-buffer parent-buffer))) - (message "You need to select something first")))) + "amend" (list) + 'darcsum-logfile nil + 'darcsum-changeset-to-record changeset + 'darcsum-parent-buffer parent-buffer))) + (message "You need to select something first")))) hunk ./site-lisp/darcsum.el 1042 -;;;;;;;; TODO: history of previous record comments, like in vc-mode hunk ./site-lisp/darcsum.el 1048 +(defun darcsum-kill-ancillary-buffer () + "Kill an ancillary buffer called by darcsum." + (interactive) + (kill-this-buffer) + (delete-window)) + +(defun darcsum-changes-mode-next-comment (&optional n) + "Move to the next comment. + +If called with a positive argument then move N comments forward." + (interactive "p") + (if (and n (< 0 n)) + (let ((comment-start-regexp "^[A-Z][a-z]\\{2\\} [A-Z][a-z]\\{2\\}.*$")) + (when (looking-at comment-start-regexp) + (forward-line 1)) + (let ((next (re-search-forward comment-start-regexp + (point-max) t (or n 1)))) + (if next + (goto-char (point-at-bol)) + (message "No earlier changes")))) + (darcsum-changes-mode-previous-comment n))) + +(defun darcsum-new-buffer (&optional subdir) + "Generate new darcsum buffer. Optional argument SUBDIR selects subdirectory." + (generate-new-buffer + (concat "*darcs " + (file-name-nondirectory + (directory-file-name + (file-name-directory default-directory))) + (when subdir "/") + (when subdir + (if (file-name-absolute-p subdir) + (file-relative-name subdir) + subdir)) + "*"))) + +(defun darcsum-changes-mode-previous-comment (&optional n) + "Move to the previous comment. + +If called with a positive argument then move N comments backward." + (interactive "p") + (when (and n (< n 0)) + (error "To move forward call `darcsum-changes-mode-next-comment' instead")) + (let ((comment-start-regexp "^[A-Z][a-z]\\{2\\} [A-Z][a-z]\\{2\\}.*$")) + (when (looking-at comment-start-regexp) + (forward-line -1)) + (let ((next (re-search-backward comment-start-regexp + (point-min) t (or n 1)))) + (if next + (goto-char (point-at-bol)) + (message "No later changes"))))) + +(defun darcsum-query-kill-buffer () + (interactive) + (kill-this-buffer) + (delete-window)) + +(defvar darcsum-query-mode-map + (let ((map (make-sparse-keymap))) + (define-key map "q" 'darcsum-query-kill-buffer) + map)) + +(defvar darcsum-changes-mode-map + (let ((map (make-sparse-keymap))) + (define-key map "q" 'darcsum-kill-ancillary-buffer) + (define-key map "n" 'darcsum-changes-mode-next-comment) + (define-key map "p" 'darcsum-changes-mode-previous-comment) + map)) + hunk ./site-lisp/darcsum.el 1124 +(define-derived-mode darcsum-query-mode indented-text-mode "Darcs Query" + "Major mode for output from \\\\[darcsum-query-manifest]. + +\\{darcsum-query-mode-map}" + :group 'darcsum + (setq truncate-lines t)) + +(define-derived-mode darcsum-changes-mode indented-text-mode "Darcs Changes" + "Major mode for output from \\\\[darcsum-changes]. + +\\{darcsum-changes-mode-map}" + :group 'darcsum + (setq truncate-lines nil) + (setq buffer-read-only t)) + hunk ./site-lisp/darcsum.el 1146 - (let ((type (get-text-property (point) 'darcsum-line-type))) + (unless (null (darcsum-get-line-type)) + (goto-char (line-beginning-position)) hunk ./site-lisp/darcsum.el 1149 - ((eq type 'dir) - (goto-char (+ (line-beginning-position) 13))) - ((eq type 'file) - (goto-char (+ (line-beginning-position) 38))) - ((eq type 'change) - (goto-char (line-beginning-position)))))) + ((looking-at "in directory") (forward-char 13)) + ((looking-at "\t") (forward-char 31)) ; at column 38 + ))) hunk ./site-lisp/darcsum.el 1154 - (let ((buf (or other-buffer (generate-new-buffer "*darcs*")))) + (let ((buf (or other-buffer (darcsum-new-buffer)))) hunk ./site-lisp/darcsum.el 1157 - (darcsum-mode)) + (darcsum-mode)) hunk ./site-lisp/darcsum.el 1169 - (changeset (darcsum-selected-changeset)) + (changeset (darcsum-selected-changeset)) hunk ./site-lisp/darcsum.el 1172 - (darcsum-remove-changeset darcsum-data changeset)) + (darcsum-remove-changeset darcsum-data changeset)) hunk ./site-lisp/darcsum.el 1174 - (darcsum-apply-to-changeset - changeset - (function - (lambda (dir file change) - (cond - ((listp (car change)) - (setcar change (caar change))) - ((not (equal (car change) (darcsum-visible-item (car change)))) - (setcar change (darcsum-visible-item (car change)))))))) - (setq darcsum-data - (darcsum-add-changeset darcsum-data changeset)) + (darcsum-apply-to-changes changeset 'darcsum-change-remove-all-flags) + (setq darcsum-data (darcsum-add-changeset darcsum-data changeset)) hunk ./site-lisp/darcsum.el 1179 -(defun darcsum-find-file (e &optional other view) +(defun darcsum-find-file (&optional other view) hunk ./site-lisp/darcsum.el 1182 +If OTHER is 'dont-select, don't select the buffer. hunk ./site-lisp/darcsum.el 1184 - (interactive (list last-input-event current-prefix-arg)) - (let* ((type (get-text-property (point) 'darcsum-line-type)) - (file (if (eq 'type 'dir) - (get-text-property (point) 'darcsum-dir) - (darcsum-path (point))))) - (cond - ((eq type 'dir) - (find-file (get-text-property (point) 'darcsum-dir))) - ((eq type 'file) - (cond ((eq other 'dont-select) - (display-buffer (find-file-noselect file))) - ((and other view) - (view-file-other-window file)) - (view (view-file file)) - (other (find-file-other-window file)) - (t (find-file file)))) - ((eq type 'change) - (let ((change-line (car (get-text-property (point) 'darcsum-change)))) - (with-current-buffer (cond ((eq other 'dont-select) - (display-buffer (find-file-noselect file))) - ((and other view) - (view-file-other-window file)) - (view (view-file file)) - (other (find-file-other-window file)) - (t (find-file file))) - (if (listp change-line) - (setq change-line (car change-line))) - (goto-line (abs change-line)))))))) + (interactive "P") + (let ((file (darcsum-path (point))) + (start (point-at-bol)) + (change-line + (and (eq 'change (darcsum-get-line-type)) + (caadar (darcsum-changeset-at-point t))))) + (if (numberp change-line) + (save-excursion + (goto-char start) + (cond + ((looking-at " ") ; We were in context + (while (looking-at " ") (forward-line)) + (if (looking-at "[-+]") ; ..before change + (setq change-line (- change-line (count-lines start (point)))) + (goto-char start) ; ...after change + (while (looking-at " ") + (forward-line -1)) + (setq change-line (+ change-line -1 (count-lines (point) start))))) + ((looking-at "[+]") + (while (looking-at "[+]") + (forward-line -1)) + (setq change-line (+ change-line -1 (count-lines (point) start))))))) + (with-current-buffer + (cond ((eq other 'dont-select) + (find-file-noselect file)) + ((and other view) + (view-file-other-window file)) + (view (view-file file)) + (other (find-file-other-window file)) + (t (find-file file))) + (if (numberp change-line) + (goto-line change-line)) + (display-buffer (current-buffer)) + (recenter '(4))))) hunk ./site-lisp/darcsum.el 1219 -(defun darcsum-find-file-other-window (e) - "Select a buffer containing the file in another window." - (interactive (list last-input-event)) - (darcsum-find-file e t)) +(defun darcsum-find-file-other-window () + "Select a buffer containing the file with current change in another window" +"possibly moving point to the change's location." + (interactive) + (darcsum-check-darcsum-mode) + (darcsum-find-file t)) hunk ./site-lisp/darcsum.el 1227 - "Open the selected entry, possibly moving point to the change's location." + "Select a buffer containing the file with current change in another window" +"possibly moving point to the change's location." hunk ./site-lisp/darcsum.el 1230 - (let ((type (get-text-property (point) 'darcsum-line-type))) - (cond - ((eq type 'dir) - (find-file-other-window - (get-text-property (point) 'darcsum-dir))) - ((eq type 'file) - (find-file-other-window (darcsum-path (point)))) - ((eq type 'change) - (let ((change-line (car (get-text-property (point) 'darcsum-change)))) - (find-file-other-window (darcsum-path (point))) - (if (listp change-line) - (setq change-line (car change-line))) - (goto-line (abs change-line))))))) + (darcsum-check-darcsum-mode) + (darcsum-find-file t)) + +(defun darcsum-display-change () + "Display a buffer containing the current change in another window." + (interactive) + (darcsum-check-darcsum-mode) + (darcsum-find-file 'dont-select)) hunk ./site-lisp/darcsum.el 1243 - (let ((dir default-directory) - (darcsum-default-expanded t)) - (message "Re-running darcsum-whatsnew") - (let ((changes (darcsum-whatsnew dir nil t darcsum-show-context))) - (setq darcsum-data changes)) - (darcsum-refresh))) + (darcsum-redo)) hunk ./site-lisp/darcsum.el 1253 - (darcsum-apply-to-changeset changeset - (function - (lambda (dir file change) - (if (listp (car change)) - (setcar change (caar change)) - (setcar change (list (car change)))))))) + (darcsum-apply-to-changes changeset 'darcsum-change-toggle-mark)) + (darcsum-refresh)) + +(defun darcsum-mouse-toggle-mark () + "Move point to mouse and toggle mark on changeset." + (interactive) + (unless (not current-mouse-event) + (mouse-set-point current-mouse-event) + (darcsum-toggle-mark))) + +(defun darcsum-show () + "Activate the current changeset." + (interactive) + (darcsum-check-darcsum-mode) + (let ((changeset (darcsum-changeset-at-point t))) + (darcsum-apply-to-changes changeset 'darcsum-change-remove-hide)) hunk ./site-lisp/darcsum.el 1280 - (let ((any-visible - (darcsum-applicable-p - changeset - (function - (lambda (d f change) - (darcsum-item-visible-p (darcsum-change-item change))))))) - (darcsum-apply-to-changeset - changeset - (function - (lambda (dir file change) - (let ((item (darcsum-change-item change))) - (if any-visible - (setcar change (darcsum-invisible-item item)) - (if (listp (car change)) - (setcar change (list (darcsum-visible-item item))) - (setcar change (darcsum-visible-item item)))))))))) + (if (darcsum-changeset-any-visible-p changeset) + (darcsum-apply-to-changes changeset 'darcsum-change-add-hide) + (darcsum-apply-to-changes changeset 'darcsum-change-toggle-hide))) hunk ./site-lisp/darcsum.el 1285 -(defun darcsum-refresh () - "Refresh the visualization of the changesets." +(defun darcsum-refresh (&optional line) + "Refresh the visualization of the changesets. + +If LINE is not nil, move to LINE. Otherwise, stay on current line." hunk ./site-lisp/darcsum.el 1291 - (let ((line (count-lines (point-min) (point))) - (inhibit-redisplay t)) - (if (/= (point) (line-beginning-position)) - (setq line (1- line))) + (let ((inhibit-redisplay t)) + (unless line + (setq line (count-lines (point-min) (point-at-bol)))) hunk ./site-lisp/darcsum.el 1302 - (let ((type (get-text-property (point) 'darcsum-line-type))) + (let ((type (darcsum-get-line-type))) hunk ./site-lisp/darcsum.el 1304 - ('new (and (eq 'file type) (looking-at " +New"))) - ('modified (or (and (eq 'file type) (looking-at "\\s-+Modified")) - (eq 'change type))) - ('file (eq 'file type)) - ('change (eq 'change type)) - ('marked - (memq (get-text-property (point) 'face) - '(darcsum-marked-face darcsum-need-action-marked-face))))))) + ('new (and (eq 'file type) (looking-at " +New"))) + ('modified (or (and (eq 'file type) (looking-at "\\s-+Modified")) + (eq 'change type))) + ('file (eq 'file type)) + ('change (eq 'change type)) + ('marked + (memq (get-text-property (point) 'face) + '(darcsum-marked-face darcsum-need-action-marked-face))))))) hunk ./site-lisp/darcsum.el 1318 - (dotimes (i (or arg 1)) - (forward-line (if backward -1)) - (beginning-of-line) - (while (and (not (if backward (bobp) (eobp))) - (not (looking-at "[0-9]")) ; stop at line headers - (darcsum-line-is 'change)) - (forward-line (if backward -1 1))) - (unless (get-text-property (point) 'darcsum-line-type) - (goto-char (if backward (point-max) (point-min))) - (forward-line (if backward -3 3))) - (darcsum-reposition))) + (let (changeset) + (dotimes (i (or arg 1)) + (setq changeset (darcsum-changeset-at-point t)) + (beginning-of-line) + (while (progn + (forward-line (if backward -1)) + (not (or (null (darcsum-get-line-type)) + (and (looking-at "[0-9i\t]") ; stop at headers + (not (eq changeset (darcsum-changeset-at-point t)))))))))) + (unless (darcsum-get-line-type) + (goto-char (if backward (point-max) (point-min))) ;; Wrap around + (forward-line (if backward -3 3))) + (darcsum-reposition)) hunk ./site-lisp/darcsum.el 1344 -(defun darcsum-original-path (pos) - (let ((file (get-text-property pos 'darcsum-file)) - (dir (get-text-property pos 'darcsum-dir))) - (let ((path (expand-file-name ; new-style - file (file-name-as-directory - (expand-file-name dir "_darcs/pristine"))))) - (if (file-readable-p path) - path - (let ((path (expand-file-name ; old-style - file (file-name-as-directory - (expand-file-name dir "_darcs/current"))))) - (if (file-readable-p path) - path)))))) +(defun darcsum-mark-and-next-entity (&optional arg) + "Mark then move to the next unmarked directory, file or change. +With ARG, mark and move that many times." + (interactive "P") + (unless + (darcsum-apply-and-next-entity + (function darcsum-change-add-mark) + (function darcsum-changeset-any-unmarked-p) + arg) + (message "No more unmarked changes.")) + (darcsum-refresh)) hunk ./site-lisp/darcsum.el 1356 -(defun darcsum-path (pos) - (expand-file-name (get-text-property pos 'darcsum-file) - (file-name-as-directory - (get-text-property pos 'darcsum-dir)))) +(defun darcsum-unmark-and-next-entity (&optional arg) + "Unmark then move to the next marked directory, file or change. +With ARG, mark and move that many times." + (interactive "P") + (unless + (darcsum-apply-and-next-entity + (function darcsum-change-remove-mark) + (function darcsum-changeset-any-marked-p) + arg) + (message "No more marked changes.")) + (darcsum-refresh)) + +(defun darcsum-apply-and-next-entity (func next-p &optional arg backward) + "Apply FUNC to current changeset and move forward until NEXT-P changeset. +With ARG, mark and move that many times. With BACKWARD, move to previous. +Return nil if there is no changeset matching NEXT-P." + (let ((started (point)) + changeset + (type (darcsum-get-line-type))) + (if (catch 'exit + (ignore + (dotimes (i (or arg 1)) + (setq changeset (darcsum-changeset-at-point t)) + (darcsum-apply-to-changes changeset func) + (beginning-of-line) + (while (progn + (forward-line (if backward -1)) + (unless (darcsum-get-line-type) + (throw 'exit t)) + (not (and + (looking-at "[0-9i\t]") ; stop at headers + ; Don't stop at dir unless started from dir + (or (eq type 'dir) + (not (eq 'dir (darcsum-get-line-type)))) + (funcall next-p (darcsum-changeset-at-point t)))))) + ))) + (ignore (goto-char started)) + t))) hunk ./site-lisp/darcsum.el 1402 + ; XXX - does not work with darcs2! hunk ./site-lisp/darcsum.el 1404 - (if (not (darcsum-original-path (point))) - (error "No record of this file in darcs")) - (let ((type (get-text-property (point) 'darcsum-line-type))) + (let ((type (darcsum-get-line-type)) + (original-path (darcsum-original-path (point)))) hunk ./site-lisp/darcsum.el 1407 + ((not original-path) + (error "No record of this file in darcs")) hunk ./site-lisp/darcsum.el 1411 - (eq type 'change)) - (require 'diff) ; for `diff-switches' - (diff (darcsum-original-path (point)) - (darcsum-path (point)) - (or darcsum-diff-switches diff-switches)))))) + (eq type 'change)) + (require 'diff) ; for `diff-switches' + (diff original-path + (darcsum-path (point)) + (or darcsum-diff-switches diff-switches)))))) + +(defun darcsum-path (pos) + (expand-file-name (get-text-property pos 'darcsum-line-path))) + +(defun darcsum-original-path (pos) + (let* ((path (get-text-property pos 'darcsum-line-path)) + (pristine-path (expand-file-name path "_darcs/pristine")) + (current-path (expand-file-name path "_darcs/current"))) + (cond ((file-readable-p pristine-path) pristine-path) + ((file-readable-p current-path) current-path)))) hunk ./site-lisp/darcsum.el 1431 - (darcsum-remove-changeset darcsum-data - (darcsum-selected-changeset))) + (darcsum-remove-changeset darcsum-data + (darcsum-selected-changeset))) hunk ./site-lisp/darcsum.el 1436 - "Remove a file from the repository." + "Remove a file from the repository. + +This runs darcs remove (which undoes accidental addfile or adddir). + +If you want to remove an existing file or directory, remove file or +directory otherwise and record change." hunk ./site-lisp/darcsum.el 1444 - (let ((type (get-text-property (point) 'darcsum-line-type))) + (let ((changeset (darcsum-changeset-at-point t)) + (type (darcsum-get-line-type)) + (path (get-text-property (point) 'darcsum-line-path))) hunk ./site-lisp/darcsum.el 1448 - ((eq type 'dir) - (error "Cannot remove whole directories yet; try file by file for now")) - ((memq type '(file change)) - (let* ((dir (get-text-property (point) 'darcsum-dir)) - (dentry (and dir (assoc dir darcsum-data))) - (file (get-text-property (point) 'darcsum-file)) - (fentry (assoc file dentry)) - (sym (darcsum-change-item (cadr fentry))) - file-to-remove) - (cond - ((not (symbolp sym)) - (when (yes-or-no-p - (format "Really delete file with changes `%s'? " file)) - (delete-file (expand-file-name file dir)) - (setq file-to-remove file))) - ((eq sym 'newfile) - (delete-file (expand-file-name file dir))) - ((eq sym 'addfile) - (setq file-to-remove file) - (delete-file (expand-file-name file dir))) - (t - (error "Removing makes no sense for that entry"))) - (if file-to-remove - (with-temp-buffer - (cd (expand-file-name dir)) - (if (/= 0 (call-process darcsum-program nil t nil - "remove" file-to-remove)) - (error "Error running `darcsum remove'")))))))) - (darcsum-redo)) + ((eq (caadar changeset) 'adddir) + (setq changeset (cdr changeset)) + (while (memq (caadar changeset) '(newfile newdir)) + (setq changeset (cdr changeset))) + (if changeset + (error "Remove pending changes in directory first"))) + ((eq (caadar changeset) 'addfile) + (setq changeset (cdr changeset)) + (while (numberp (caadar changeset)) + (setq changeset (cdr changeset))) + (if changeset + (error "First undo pending changes in file"))) + (t + (error "Not added file or directory"))) + (unless (= 0 (call-process darcsum-program nil t nil + "remove" path)) + (error "Error running `darcs remove'")) + (darcsum-redo))) hunk ./site-lisp/darcsum.el 1471 - (dolist (dir (darcsum-selected-changeset)) - (dolist (file (cdr dir)) - (let ((item (darcsum-change-item (cadr file)))) - (if (and (symbolp item) (eq item 'newfile)) - (progn - (setcar (cadr file) 'addfile) - (with-temp-buffer - (cd (expand-file-name (car dir))) - (if (/= 0 (call-process darcsum-program nil t nil - "add" (car file))) - (error "Error running `darcsum add' for `%s' in dir `%s'" - (car file) (car dir))))) - (error "Can only add New entries for `%s' in dir `%s'" - (car file) (car dir)))))) + (let ((changeset (darcsum-selected-changeset)) + file path change added) + (dolist (file changeset) + (setq path (car file) + change (cadr file)) + (if (memq (car change) '(newfile newdir)) + (with-temp-buffer + (if (/= 0 (call-process + darcsum-program nil t nil "add" path)) + (error "Error running `darcs add' for `%s'" path) + (setcar change (cdr (assoc (car change) '((newfile . addfile) + (newdir . adddir)))))) + (setq added t)))) + (unless added + (error "No new entries, cannot add"))) hunk ./site-lisp/darcsum.el 1494 - (let ((type (get-text-property (point) 'darcsum-line-type))) + (let ((type (darcsum-get-line-type)) + (path (get-text-property (point) 'darcsum-line-path))) + (if (string-match "^\\./" path) + (setq path (substring path 2))) + (setq path (regexp-quote path)) hunk ./site-lisp/darcsum.el 1501 - (setq path (get-text-property (point) 'darcsum-dir)) - (if (string-match "^\\./" path) - (setq path (substring path 2))) - (setq path (concat "(^|/)" (regexp-quote path) "($|/)"))) + (setq path (concat "(^|/)" path "($|/)"))) hunk ./site-lisp/darcsum.el 1503 - (setq path (get-text-property (point) 'darcsum-file)) hunk ./site-lisp/darcsum.el 1516 - (let ((type (get-text-property (point) 'darcsum-line-type))) + (let ((type (darcsum-get-line-type))) hunk ./site-lisp/darcsum.el 1520 - (eq type 'change)) + (eq type 'change)) hunk ./site-lisp/darcsum.el 1527 - (let ((type (get-text-property (point) 'darcsum-line-type))) + (let ((type (darcsum-get-line-type))) hunk ./site-lisp/darcsum.el 1531 - (eq type 'change)) + (eq type 'change)) hunk ./site-lisp/darcsum.el 1533 - (working-filename (darcsum-path (point))) - (old-window-configuration (current-window-configuration)) ;;Save the current window configuration, before opening ediff - ) + (working-filename (darcsum-path (point))) + ;; Save the current window configuration, before opening ediff + (old-window-configuration (current-window-configuration)) + ) hunk ./site-lisp/darcsum.el 1538 - (save-excursion - (find-file-read-only pristine-filename) ;;Pristine copy should not be modified - (rename-buffer (concat "*darcsum-pristine:" pristine-filename "*")) ;;It should be clear this is not a buffer you want to touch. - ) - (ediff pristine-filename working-filename - ;;Add this anonymous function as a startup hook in ediff-mode - (lambda () (progn - (make-variable-buffer-local 'pre-darcsum-ediff-window-configuration) ;;make buffer-local variable storing old window configuration, since "let" bindings die before ediff buffers are killed - (setq pre-darcsum-ediff-window-configuration old-window-configuration) - (make-local-hook 'ediff-quit-hook) ;;After we quit THIS PARTICULAR ediff buffer, restore the old window configuration - (add-hook 'ediff-quit-hook (lambda () (set-window-configuration pre-darcsum-ediff-window-configuration))) - ))) - )))))) + (save-excursion + ;; Pristine copy should not be modified + (find-file-read-only pristine-filename) + ;; It should be clear this is not a buffer you want to touch. + (rename-buffer (concat "*darcsum-pristine:" pristine-filename "*")) + ) + (ediff pristine-filename working-filename + ;;Add this anonymous function as a startup hook in ediff-mode + (lambda () + (progn + (setq darcsum-pre-ediff-window-configuration + old-window-configuration) + ;; After we quit THIS PARTICULAR ediff buffer, + ;; restore the old window configuration + (add-hook + 'ediff-quit-hook + (lambda () (set-window-configuration + darcsum-pre-ediff-window-configuration) + ) nil t) + ))) + )))))) hunk ./site-lisp/darcsum.el 1563 - (let ((type (get-text-property (point) 'darcsum-line-type))) + (let ((type (darcsum-get-line-type))) hunk ./site-lisp/darcsum.el 1567 - (eq type 'change)) + (eq type 'change)) hunk ./site-lisp/darcsum.el 1569 - (darcsum-path (point))))))) + (darcsum-path (point))))))) hunk ./site-lisp/darcsum.el 1575 - (let ((dir default-directory) - (look-for-adds (or arg darcsum-look-for-adds)) - (darcsum-default-expanded t)) + (let ((dir (expand-file-name darcsum-subdirectory default-directory)) + (look-for-adds (or arg darcsum-look-for-adds)) + (darcsum-default-expanded t)) hunk ./site-lisp/darcsum.el 1580 - dir look-for-adds t darcsum-show-context))) + dir look-for-adds t darcsum-show-context))) hunk ./site-lisp/darcsum.el 1582 - (darcsum-merge-changeset darcsum-data changes))) + (darcsum-merge-changeset darcsum-data changes))) hunk ./site-lisp/darcsum.el 1617 - (forward-line 1) ; skip header + (forward-line 1) ; skip header hunk ./site-lisp/darcsum.el 1641 - (goto-char (point-max)) - (re-search-backward "^." nil t) - (end-of-line) - (insert "\n* ") - (if entry (insert entry)))) + (goto-char (point-max)) + (re-search-backward "^." nil t) + (end-of-line) + (insert "\n* ") + (if entry (insert entry)))) hunk ./site-lisp/darcsum.el 1688 + (define-key map "\C-\M-m" 'darcsum-show) hunk ./site-lisp/darcsum.el 1690 + (define-key map [tab] 'darcsum-next-entity) + (define-key map [space] 'darcsum-mark-and-next-entity) + (define-key map " " 'darcsum-mark-and-next-entity) + (define-key map [backspace] 'darcsum-unmark-and-next-entity) + (define-key map [delete] 'darcsum-unmark-and-next-entity) hunk ./site-lisp/darcsum.el 1697 + (define-key map "v" 'darcsum-display-change) hunk ./site-lisp/darcsum.el 1711 - ;; (define-key map "r" 'darcsum-remove) + (define-key map "r" 'darcsum-remove) hunk ./site-lisp/darcsum.el 1714 + (define-key map [button2] 'darcsum-mouse-toggle-mark) hunk ./site-lisp/darcsum.el 1722 - ["Open file.." darcsum-find-file - (or (darcsum-line-is 'file) - (darcsum-line-is 'change))] - [" ..other window" darcsum-find-file-other-window - (or (darcsum-line-is 'file) - (darcsum-line-is 'change))] - ["Display in other window" darcsum-display-file t] + ["Open file.." darcsum-find-file + (or (darcsum-line-is 'file) + (darcsum-line-is 'change))] + [" ..other window" darcsum-find-file-other-window + (or (darcsum-line-is 'file) + (darcsum-line-is 'change))] + ["Display in other window" darcsum-display-file t] hunk ./site-lisp/darcsum.el 1730 - ["Interactive diff" darcsum-ediff t] - ["Current diff" darcsum-diff t] - ["Interactive merge" darcsum-ediff-merge t]) -;; ["View log" darcsum-log t] + ["Interactive diff" darcsum-ediff t] + ["Current diff" darcsum-diff t] + ["Interactive merge" darcsum-ediff-merge t]) +;; ["View log" darcsum-log t] hunk ./site-lisp/darcsum.el 1735 - ["Re-examine" darcsum-redo t] - ["Record changes" darcsum-record t] ; fixme: condition - ["Amend last changeset" darcsum-amend t] ; fixme: condition -;; ["Tag" darcsum-tag t] - ["Undo changes" darcsum-revert t] ; fixme: condition - ["Add" darcsum-add (darcsum-line-is 'new)] - ["Remove" darcsum-remove (darcsum-line-is 'file)] - ["Ignore" darcsum-add-to-boring (darcsum-line-is 'file)] - ["Add ChangeLog" darcsum-add-change-log-entry t] - ["Delete" darcsum-delete t] + ["Re-examine" darcsum-redo t] + ["Record changes" darcsum-record t] ; fixme: condition + ["Amend last changeset" darcsum-amend t] ; fixme: condition +;; ["Tag" darcsum-tag t] + ["Undo changes" darcsum-revert t] ; fixme: condition + ["Add" darcsum-add (darcsum-line-is 'new)] + ["Remove" darcsum-remove (darcsum-line-is 'file)] + ["Ignore" darcsum-add-to-boring (darcsum-line-is 'file)] + ["Add ChangeLog" darcsum-add-change-log-entry t] + ["Delete" darcsum-delete t] hunk ./site-lisp/darcsum.el 1746 - ["(Un)activate change" darcsum-toggle t] - ["(Un)mark change" darcsum-toggle-mark - :style toggle - :selected (darcsum-line-is 'marked)] - ["Next file/change" darcsum-next-line t] - ["Previous file/change" darcsum-previous-line t] - ["Move changeset" darcsum-move t] - ["Show change context" darcsum-toggle-context - :style toggle :selected darcsum-show-context] + ["(Un)activate change" darcsum-toggle t] + ["(Un)mark change" darcsum-toggle-mark + :style toggle + :selected (darcsum-line-is 'marked)] + ["Next file/change" darcsum-next-line t] + ["Previous file/change" darcsum-previous-line t] + ["Move changeset" darcsum-move t] + ["Show change context" darcsum-toggle-context + :style toggle :selected darcsum-show-context] hunk ./site-lisp/darcsum.el 1756 - ["Quit" darcsum-quit t] + ["Quit" darcsum-quit t] hunk ./site-lisp/darcsum.el 1763 + (make-local-variable 'darcsum-data) + (make-local-variable 'darcsum-look-for-adds) + (make-local-variable 'darcsum-show-context) + (make-local-variable 'darcsum-subdirectory) + (setq darcsum-data nil) hunk ./site-lisp/darcsum.el 1773 -(custom-add-option 'darcsum-mode-hook - '(lambda () ; Should be a minor mode for this! - "Show trailing whitespace in changes." - (setq show-trailing-whitespace t))) +(defun darcsum-display (changeset &optional look-for-adds sub-directory) + "Display CHANGESET from SUB-DIRECTORY in a buffer. hunk ./site-lisp/darcsum.el 1776 -;;; This is the entry code, M-x darcsum-whatsnew +If there there already is a buffer for displaying changes in this darcs +repository (and subdirectory within it), use the existing buffer (unless +darcsum-display-with-existing-buffer is nil)." + (unless sub-directory (setq sub-directory ".")) + (with-current-buffer + (or (if darcsum-display-with-existing-buffer + (darcsum-find-buffer default-directory sub-directory)) + (darcsum-new-buffer default-directory sub-directory)) + (setq darcsum-data (darcsum-merge-changeset darcsum-data changeset)) + (setq darcsum-look-for-adds look-for-adds) + (setq darcsum-subdirectory sub-directory) + (darcsum-refresh 0) + (darcsum-next-line 0) + (unless (darcsum-changeset-all-visible-p darcsum-data) + (message + "Press %s to show all changes" + (darcsum-where-is (function darcsum-show)))) + (switch-to-buffer (current-buffer)))) hunk ./site-lisp/darcsum.el 1795 -(defun darcsum-display (data &optional look-for-adds) - (with-current-buffer (generate-new-buffer "*darcs*") +(defcustom darcsum-display-with-existing-buffer t + "*If nil, always create new buffer to display changeset." + :type 'boolean + :group 'darcsum) + +(defun darcsum-new-buffer (&optional dir subdir) + "Generate new darcsum buffer for (SUBDIR in DIR)." + (setq dir (file-name-nondirectory + (directory-file-name (file-name-directory + (or dir default-directory))))) + (if (string= subdir ".") + (setq subdir nil)) + (with-current-buffer + (generate-new-buffer + (concat "*darcs " dir + (when subdir "/") + (when subdir + (if (file-name-absolute-p subdir) + (file-relative-name subdir) + subdir)) + "*")) hunk ./site-lisp/darcsum.el 1817 - (set (make-local-variable 'darcsum-data) data) - (set (make-local-variable 'darcsum-look-for-adds) look-for-adds) - (set (make-local-variable 'darcsum-show-context) nil) - (darcsum-refresh) - (goto-char (point-min)) - (forward-line 3) - (darcsum-reposition) - (switch-to-buffer (current-buffer)))) + (current-buffer))) + +(defun darcsum-find-buffer (&optional dir subdir) + "Get existing darcsum buffer (for SUBDIR in DIR)." + (catch 'exit + (ignore + (let (buffer locals mode buffer-dir) + (dolist (buffer (buffer-list)) + (setq locals (buffer-local-variables buffer) + mode (cdr (assq 'major-mode locals)) + buffer-dir (cdr (assq 'default-directory locals)) + buffer-subdir (cdr (assq 'darcsum-subdirectory locals))) + (if (and (eq mode 'darcsum-mode) + (or (null dir) (string= buffer-dir dir)) + (or (null subdir) (string= buffer-subdir subdir))) + (throw 'exit buffer))))))) + +(defun darcsum-where-is (command) + "Return the representation of key sequences that invoke specified COMMAND." + (let ((keys (where-is-internal command))) + (if keys + (if (featurep 'xemacs) + (sorted-key-descriptions keys) + (mapconcat 'key-description keys ", ")) + (format "M-x %s RET" command)))) hunk ./site-lisp/darcsum.el 1866 +;;; This is the entry code, M-x darcsum-whatsnew + hunk ./site-lisp/darcsum.el 1870 - &optional look-for-adds no-display show-context) + &optional look-for-adds no-display show-context) hunk ./site-lisp/darcsum.el 1877 - (if darcsum-whatsnew-at-toplevel - (darcsum-repository-root) - default-directory))) + (if darcsum-whatsnew-at-toplevel + (darcsum-repository-root) + default-directory))) hunk ./site-lisp/darcsum.el 1881 - 'read-directory-name - 'read-file-name) - "Directory: " root root) - (or darcsum-look-for-adds current-prefix-arg)))) + 'read-directory-name + 'read-file-name) + "Directory: " root root) + (or darcsum-look-for-adds current-prefix-arg)))) hunk ./site-lisp/darcsum.el 1889 - (error "Directory `%s' is not under darcs version control" - directory)) + (error "Directory `%s' is not under darcs version control" + directory)) hunk ./site-lisp/darcsum.el 1892 - (let* ((process-environment (append - (list "DARCS_DONT_ESCAPE_TRAILING_SPACES=1" - "DARCS_DONT_COLOR=1" - "DARCS_DONT_ESCAPE_TRAILING_CR=1") - process-environment)) - (args (append - ;; Build a list of arguments for call-process - (list darcsum-program nil t nil) - (list "whatsnew" "--no-summary") - (darcsum-fix-switches darcsum-whatsnew-switches) - ; Arguments override user preferences - (unless (null look-for-adds) (list "--look-for-adds")) - (unless (null show-context) (list "--unified")) - (unless (string= directory default-directory) - (list (file-relative-name - directory default-directory))) - nil)) - (result (apply 'call-process args))) + (let* ((process-environment (append + darcsum-environment + darcsum-output-environment + process-environment)) + (args (append + ;; Build a list of arguments for call-process + (list darcsum-program nil t nil) + (list "whatsnew" "--no-summary") + (darcsum-fix-switches darcsum-whatsnew-switches) + ; Arguments override user preferences + (unless (null look-for-adds) (list "--look-for-adds")) + (unless (null show-context) (list "--unified")) + (unless (string= directory default-directory) + (list (file-relative-name + directory default-directory))) + nil)) + (result (apply 'call-process args)) + message) hunk ./site-lisp/darcsum.el 1911 - (if (= result 1) - (progn (and (interactive-p) (message "No changes!")) - nil) - (progn (if (member "*darcs-output*" - (mapcar (lambda (&rest x) - (apply 'buffer-name x)) - (buffer-list)) ) - (kill-buffer "*darcs-output*")) - (if (fboundp 'clone-buffer) - (clone-buffer "*darcs-output*" t)) - (error "Error running darcsum whatsnew"))) - (let ((changes (darcsum-read-changeset darcsum-default-expanded))) - (if (and changes (not no-display)) - (darcsum-display changes look-for-adds)) - changes))))) + (if (= result 1) + (ignore (and (interactive-p) (message "No changes!"))) + (ignore + (if (fboundp 'clone-buffer) + (progn + (condition-case nil (kill-buffer "*darcs-output*") (error nil)) + (clone-buffer "*darcs-output*" t)) + (goto-char (point-min)) + (if (looking-at "\n*darcs failed\\(: .*\\)") + (setq message (match-string 1)))) + (error (concat "Error running darcs whatsnew" message)))) + (let ((changes (darcsum-read-changeset darcsum-default-expanded))) + (if (and changes (not no-display)) + (darcsum-display changes look-for-adds + (directory-file-name + (file-relative-name directory)))) + changes))))) hunk ./site-lisp/darcsum.el 1935 - (while (string-match "\\(\\S-+\\)" switch-spec start) - (setq result (cons (substring switch-spec (match-beginning 1) - (match-end 1)) - result) - start (match-end 0))) - (nreverse result)) + (while (string-match "\\(\\S-+\\)" switch-spec start) + (setq result (cons (substring switch-spec (match-beginning 1) + (match-end 1)) + result) + start (match-end 0))) + (nreverse result)) hunk ./site-lisp/darcsum.el 1953 - 'read-directory-name - 'read-file-name) - "Directory: " - (darcsum-repository-root)))) + 'read-directory-name + 'read-file-name) + "Directory: " + (darcsum-repository-root)))) hunk ./site-lisp/darcsum.el 1959 - directory)) + directory)) hunk ./site-lisp/darcsum.el 1961 - (goto-char (1- (point)))) - (search-backward "{" nil t)) + (goto-char (1- (point)))) + (search-backward "{" nil t)) hunk ./site-lisp/darcsum.el 1964 - (default-directory directory)) - (darcsum-display changes)) + (default-directory directory)) + (darcsum-display changes)) hunk ./site-lisp/darcsum.el 1977 + (eval-when-compile (require 'gnus) + (require 'gnus-sum) + (require 'gnus-art) + (require 'gnus-fun) + (require 'gnus-win) + (require 'gnus-util) + (require 'mm-view) + (require 'mail-parse) + hunk ./site-lisp/darcsum.el 1989 - (directory - (funcall (if (fboundp 'read-directory-name) - 'read-directory-name - 'read-file-name) - "Apply patch to directory: "))) + (directory + (funcall (if (fboundp 'read-directory-name) + 'read-directory-name + 'read-file-name) + "Apply patch to directory: "))) hunk ./site-lisp/darcsum.el 1995 - (mm-insert-part handle) - (let ((coding-system-for-write 'binary)) - (goto-char (point-min)) - (darcsum-view directory) - (delete-other-windows))))) + (mm-insert-part handle) + (let ((coding-system-for-write 'binary)) + (goto-char (point-min)) + (darcsum-view directory) + (delete-other-windows))))) hunk ./site-lisp/darcsum.el 2007 - (mm-view-darcs-patch data)))) + (mm-view-darcs-patch data)))) hunk ./site-lisp/darcsum.el 2017 - '(("apply darcs patch" . gnus-mime-view-darcs-patch))) + '(("apply darcs patch" . gnus-mime-view-darcs-patch))) hunk ./site-lisp/darcsum.el 2019 - '((gnus-mime-view-darcs-patch "V" "Apply darcs patch..."))))) + '((gnus-mime-view-darcs-patch "V" "Apply darcs patch..."))))) hunk ./site-lisp/darcsum.el 2027 - (save-restriction - (widen) - (goto-char (point-min)) - (darcsum-view directory))))) + (save-restriction + (widen) + (goto-char (point-min)) + (darcsum-view directory))))) hunk ./site-lisp/darcsum.el 2036 - 'gnus-summary-view-darcs-patch)))) + 'gnus-summary-view-darcs-patch))))) }