From 6aa29e82ae26d7de97e6b8dad7ab36a7401311b0 Mon Sep 17 00:00:00 2001 From: Jan Felix Langenbach Date: Thu, 13 May 2021 01:06:30 +0200 Subject: [PATCH 1/3] Fix #4577: WS not at BOL is deleted to tab columns Changes the behavior of doom/backward-delete-whitespace-to-column to only delete to the closest tab column if there is only whitespace between point and BOL. This coincides with what the comments state to be the original intent. --- modules/config/default/autoload/text.el | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/config/default/autoload/text.el b/modules/config/default/autoload/text.el index 9d0144aaa..8fad8de66 100644 --- a/modules/config/default/autoload/text.el +++ b/modules/config/default/autoload/text.el @@ -71,7 +71,7 @@ possible, or just one char if that's not possible." (ignore-errors (sp-get-thing)))) (op (plist-get context :op)) (cl (plist-get context :cl)) - open-len close-len) + open-len close-len current-column) (cond ;; When in strings (sp acts weird with quotes; this is the fix) ;; Also, skip closing delimiters ((and op cl @@ -89,13 +89,12 @@ possible, or just one char if that's not possible." (> tab-width 1) (not (bolp)) (not (doom-point-in-string-p)) - (save-excursion (>= (- (skip-chars-backward " \t")) tab-width))) - (let ((movement (% (current-column) tab-width))) + (save-excursion (>= (- (skip-chars-backward " \t")) + (setq current-column (current-column))))) + (let ((movement (% current-column tab-width))) (when (= movement 0) (setq movement tab-width)) - (delete-char (- movement))) - (unless (memq (char-before) (list ?\n ?\ )) - (insert " "))) + (delete-char (- movement)))) ;; Otherwise do a regular delete ((delete-char -1))))) From 3c41823824c6deb30e8bc5d6c1602506590a1ef3 Mon Sep 17 00:00:00 2001 From: Jan Felix Langenbach Date: Thu, 13 May 2021 09:49:30 +0200 Subject: [PATCH 2/3] Fix wrong column being used and resulting bugs --- modules/config/default/autoload/text.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/config/default/autoload/text.el b/modules/config/default/autoload/text.el index 8fad8de66..7ca3c3490 100644 --- a/modules/config/default/autoload/text.el +++ b/modules/config/default/autoload/text.el @@ -89,8 +89,8 @@ possible, or just one char if that's not possible." (> tab-width 1) (not (bolp)) (not (doom-point-in-string-p)) - (save-excursion (>= (- (skip-chars-backward " \t")) - (setq current-column (current-column))))) + (>= (abs (save-excursion (skip-chars-backward " \t"))) + (setq current-column (current-column)))) (let ((movement (% current-column tab-width))) (when (= movement 0) (setq movement tab-width)) From c84bc953d997f84254018cb4d712b5c2e204512f Mon Sep 17 00:00:00 2001 From: Jan Felix Langenbach Date: Thu, 13 May 2021 10:50:44 +0200 Subject: [PATCH 3/3] Simplify (% current-column tab-width) code --- modules/config/default/autoload/text.el | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/config/default/autoload/text.el b/modules/config/default/autoload/text.el index 7ca3c3490..056d3defd 100644 --- a/modules/config/default/autoload/text.el +++ b/modules/config/default/autoload/text.el @@ -91,10 +91,7 @@ possible, or just one char if that's not possible." (not (doom-point-in-string-p)) (>= (abs (save-excursion (skip-chars-backward " \t"))) (setq current-column (current-column)))) - (let ((movement (% current-column tab-width))) - (when (= movement 0) - (setq movement tab-width)) - (delete-char (- movement)))) + (delete-char (- (1+ (% (1- current-column) tab-width))))) ;; Otherwise do a regular delete ((delete-char -1)))))