From 309cdc65dcc1f7e0c596460fee0493e6a9e5a46b Mon Sep 17 00:00:00 2001 From: kovan Date: Fri, 27 Feb 2026 00:44:53 +0100 Subject: [PATCH] fix(racket): add smart bracket mode toggle Add `+racket-smart-open-bracket-mode` variable so users can disable the DrRacket-style bracket auto-conversion that changes `[` to `(` based on context. Also update README documentation to accurately describe the default behavior and how to configure it. Fix: #1452 Co-authored-by: Claude Opus 4.6 --- modules/lang/racket/README.org | 14 ++++++++++---- modules/lang/racket/config.el | 13 ++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/modules/lang/racket/README.org b/modules/lang/racket/README.org index b2a15145a..5ceca0ad7 100644 --- a/modules/lang/racket/README.org +++ b/modules/lang/racket/README.org @@ -62,14 +62,20 @@ Formatting is handled using the [[doom-module::editor format]] module via [[http #+end_quote ** racket-smart-open-bracket-mode -~racket-smart-open-bracket-mode~ gets turned off automatically if you use -~parinfer~, ~lispy~. If you wish to enable it: +~racket-smart-open-bracket-mode~ is enabled by default (mimicking DrRacket's +behavior). It automatically inserts ~(~ or ~[~ based on the surrounding +syntactic context when you press ~[~. It is disabled automatically if you use +~parinfer~ or ~lispy~. + +To disable it, set ~+racket-smart-open-bracket-mode~ to nil before racket-mode +loads: #+begin_src emacs-lisp ;; in $DOOMDIR/config.el -(with-eval-after-load 'racket-mode - (add-hook 'racket-mode-hook #'racket-smart-open-bracket-mode)) +(setq +racket-smart-open-bracket-mode nil) #+end_src +To force a literal ~[~ without disabling the mode, use =C-q [=. + ** Unicode Input The optional ~racket-unicode~ input method lets you type unicode characters such as λ or π. To enable unicode input for a single buffer, run diff --git a/modules/lang/racket/config.el b/modules/lang/racket/config.el index 13658bedf..fc5007551 100644 --- a/modules/lang/racket/config.el +++ b/modules/lang/racket/config.el @@ -4,6 +4,16 @@ (after! projectile (add-to-list 'projectile-project-root-files "info.rkt")) +(defvar +racket-smart-open-bracket-mode t + "If non-nil, enable `racket-smart-open-bracket-mode'. + +This mode, inspired by DrRacket, automatically inserts `(' or `[' based on +the surrounding syntactic context when you press `['. It is disabled +automatically if `:editor parinfer' or `:editor lispy' is active. + +Set this to nil to always insert the bracket you type. You can also use +`C-q [' to force a literal `[' without disabling this mode.") + ;; ;;; Packages @@ -58,7 +68,8 @@ (cl-pushnew 'racket flycheck-disabled-checkers))))) (unless (or (modulep! :editor parinfer) - (modulep! :editor lispy)) + (modulep! :editor lispy) + (not +racket-smart-open-bracket-mode)) (add-hook mode-hook #'racket-smart-open-bracket-mode)) (map! (:map racket-xp-mode-map