(require 'cl)
(require 'ewoc)
(require 'easymenu)
+(require 'format-spec)
(defun stgit-set-default (symbol value)
"Set default value of SYMBOL to VALUE using `set-default' and
:link '(variable-link stgit-show-worktree)
:set 'stgit-set-default)
+(defcustom stgit-patch-line-format "%s%m%-30n %e%d"
+ "The format string used to format patch lines.
+The format string is passed to `format-spec' and the following
+format characters are recognized:
+
+ %s - A '+', '-', '>' or space, depending on whether the patch is
+ applied, unapplied, top, or something else.
+
+ %m - An asterisk if the patch is marked, and a space otherwise.
+
+ %n - The patch name.
+
+ %e - The string \"(empty) \" if the patch is empty.
+
+ %d - The short patch description.
+
+ %D - The short patch description, or the patch name.
+
+When `stgit-show-patch-names' is non-nil, the `stgit-noname-patch-line-format'
+variable is used instead."
+ :type 'string
+ :group 'stgit
+ :set 'stgit-set-default)
+
+(defcustom stgit-noname-patch-line-format "%s%m%e%D"
+ "The alternate format string used to format patch lines.
+It has the same semantics as `stgit-patch-line-format', and the
+display can be toggled between the two formats using
+\\<stgit-mode-map>>\\[stgit-toggle-patch-names].
+
+The alternate form is used when the patch name is hidden."
+ :type 'string
+ :group 'stgit
+ :set 'stgit-set-default)
+
+(defcustom stgit-default-show-patch-names t
+ "If non-nil, default to showing patch names in a new stgit buffer.
+
+Use \\<stgit-mode-map>\\[stgit-toggle-patch-names] to toggle the
+this setting in an already-started StGit buffer."
+ :type 'boolean
+ :group 'stgit
+ :link '(variable-link stgit-show-patch-names))
+
+(defcustom stgit-file-line-format " %-11s %-2m %n %c"
+ "The format string used to format file lines.
+The format string is passed to `format-spec' and the following
+format characters are recognized:
+
+ %s - A string describing the status of the file.
+
+ %m - Mode change information
+
+ %n - The file name.
+
+ %c - A description of file changes."
+ :type 'string
+ :group 'stgit
+ :set 'stgit-set-default)
+
(defface stgit-branch-name-face
'((t :inherit bold))
"The face used for the StGit branch name"
(defstruct (stgit-patch)
status name desc empty files-ewoc)
+(defun stgit-patch-display-name (patch)
+ (let ((name (stgit-patch-name patch)))
+ (case name
+ (:index "Index")
+ (:work "Work Tree")
+ (t (symbol-name name)))))
+
(defun stgit-patch-pp (patch)
(let* ((status (stgit-patch-status patch))
(start (point))
(name (stgit-patch-name patch))
- (face (cdr (assq status stgit-patch-status-face-alist))))
- (insert (case status
- ('applied "+")
- ('top ">")
- ('unapplied "-")
- (t " "))
- (if (memq name stgit-marked-patches)
- "*" " "))
- (if (memq status '(index work))
- (insert (propertize (if (eq status 'index) "Index" "Work tree")
- 'face face))
- (insert (format "%-30s"
- (propertize (symbol-name name)
- 'face face
- 'syntax-table (string-to-syntax "w")))
- " "
- (if (stgit-patch-empty patch) "(empty) " "")
- (propertize (or (stgit-patch-desc patch) "")
- 'face 'stgit-description-face)))
- (insert "\n")
+ (face (cdr (assq status stgit-patch-status-face-alist)))
+ (fmt (if stgit-show-patch-names
+ stgit-patch-line-format
+ stgit-noname-patch-line-format))
+ (spec (format-spec-make
+ ?s (case status
+ ('applied "+")
+ ('top ">")
+ ('unapplied "-")
+ (t " "))
+ ?m (if (memq name stgit-marked-patches)
+ "*" " ")
+ ?n (propertize (stgit-patch-display-name patch)
+ 'face face
+ 'syntax-table (string-to-syntax "w"))
+ ?e (if (stgit-patch-empty patch) "(empty) " "")
+ ?d (propertize (or (stgit-patch-desc patch) "")
+ 'face 'stgit-description-face)
+ ?D (propertize (or (stgit-patch-desc patch)
+ (stgit-patch-display-name patch))
+ 'face face))))
+
+ (insert (format-spec fmt spec) "\n")
(put-text-property start (point) 'entry-type 'patch)
(when (memq name stgit-expanded-patches)
(stgit-insert-patch-files patch))
stgit-file-status-code-strings))
(score (stgit-file-cr-score file)))
(when code
- (format "%-11s "
- (if (and score (/= score 100))
- (format "%s %s" (cdr code)
- (propertize (format "%d%%" score)
- 'face 'stgit-description-face))
- (cdr code))))))
+ (if (and score (/= score 100))
+ (format "%s %s" (cdr code)
+ (propertize (format "%d%%" score)
+ 'face 'stgit-description-face))
+ (cdr code)))))
(defun stgit-file-status-code (str &optional score)
"Return stgit status code from git status string"
((zerop old-type)
(if (= new-type #o100)
""
- (format " (%s)" (stgit-file-type-string new-type))))
- (t (format " (%s -> %s)"
+ (format "(%s)" (stgit-file-type-string new-type))))
+ (t (format "(%s -> %s)"
(stgit-file-type-string old-type)
(stgit-file-type-string new-type))))))
(concat (stgit-file-cr-from file) arrow (stgit-file-cr-to file)))))
(defun stgit-file-pp (file)
- (let ((status (stgit-file-status file))
- (name (if (stgit-file-copy-or-rename file)
- (stgit-describe-copy-or-rename file)
- (stgit-file-file file)))
- (mode-change (stgit-file-mode-change-string
- (stgit-file-old-perm file)
- (stgit-file-new-perm file)))
- (start (point)))
- (insert (format " %-12s%s%s%s%s\n"
- (stgit-file-status-code-as-string file)
- mode-change
- (if (zerop (length mode-change)) "" " ")
- name
- (propertize (stgit-file-type-change-string
- (stgit-file-old-perm file)
- (stgit-file-new-perm file))
- 'face 'stgit-description-face)))
+ (let ((start (point))
+ (spec (format-spec-make
+ ?s (stgit-file-status-code-as-string file)
+ ?m (stgit-file-mode-change-string
+ (stgit-file-old-perm file)
+ (stgit-file-new-perm file))
+ ?n (if (stgit-file-copy-or-rename file)
+ (stgit-describe-copy-or-rename file)
+ (stgit-file-file file))
+ ?c (propertize (stgit-file-type-change-string
+ (stgit-file-old-perm file)
+ (stgit-file-new-perm file))
+ 'face 'stgit-description-face))))
+ (insert (format-spec stgit-file-line-format spec) "\n")
(add-text-properties start (point)
(list 'entry-type 'file
'file-data file))))
("t" . stgit-diff-theirs)))
(suppress-keymap toggle-map)
(mapc (lambda (arg) (define-key toggle-map (car arg) (cdr arg)))
- '(("t" . stgit-toggle-worktree)
+ '(("n" . stgit-toggle-patch-names)
+ ("t" . stgit-toggle-worktree)
("i" . stgit-toggle-ignored)
("u" . stgit-toggle-unknown)))
(setq stgit-mode-map (make-keymap))
:selected stgit-show-unknown :active stgit-show-worktree]
["Show ignored files" stgit-toggle-ignored :style toggle
:selected stgit-show-ignored :active stgit-show-worktree]
+ ["Show patch names" stgit-toggle-patch-names :style toggle
+ :selected stgit-show-patch-names]
"-"
["Switch branches" stgit-branch t
:help "Switch to another branch"]
\\[stgit-revert] Revert changes to file
Display commands:
+\\[stgit-toggle-patch-names] Toggle showing patch names
\\[stgit-toggle-worktree] Toggle showing index and work tree
\\[stgit-toggle-unknown] Toggle showing unknown files
\\[stgit-toggle-ignored] Toggle showing ignored files
Customization variables:
`stgit-abbreviate-copies-and-renames'
+`stgit-default-show-patch-names'
`stgit-default-show-worktree'
`stgit-find-copies-harder'
`stgit-show-worktree-mode'
(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)
(defvar stgit-show-unknown nil
"If nil, inhibit showing files not registered with git.")
+(defvar stgit-show-patch-names t
+ "If nil, inhibit showing patch names.")
+
(defun stgit-toggle-worktree (&optional arg)
"Toggle the visibility of the work tree.
With ARG, show the work tree if ARG is positive.
(not stgit-show-unknown)))
(stgit-reload))
+(defun stgit-toggle-patch-names (&optional arg)
+ "Toggle the visibility of patch names. With ARG, show patch names
+if ARG is positive.
+
+The initial setting is controlled by `stgit-default-show-patch-names'."
+ (interactive)
+ (stgit-assert-mode)
+ (setq stgit-show-patch-names
+ (if (numberp arg)
+ (> arg 0)
+ (not stgit-show-patch-names)))
+ (stgit-reload))
+
(provide 'stgit)