Fix whitespacing-eating in org-tables on SPC/DEL

This commit is contained in:
Henrik Lissner 2017-05-19 13:20:50 +02:00
parent 4cd56b46cc
commit 13b2cc9446

View file

@ -103,44 +103,50 @@ afterwards, kill line to column 1."
"Delete back to the previous column of whitespace, or as much whitespace as "Delete back to the previous column of whitespace, or as much whitespace as
possible, or just one char if that's not possible." possible, or just one char if that's not possible."
(interactive) (interactive)
(let* ((context (sp--get-pair-list-context 'navigate)) (let* ((delete-backward-char (if (derived-mode-p 'org-mode)
#'org-delete-backward-char
#'delete-backward-char))
(context (sp--get-pair-list-context 'navigate))
(open-pair-re (sp--get-opening-regexp context)) (open-pair-re (sp--get-opening-regexp context))
(close-pair-re (sp--get-closing-regexp context)) (close-pair-re (sp--get-closing-regexp context))
open-len close-len) open-len close-len)
(cond ;; When in strings (sp acts weird with quotes; this is the fix) (cond ;; When in strings (sp acts weird with quotes; this is the fix)
;; Also, skip closing delimiters ;; Also, skip closing delimiters
((and (and (sp--looking-back open-pair-re) ((and (and (sp--looking-back open-pair-re)
(setq open-len (- (match-beginning 0) (match-end 0)))) (setq open-len (- (match-beginning 0) (match-end 0))))
(and (looking-at close-pair-re) (and (looking-at close-pair-re)
(setq close-len (- (match-beginning 0) (match-end 0)))) (setq close-len (- (match-beginning 0) (match-end 0))))
(string= (plist-get (sp-get-thing t) :op) (string= (plist-get (sp-get-thing t) :op)
(plist-get (sp-get-thing) :cl))) (plist-get (sp-get-thing) :cl)))
(delete-char (- 0 open-len)) (delete-char (- 0 open-len))
(delete-char close-len)) (delete-char close-len))
;; Delete up to the nearest tab column IF only whitespace between
;; point and bol. ;; Delete up to the nearest tab column IF only whitespace between
((save-match-data (looking-back "^[\\t ]*" (line-beginning-position))) ;; point and bol.
(let ((movement (% (current-column) tab-width)) ((save-match-data (looking-back "^[\\t ]*" (line-beginning-position)))
(p (point))) (let ((movement (% (current-column) tab-width))
(when (= movement 0) (p (point)))
(setq movement tab-width)) (when (= movement 0)
(save-match-data (setq movement tab-width))
(if (string-match "\\w*\\(\\s-+\\)$" (save-match-data
(buffer-substring-no-properties (max (point-min) (- p movement)) p)) (if (string-match "\\w*\\(\\s-+\\)$"
(delete-char (- 0 (- (match-end 1) (match-beginning 1)))) (buffer-substring-no-properties (max (point-min) (- p movement)) p))
(call-interactively #'delete-backward-char))))) (sp-delete-char (- 0 (- (match-end 1) (match-beginning 1))))
;; Otherwise do a regular delete (call-interactively delete-backward-char)))))
(t (call-interactively #'delete-backward-char)))))
;; Otherwise do a regular delete
(t (call-interactively delete-backward-char)))))
;;;###autoload ;;;###autoload
(defun doom/inflate-space-maybe () (defun doom/inflate-space-maybe ()
"Checks if point is surrounded by {} [] () delimiters and adds a "Checks if point is surrounded by {} [] () delimiters and adds a
space on either side of the point if so." space on either side of the point if so."
(interactive) (interactive)
(if (doom--surrounded-p) (let ((command (or (command-remapping #'self-insert-command) #'self-insert-command)))
(progn (call-interactively #'self-insert-command) (if (doom--surrounded-p)
(save-excursion (call-interactively #'self-insert-command))) (progn (call-interactively command)
(call-interactively #'self-insert-command))) (save-excursion (call-interactively command)))
(call-interactively command))))
;;;###autoload ;;;###autoload
(defun doom/deflate-space-maybe () (defun doom/deflate-space-maybe ()