From aad24fa54e562e7e34359c6b2ee2092bc97595bb Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 16:06:44 +0100 Subject: [PATCH 01/15] Basics working. Keybindings, highlighting. --- rebase-mode.el | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 rebase-mode.el diff --git a/rebase-mode.el b/rebase-mode.el new file mode 100644 index 00000000..678519b0 --- /dev/null +++ b/rebase-mode.el @@ -0,0 +1,92 @@ +(defvar rebase-mode-action-line-re + (rx + line-start + (group + (| + (any "presf") + "pick" + "reword" + "edit" + "squash" + "fixup")) + (char space) + (group (** 7 40 (char "0-9" "a-f" "A-F"))))) + +(defvar rebase-font-lock-keywords + (list + (list rebase-mode-action-line-re + '(1 font-lock-keyword-face) + '(2 font-lock-builtin-face)))) + +(defun rebase-mode-edit-line (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))) + +(defun rebase-mode-setup () + (setq buffer-read-only t) + (use-local-map rebase-mode-map)) + +(defun rebase-mode-move-line-up () + (interactive) + (transpose-lines 1) + (previous-line 2)) + +(defun rebase-mode-move-line-down () + (interactive) + (next-line 1) + (transpose-lines 1) + (previous-line 1)) + +(defvar rebase-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "q") 'server-edit) + (define-key map (kbd "M-p") (lambda () + (interactive) + (let ((buffer-read-only nil)) + (rebase-mode-move-line-up)))) + (define-key map (kbd "M-n") (lambda () + (interactive) + (let ((buffer-read-only nil)) + (rebase-mode-move-line-down)))) + (define-key map (kbd "k") (lambda () + (interactive) + (let ((buffer-read-only nil)) + (kill-region (point-at-bol) (point-at-eol))))) + (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)) + +(define-generic-mode 'rebase-mode + '("#") + nil + rebase-font-lock-keywords + '("git-rebase-todo") + '(rebase-mode-setup) + "Mode for blah") + +;;(defun rebase-mode () +;; (interactive) +;; (kill-all-local-variables) +;; (make-local-variable 'font-lock-defaults) +;; (setq font-lock-defaults '(rebase-font-lock-keywords nil t nil nil)) +;; +;; (set (make-local-variable 'comment-start) "#") +;; (set (make-local-variable 'comment-end) "") +;; +;; (setq mode-name "rebase" major-mode 'rebase-mode)) + +(provide 'rebase-mode) + + +;; "\\([0-9a-fA-F]\\{40\\}\\) " From 1f565629353bbcc906a5ee7fbc55b490f0e57dcf Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 16:21:28 +0100 Subject: [PATCH 02/15] Added and mapped `rebase-mode-kill-line'. --- rebase-mode.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rebase-mode.el b/rebase-mode.el index 678519b0..149c7013 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -40,6 +40,15 @@ (next-line 1) (transpose-lines 1) (previous-line 1)) +(defun rebase-mode-kill-line () + (interactive) + (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 + (text (apply 'buffer-substring region))) + (apply 'kill-region region))) (defvar rebase-mode-map (let ((map (make-sparse-keymap))) @@ -56,6 +65,7 @@ (interactive) (let ((buffer-read-only nil)) (kill-region (point-at-bol) (point-at-eol))))) + (define-key map (kbd "k") 'rebase-mode-kill-line) (dolist (key-fun '(("p" . "pick") ("r" . "reword") ("e" . "edit") From d50d80e6cd5253661cde4d974a811dc735349b4d Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 16:22:32 +0100 Subject: [PATCH 03/15] Made move-{up,down} functions rebase-mode specific. --- rebase-mode.el | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/rebase-mode.el b/rebase-mode.el index 149c7013..2c90ea6a 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -32,14 +32,17 @@ (defun rebase-mode-move-line-up () (interactive) - (transpose-lines 1) - (previous-line 2)) + (let ((buffer-read-only nil)) + (transpose-lines 1) + (previous-line 2))) (defun rebase-mode-move-line-down () (interactive) - (next-line 1) - (transpose-lines 1) - (previous-line 1)) + (let ((buffer-read-only nil)) + (next-line 1) + (transpose-lines 1) + (previous-line 1))) + (defun rebase-mode-kill-line () (interactive) (let* ((buffer-read-only nil) @@ -53,18 +56,8 @@ (defvar rebase-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "q") 'server-edit) - (define-key map (kbd "M-p") (lambda () - (interactive) - (let ((buffer-read-only nil)) - (rebase-mode-move-line-up)))) - (define-key map (kbd "M-n") (lambda () - (interactive) - (let ((buffer-read-only nil)) - (rebase-mode-move-line-down)))) - (define-key map (kbd "k") (lambda () - (interactive) - (let ((buffer-read-only nil)) - (kill-region (point-at-bol) (point-at-eol))))) + (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) (dolist (key-fun '(("p" . "pick") ("r" . "reword") From 1aecf75104835e6b7df1ec50b2719dad81df2736 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 16:40:58 +0100 Subject: [PATCH 04/15] Improve the move-{up,down} functions. --- rebase-mode.el | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/rebase-mode.el b/rebase-mode.el index 2c90ea6a..4d8fe677 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -10,7 +10,11 @@ "squash" "fixup")) (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 (list @@ -26,22 +30,33 @@ (insert change-to) (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 () (setq buffer-read-only t) (use-local-map rebase-mode-map)) (defun rebase-mode-move-line-up () (interactive) - (let ((buffer-read-only nil)) - (transpose-lines 1) - (previous-line 2))) + (when (rebase-mode-looking-at-action) + (let ((buffer-read-only nil)) + (transpose-lines 1) + (previous-line 2)))) (defun rebase-mode-move-line-down () (interactive) - (let ((buffer-read-only nil)) - (next-line 1) - (transpose-lines 1) - (previous-line 1))) + ;; 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)))) (defun rebase-mode-kill-line () (interactive) @@ -49,7 +64,8 @@ (region (list (point-at-bol) (progn (forward-line) (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))) (apply 'kill-region region))) From a45558e61ea9d7cfca6999d13f4bff9055b2d0ed Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 16:44:27 +0100 Subject: [PATCH 05/15] Added `rebase-mode-abort'. --- rebase-mode.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rebase-mode.el b/rebase-mode.el index 4d8fe677..a3ea7504 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -58,6 +58,13 @@ (transpose-lines 1) (previous-line 1)))) +(defun rebase-mode-abort () + (interactive) + (let ((buffer-read-only nil)) + (delete-region (point-min) (point-max)) + (save-buffer) + (server-edit))) + (defun rebase-mode-kill-line () (interactive) (let* ((buffer-read-only nil) @@ -75,6 +82,7 @@ (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") From c5978a4cde4e6130f6f3838f50afa7cff5d8439e Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 16:46:25 +0100 Subject: [PATCH 06/15] Docs for variables. --- rebase-mode.el | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/rebase-mode.el b/rebase-mode.el index a3ea7504..927aa75a 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -14,13 +14,34 @@ (** 7 40 (char "0-9" "a-f" "A-F"))) ;sha1 (char space) (* anything) ; msg - line-end)) + line-end) + "Regexp that matches an action line in a rebase buffer.") (defvar rebase-font-lock-keywords (list (list rebase-mode-action-line-re '(1 font-lock-keyword-face) - '(2 font-lock-builtin-face)))) + '(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.") (defun rebase-mode-edit-line (change-to) (let ((buffer-read-only nil) @@ -76,24 +97,6 @@ (text (apply 'buffer-substring region))) (apply 'kill-region region))) -(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)) - (define-generic-mode 'rebase-mode '("#") nil From 480f0726d0f995f17ddba06877499e0b77f1528f Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 16:49:29 +0100 Subject: [PATCH 07/15] Document functions, mode. --- rebase-mode.el | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/rebase-mode.el b/rebase-mode.el index 927aa75a..9c3ce1af 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -44,23 +44,28 @@ "Keymap for rebase-mode.") (defun rebase-mode-edit-line (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))) + "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))) (defun rebase-mode-looking-at-action () + "Returns non-nil if looking at an action line." (save-excursion (goto-char (point-at-bol)) (looking-at rebase-mode-action-line-re))) (defun rebase-mode-setup () + "Function run when initialising rebase-mode." (setq buffer-read-only t) (use-local-map rebase-mode-map)) (defun rebase-mode-move-line-up () + "Move the current action line up." (interactive) (when (rebase-mode-looking-at-action) (let ((buffer-read-only nil)) @@ -68,6 +73,8 @@ (previous-line 2)))) (defun rebase-mode-move-line-down () + "Assuming the next line is also an action line, move the +current line down." (interactive) ;; if we're on an action and the next line is also an action (when (and (rebase-mode-looking-at-action) @@ -80,6 +87,7 @@ (previous-line 1)))) (defun rebase-mode-abort () + "Abort this rebase." (interactive) (let ((buffer-read-only nil)) (delete-region (point-min) (point-max)) @@ -87,6 +95,7 @@ (server-edit))) (defun rebase-mode-kill-line () + "Kill the current action line." (interactive) (let* ((buffer-read-only nil) (region (list (point-at-bol) @@ -103,20 +112,6 @@ rebase-font-lock-keywords '("git-rebase-todo") '(rebase-mode-setup) - "Mode for blah") - -;;(defun rebase-mode () -;; (interactive) -;; (kill-all-local-variables) -;; (make-local-variable 'font-lock-defaults) -;; (setq font-lock-defaults '(rebase-font-lock-keywords nil t nil nil)) -;; -;; (set (make-local-variable 'comment-start) "#") -;; (set (make-local-variable 'comment-end) "") -;; -;; (setq mode-name "rebase" major-mode 'rebase-mode)) + "Major mode for interactively editing git rebase files.") (provide 'rebase-mode) - - -;; "\\([0-9a-fA-F]\\{40\\}\\) " From 0244b8b1b1687d5795bb63f6d4e8fc82f2aa83fd Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 16:50:02 +0100 Subject: [PATCH 08/15] Only kill a line if it looks like an action line. --- rebase-mode.el | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/rebase-mode.el b/rebase-mode.el index 9c3ce1af..f80bea90 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -97,14 +97,15 @@ current line down." (defun rebase-mode-kill-line () "Kill the current action line." (interactive) - (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))) + (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)))) (define-generic-mode 'rebase-mode '("#") From c0abcc096abd7f25085661b3999bed657f763092 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 16:51:06 +0100 Subject: [PATCH 09/15] Ask the user when aborting a rebase. --- rebase-mode.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rebase-mode.el b/rebase-mode.el index f80bea90..9d02b4ce 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -89,10 +89,11 @@ current line down." (defun rebase-mode-abort () "Abort this rebase." (interactive) - (let ((buffer-read-only nil)) - (delete-region (point-min) (point-max)) - (save-buffer) - (server-edit))) + (when (y-or-n-p "Abort this rebase? ") + (let ((buffer-read-only nil)) + (delete-region (point-min) (point-max)) + (save-buffer) + (server-edit)))) (defun rebase-mode-kill-line () "Kill the current action line." From a7048a9b71cdd0ad3cdde38efb72f5de8365cfad Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 16:54:39 +0100 Subject: [PATCH 10/15] Clarify abort docs. --- rebase-mode.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rebase-mode.el b/rebase-mode.el index 9d02b4ce..3a5eab96 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -87,7 +87,8 @@ current line down." (previous-line 1)))) (defun rebase-mode-abort () - "Abort this rebase." + "Abort this rebase (by emptying the buffer, saving and closing +server connection)." (interactive) (when (y-or-n-p "Abort this rebase? ") (let ((buffer-read-only nil)) From adb85163dea1e946a5777b8b2755115fcb5dff6e Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 16:56:04 +0100 Subject: [PATCH 11/15] Licence, a little commentary. --- rebase-mode.el | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/rebase-mode.el b/rebase-mode.el index 3a5eab96..13c1c724 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -1,3 +1,26 @@ +;;; rebase-mode -- edit git rebase files. + +;; Copyright (C) 2010 Phil Jackson +;; +;; Magit is free software; you can redistribute it and/or modify it +;; under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. +;; +;; Magit is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +;; License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with Magit. If not, see . + +;;; Commentary: + +;; Allows the editing of a git rebase file (which you might get when +;; using 'git rebase -i' or hitting 'E' in Magit). Assumes editing is +;; happening in a server. + (defvar rebase-mode-action-line-re (rx line-start @@ -115,6 +138,7 @@ server connection)." rebase-font-lock-keywords '("git-rebase-todo") '(rebase-mode-setup) - "Major mode for interactively editing git rebase files.") + "Major mode for interactively editing git rebase files. +\\{rebase-mode-map}") (provide 'rebase-mode) From 41ab790cde63042331869d2a2f802d293a817d88 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 17:00:02 +0100 Subject: [PATCH 12/15] Bit of formatting. --- rebase-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rebase-mode.el b/rebase-mode.el index 13c1c724..ca351053 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -60,7 +60,7 @@ ("s" . "squash") ("f" . "fixup"))) (define-key map (car key-fun) - `(lambda () + `(lambda () (interactive) (rebase-mode-edit-line ,(cdr key-fun))))) map) From 98b845afa1e05ec24286c2d5f9f920776e7b6e54 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 17:12:19 +0100 Subject: [PATCH 13/15] Create the edit function dynamically so we get a description in `describe-mode'. --- rebase-mode.el | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/rebase-mode.el b/rebase-mode.el index ca351053..bb303059 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -47,6 +47,13 @@ '(2 font-lock-builtin-face))) "Font lock keywords for rebase-mode.") +(defvar key-to-action-map '(("p" . "pick") + ("r" . "reword") + ("e" . "edit") + ("s" . "squash") + ("f" . "fixup")) + "Mapping from key to action.") + (defvar rebase-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "q") 'server-edit) @@ -54,17 +61,22 @@ (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.") + "Keymap for rebase-mode. Note this will be added to by the + top-level code which defines the edit functions.") + +;; create the functions which edit the action lines themselves (based +;; on `key-to-action-map' above) +(mapc (lambda (key-action) + (let ((fun-name (intern (concat "rebase-mode-" (cdr key-action))))) + ;; define the function + (eval `(defun ,fun-name () + (interactive) + (rebase-mode-edit-line ,(cdr key-action)))) + + ;; bind the function in `rebase-mode-map' + (define-key rebase-mode-map (car key-action) fun-name))) + key-to-action-map) (defun rebase-mode-edit-line (change-to) "Change the keyword at the start of the current action line to From 4ad4e945c3ade7fef863ffe62cf0466075fc1081 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 17:17:53 +0100 Subject: [PATCH 14/15] Keep column position when moving lines. --- rebase-mode.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rebase-mode.el b/rebase-mode.el index bb303059..74800fe7 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -99,12 +99,18 @@ that of CHANGE-TO." (setq buffer-read-only t) (use-local-map rebase-mode-map)) +(defun rebase-mode-transpose-lines (arg) + "Wraps emacs `transpose-lines' but saves column position." + (let ((col (current-column))) + (transpose-lines arg) + (move-to-column col))) + (defun rebase-mode-move-line-up () "Move the current action line up." (interactive) (when (rebase-mode-looking-at-action) (let ((buffer-read-only nil)) - (transpose-lines 1) + (rebase-mode-transpose-lines 1) (previous-line 2)))) (defun rebase-mode-move-line-down () @@ -118,7 +124,7 @@ current line down." (rebase-mode-looking-at-action))) (let ((buffer-read-only nil)) (next-line 1) - (transpose-lines 1) + (rebase-mode-transpose-lines 1) (previous-line 1)))) (defun rebase-mode-abort () From ddc55ba6a03c153179c19972aab712ad2bb56416 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Mon, 31 May 2010 17:38:47 +0100 Subject: [PATCH 15/15] Move column handling up a level in move functions. --- rebase-mode.el | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/rebase-mode.el b/rebase-mode.el index 74800fe7..83b011de 100644 --- a/rebase-mode.el +++ b/rebase-mode.el @@ -99,19 +99,15 @@ that of CHANGE-TO." (setq buffer-read-only t) (use-local-map rebase-mode-map)) -(defun rebase-mode-transpose-lines (arg) - "Wraps emacs `transpose-lines' but saves column position." - (let ((col (current-column))) - (transpose-lines arg) - (move-to-column col))) - (defun rebase-mode-move-line-up () "Move the current action line up." (interactive) (when (rebase-mode-looking-at-action) - (let ((buffer-read-only nil)) - (rebase-mode-transpose-lines 1) - (previous-line 2)))) + (let ((buffer-read-only nil) + (col (current-column))) + (transpose-lines 1) + (previous-line 2) + (move-to-column col)))) (defun rebase-mode-move-line-down () "Assuming the next line is also an action line, move the @@ -122,10 +118,12 @@ current line down." (save-excursion (forward-line) (rebase-mode-looking-at-action))) - (let ((buffer-read-only nil)) + (let ((buffer-read-only nil) + (col (current-column))) (next-line 1) - (rebase-mode-transpose-lines 1) - (previous-line 1)))) + (transpose-lines 1) + (previous-line 1) + (move-to-column col)))) (defun rebase-mode-abort () "Abort this rebase (by emptying the buffer, saving and closing