Introduce more opinionated backspace/del/newline behavior
+ Instead of remapping delete-backward-char to doom/delete-backward-char (which was unreliable, depending on the mode), it is now overridden with it, without sacrificing its original functionality. The new behavior is as follows: + Fall back to sp-backward-delete-char when it makes sense to delete the adjacent pair: {|} => | + Collapse an indented pair block, if at bolp in between: { | } => {|} + Refresh a pair's :post-handlers when deleting into pair: { | } => {|} => { | } (can be repeated) + When cursor is preceded by whitespace, delete in increments of tab-width. + newline-and-indent has been advised to: + Only newline when in a string. + Continue comment lines consistently (needs more testing!) + Falls back to basic newline-and-indent, without affecting whitespace in the origin line (it would originally delete-horizontal-space before creating a new line). + Incorporates a set of reasonable defaults for brace expansion on RET or SPC, as mentioned in #343 and #413. Affects #343, #413
This commit is contained in:
parent
b43743d565
commit
57adae5ec6
3 changed files with 181 additions and 113 deletions
|
@ -9,6 +9,7 @@
|
|||
|
||||
(map! [remap evil-jump-to-tag] #'projectile-find-tag
|
||||
[remap find-tag] #'projectile-find-tag
|
||||
[remap newline] #'newline-and-indent
|
||||
|
||||
;; Ensure there are no conflicts
|
||||
:nmvo doom-leader-key nil
|
||||
|
@ -698,27 +699,13 @@
|
|||
:i "C-u" #'doom/backward-kill-to-bol-and-indent
|
||||
|
||||
;; textmate-esque newline insertion
|
||||
:i [M-return] #'evil-open-below
|
||||
:i [S-M-return] #'evil-open-above
|
||||
:i [M-return] #'evil-open-below
|
||||
:i [S-M-return] #'evil-open-above
|
||||
;; textmate-esque deletion
|
||||
[M-backspace] #'doom/backward-kill-to-bol-and-indent
|
||||
:i [backspace] #'delete-backward-char
|
||||
:i [M-backspace] #'doom/backward-kill-to-bol-and-indent
|
||||
:ig [M-backspace] #'doom/backward-kill-to-bol-and-indent
|
||||
;; Emacsien motions for insert mode
|
||||
:i "C-b" #'backward-word
|
||||
:i "C-f" #'forward-word
|
||||
|
||||
;; Highjacks space/backspace to:
|
||||
;; a) balance spaces inside brackets/parentheses ( | ) -> (|)
|
||||
;; b) delete space-indented blocks intelligently
|
||||
;; c) do none of this when inside a string
|
||||
:i "SPC" #'doom/inflate-space-maybe
|
||||
:i [remap delete-backward-char] #'doom/deflate-space-maybe
|
||||
:i [remap newline] #'doom/newline-and-indent
|
||||
|
||||
(:after org
|
||||
(:map org-mode-map
|
||||
:i [remap doom/inflate-space-maybe] #'org-self-insert-command))
|
||||
:i "C-b" #'backward-word
|
||||
:i "C-f" #'forward-word
|
||||
|
||||
;; Restore common editing keys (and ESC) in minibuffer
|
||||
(:map (minibuffer-local-map
|
||||
|
|
|
@ -23,6 +23,51 @@
|
|||
epa-pinentry-mode 'loopback))
|
||||
|
||||
|
||||
;; disable :unless predicates with (sp-pair "'" nil :unless nil)
|
||||
;; disable :post-handlers with (sp-pair "{" nil :post-handlers nil)
|
||||
;; ...or specific :post-handlers with (sp-pair "{" nil :post-handlers '(:rem ("| " "SPC")))
|
||||
(after! smartparens
|
||||
;; Autopair quotes more conservatively; if I'm next to a word/before another
|
||||
;; quote, I likely don't want another pair.
|
||||
(let ((unless-list '(sp-point-before-word-p
|
||||
sp-point-after-word-p
|
||||
sp-point-before-same-p)))
|
||||
(sp-pair "'" nil :unless unless-list)
|
||||
(sp-pair "\"" nil :unless unless-list))
|
||||
|
||||
;; Expand {|} => { | }
|
||||
;; Expand {|} => {
|
||||
;; |
|
||||
;; }
|
||||
(dolist (brace '("(" "{" "["))
|
||||
(sp-pair brace nil
|
||||
:post-handlers '(("||\n[i]" "RET") ("| " "SPC"))
|
||||
;; I likely don't want a new pair if adjacent to a word or opening brace
|
||||
:unless '(sp-point-before-word-p sp-point-before-same-p)))
|
||||
|
||||
;; Don't do square-bracket space-expansion where it doesn't make sense to
|
||||
(sp-local-pair '(emacs-lisp-mode org-mode markdown-mode gfm-mode)
|
||||
"[" nil :post-handlers '(:rem ("| " "SPC")))
|
||||
|
||||
;; Highjacks backspace to:
|
||||
;; a) balance spaces inside brackets/parentheses ( | ) -> (|)
|
||||
;; b) delete space-indented `tab-width' steps at a time
|
||||
;; c) close empty multiline brace blocks in one step:
|
||||
;; {
|
||||
;; |
|
||||
;; }
|
||||
;; becomes {|}
|
||||
;; d) refresh smartparens' :post-handlers, so SPC and RET expansions work
|
||||
;; even after a backspace.
|
||||
;; e) properly delete smartparen pairs when they are encountered, without the
|
||||
;; need for strict mode.
|
||||
;; f) do none of this when inside a string
|
||||
(advice-add #'delete-backward-char :override #'doom/delete-backward-char)
|
||||
|
||||
;; Makes `newline-and-indent' smarter when dealing with comments
|
||||
(advice-add #'newline-and-indent :around #'doom*newline-and-indent))
|
||||
|
||||
|
||||
(when (featurep 'evil)
|
||||
(when (featurep! +evil-commands)
|
||||
(load! +evil-commands))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue