From 22c82d63e63b0f738bf6be83ac70215725424432 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 24 Jul 2015 13:06:19 +0200 Subject: [PATCH] Smarter dumb indentation --- core/lib/defuns-whitespace.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/lib/defuns-whitespace.el b/core/lib/defuns-whitespace.el index 03a4a1db3..ebefc66ad 100644 --- a/core/lib/defuns-whitespace.el +++ b/core/lib/defuns-whitespace.el @@ -75,13 +75,14 @@ whitespace as possible, or just one char if that's not possible." (t (backward-delete-char-untabify 1)))) ;;;###autoload -(defun narf/dumb-indent () +(defun narf/dumb-indent (&optional smart) "Inserts a tab character (or spaces x tab-width). Checks if the auto-complete window is open." (interactive) - (if indent-tabs-mode - (insert "\t") - (let* ((movement (% (current-column) tab-width)) + (if (or (and smart (looking-back "^[\s\t]*")) + indent-tabs-mode) + (insert "\t") + (let* ((movement (% (current-column) tab-width)) (spaces (if (zerop movement) tab-width (- tab-width movement)))) (insert (s-repeat spaces " ")))))