Move RET & backspace fixes out of +smartparens feature
Neither of these are tied to smartparens, and should be available to folks that have disabled +smartparens.
This commit is contained in:
parent
bc5bbb1770
commit
82ddc86335
2 changed files with 54 additions and 52 deletions
|
@ -50,8 +50,8 @@ If `buffer-file-name' isn't set, uses `default-directory'."
|
|||
(abbreviate-file-name path)
|
||||
(file-name-nondirectory path)))))
|
||||
|
||||
|
||||
(defun doom--backward-delete-whitespace-to-column ()
|
||||
;;;###autoload
|
||||
(defun doom/backward-delete-whitespace-to-column ()
|
||||
"Delete back to the previous column of whitespace, or as much whitespace as
|
||||
possible, or just one char if that's not possible."
|
||||
(interactive)
|
||||
|
@ -74,7 +74,7 @@ possible, or just one char if that's not possible."
|
|||
;; point and bol.
|
||||
((and (not indent-tabs-mode)
|
||||
(not (bolp))
|
||||
(not (sp-point-in-string))
|
||||
(not (doom-point-in-string-p))
|
||||
(save-excursion (>= (- (skip-chars-backward " \t")) tab-width)))
|
||||
(let ((movement (% (current-column) tab-width)))
|
||||
(when (= movement 0)
|
||||
|
@ -97,7 +97,7 @@ possible, or just one char if that's not possible."
|
|||
{
|
||||
|
|
||||
} => {|}
|
||||
+ Otherwise, resort to `doom--backward-delete-whitespace-to-column'.
|
||||
+ Otherwise, resort to `doom/backward-delete-whitespace-to-column'.
|
||||
+ Resorts to `delete-char' if n > 1"
|
||||
(interactive "p\nP")
|
||||
(or (integerp n)
|
||||
|
@ -120,12 +120,14 @@ possible, or just one char if that's not possible."
|
|||
(save-excursion
|
||||
(insert-char ?\s (- ocol (current-column)) nil))))
|
||||
;;
|
||||
((and (= n 1) (bound-and-true-p smartparens-mode))
|
||||
(cond ((and (memq (char-before) (list ?\ ?\t))
|
||||
((= n 1)
|
||||
(cond ((or (not (featurep! +smartparens))
|
||||
(not (bound-and-true-p smartparens-mode))
|
||||
(and (memq (char-before) (list ?\ ?\t))
|
||||
(save-excursion
|
||||
(and (/= (skip-chars-backward " \t" (line-beginning-position)) 0)
|
||||
(bolp))))
|
||||
(doom--backward-delete-whitespace-to-column))
|
||||
(bolp)))))
|
||||
(doom/backward-delete-whitespace-to-column))
|
||||
((let* ((pair (ignore-errors (sp-get-thing)))
|
||||
(op (plist-get pair :op))
|
||||
(cl (plist-get pair :cl))
|
||||
|
@ -144,6 +146,6 @@ possible, or just one char if that's not possible."
|
|||
(sp-insert-pair op)
|
||||
t)
|
||||
((run-hook-with-args-until-success 'doom-delete-backward-functions))
|
||||
((doom--backward-delete-whitespace-to-column)))))))
|
||||
((doom/backward-delete-whitespace-to-column)))))))
|
||||
;; Otherwise, do simple deletion.
|
||||
((delete-char (- n) killflag))))
|
||||
|
|
|
@ -204,36 +204,40 @@
|
|||
|
||||
;; This keybind allows * to skip over **.
|
||||
(map! :map markdown-mode-map
|
||||
:ig "*" (λ! (if (looking-at-p "\\*\\* *$")
|
||||
(forward-char 2)
|
||||
(call-interactively 'self-insert-command)))))
|
||||
:ig "*" (general-predicate-dispatch nil
|
||||
(looking-at-p "\\*\\* *")
|
||||
(λ! (forward-char 2)))))))
|
||||
|
||||
;; Highjacks backspace to:
|
||||
;; a) balance spaces inside brackets/parentheses ( | ) -> (|)
|
||||
;; b) delete up to nearest column multiple of `tab-width' 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 #'+default--delete-backward-char-a))
|
||||
|
||||
;; HACK Makes `newline-and-indent' continue comments (and more reliably).
|
||||
;; Consults `doom-point-in-comment-functions' to detect a commented
|
||||
;; region and uses that mode's `comment-line-break-function' to continue
|
||||
;; comments. If neither exists, it will fall back to the normal behavior
|
||||
;; of `newline-and-indent'.
|
||||
;;
|
||||
;; We use an advice here instead of a remapping because many modes define
|
||||
;; and remap to their own newline-and-indent commands, and tackling all
|
||||
;; those cases was judged to be more work than dealing with the edge
|
||||
;; cases on a case by case basis.
|
||||
(defadvice! +default--newline-indent-and-continue-comments-a (&rest _)
|
||||
;;
|
||||
;;; Keybinding fixes
|
||||
|
||||
;; Highjacks backspace to delete up to nearest column multiple of `tab-width' at
|
||||
;; a time. If you have smartparens enabled, it will also:
|
||||
;; a) balance spaces inside brackets/parentheses ( | ) -> (|)
|
||||
;; b) close empty multiline brace blocks in one step:
|
||||
;; {
|
||||
;; |
|
||||
;; }
|
||||
;; becomes {|}
|
||||
;; c) refresh smartparens' :post-handlers, so SPC and RET expansions work even
|
||||
;; after a backspace.
|
||||
;; d) properly delete smartparen pairs when they are encountered, without the
|
||||
;; need for strict mode.
|
||||
;; e) do none of this when inside a string
|
||||
(advice-add #'delete-backward-char :override #'doom/backward-delete-whitespace-to-column)
|
||||
|
||||
;; HACK Makes `newline-and-indent' continue comments (and more reliably).
|
||||
;; Consults `doom-point-in-comment-functions' to detect a commented region
|
||||
;; and uses that mode's `comment-line-break-function' to continue comments.
|
||||
;; If neither exists, it will fall back to the normal behavior of
|
||||
;; `newline-and-indent'.
|
||||
;;
|
||||
;; We use an advice here instead of a remapping because many modes define
|
||||
;; and remap to their own newline-and-indent commands, and tackling all
|
||||
;; those cases was judged to be more work than dealing with the edge cases
|
||||
;; on a case by case basis.
|
||||
(defadvice! +default--newline-indent-and-continue-comments-a (&rest _)
|
||||
"A replacement for `newline-and-indent'.
|
||||
|
||||
Continues comments if executed from a commented line. Consults
|
||||
|
@ -244,11 +248,7 @@ Continues comments if executed from a commented line. Consults
|
|||
(doom-point-in-comment-p)
|
||||
(fboundp comment-line-break-function))
|
||||
(funcall comment-line-break-function nil)
|
||||
t)))
|
||||
|
||||
|
||||
;;
|
||||
;;; Keybinding fixes
|
||||
t))
|
||||
|
||||
;; This section is dedicated to "fixing" certain keys so that they behave
|
||||
;; sensibly (and consistently with similar contexts).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue