summaryrefslogtreecommitdiffstats
path: root/.emacs.d/init.org
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/init.org')
-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