X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/e8faa44b9a8771490b14044bbb99fa2538d0f42e..a0689e114cdccceedc366e1bfa5be00ad62b2a31:/contrib/stgit.el diff --git a/contrib/stgit.el b/contrib/stgit.el index 6248cd9..4843f1e 100644 --- a/contrib/stgit.el +++ b/contrib/stgit.el @@ -14,6 +14,7 @@ (require 'git nil t) (require 'cl) +(require 'comint) (require 'ewoc) (require 'easymenu) (require 'format-spec) @@ -43,12 +44,30 @@ instead of \"dir/old/file -> dir/new/file\"." (defcustom stgit-default-show-worktree t "Set to non-nil to by default show the working tree in a new stgit buffer. -Use \\\\[stgit-toggle-worktree] to toggle the -this setting in an already-started StGit buffer." +Use \\\\[stgit-toggle-worktree] to toggle this \ +setting in an already-started StGit buffer." :type 'boolean :group 'stgit :link '(variable-link stgit-show-worktree)) +(defcustom stgit-default-show-unknown nil + "Set to non-nil to by default show unknown files a new stgit buffer. + +Use \\\\[stgit-toggle-unknown] to toggle this \ +setting in an already-started StGit buffer." + :type 'boolean + :group 'stgit + :link '(variable-link stgit-show-unknown)) + +(defcustom stgit-default-show-ignored nil + "Set to non-nil to by default show ignored files a new stgit buffer. + +Use \\\\[stgit-toggle-ignored] to toggle this \ +setting in an already-started StGit buffer." + :type 'boolean + :group 'stgit + :link '(variable-link stgit-show-ignored)) + (defcustom stgit-find-copies-harder nil "Try harder to find copied files when listing patches. @@ -733,10 +752,12 @@ Cf. `stgit-file-type-change-string'." (defun stgit-insert-patch-files (patch) "Expand (show modification of) the patch PATCH after the line at point." - (let* ((patchsym (stgit-patch->name patch)) - (end (point-marker)) - (args (list "-z" (stgit-find-copies-harder-diff-arg))) - (ewoc (ewoc-create #'stgit-file-pp nil nil t))) + (let* ((patchsym (stgit-patch->name patch)) + (end (point-marker)) + (args (list "-z" (stgit-find-copies-harder-diff-arg))) + (ewoc (ewoc-create #'stgit-file-pp nil nil t)) + (show-ignored stgit-show-ignored) + (show-unknown stgit-show-unknown)) (set-marker-insertion-type end t) (setf (stgit-patch->files-ewoc patch) ewoc) (with-temp-buffer @@ -752,9 +773,9 @@ at point." `("diff-tree" ,@args "-r" ,(stgit-id patchsym))))) (when (and (eq patchsym :work)) - (when stgit-show-ignored + (when show-ignored (stgit-insert-ls-files '("--ignored" "--others") "I")) - (when stgit-show-unknown + (when show-unknown (stgit-insert-ls-files '("--directory" "--no-empty-directory" "--others") "X")) @@ -843,6 +864,8 @@ See also `stgit-expand'." (stgit-process-files (lambda (f) (setq node (ewoc-enter-after ewoc node f)))))) + (move-to-column (stgit-goal-column)) + (let ((inhibit-read-only t)) (put-text-property start end 'patch-data patch)))) @@ -943,7 +966,6 @@ file for (applied) copies and renames." (unless stgit-mode-map (let ((diff-map (make-sparse-keymap)) (toggle-map (make-sparse-keymap))) - (suppress-keymap diff-map) (mapc (lambda (arg) (define-key diff-map (car arg) (cdr arg))) '(("b" . stgit-diff-base) ("c" . stgit-diff-combined) @@ -951,7 +973,6 @@ file for (applied) copies and renames." ("o" . stgit-diff-ours) ("r" . stgit-diff-range) ("t" . stgit-diff-theirs))) - (suppress-keymap toggle-map) (mapc (lambda (arg) (define-key toggle-map (car arg) (cdr arg))) '(("n" . stgit-toggle-patch-names) ("t" . stgit-toggle-worktree) @@ -1226,7 +1247,9 @@ Commands for branches: Customization variables: `stgit-abbreviate-copies-and-renames' +`stgit-default-show-ignored' `stgit-default-show-patch-names' +`stgit-default-show-unknown' `stgit-default-show-worktree' `stgit-find-copies-harder' `stgit-show-worktree-mode' @@ -1238,15 +1261,17 @@ See also \\[customize-group] for the \"stgit\" group." major-mode 'stgit-mode goal-column 2) (use-local-map stgit-mode-map) - (set (make-local-variable 'list-buffers-directory) default-directory) - (set (make-local-variable 'stgit-marked-patches) nil) - (set (make-local-variable 'stgit-expanded-patches) (list :work :index)) - (set (make-local-variable 'stgit-show-patch-names) - stgit-default-show-patch-names) - (set (make-local-variable 'stgit-show-worktree) stgit-default-show-worktree) - (set (make-local-variable 'stgit-index-node) nil) - (set (make-local-variable 'stgit-worktree-node) nil) - (set (make-local-variable 'parse-sexp-lookup-properties) t) + (mapc (lambda (x) (set (make-local-variable (car x)) (cdr x))) + `((list-buffers-directory . ,default-directory) + (parse-sexp-lookup-properties . t) + (stgit-expanded-patches . (:work :index)) + (stgit-index-node . nil) + (stgit-worktree-node . nil) + (stgit-marked-patches . nil) + (stgit-show-ignored . ,stgit-default-show-ignored) + (stgit-show-patch-names . ,stgit-default-show-patch-names) + (stgit-show-unknown . ,stgit-default-show-unknown) + (stgit-show-worktree . ,stgit-default-show-worktree))) (set-variable 'truncate-lines 't) (add-hook 'after-save-hook 'stgit-update-stgit-for-buffer) (unless stgit-did-advise @@ -1495,9 +1520,16 @@ If ALL is not nil, also return non-stgit branches." ((not (string-match stgit-allowed-branch-name-re branch)) (error "Invalid branch name")) ((yes-or-no-p (format "Create branch \"%s\"? " branch)) - (stgit-capture-output nil (stgit-run "branch" "--create" "--" - branch)) - t)) + (let ((branch-point (completing-read + "Branch from (default current branch): " + (stgit-available-branches)))) + (stgit-capture-output nil + (apply 'stgit-run + `("branch" "--create" "--" + ,branch + ,@(unless (zerop (length branch-point)) + (list branch-point))))) + t))) (stgit-reload))) (defun stgit-available-refs (&optional omit-stgit) @@ -2225,6 +2257,19 @@ deepest patch had before the squash." (stgit-reload))) (funcall old-sentinel process sentinel))) +(defun stgit-execute-process-filter (process output) + (with-current-buffer (process-buffer process) + (let* ((old-point (point)) + (pmark (process-mark process)) + (insert-at (marker-position pmark)) + (at-pmark (= insert-at old-point))) + (goto-char insert-at) + (insert-before-markers output) + (comint-carriage-motion insert-at (point)) + (set-marker pmark (point)) + (unless at-pmark + (goto-char old-point))))) + (defun stgit-execute () "Prompt for an stg command to execute in a shell. @@ -2263,7 +2308,10 @@ When the command has finished, reload the stgit buffer." (process-sentinel process)) (set (make-local-variable 'stgit-buffer) old-buffer) + (set-process-filter process 'stgit-execute-process-filter) (set-process-sentinel process 'stgit-execute-process-sentinel)))) + (with-current-buffer buffer + (comint-carriage-motion (point-min) (point-max))) (shrink-window-if-larger-than-buffer (get-buffer-window buffer)) (stgit-reload)))) @@ -2353,6 +2401,8 @@ work tree will show up." "Toggle the visibility of files ignored by git in the work tree. With ARG, show these files if ARG is positive. +Its initial setting is controlled by `stgit-default-show-ignored'. + Use \\[stgit-toggle-worktree] to show the work tree." (interactive) (stgit-assert-mode) @@ -2366,6 +2416,8 @@ Use \\[stgit-toggle-worktree] to show the work tree." "Toggle the visibility of files not registered with git in the work tree. With ARG, show these files if ARG is positive. +Its initial setting is controlled by `stgit-default-show-unknown'. + Use \\[stgit-toggle-worktree] to show the work tree." (interactive) (stgit-assert-mode)