From 7ddda8527b8126fc26a6700136497f7dd4a0e525 Mon Sep 17 00:00:00 2001 From: Patrick Seebauer Date: Fri, 5 Sep 2014 18:36:04 +0200 Subject: [PATCH 1/2] Added vertical align commands Squashed commit of the following: commit 243a14e69501bf938eea54449782f43be2084ef2 Author: Patrick Seebauer Date: Fri Sep 5 18:06:19 2014 +0200 removed uniq line check and added warning in the docs about cursors on the same line. commit 438658ef0358b0a1540c2663aedba0253150a007 Author: Patrick Seebauer Date: Fri Sep 5 17:59:55 2014 +0200 fixed tests for commands with character inputs commit c565969c6bb01e37ec42cfe311ada87643e38ccc Author: Patrick Seebauer Date: Fri Sep 5 17:36:41 2014 +0200 renamed to vertical align, added non-whitespace option commit 941c40a319f571680017293681ff7d796ba4e1f4 Author: Patrick Seebauer Date: Fri Sep 5 16:58:14 2014 +0200 added test commit d9a4a55ebde9b51c3f62b14948529759aaaa9bf6 Author: Patrick Seebauer Date: Tue Sep 2 19:32:49 2014 +0200 added interactives, added abort if cursors are on the same line commit 12d01fe4db5109061533b0524d99177d1204eb85 Author: Patrick Seebauer Date: Tue Sep 2 18:55:47 2014 +0200 some adjustments commit 9fddf98b6cd1bb68c334ab46fe1c9bcc08397796 Author: Patrick Seebauer Date: Tue Sep 2 18:47:39 2014 +0200 rough sketch --- features/vertical-align.feature | 27 +++++++++++++++++++++++++++ mc-separate-operations.el | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 features/vertical-align.feature diff --git a/features/vertical-align.feature b/features/vertical-align.feature new file mode 100644 index 0000000..3a5a124 --- /dev/null +++ b/features/vertical-align.feature @@ -0,0 +1,27 @@ +Feature: Align cursors with whitespaces + + Scenario: Vertical aligning with `x' + Given I have cursors at "word" in : + """ + One word + Another word + """ + And I press "<> \170" + Then I should see: + """ + One xxxxword + Another word + """ + + Scenario: Vertical aligning with space + Given I have cursors at "word" in : + """ + One word + Another word + """ + And I press "<>" + Then I should see: + """ + One word + Another word + """ diff --git a/mc-separate-operations.el b/mc-separate-operations.el index abbfaee..7543232 100644 --- a/mc-separate-operations.el +++ b/mc-separate-operations.el @@ -86,5 +86,37 @@ (setq mc--strings-to-replace (sort (mc--ordered-region-strings) 'string<)) (mc--replace-region-strings)) + +;;;###autoload +(defun mc/vertical-align (character) + "Aligns all cursors vertically with a given CHARACTER to the one with the +highest colum number (the rightest) +Aborts if the some cursors are on the same line. +Might not behave as intended if more than one cursors are on the same line." + (interactive "c") + (let ((rightest-column (current-column))) + (mc/execute-command-for-all-cursors + (lambda () "get the rightest cursor" + (interactive) + (setq rightest-column (max (current-column) rightest-column)) + )) + (mc/execute-command-for-all-cursors + (lambda () + (interactive) + (let ((missing-spaces (- rightest-column (current-column)))) + (save-excursion (insert (make-string missing-spaces character))) + (forward-char missing-spaces) + ) + )) + ) + ) + +;;;###autoload +(defun mc/vertical-align-with-space () + "Aligns all cursors with whitespace like `mc/vertical-align' does" + (interactive) + (mc/vertical-align 32) + ) + (provide 'mc-separate-operations) ;;; mc-separate-operations.el ends here From 715665129e5cd37c80fbed55d0745c730949b059 Mon Sep 17 00:00:00 2001 From: Patrick Seebauer Date: Fri, 5 Sep 2014 18:45:34 +0200 Subject: [PATCH 2/2] fixed documentation --- mc-separate-operations.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mc-separate-operations.el b/mc-separate-operations.el index 7543232..b587530 100644 --- a/mc-separate-operations.el +++ b/mc-separate-operations.el @@ -90,8 +90,7 @@ ;;;###autoload (defun mc/vertical-align (character) "Aligns all cursors vertically with a given CHARACTER to the one with the -highest colum number (the rightest) -Aborts if the some cursors are on the same line. +highest colum number (the rightest). Might not behave as intended if more than one cursors are on the same line." (interactive "c") (let ((rightest-column (current-column)))