add sort-lines arg, reverse func and key binding

This commit is contained in:
duianto 2016-12-24 12:06:21 +01:00 committed by bmag
parent 0c3afd5a3f
commit e14c29e1df
2 changed files with 13 additions and 5 deletions

View File

@ -825,12 +825,19 @@ With negative N, comment out original line and use the absolute value."
(while (re-search-forward "^\\(.*\n\\)\\1+" end t)
(replace-match "\\1"))))))
(defun spacemacs/sort-lines ()
"Sort lines in region or current buffer"
(defun spacemacs/sort-lines (&optional reverse)
"Sort lines in a region or the current buffer.
A non-nil argument sorts in reverse order."
(interactive "P")
(let* ((region-active (or (region-active-p) (evil-visual-state-p)))
(beg (if region-active (region-beginning) (point-min)))
(end (if region-active (region-end) (point-max))))
(sort-lines reverse beg end)))
(defun spacemacs/sort-lines-reverse ()
"Sort lines in reverse order, in a region or the 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)))
(spacemacs/sort-lines -1))
;; BEGIN linum mouse helpers

View File

@ -437,6 +437,7 @@
"xjr" 'set-justification-right
"xld" 'spacemacs/duplicate-line-or-region
"xls" 'spacemacs/sort-lines
"xlS" 'spacemacs/sort-lines-reverse
"xlu" 'spacemacs/uniquify-lines
"xtc" 'transpose-chars
"xtl" 'transpose-lines