about summary refs log tree commit diff stats
path: root/.emacs.d/lisp/init-smartparens.el
diff options
context:
space:
mode:
authorDavid Morgan <djm_uk@protonmail.com>2022-11-01 16:27:42 +0000
committerDavid Morgan <djm_uk@protonmail.com>2022-11-01 16:27:42 +0000
commitaba1ab31911602127f7e5ae54fa9f8e7b9582c2d (patch)
tree31b5971d5ebe429790faa59fbc12d40505be6da8 /.emacs.d/lisp/init-smartparens.el
parent45c2459c8e72c9a919176d7b7c3f244856a83d80 (diff)
downloaddotfiles-aba1ab31911602127f7e5ae54fa9f8e7b9582c2d.tar.gz
Mostly use smartparens
Diffstat (limited to '.emacs.d/lisp/init-smartparens.el')
-rw-r--r--.emacs.d/lisp/init-smartparens.el87
1 files changed, 52 insertions, 35 deletions
diff --git a/.emacs.d/lisp/init-smartparens.el b/.emacs.d/lisp/init-smartparens.el
index fa8c122..b80d184 100644
--- a/.emacs.d/lisp/init-smartparens.el
+++ b/.emacs.d/lisp/init-smartparens.el
@@ -2,53 +2,70 @@
 ;;; Commentary:
 ;;; Code:
 
