summaryrefslogtreecommitdiffstats
path: root/.emacs.d
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-11-07 17:20:18 +0100
committerGravatar Tom Willemse2013-11-07 17:20:18 +0100
commit4a62144606f358864203aca4901e2b153b32ebf1 (patch)
treed6389510efa1ff0e730fab2cc5e1dafef1c53aed /.emacs.d
parent33420ba262460bfa97eca87bc40865b8e1ead009 (diff)
downloademacs-4a62144606f358864203aca4901e2b153b32ebf1.tar.gz
emacs-4a62144606f358864203aca4901e2b153b32ebf1.zip
Add sort-imports command
Diffstat (limited to '.emacs.d')
-rw-r--r--.emacs.d/init.org30
1 files changed, 30 insertions, 0 deletions
diff --git a/.emacs.d/init.org b/.emacs.d/init.org
index 368ae0e..ef4b381 100644
--- a/.emacs.d/init.org
+++ b/.emacs.d/init.org
@@ -276,3 +276,33 @@
:size 12.4
:weight 'normal))
#+END_SRC
+
+* A function to sort python includes
+
+ At work I use Python. Our project is getting bigger and bigger,
+ import statements are growing. We use the following style:
+
+ #+BEGIN_SRC python :tangle no
+ from somemodule import (
+ Class1,
+ Class2,
+ Class3,
+ )
+ #+END_SRC
+
+ Which we found to be one of the better-looking ways to handle
+ multi-line import statements. To sort these lines I wrote a very
+ simplistic (and error-prone, but I'll handle it when I get to it)
+ command.
+
+ All it does is save the current point, searches backwards for a ~(~,
+ then forwards for a ~)~ and sorts the region in between (not
+ including) the ~()~.
+
+ #+BEGIN_SRC emacs-lisp
+ (defun sort-imports ()
+ (interactive)
+ (save-excursion
+ (sort-lines nil (1+ (search-backward "("))
+ (1- (search-forward ")")))))
+ #+END_SRC