Created
August 3, 2014 13:12
-
-
Save agumonkey/27785d8a6460b63a7fd9 to your computer and use it in GitHub Desktop.
Fast function addition: Jumps below the current defun, from anywhere inside it, at the same indentation level
This file contains 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 python/find-relative-indentation () | |
"find the previous defun indent level" | |
(with-current-buffer (current-buffer) | |
(save-excursion | |
(let* ((previous-def (progn (search-backward "def ") (point))) | |
(previous-bol (progn (beginning-of-line) (point))) | |
(indent (- previous-def previous-bol))) | |
indent)))) | |
;; def foo(): | |
;; """ | |
;; """ | |
;; def bar(): | |
;; """ | |
;; """ | |
;; def duh(): | |
;; """ | |
;; """ | |
;; a = 1<CARET> | |
;; b = 2 | |
;; def foo(): | |
;; """ | |
;; """ | |
;; def bar(): | |
;; """ | |
;; """ | |
;; def duh(): | |
;; """ | |
;; """ | |
;; a = 1 | |
;; b = 2 | |
;; | |
;; <CARET> | |
(defun python/newdef () | |
"place point below the current defun, from anywhere inside it, at the same indent level" | |
(interactive) | |
(python-nav-end-of-defun) | |
(newline) | |
(let ((indent (python/find-relative-indentation))) | |
(indent-to indent))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment