Improve log editing.
* magit.el (magit-log-fill-paragraph, magit-log-edit-mode): New, for better paragraph filling. (magit-log-edit): Use it. (magit-add-log): Add entries also for diffs. Be more careful when inserting new function sub-entries into existing file entries.
This commit is contained in:
parent
e20322754c
commit
1f74c1b0c1
1 changed files with 43 additions and 15 deletions
58
magit.el
58
magit.el
|
@ -1607,7 +1607,7 @@ Please see the manual for a complete description of Magit.
|
||||||
(interactive)
|
(interactive)
|
||||||
(magit-run-async "git" "push" "-v"))
|
(magit-run-async "git" "push" "-v"))
|
||||||
|
|
||||||
;;; Committing
|
;;; Log edit mode
|
||||||
|
|
||||||
(defvar magit-log-edit-map
|
(defvar magit-log-edit-map
|
||||||
(let ((map (make-sparse-keymap)))
|
(let ((map (make-sparse-keymap)))
|
||||||
|
@ -1619,6 +1619,23 @@ Please see the manual for a complete description of Magit.
|
||||||
|
|
||||||
(defvar magit-pre-log-edit-window-configuration nil)
|
(defvar magit-pre-log-edit-window-configuration nil)
|
||||||
|
|
||||||
|
(defun magit-log-fill-paragraph (&optional justify)
|
||||||
|
"Fill the paragraph, but preserve open parentheses at beginning of lines.
|
||||||
|
Prefix arg means justify as well."
|
||||||
|
(interactive "P")
|
||||||
|
;; Add lines starting with a left paren or an asterisk.
|
||||||
|
(let ((paragraph-start (concat paragraph-start "\\|*\\|(")))
|
||||||
|
(let ((end (progn (forward-paragraph) (point)))
|
||||||
|
(beg (progn (backward-paragraph) (point)))
|
||||||
|
(adaptive-fill-mode nil))
|
||||||
|
(fill-region beg end justify)
|
||||||
|
t)))
|
||||||
|
|
||||||
|
(define-derived-mode magit-log-edit-mode text-mode "Magit Log Edit"
|
||||||
|
(set (make-local-variable 'fill-paragraph-function)
|
||||||
|
'magit-log-fill-paragraph)
|
||||||
|
(use-local-map magit-log-edit-map))
|
||||||
|
|
||||||
(defun magit-log-edit-cleanup ()
|
(defun magit-log-edit-cleanup ()
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
|
@ -1737,29 +1754,39 @@ Please see the manual for a complete description of Magit.
|
||||||
(current-window-configuration))
|
(current-window-configuration))
|
||||||
(pop-to-buffer buf)
|
(pop-to-buffer buf)
|
||||||
(setq default-directory dir)
|
(setq default-directory dir)
|
||||||
(use-local-map magit-log-edit-map)
|
(magit-log-edit-mode)
|
||||||
(message "Type C-c C-c to commit.")))
|
(message "Type C-c C-c to commit.")))
|
||||||
|
|
||||||
(defun magit-add-log ()
|
(defun magit-add-log ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((section (magit-current-section)))
|
(let ((section (magit-current-section)))
|
||||||
(if (not (eq (magit-section-type section) 'hunk))
|
(let ((fun (if (eq (magit-section-type section) 'hunk)
|
||||||
(error "No hunk at point."))
|
(save-window-excursion
|
||||||
(let ((fun (save-window-excursion
|
(save-excursion
|
||||||
(save-excursion
|
(magit-visit-item)
|
||||||
(magit-visit-item)
|
(add-log-current-defun)))
|
||||||
(add-log-current-defun))))
|
nil))
|
||||||
(file (magit-diff-item-file (magit-hunk-item-diff section))))
|
(file (magit-diff-item-file
|
||||||
|
(cond ((eq (magit-section-type section) 'hunk)
|
||||||
|
(magit-hunk-item-diff section))
|
||||||
|
((eq (magit-section-type section) 'diff)
|
||||||
|
section)
|
||||||
|
(error "No change at point")))))
|
||||||
(magit-log-edit)
|
(magit-log-edit)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(cond ((not (search-forward-regexp (format "^\\* %s" (regexp-quote file))
|
(cond ((not (search-forward-regexp (format "^\\* %s" (regexp-quote file))
|
||||||
nil t))
|
nil t))
|
||||||
;; No entry for file, create it.
|
;; No entry for file, create it.
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(insert (format "\n* %s (%s): " file fun)))
|
(insert (format "\n* %s" file))
|
||||||
(t
|
(if fun
|
||||||
|
(insert (format " (%s)" fun)))
|
||||||
|
(insert ": "))
|
||||||
|
(fun
|
||||||
;; found entry for file, look for fun
|
;; found entry for file, look for fun
|
||||||
(let ((limit (or (search-forward-regexp "^\\* " nil t)
|
(let ((limit (or (save-excursion
|
||||||
|
(and (search-forward-regexp "^\\* " nil t)
|
||||||
|
(match-beginning 0)))
|
||||||
(point-max))))
|
(point-max))))
|
||||||
(cond ((search-forward-regexp (format "(.*\\<%s\\>.*):"
|
(cond ((search-forward-regexp (format "(.*\\<%s\\>.*):"
|
||||||
(regexp-quote fun))
|
(regexp-quote fun))
|
||||||
|
@ -1769,10 +1796,11 @@ Please see the manual for a complete description of Magit.
|
||||||
(backward-char 2)
|
(backward-char 2)
|
||||||
(goto-char limit)))
|
(goto-char limit)))
|
||||||
(t
|
(t
|
||||||
;; not found insert new entry
|
;; not found, insert new entry
|
||||||
(goto-char limit)
|
(goto-char limit)
|
||||||
(beginning-of-line)
|
(if (bolp)
|
||||||
(open-line 1)
|
(open-line 1)
|
||||||
|
(newline))
|
||||||
(insert (format "(%s): " fun))))))))))
|
(insert (format "(%s): " fun))))))))))
|
||||||
|
|
||||||
;;; Commits
|
;;; Commits
|
||||||
|
|
Loading…
Reference in a new issue