Last active
August 7, 2017 09:28
-
-
Save amirkarimi/eb07c70681504637a72f7dfdb403bf1c to your computer and use it in GitHub Desktop.
My Emacs Lisp Scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun sort-import-group () | |
"This function basically sorts a comma separated list of strings but it's been | |
written to sort grouped imports in Scala. | |
Example: | |
`import org.temp.{ B, C, A }` | |
By selecting the grouped imported items (`B, C, A`) from the above code sample and run (M-x) `sort-group` | |
you'll get the following result: | |
`import org.temp.{ A, B, C }`" | |
(interactive) | |
(let* ((bounds (cons (region-beginning) (region-end))) | |
(text (buffer-substring-no-properties (car bounds) (cdr bounds)))) | |
(when bounds | |
(delete-region (car bounds) (cdr bounds)) | |
(let ((splited-sorted (sort | |
(split-string text | |
"," | |
nil | |
" ") | |
'string<))) | |
(insert (mapconcat 'identity | |
splited-sorted | |
", ")))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment