diff --git a/core/core-editor.el b/core/core-editor.el index 77ddf4798..ae504af4b 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -71,11 +71,11 @@ (defadvice delete-trailing-whitespace (around delete-trailing-whitespace-ignore-line activate) "Don't delete trailing whitespace on current line, if in insert mode." - (let ((spaces (current-column)) - (first-col (1+ (save-excursion (evil-first-non-blank) (current-column))))) + (let ((spaces (1- (current-column))) + (linestr (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) ad-do-it - (when (= spaces first-col) - (insert (make-string (abs spaces) ? ))))) + (when (string-match-p "^[\s\t]*$" linestr) + (insert linestr)))) ;; Line wrapping (add-hook! text-mode 'narf|enable-hard-wrap) diff --git a/core/lib/defuns-whitespace.el b/core/lib/defuns-whitespace.el index 626fafd34..d1ac9a8c1 100644 --- a/core/lib/defuns-whitespace.el +++ b/core/lib/defuns-whitespace.el @@ -157,14 +157,5 @@ spaces on either side of the point if so. Resorts to (align-regexp beg end (concat "\\(\\s-*\\)" (rxt-pcre-to-elisp regexp)) 1 1))) -;;;###autoload -(defun narf:toggle-delete-trailing-whitespace () - (interactive) - (if (memq 'delete-trailing-whitespace before-save-hook) - (progn (message "Remove trailing whitespace: OFF") - (remove-hook 'before-save-hook 'delete-trailing-whitespace)) - (message "Remove trailing whitespace: ON") - (add-hook 'before-save-hook 'delete-trailing-whitespace))) - (provide 'defuns-whitespace) ;;; defuns-whitespace.el ends here