Added text line sort and uniquify commands

This commit is contained in:
Andrew Oppenlander 2015-08-27 18:17:16 -04:00 committed by syl20bnr
parent f418dfc2d8
commit 7274d9d5c2
4 changed files with 23 additions and 0 deletions

View File

@ -1924,6 +1924,8 @@ Text related commands (start with ~x~):
| ~SPC x g T~ | reverse source and target languages |
| ~SPC x J~ | move down a line of text (enter micro-state) |
| ~SPC x K~ | move up a line of text (enter micro-state) |
| ~SPC x l s~ | sort lines |
| ~SPC x l u~ | uniquify lines |
| ~SPC x t c~ | swap (transpose) the current character with the previous one |
| ~SPC x t w~ | swap (transpose) the current word with the previous one |
| ~SPC x t l~ | swap (transpose) the current line with the previous one |

View File

@ -57,6 +57,7 @@
("xa" "text-align")
("xd" "text-delete")
("xg" "text-google-translate")
("xl" "text-lines")
("xm" "text-move")
("xt" "text-transpose")
("xw" "text-words")

View File

@ -1029,3 +1029,21 @@ is nonempty."
(cond ((listp val) val)
((stringp val) (< 0 (length val)))
(t))))
(defun spacemacs/uniquify-lines ()
"Remove duplicate adjacent lines in region or current buffer"
(interactive)
(save-excursion
(save-restriction
(let ((beg (if (region-active-p) (region-beginning) (point-min)))
(end (if (region-active-p) (region-end) (point-max))))
(goto-char beg)
(while (re-search-forward "^\\(.*\n\\)\\1+" end t)
(replace-match "\\1"))))))
(defun spacemacs/sort-lines ()
"Sort lines in region or current buffer"
(interactive)
(let ((beg (if (region-active-p) (region-beginning) (point-min)))
(end (if (region-active-p) (region-end) (point-max))))
(sort-lines nil beg end)))

View File

@ -337,6 +337,8 @@ Ensure that helm is required before calling FUNC."
"xa(" 'spacemacs/align-repeat-left-paren
"xa)" 'spacemacs/align-repeat-right-paren
"xdw" 'delete-trailing-whitespace
"xls" 'spacemacs/sort-lines
"xlu" 'spacemacs/uniquify-lines
"xtc" 'transpose-chars
"xtl" 'transpose-lines
"xtw" 'transpose-words