Skip to content

Instantly share code, notes, and snippets.

@agumonkey
Created August 3, 2014 13:12
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 agumonkey/27785d8a6460b63a7fd9 to your computer and use it in GitHub Desktop.
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
(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