branch: elpa/multiple-cursors
commit 533e1576e309abf6e3ff98eb9ede807f00f1ef0c
Merge: faf331d 7156651
Author: Magnar Sveen <[email protected]>
Commit: Magnar Sveen <[email protected]>
Merge pull request #160 from P-Seebauer/master
Added whitespace functionality.
---
features/vertical-align.feature | 27 +++++++++++++++++++++++++++
mc-separate-operations.el | 31 +++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
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 "<<mc/vertical-align>> \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 "<<mc/vertical-align-with-space>>"
+ Then I should see:
+ """
+ One word
+ Another word
+ """
diff --git a/mc-separate-operations.el b/mc-separate-operations.el
index abbfaee..b587530 100644
--- a/mc-separate-operations.el
+++ b/mc-separate-operations.el
@@ -86,5 +86,36 @@
(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).
+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