Improve the move-{up,down} functions.

This commit is contained in:
Phil Jackson 2010-05-31 16:40:58 +01:00
parent d50d80e6cd
commit 1aecf75104

View file

@ -10,7 +10,11 @@
"squash" "squash"
"fixup")) "fixup"))
(char space) (char space)
(group (** 7 40 (char "0-9" "a-f" "A-F"))))) (group
(** 7 40 (char "0-9" "a-f" "A-F"))) ;sha1
(char space)
(* anything) ; msg
line-end))
(defvar rebase-font-lock-keywords (defvar rebase-font-lock-keywords
(list (list
@ -26,22 +30,33 @@
(insert change-to) (insert change-to)
(goto-char start))) (goto-char start)))
(defun rebase-mode-looking-at-action ()
(save-excursion
(goto-char (point-at-bol))
(looking-at rebase-mode-action-line-re)))
(defun rebase-mode-setup () (defun rebase-mode-setup ()
(setq buffer-read-only t) (setq buffer-read-only t)
(use-local-map rebase-mode-map)) (use-local-map rebase-mode-map))
(defun rebase-mode-move-line-up () (defun rebase-mode-move-line-up ()
(interactive) (interactive)
(let ((buffer-read-only nil)) (when (rebase-mode-looking-at-action)
(transpose-lines 1) (let ((buffer-read-only nil))
(previous-line 2))) (transpose-lines 1)
(previous-line 2))))
(defun rebase-mode-move-line-down () (defun rebase-mode-move-line-down ()
(interactive) (interactive)
(let ((buffer-read-only nil)) ;; if we're on an action and the next line is also an action
(next-line 1) (when (and (rebase-mode-looking-at-action)
(transpose-lines 1) (save-excursion
(previous-line 1))) (forward-line)
(rebase-mode-looking-at-action)))
(let ((buffer-read-only nil))
(next-line 1)
(transpose-lines 1)
(previous-line 1))))
(defun rebase-mode-kill-line () (defun rebase-mode-kill-line ()
(interactive) (interactive)
@ -49,7 +64,8 @@
(region (list (point-at-bol) (region (list (point-at-bol)
(progn (forward-line) (progn (forward-line)
(point-at-bol)))) (point-at-bol))))
;; might be handy to let the user know what went somehow ;; might be handy to let the user know what went
;; somehow... sometime
(text (apply 'buffer-substring region))) (text (apply 'buffer-substring region)))
(apply 'kill-region region))) (apply 'kill-region region)))