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