2010-05-31 17:06:44 +02:00
|
|
|
(defvar rebase-mode-action-line-re
|
|
|
|
(rx
|
|
|
|
line-start
|
|
|
|
(group
|
|
|
|
(|
|
|
|
|
(any "presf")
|
|
|
|
"pick"
|
|
|
|
"reword"
|
|
|
|
"edit"
|
|
|
|
"squash"
|
|
|
|
"fixup"))
|
|
|
|
(char space)
|
2010-05-31 17:40:58 +02:00
|
|
|
(group
|
|
|
|
(** 7 40 (char "0-9" "a-f" "A-F"))) ;sha1
|
|
|
|
(char space)
|
|
|
|
(* anything) ; msg
|
2010-05-31 17:46:25 +02:00
|
|
|
line-end)
|
|
|
|
"Regexp that matches an action line in a rebase buffer.")
|
2010-05-31 17:06:44 +02:00
|
|
|
|
|
|
|
(defvar rebase-font-lock-keywords
|
|
|
|
(list
|
|
|
|
(list rebase-mode-action-line-re
|
|
|
|
'(1 font-lock-keyword-face)
|
2010-05-31 17:46:25 +02:00
|
|
|
'(2 font-lock-builtin-face)))
|
|
|
|
"Font lock keywords for rebase-mode.")
|
|
|
|
|
|
|
|
(defvar rebase-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map (kbd "q") 'server-edit)
|
|
|
|
(define-key map (kbd "M-p") 'rebase-mode-move-line-up)
|
|
|
|
(define-key map (kbd "M-n") 'rebase-mode-move-line-down)
|
|
|
|
(define-key map (kbd "k") 'rebase-mode-kill-line)
|
|
|
|
(define-key map (kbd "a") 'rebase-mode-abort)
|
|
|
|
(dolist (key-fun '(("p" . "pick")
|
|
|
|
("r" . "reword")
|
|
|
|
("e" . "edit")
|
|
|
|
("s" . "squash")
|
|
|
|
("f" . "fixup")))
|
|
|
|
(define-key map (car key-fun)
|
|
|
|
`(lambda ()
|
|
|
|
(interactive)
|
|
|
|
(rebase-mode-edit-line ,(cdr key-fun)))))
|
|
|
|
map)
|
|
|
|
"Keymap for rebase-mode.")
|
2010-05-31 17:06:44 +02:00
|
|
|
|
|
|
|
(defun rebase-mode-edit-line (change-to)
|
2010-05-31 17:49:29 +02:00
|
|
|
"Change the keyword at the start of the current action line to
|
|
|
|
that of CHANGE-TO."
|
|
|
|
(let ((buffer-read-only nil)
|
|
|
|
(start (point)))
|
|
|
|
(goto-char (point-at-bol))
|
|
|
|
(kill-region (point) (progn (forward-word 1) (point)))
|
|
|
|
(insert change-to)
|
|
|
|
(goto-char start)))
|
2010-05-31 17:06:44 +02:00
|
|
|
|
2010-05-31 17:40:58 +02:00
|
|
|
(defun rebase-mode-looking-at-action ()
|
2010-05-31 17:49:29 +02:00
|
|
|
"Returns non-nil if looking at an action line."
|
2010-05-31 17:40:58 +02:00
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-at-bol))
|
|
|
|
(looking-at rebase-mode-action-line-re)))
|
|
|
|
|
2010-05-31 17:06:44 +02:00
|
|
|
(defun rebase-mode-setup ()
|
2010-05-31 17:49:29 +02:00
|
|
|
"Function run when initialising rebase-mode."
|
2010-05-31 17:06:44 +02:00
|
|
|
(setq buffer-read-only t)
|
|
|
|
(use-local-map rebase-mode-map))
|
|
|
|
|
|
|
|
(defun rebase-mode-move-line-up ()
|
2010-05-31 17:49:29 +02:00
|
|
|
"Move the current action line up."
|
2010-05-31 17:06:44 +02:00
|
|
|
(interactive)
|
2010-05-31 17:40:58 +02:00
|
|
|
(when (rebase-mode-looking-at-action)
|
|
|
|
(let ((buffer-read-only nil))
|
|
|
|
(transpose-lines 1)
|
|
|
|
(previous-line 2))))
|
2010-05-31 17:06:44 +02:00
|
|
|
|
|
|
|
(defun rebase-mode-move-line-down ()
|
2010-05-31 17:49:29 +02:00
|
|
|
"Assuming the next line is also an action line, move the
|
|
|
|
current line down."
|
2010-05-31 17:06:44 +02:00
|
|
|
(interactive)
|
2010-05-31 17:40:58 +02:00
|
|
|
;; if we're on an action and the next line is also an action
|
|
|
|
(when (and (rebase-mode-looking-at-action)
|
|
|
|
(save-excursion
|
|
|
|
(forward-line)
|
|
|
|
(rebase-mode-looking-at-action)))
|
|
|
|
(let ((buffer-read-only nil))
|
|
|
|
(next-line 1)
|
|
|
|
(transpose-lines 1)
|
|
|
|
(previous-line 1))))
|
2010-05-31 17:22:32 +02:00
|
|
|
|
2010-05-31 17:44:27 +02:00
|
|
|
(defun rebase-mode-abort ()
|
2010-05-31 17:49:29 +02:00
|
|
|
"Abort this rebase."
|
2010-05-31 17:44:27 +02:00
|
|
|
(interactive)
|
|
|
|
(let ((buffer-read-only nil))
|
|
|
|
(delete-region (point-min) (point-max))
|
|
|
|
(save-buffer)
|
|
|
|
(server-edit)))
|
|
|
|
|
2010-05-31 17:21:28 +02:00
|
|
|
(defun rebase-mode-kill-line ()
|
2010-05-31 17:49:29 +02:00
|
|
|
"Kill the current action line."
|
2010-05-31 17:21:28 +02:00
|
|
|
(interactive)
|
2010-05-31 17:50:02 +02:00
|
|
|
(when (rebase-mode-looking-at-action)
|
|
|
|
(let* ((buffer-read-only nil)
|
|
|
|
(region (list (point-at-bol)
|
|
|
|
(progn (forward-line)
|
|
|
|
(point-at-bol))))
|
|
|
|
;; might be handy to let the user know what went
|
|
|
|
;; somehow... sometime
|
|
|
|
(text (apply 'buffer-substring region)))
|
|
|
|
(apply 'kill-region region))))
|
2010-05-31 17:06:44 +02:00
|
|
|
|
|
|
|
(define-generic-mode 'rebase-mode
|
|
|
|
'("#")
|
|
|
|
nil
|
|
|
|
rebase-font-lock-keywords
|
|
|
|
'("git-rebase-todo")
|
|
|
|
'(rebase-mode-setup)
|
2010-05-31 17:49:29 +02:00
|
|
|
"Major mode for interactively editing git rebase files.")
|
2010-05-31 17:06:44 +02:00
|
|
|
|
|
|
|
(provide 'rebase-mode)
|