From 7ddda8527b8126fc26a6700136497f7dd4a0e525 Mon Sep 17 00:00:00 2001 From: Patrick Seebauer Date: Fri, 5 Sep 2014 18:36:04 +0200 Subject: [PATCH 1/7] 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/7] 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))) From 7cf6374333758db0fe27855f935660cce4c4e4ee Mon Sep 17 00:00:00 2001 From: Grant Rettke Date: Thu, 5 Feb 2015 11:15:09 -0600 Subject: [PATCH 3/7] Typo fixo. cursos -> cursors --- mc-hide-unmatched-lines-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mc-hide-unmatched-lines-mode.el b/mc-hide-unmatched-lines-mode.el index 684080e..2bacb38 100644 --- a/mc-hide-unmatched-lines-mode.el +++ b/mc-hide-unmatched-lines-mode.el @@ -48,7 +48,7 @@ ;;;###autoload (define-minor-mode mc-hide-unmatched-lines-mode - "Minor mode when enabled hides all lines where no cursos (and + "Minor mode when enabled hides all lines where no cursors (and also hum/lines-to-expand below and above) To make use of this mode press \"C-'\" while multiple-cursor-mode is active. You can still edit lines while you are in mc-hide-unmatched-lines From 72b4bf3911cc18e87a80b2152a6f707d12f2b531 Mon Sep 17 00:00:00 2001 From: uk-ar Date: Sat, 4 Apr 2015 06:29:46 +0900 Subject: [PATCH 4/7] Enable to specify search word in mc/mark-all-in-region --- mc-mark-more.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mc-mark-more.el b/mc-mark-more.el index 45a87fc..445f6d3 100644 --- a/mc-mark-more.el +++ b/mc-mark-more.el @@ -271,10 +271,10 @@ With zero ARG, skip the last one and mark next." (mc/mark-all-like-this))) ;;;###autoload -(defun mc/mark-all-in-region (beg end) +(defun mc/mark-all-in-region (beg end &optional search) "Find and mark all the parts in the region matching the given search" (interactive "r") - (let ((search (read-from-minibuffer "Mark all in region: ")) + (let ((search (or search (read-from-minibuffer "Mark all in region: "))) (case-fold-search nil)) (if (string= search "") (message "Mark aborted") From 4969d382def07a7064521cb84433c417781f7cea Mon Sep 17 00:00:00 2001 From: kissge Date: Sun, 24 May 2015 13:06:21 +0900 Subject: [PATCH 5/7] Move mc/list-file to the user-emacs-directory --- multiple-cursors-core.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el index 54a993f..3330384 100644 --- a/multiple-cursors-core.el +++ b/multiple-cursors-core.el @@ -524,7 +524,11 @@ from being executed if in multiple-cursors-mode." (overlay-put cursor 'kill-ring kill-ring) (overlay-put cursor 'kill-ring-yank-pointer kill-ring-yank-pointer))))))) -(defvar mc/list-file "~/.emacs.d/.mc-lists.el" +(defvar mc/list-file (expand-file-name + (concat (if (boundp 'user-emacs-directory) + user-emacs-directory + "~/.emacs.d/") + ".mc-lists.el")) "The position of the file that keeps track of your preferences for running commands with multiple cursors.") From 142fdd6534c888c29627d29cdf730870740536ee Mon Sep 17 00:00:00 2001 From: Magnar Sveen Date: Tue, 26 May 2015 09:07:50 +0200 Subject: [PATCH 6/7] Use locate-user-emacs-file to find directory for .mc-lists.el --- multiple-cursors-core.el | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el index 3330384..8971a42 100644 --- a/multiple-cursors-core.el +++ b/multiple-cursors-core.el @@ -524,11 +524,7 @@ from being executed if in multiple-cursors-mode." (overlay-put cursor 'kill-ring kill-ring) (overlay-put cursor 'kill-ring-yank-pointer kill-ring-yank-pointer))))))) -(defvar mc/list-file (expand-file-name - (concat (if (boundp 'user-emacs-directory) - user-emacs-directory - "~/.emacs.d/") - ".mc-lists.el")) +(defvar mc/list-file (locate-user-emacs-file ".mc-lists.el") "The position of the file that keeps track of your preferences for running commands with multiple cursors.") From 2588ccef6939b77896105f23642483c30c4a4e06 Mon Sep 17 00:00:00 2001 From: Magnar Sveen Date: Fri, 29 May 2015 08:03:15 +0200 Subject: [PATCH 7/7] Revert "Support unmarking with no region. Change mc/mark-lines to preserve point." This reverts commit 2d6ffce4c94cdbec1ea8ec086ea346423bafcdf1. Fixes #201 --- mc-mark-more.el | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/mc-mark-more.el b/mc-mark-more.el index 5f73d8e..445f6d3 100644 --- a/mc-mark-more.el +++ b/mc-mark-more.el @@ -127,14 +127,14 @@ Use like case-fold-search, don't recommend setting it globally.") With negative ARG, delete the last one instead. With zero ARG, skip the last one and mark next." (interactive "p") - (if (< arg 0) - (let ((cursor (mc/furthest-cursor-after-point))) - (if cursor - (mc/remove-fake-cursor cursor) - (error "No cursors to be unmarked"))) - (if (region-active-p) - (mc/mark-more-like-this (= arg 0) 'forwards) - (mc/mark-lines arg 'forwards))) + (if (region-active-p) + (if (< arg 0) + (let ((cursor (mc/furthest-cursor-after-point))) + (if cursor + (mc/remove-fake-cursor cursor) + (error "No cursors to be unmarked"))) + (mc/mark-more-like-this (= arg 0) 'forwards)) + (mc/mark-lines arg 'forwards)) (mc/maybe-multiple-cursors-mode)) ;;;###autoload @@ -155,14 +155,14 @@ With zero ARG, skip the last one and mark next." With negative ARG, delete the last one instead. With zero ARG, skip the last one and mark next." (interactive "p") - (if (< arg 0) - (let ((cursor (mc/furthest-cursor-before-point))) - (if cursor - (mc/remove-fake-cursor cursor) - (error "No cursors to be unmarked"))) - (if (region-active-p) - (mc/mark-more-like-this (= arg 0) 'backwards) - (mc/mark-lines arg 'backwards))) + (if (region-active-p) + (if (< arg 0) + (let ((cursor (mc/furthest-cursor-before-point))) + (if cursor + (mc/remove-fake-cursor cursor) + (error "No cursors to be unmarked"))) + (mc/mark-more-like-this (= arg 0) 'backwards)) + (mc/mark-lines arg 'backwards)) (mc/maybe-multiple-cursors-mode)) ;;;###autoload @@ -179,16 +179,12 @@ With zero ARG, skip the last one and mark next." (defun mc/mark-lines (num-lines direction) (dotimes (i num-lines) - (mc/save-excursion - (let ((furthest-cursor (ecase direction - (forwards (mc/furthest-cursor-after-point)) - (backwards (mc/furthest-cursor-before-point))))) - (if (overlayp furthest-cursor) - (goto-char (overlay-get furthest-cursor 'point)))) - (ecase direction - (forwards (next-logical-line 1 nil)) - (backwards (previous-logical-line 1 nil))) - (mc/create-fake-cursor-at-point)))) + (mc/create-fake-cursor-at-point) + (ecase direction + (forwards (loop do (next-logical-line 1 nil) + while (mc/all-fake-cursors (point) (1+ (point))))) + (backwards (loop do (previous-logical-line 1 nil) + while (mc/all-fake-cursors (point) (1+ (point)))))))) ;;;###autoload (defun mc/mark-next-lines (arg)