+(use-package paredit
+  :commands (paredit-semicolon paredit-comment-dwim))
+
 (use-package smartparens
   :diminish
   :custom
   (sp-base-key-bindings 'paredit)
   (sp-autoskip-closing-pair 'always)
   (sp-hybrid-kill-entire-symbol t)
-  (sp-hybrid-kill-excessive-whitespace t)
+  (sp-hybrid-kill-excessive-whitespace nil)
+  :hook (after-init . (lambda ()
+                        (smartparens-global-strict-mode)
+                        (show-smartparens-global-mode)
+                        (setq sp-paredit-bindings (delete '("M-?" . sp-convolute-sexp) sp-paredit-bindings))
+                        (require 'smartparens-config)
+                        (sp-use-paredit-bindings)))
   :config
-  (defun sp-wrap-double-quotation-marks ()
+  (sp-pair "\"" "\"" :wrap "M-\"")
+  ;; From https://github.com/bodil/emacs.d/blob/master/bodil/bodil-paredit.el
+  (defun duplicate-sexp-after-point ()
+    "Duplicates the content of the line that is after the point."
     (interactive)
-    (sp-wrap-with-pair "\""))
-  ;; https://github.com/syl20bnr/spacemacs/blob/develop/layers/+spacemacs/spacemacs-editing/funcs.el (spacemacs/smart-closing-parenthesis)
-  ;; TODO can make things unbalanced
-  (defun sp-close-round ()
+    ;; skips to the next sexp
+    (while (looking-at " ")
+      (forward-char))
+    (set-mark-command nil)
+    ;; while we find sexps we move forward on the line
+    (while (and (<= (point) (car (bounds-of-thing-at-point 'sexp)))
+                (not (= (point) (line-end-position))))
+      (forward-sexp)
+      (while (looking-at " ")
+        (forward-char)))
+    (kill-ring-save (mark) (point))
+    ;; go to the next line and copy the sexps we encountered
+    (sp-newline)
+    (set-mark-command nil)
+    (yank)
+    (exchange-point-and-mark))
+  ;; From https://github.com/bodil/emacs.d/blob/master/bodil/bodil-paredit.el
+  ;; Inverse M-(
+  (defun wrap-round-from-behind ()
+    "Wrap the previous sexp before the point with ()."
     (interactive)
-    (let* ((sp-navigate-close-if-unbalanced t)
-           (current-pos (point))
-           (current-line (line-number-at-pos current-pos))
-           next-pos next-line)
-      (save-excursion
-        (let ((buffer-undo-list)
-              (modified (buffer-modified-p)))
-          (unwind-protect
-              (progn
-                (sp-up-sexp)
-                (setq next-pos (point)
-                      next-line (line-number-at-pos)))
-            (primitive-undo (length buffer-undo-list)
-                            buffer-undo-list)
-            (set-buffer-modified-p modified))))
-      (cond
-       ((and (= current-line next-line)
-             (not (= current-pos next-pos)))
-        (sp-up-sexp))
-       (t
-        (insert-char ?\))))))
-
-  (smartparens-global-strict-mode)
-  (show-smartparens-global-mode)
-  (require 'smartparens-config)
-  (sp-use-paredit-bindings)
+    (forward-sexp -1)
+    (sp-wrap-round)
+    (insert " ")
+    (forward-char -1))
   (unbind-key "M-?" 'smartparens-mode-map)
-  :commands sp-local-pair
+  (unbind-key "M-?" 'sp-keymap)
   :bind (:map smartparens-mode-map
               ("C-M-?" . sp-convolute-sexp)
-              ;; (")" . sp-close-round)
-              ("M-\"" . sp-wrap-double-quotation-marks)))
+              ([remap mark-sexp] . sp-mark-sexp)
+              ("M-[" . paredit-smart-wrap-square)
+              ("C-c M-{" . sp-wrap-curly)
+              ("M-W" . sp-copy-sexp)
+              (")" . paredit-close-round)
+              ("]" . paredit-close-square)
+              ("}" . paredit-close-curly)
+              (";" . paredit-semicolon)
+              ("M-;" . paredit-comment-dwim)
+              ("M-q" . sp-indent-defun)
+              ("C-j" . sp-newline)
+              ("C-c C-S-d" . duplicate-sexp-after-point)
+              ("C-c M-(" . wrap-round-from-behind)))
 
 (provide 'init-smartparens)
 ;;; init-smartparens.el ends here
/span>void **state); void compare_win_nums_less(void **state); void compare_win_nums_equal(void **state); void compare_win_nums_greater(void **state); void compare_0s_equal(void **state); void compare_0_greater_than_1(void **state); void compare_1_less_than_0(void **state); void compare_0_less_than_11(void **state); void compare_11_greater_than_0(void **state); void compare_0_greater_than_9(void **state); void compare_9_less_than_0(void **state); void next_available_when_only_console(void **state); void next_available_3_at_end(void **state); void next_available_9_at_end(void **state); void next_available_0_at_end(void **state); void next_available_2_in_first_gap(void **state); void next_available_9_in_first_gap(void **state); void next_available_0_in_first_gap(void **state); void next_available_11_in_first_gap(void **state); void next_available_24_first_big_gap(void **state); void test_online_is_valid_resource_presence_string(void **state); void test_chat_is_valid_resource_presence_string(void **state); void test_away_is_valid_resource_presence_string(void **state); void test_xa_is_valid_resource_presence_string(void **state); void test_dnd_is_valid_resource_presence_string(void **state); void test_available_is_not_valid_resource_presence_string(void **state); void test_unavailable_is_not_valid_resource_presence_string(void **state); void test_blah_is_not_valid_resource_presence_string(void **state); void test_p_sha1_hash1(void **state); void test_p_sha1_hash2(void **state); void test_p_sha1_hash3(void **state); void test_p_sha1_hash4(void **state); void test_p_sha1_hash5(void **state); void test_p_sha1_hash6(void **state); void test_p_sha1_hash6(void **state); void test_p_sha1_hash7(void **state); void utf8_display_len_null_str(void **state); void utf8_display_len_1_non_wide(void **state); void utf8_display_len_1_wide(void **state); void utf8_display_len_non_wide(void **state); void utf8_display_len_wide(void **state); void utf8_display_len_all_wide(void **state); void strip_quotes_does_nothing_when_no_quoted(void **state); void strip_quotes_strips_first(void **state); void strip_quotes_strips_last(void **state); void strip_quotes_strips_both(void **state); void str_not_contains_str(void **state); void str_contains_str_at_start(void **state); void str_contains_str_at_end(void **state); void str_contains_str_in_middle(void **state); void str_contains_str_whole(void **state); void str_empty_not_contains_str(void **state); void str_not_contains_str_empty(void **state); void str_empty_not_contains_str_empty(void **state); void prof_partial_occurrences_tests(void **state); void prof_whole_occurrences_tests(void **state);