From 8cd21a0fffdf20b3954cc9022f1ad111461f1b65 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 7 Jan 2016 01:01:03 -0500 Subject: [PATCH] Add narf/smart-indent and narf/dumb-dedent --- core/lib/defuns-whitespace.el | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/core/lib/defuns-whitespace.el b/core/lib/defuns-whitespace.el index d1ac9a8c1..61d033963 100644 --- a/core/lib/defuns-whitespace.el +++ b/core/lib/defuns-whitespace.el @@ -79,13 +79,31 @@ whitespace as possible, or just one char if that's not possible." "Inserts a tab character (or spaces x tab-width). Checks if the auto-complete window is open." (interactive) - (if (or (and smart (looking-back "^[\s\t]*")) - indent-tabs-mode) - (insert "\t") - (let* ((movement (% (current-column) tab-width)) + (if indent-tabs-mode + (insert "\t") + (let* ((movement (% (current-column) tab-width)) (spaces (if (zerop movement) tab-width (- tab-width movement)))) (insert (s-repeat spaces " "))))) +;;;###autoload +(defun narf/smart-indent () + (interactive) + (save-excursion + (back-to-indentation) + (narf/dumb-indent))) + +;;;###autoload +(defun narf/dumb-dedent () + (interactive) + (if indent-tabs-mode + (delete-char -1) + (save-excursion + (unless (looking-back "^[\s\t]*") + (evil-first-non-blank)) + (let* ((movement (% (current-column) tab-width)) + (spaces (if (zerop movement) tab-width (- tab-width movement)))) + (delete-char (- spaces)))))) + ;;;###autoload (defun narf/inflate-space-maybe () "Checks if point is surrounded by {} [] () delimiters and adds a