sp: fix quote auto-deleting + conservative backquotes

This commit is contained in:
Henrik Lissner 2016-05-26 18:53:46 -04:00
parent 82fa5d977a
commit 2a4438890f
2 changed files with 43 additions and 35 deletions

View file

@ -237,7 +237,7 @@
;; Auto-close more conservatively ;; Auto-close more conservatively
(sp-pair "'" nil :unless '(sp-point-after-word-p)) (sp-pair "'" nil :unless '(sp-point-after-word-p))
(sp-pair "\"" nil :unless '(sp-point-before-word-p sp-point-before-same-p)) (sp-pair "\"" nil :unless '(sp-point-before-word-p sp-point-after-word-p sp-point-before-same-p))
(sp-pair "{" nil :post-handlers '(("||\n[i]" "RET") ("| " " ")) (sp-pair "{" nil :post-handlers '(("||\n[i]" "RET") ("| " " "))
:unless '(sp-point-before-word-p sp-point-before-same-p)) :unless '(sp-point-before-word-p sp-point-before-same-p))
(sp-pair "(" nil :post-handlers '(("||\n[i]" "RET") ("| " " ")) (sp-pair "(" nil :post-handlers '(("||\n[i]" "RET") ("| " " "))
@ -247,8 +247,7 @@
(sp-local-pair (sp-local-pair
'css-mode "/*" "*/" :post-handlers '(("[d-3]||\n[i]" "RET") ("| " "SPC"))) 'css-mode "/*" "*/" :post-handlers '(("[d-3]||\n[i]" "RET") ("| " "SPC")))
(sp-local-pair (sp-local-pair '(sh-mode markdown-mode) "`" nil
'(sh-mode markdown-mode) "`" "`"
:unless '(sp-point-before-word-p sp-point-before-same-p)) :unless '(sp-point-before-word-p sp-point-before-same-p))
(sp-with-modes '(xml-mode nxml-mode php-mode) (sp-with-modes '(xml-mode nxml-mode php-mode)
(sp-local-pair "<!--" "-->" :post-handlers '(("| " "SPC"))))) (sp-local-pair "<!--" "-->" :post-handlers '(("| " "SPC")))))
@ -280,7 +279,7 @@
;; b) allow backspace to delete space-indented blocks intelligently ;; b) allow backspace to delete space-indented blocks intelligently
;; c) but do none of this when inside a string ;; c) but do none of this when inside a string
:i "SPC" 'doom/inflate-space-maybe :i "SPC" 'doom/inflate-space-maybe
:i [remap backward-delete-char-untabify] 'doom/deflate-space-maybe :i [remap delete-backward-char] 'doom/deflate-space-maybe
:i [remap newline] 'doom/newline-and-indent :i [remap newline] 'doom/newline-and-indent
;; Smarter move-to-beginning-of-line ;; Smarter move-to-beginning-of-line
:i [remap move-beginning-of-line] 'doom/move-to-bol :i [remap move-beginning-of-line] 'doom/move-to-bol

View file

@ -48,20 +48,30 @@ already there, move it to the true bol."
;; Mimic expandtab in vim ;; Mimic expandtab in vim
;;;###autoload ;;;###autoload
;;;###autoload
(defun doom/backward-delete-whitespace-to-column () (defun doom/backward-delete-whitespace-to-column ()
"Delete back to the previous column of whitespace, or as much "Delete back to the previous column of whitespace, or as much whitespace as
whitespace as possible, or just one char if that's not possible." possible, or just one char if that's not possible."
(interactive) (interactive)
(cond ;; If in a string (let* ((context (sp--get-pair-list-context 'navigate))
((sp-point-in-string) (open-pair (sp--get-opening-regexp context))
(call-interactively 'backward-delete-char-untabify)) (close-pair (sp--get-closing-regexp context))
open-len close-len)
(cond ;; When in strings (sp acts weird with quotes; this is the fix)
;; Also, skip closing delimiters
((and (and (sp--looking-back open-pair)
(setq open-len (- (match-beginning 0) (match-end 0))))
(and (looking-at close-pair)
(setq close-len (- (match-beginning 0) (match-end 0)))))
(delete-backward-char open-len)
(delete-char close-len))
;; If using tabs (or at bol), just delete normally ;; If using tabs (or at bol), just delete normally
((or indent-tabs-mode ((or indent-tabs-mode
(= (point-at-bol) (point))) (= (point-at-bol) (point)))
(call-interactively 'backward-delete-char)) (call-interactively 'backward-delete-char-untabify))
;; Delete up to the nearest tab column IF only whitespace between point ;; Delete up to the nearest tab column IF only whitespace between
;; and bol. ;; point and bol.
((looking-back "^[\\t ]*" (point-at-bol)) ((sp--looking-back-p "^[\\t ]*" (point-at-bol))
(let ((movement (% (current-column) tab-width)) (let ((movement (% (current-column) tab-width))
(p (point))) (p (point)))
(when (= movement 0) (when (= movement 0)
@ -69,10 +79,10 @@ whitespace as possible, or just one char if that's not possible."
(save-match-data (save-match-data
(if (string-match "\\w*\\(\\s-+\\)$" (if (string-match "\\w*\\(\\s-+\\)$"
(buffer-substring-no-properties (- p movement) p)) (buffer-substring-no-properties (- p movement) p))
(backward-delete-char (- (match-end 1) (match-beginning 1))) (delete-backward-char (- (match-end 1) (match-beginning 1)))
(backward-delete-char-untabify 1))))) (call-interactively 'delete-backward-char)))))
;; Otherwise do a regular delete ;; Otherwise do a regular delete
(t (backward-delete-char-untabify 1)))) (t (call-interactively 'delete-backward-char)))))
;;;###autoload ;;;###autoload
(defun doom/dumb-indent (&optional smart) (defun doom/dumb-indent (&optional smart)
@ -96,7 +106,7 @@ auto-complete window is open."
(defun doom/dumb-dedent () (defun doom/dumb-dedent ()
(interactive) (interactive)
(if indent-tabs-mode (if indent-tabs-mode
(delete-char -1) (call-interactively 'backward-delete-char)
(save-excursion (save-excursion
(unless (looking-back "^[\s\t]*") (unless (looking-back "^[\s\t]*")
(evil-first-non-blank)) (evil-first-non-blank))
@ -124,13 +134,12 @@ spaces on either side of the point if so. Resorts to
(if (doom/surrounded-p) (if (doom/surrounded-p)
(let ((whitespace-match (match-string 1))) (let ((whitespace-match (match-string 1)))
(cond ((not whitespace-match) (cond ((not whitespace-match)
(call-interactively 'sp-backward-delete-char)) (call-interactively 'delete-backward-char))
((string-match "\n" whitespace-match) ((string-match "\n" whitespace-match)
(evil-delete (point-at-bol) (point)) (evil-delete (point-at-bol) (point))
(delete-char -1) (call-interactively 'delete-backward-char)
(save-excursion (delete-char 1))) (save-excursion (call-interactively 'delete-char)))
(t (t (just-one-space 0))))
(just-one-space 0))))
(doom/backward-delete-whitespace-to-column)))) (doom/backward-delete-whitespace-to-column))))
;;;###autoload ;;;###autoload