Skip to content

Instantly share code, notes, and snippets.

@amirkarimi
Last active August 7, 2017 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirkarimi/eb07c70681504637a72f7dfdb403bf1c to your computer and use it in GitHub Desktop.
Save amirkarimi/eb07c70681504637a72f7dfdb403bf1c to your computer and use it in GitHub Desktop.
My Emacs Lisp Scripts
(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