From f9aa8e01a1c13de7eb0ebd781dd0fb59087852fe Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Wed, 12 Apr 2023 16:40:39 +0200 Subject: [PATCH] fix electric indent, tab indent and smartparens --- TODO.md | 1 - conf-lisp/elisp.el | 2 +- conf-lisp/smartparens.el | 238 +++++++++++++++++----------------- conf-lisp/textmanipulation.el | 3 + 4 files changed, 124 insertions(+), 120 deletions(-) diff --git a/TODO.md b/TODO.md index 818d82c..e69de29 100644 --- a/TODO.md +++ b/TODO.md @@ -1 +0,0 @@ -# Pasting from unix into emacs doesn't work anymore diff --git a/conf-lisp/elisp.el b/conf-lisp/elisp.el index ff81099..7474ce1 100644 --- a/conf-lisp/elisp.el +++ b/conf-lisp/elisp.el @@ -122,7 +122,7 @@ Returns t if version changed, nil otherwise." ;; enable outshine mode (outshine-hook-function) - (electric-indent-mode t))) + (electric-indent-local-mode t))) ;; use UP arrow for history in *ielm* as well, just as C-up (add-hook 'comint-mode-hook diff --git a/conf-lisp/smartparens.el b/conf-lisp/smartparens.el index 1b709d5..a8c8061 100644 --- a/conf-lisp/smartparens.el +++ b/conf-lisp/smartparens.el @@ -30,27 +30,29 @@ Used when enabling smartparens-mode." (goto-char beg)))) (use-package smartparens - :config - (require 'smartparens-config) - (require 'cl-lib) + :config + (require 'smartparens-config) + (require 'cl-lib) - ;; enable sp in minibuffer as well - ;; maybe, see: https://github.com/Fuco1/smartparens/issues/33: - ;; (sp-local-pair 'minibuffer-inactive-mode "'" nil :actions nil) - (setq sp-ignore-modes-list - (delete 'minibuffer-inactive-mode sp-ignore-modes-list)) + ;; enable sp in minibuffer as well + ;; maybe, see: https://github.com/Fuco1/smartparens/issues/33: + ;; (sp-local-pair 'minibuffer-inactive-mode "'" nil :actions nil) + (setq sp-ignore-modes-list + (delete 'minibuffer-inactive-mode sp-ignore-modes-list)) - ;; automatically enable where needed - (add-something-to-mode-hooks - '(rust emacs-lisp ielm lisp lisp-interaction scheme slime-repl ) 'smartparens-mode) + ;; automatically enable where needed + (add-something-to-mode-hooks + '(rust emacs-lisp ielm lisp elisp lisp-interaction scheme slime-repl ) 'smartparens-mode) - ;; also in some select prog modes - (add-something-to-mode-hooks - '(perl ruby c c++ sh makefile config-general yaml go) 'smartparens-mode) + ;; also in some select prog modes + ;; (add-something-to-mode-hooks + ;; '(perl ruby c c++ sh makefile config-general yaml go) (smartparens-mode t)) + ;; the above doesn't work anymore, for whatever reasons, so I enable it for all + (smartparens-global-mode t) - ;; via https://ebzzry.io/en/emacs-pairs/: - (defmacro def-pairs (pairs) - "Define functions for pairing. PAIRS is an alist of (NAME . STRING) + ;; via https://ebzzry.io/en/emacs-pairs/: + (defmacro def-pairs (pairs) + "Define functions for pairing. PAIRS is an alist of (NAME . STRING) conses, where NAME is the function name that will be created and STRING is a single-character string that marks the opening character. @@ -59,81 +61,81 @@ STRING is a single-character string that marks the opening character. defines the functions WRAP-WITH-PAREN and WRAP-WITH-BRACKET, respectively." - `(progn - ,@(cl-loop for (key . val) in pairs - collect - `(defun ,(read (concat - "wrap-with-" - (prin1-to-string key) - "s")) - (&optional arg) - (interactive "p") - (sp-wrap-with-pair ,val))))) + `(progn + ,@(cl-loop for (key . val) in pairs + collect + `(defun ,(read (concat + "wrap-with-" + (prin1-to-string key) + "s")) + (&optional arg) + (interactive "p") + (sp-wrap-with-pair ,val))))) - (def-pairs ((paren . "(") - (bracket . "[") - (brace . "{") - (single-quote . "'") - (double-quote . "\"") - (back-quote . "`"))) + (def-pairs ((paren . "(") + (bracket . "[") + (brace . "{") + (single-quote . "'") + (double-quote . "\"") + (back-quote . "`"))) - ;;(add-hook 'smartparens-enabled-hook #'tvd-disable-par-and-pair) - ;;(add-hook 'smartparens-enabled-hook #'turn-on-smartparens-strict-mode) + ;;(add-hook 'smartparens-enabled-hook #'tvd-disable-par-and-pair) + ;;(add-hook 'smartparens-enabled-hook #'turn-on-smartparens-strict-mode) - ;; auto wrapping w/o region - (define-key smartparens-mode-map (kbd "C-c (") 'wrap-with-parens) - (define-key smartparens-mode-map (kbd "C-c [") 'wrap-with-brackets) - (define-key smartparens-mode-map (kbd "C-c {") 'wrap-with-braces) - (define-key smartparens-mode-map (kbd "C-c '") 'wrap-with-single-quotes) - (define-key smartparens-mode-map (kbd "C-c \"") 'wrap-with-double-quotes) - (define-key smartparens-mode-map (kbd "C-c `") 'wrap-with-back-quotes) + ;; auto wrapping w/o region + (define-key smartparens-mode-map (kbd "C-c (") 'wrap-with-parens) + (define-key smartparens-mode-map (kbd "C-c [") 'wrap-with-brackets) + (define-key smartparens-mode-map (kbd "C-c {") 'wrap-with-braces) + (define-key smartparens-mode-map (kbd "C-c '") 'wrap-with-single-quotes) + (define-key smartparens-mode-map (kbd "C-c \"") 'wrap-with-double-quotes) + (define-key smartparens-mode-map (kbd "C-c `") 'wrap-with-back-quotes) - ;; modification - (define-key smartparens-mode-map (kbd "C-k") 'sp-kill-hybrid-sexp) - (define-key smartparens-mode-map (kbd "C-") 'sp-forward-slurp-sexp) - (define-key smartparens-mode-map (kbd "C-") 'sp-forward-barf-sexp) + ;; modification + (define-key smartparens-mode-map (kbd "C-k") 'sp-kill-hybrid-sexp) + (define-key smartparens-mode-map (kbd "C-") 'sp-forward-slurp-sexp) + (define-key smartparens-mode-map (kbd "C-") 'sp-forward-barf-sexp) - ;; movement - ;; Also Check: https://github.com/Fuco1/smartparens/wiki/Working-with-expressions - ;; (look for "quick summary for each navigation function") - ;; - ;; Jump after the next balanced expression. If inside one and - ;; there is no forward exp., jump after its closing pair. - (define-key smartparens-mode-map (kbd "C-M-") 'sp-forward-sexp) - ;; Jump before the previous balanced expression. If inside one - ;; and there is no previous exp., jump before its opening pair. - (define-key smartparens-mode-map (kbd "C-M-") 'sp-backward-sexp) - ;; Jump up one level from the current balanced expression. This - ;; means skipping all the enclosed expressions within this and - ;; then jumping after the closing pair. - (define-key smartparens-mode-map (kbd "C-M-") 'sp-up-sexp) - ;; Jump after the opening pair of next balanced expression. This - ;; effectively descends one level down in the "expression - ;; hierarchy". If there is no expression to descend to, jump - ;; after current expression's opening pair. This can be used to - ;; quickly navigate to the beginning of current balanced - ;; expression. - (define-key smartparens-mode-map (kbd "C-M-") 'sp-down-sexp) - ;; Jump to the beginning of following balanced expression. If - ;; there is no following expression on the current level, jump - ;; one level up backward, effectively doing sp-backward-up-sexp. - (define-key smartparens-mode-map (kbd "C-S-") 'sp-next-sexp) - ;; Jump to the end of the previous balanced expression. If there - ;; is no previous expression on the current level, jupm one level - ;; up forward, effectively doing sp-up-sexp. - (define-key smartparens-mode-map (kbd "C-S-") 'sp-previous-sexp) + ;; movement + ;; Also Check: https://github.com/Fuco1/smartparens/wiki/Working-with-expressions + ;; (look for "quick summary for each navigation function") + ;; + ;; Jump after the next balanced expression. If inside one and + ;; there is no forward exp., jump after its closing pair. + (define-key smartparens-mode-map (kbd "C-M-") 'sp-forward-sexp) + ;; Jump before the previous balanced expression. If inside one + ;; and there is no previous exp., jump before its opening pair. + (define-key smartparens-mode-map (kbd "C-M-") 'sp-backward-sexp) + ;; Jump up one level from the current balanced expression. This + ;; means skipping all the enclosed expressions within this and + ;; then jumping after the closing pair. + (define-key smartparens-mode-map (kbd "C-M-") 'sp-up-sexp) + ;; Jump after the opening pair of next balanced expression. This + ;; effectively descends one level down in the "expression + ;; hierarchy". If there is no expression to descend to, jump + ;; after current expression's opening pair. This can be used to + ;; quickly navigate to the beginning of current balanced + ;; expression. + (define-key smartparens-mode-map (kbd "C-M-") 'sp-down-sexp) + ;; Jump to the beginning of following balanced expression. If + ;; there is no following expression on the current level, jump + ;; one level up backward, effectively doing sp-backward-up-sexp. + (define-key smartparens-mode-map (kbd "C-S-") 'sp-next-sexp) + ;; Jump to the end of the previous balanced expression. If there + ;; is no previous expression on the current level, jupm one level + ;; up forward, effectively doing sp-up-sexp. + (define-key smartparens-mode-map (kbd "C-S-") 'sp-previous-sexp) - ;; comment the whole sexp - (define-key smartparens-mode-map (kbd ";") 'tvd-lisp-comment) + ;; comment the whole sexp + (define-key smartparens-mode-map (kbd ";") 'tvd-lisp-comment) - ;; replace my global setting - ;; FIXME: fhceck/fix M! - (define-key smartparens-mode-map (kbd "M-") 'sp-forward-symbol) - (define-key smartparens-mode-map (kbd "M-") 'sp-backward-symbol) + ;; replace my global setting + ;; FIXME: fhceck/fix M! + (define-key smartparens-mode-map (kbd "M-") 'sp-forward-symbol) + (define-key smartparens-mode-map (kbd "M-") 'sp-backward-symbol) - (when (fboundp 'defhydra) - (defhydra hydra-smartparens (:hint nil) - " + (when (fboundp 'defhydra) + (defhydra hydra-smartparens (:hint nil) + " Sexps [quit with _q_, reach this hydra with 'C-x ('] ^Nav^ ^Barf/Slurp^ ^Depth^ @@ -154,41 +156,41 @@ _k_: kill (C-k) _s_: split _{_: wrap with { } ^^ _i_: indent defun " - ("q" nil) - ;; Wrapping - ("(" (lambda (_) (interactive "P") (sp-wrap-with-pair "("))) - ("{" (lambda (_) (interactive "P") (sp-wrap-with-pair "{"))) - ("'" (lambda (_) (interactive "P") (sp-wrap-with-pair "'"))) - ("\"" (lambda (_) (interactive "P") (sp-wrap-with-pair "\""))) - ;; Navigation - ("f" sp-forward-sexp ) - ("b" sp-backward-sexp) - ("u" sp-backward-up-sexp) - ("d" sp-down-sexp) - ("p" sp-backward-down-sexp) - ("n" sp-up-sexp) - ;; Kill/copy - ("w" sp-copy-sexp) - ("k" sp-kill-sexp) - ;; Misc - ("t" sp-transpose-sexp) - ("j" sp-join-sexp) - ("s" sp-split-sexp) - ("c" sp-convolute-sexp) - ("i" sp-indent-defun) - ;; Depth changing - ("R" sp-splice-sexp) - ("r" sp-splice-sexp-killing-around) - ("" sp-splice-sexp-killing-backward) - ("" sp-splice-sexp-killing-forward) - ;; Barfing/slurping - ("" sp-forward-slurp-sexp) - ("" sp-forward-barf-sexp) - ("C-" sp-backward-barf-sexp) - ("C-" sp-backward-slurp-sexp)) + ("q" nil) + ;; Wrapping + ("(" (lambda (_) (interactive "P") (sp-wrap-with-pair "("))) + ("{" (lambda (_) (interactive "P") (sp-wrap-with-pair "{"))) + ("'" (lambda (_) (interactive "P") (sp-wrap-with-pair "'"))) + ("\"" (lambda (_) (interactive "P") (sp-wrap-with-pair "\""))) + ;; Navigation + ("f" sp-forward-sexp ) + ("b" sp-backward-sexp) + ("u" sp-backward-up-sexp) + ("d" sp-down-sexp) + ("p" sp-backward-down-sexp) + ("n" sp-up-sexp) + ;; Kill/copy + ("w" sp-copy-sexp) + ("k" sp-kill-sexp) + ;; Misc + ("t" sp-transpose-sexp) + ("j" sp-join-sexp) + ("s" sp-split-sexp) + ("c" sp-convolute-sexp) + ("i" sp-indent-defun) + ;; Depth changing + ("R" sp-splice-sexp) + ("r" sp-splice-sexp-killing-around) + ("" sp-splice-sexp-killing-backward) + ("" sp-splice-sexp-killing-forward) + ;; Barfing/slurping + ("" sp-forward-slurp-sexp) + ("" sp-forward-barf-sexp) + ("C-" sp-backward-barf-sexp) + ("C-" sp-backward-slurp-sexp)) - (define-key smartparens-mode-map (kbd "C-x (") 'hydra-smartparens/body) - )) + (define-key smartparens-mode-map (kbd "C-x (") 'hydra-smartparens/body) + )) ;;; Parens config goes here as well diff --git a/conf-lisp/textmanipulation.el b/conf-lisp/textmanipulation.el index 0a94c46..30240c6 100644 --- a/conf-lisp/textmanipulation.el +++ b/conf-lisp/textmanipulation.el @@ -277,3 +277,6 @@ in between will be killed. If INS is non-nil, it will be inserted then." (advice-add 'iedit-mode :after '(lambda (&rest args) ;; restore previously saved (setq buffer-undo-list tvd-buffer-undo-list)))) + +(add-hook 'text-mode-hook + (lambda () (electric-indent-local-mode -1)))