diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-15 21:34:09 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-15 21:34:09 -0500 |
| commit | 902290a4c15d905418e1ad354e7ee06cfa35b3f1 (patch) | |
| tree | 0747e21e2a8307709ea26b44cee1623b03cd35bd | |
| parent | 7d58ccfb5baad7ab6e3069f9cb4e181482438357 (diff) | |
| download | dotemacs-902290a4c15d905418e1ad354e7ee06cfa35b3f1.tar.gz dotemacs-902290a4c15d905418e1ad354e7ee06cfa35b3f1.zip | |
fix(prog): keep electric-pair and line-number setup buffer-local
- Go/C/shell setup hooks called the global electric-pair-mode, so one prog buffer turned pairing on in org and text everywhere. Use electric-pair-local-mode.
- prog-general set display-line-numbers-type inside the hook, after the mode turned on, so the first prog buffer of a session got absolute numbers. Set the type and width at top level instead.
- Updated the go/c tests to stub the local mode.
| -rw-r--r-- | modules/prog-c.el | 2 | ||||
| -rw-r--r-- | modules/prog-general.el | 8 | ||||
| -rw-r--r-- | modules/prog-go.el | 2 | ||||
| -rw-r--r-- | modules/prog-shell.el | 2 | ||||
| -rw-r--r-- | tests/test-prog-c-mode-settings.el | 6 | ||||
| -rw-r--r-- | tests/test-prog-go-commands.el | 10 |
6 files changed, 17 insertions, 13 deletions
diff --git a/modules/prog-c.el b/modules/prog-c.el index dd5d7ace5..294375cb4 100644 --- a/modules/prog-c.el +++ b/modules/prog-c.el @@ -70,7 +70,7 @@ (setq-local fill-column 80) ;; wrap at 80 columns (setq-local comment-auto-fill-only-comments t) ;; only auto-fill inside comments (auto-fill-mode) ;; auto-fill multiline comments - (electric-pair-mode) ;; automatic parenthesis pairing + (electric-pair-local-mode) ;; automatic parenthesis pairing ;; Enable LSP if available (when (and (fboundp 'lsp-deferred) diff --git a/modules/prog-general.el b/modules/prog-general.el index cb46ce6b8..53f20ce46 100644 --- a/modules/prog-general.el +++ b/modules/prog-general.el @@ -72,12 +72,16 @@ ;; --------------------- General Programming Mode Settings --------------------- ;; keybindings, minor-modes, and prog-mode settings +;; Set the line-number type and width before any prog buffer enables +;; display-line-numbers-mode. Setting them inside the hook ran after the mode +;; turned on, so the first prog buffer of a session got absolute numbers. +(setq display-line-numbers-type 'relative) ;; numbers relative to point +(setq-default display-line-numbers-width 3) ;; 3 chars reserved for numbers + (defun cj/general-prog-settings () "Keybindings, minor modes, and settings for programming mode." (interactive) (display-line-numbers-mode) ;; show line numbers - (setq display-line-numbers-type 'relative) ;; display numbers relative to 'the point' - (setq-default display-line-numbers-width 3) ;; 3 characters reserved for line numbers (turn-on-visual-line-mode) ;; word-wrapping (auto-fill-mode) ;; auto wrap at the fill column set (local-set-key (kbd "M-;") 'comment-dwim) ;; comment/uncomment region as appropriate diff --git a/modules/prog-go.el b/modules/prog-go.el index 0edfc2065..8d0707b00 100644 --- a/modules/prog-go.el +++ b/modules/prog-go.el @@ -61,7 +61,7 @@ Install with: go install github.com/go-delve/delve/cmd/dlv@latest") (setq-local tab-width 4) ;; Go standard tab width (setq-local standard-indent 4) ;; indent 4 spaces per level (setq-local indent-tabs-mode t) ;; use real tabs (Go convention) - (electric-pair-mode t) ;; match delimiters automatically + (electric-pair-local-mode t) ;; match delimiters automatically ;; Enable LSP if available (when (and (fboundp 'lsp-deferred) diff --git a/modules/prog-shell.el b/modules/prog-shell.el index ca990c614..45c0afbca 100644 --- a/modules/prog-shell.el +++ b/modules/prog-shell.el @@ -74,7 +74,7 @@ Install with: sudo pacman -S shellcheck") (setq-local sh-basic-offset 2) ;; 2 spaces (common shell convention) (setq-local tab-width 2) ;; tab displays as 2 spaces (setq-local fill-column 80) ;; wrap at 80 columns - (electric-pair-mode t) ;; automatic quote/bracket pairing + (electric-pair-local-mode t) ;; automatic quote/bracket pairing ;; Enable LSP if available (skip remote files - slow and prompts for project root) (when (and (fboundp 'lsp-deferred) diff --git a/tests/test-prog-c-mode-settings.el b/tests/test-prog-c-mode-settings.el index eef2d9102..37a77a213 100644 --- a/tests/test-prog-c-mode-settings.el +++ b/tests/test-prog-c-mode-settings.el @@ -16,7 +16,7 @@ "Normal: cj/c-mode-settings applies the documented buffer-local values." (with-temp-buffer (cl-letf (((symbol-function 'auto-fill-mode) (lambda (&rest _) nil)) - ((symbol-function 'electric-pair-mode) (lambda (&rest _) nil)) + ((symbol-function 'electric-pair-local-mode) (lambda (&rest _) nil)) ((symbol-function 'lsp-deferred) (lambda (&rest _) nil)) ((symbol-function 'executable-find) (lambda (_) nil))) (cj/c-mode-settings)) @@ -31,7 +31,7 @@ (let ((lsp-calls 0)) (with-temp-buffer (cl-letf (((symbol-function 'auto-fill-mode) (lambda (&rest _) nil)) - ((symbol-function 'electric-pair-mode) (lambda (&rest _) nil)) + ((symbol-function 'electric-pair-local-mode) (lambda (&rest _) nil)) ((symbol-function 'lsp-deferred) (lambda () (cl-incf lsp-calls))) ((symbol-function 'executable-find) (lambda (_) "/usr/bin/clangd"))) (cj/c-mode-settings))) @@ -42,7 +42,7 @@ (let ((lsp-calls 0)) (with-temp-buffer (cl-letf (((symbol-function 'auto-fill-mode) (lambda (&rest _) nil)) - ((symbol-function 'electric-pair-mode) (lambda (&rest _) nil)) + ((symbol-function 'electric-pair-local-mode) (lambda (&rest _) nil)) ((symbol-function 'lsp-deferred) (lambda () (cl-incf lsp-calls))) ((symbol-function 'executable-find) (lambda (_) nil))) (cj/c-mode-settings))) diff --git a/tests/test-prog-go-commands.el b/tests/test-prog-go-commands.el index 6947f358b..a2fc0625f 100644 --- a/tests/test-prog-go-commands.el +++ b/tests/test-prog-go-commands.el @@ -27,19 +27,19 @@ "Normal: tab-width 4, standard-indent 4, indent-tabs-mode t (Go convention)." (with-temp-buffer (cl-letf (((symbol-function 'company-mode) #'ignore) - ((symbol-function 'electric-pair-mode) #'ignore)) + ((symbol-function 'electric-pair-local-mode) #'ignore)) (cj/go-setup) (should (= tab-width 4)) (should (= standard-indent 4)) (should indent-tabs-mode)))) (ert-deftest test-prog-go-setup-enables-mode-helpers () - "Normal: company-mode and electric-pair-mode are both called." + "Normal: company-mode and electric-pair-local-mode are both called." (with-temp-buffer (let ((called nil)) (cl-letf (((symbol-function 'company-mode) (lambda (&rest _) (push 'company called))) - ((symbol-function 'electric-pair-mode) + ((symbol-function 'electric-pair-local-mode) (lambda (arg) (push (cons 'pair arg) called)))) (cj/go-setup)) (should (memq 'company called)) @@ -50,7 +50,7 @@ (with-temp-buffer (let ((started nil)) (cl-letf (((symbol-function 'company-mode) #'ignore) - ((symbol-function 'electric-pair-mode) #'ignore) + ((symbol-function 'electric-pair-local-mode) #'ignore) ((symbol-function 'lsp-deferred) (lambda (&rest _) (setq started t))) ((symbol-function 'executable-find) @@ -63,7 +63,7 @@ (with-temp-buffer (let ((started nil)) (cl-letf (((symbol-function 'company-mode) #'ignore) - ((symbol-function 'electric-pair-mode) #'ignore) + ((symbol-function 'electric-pair-local-mode) #'ignore) ((symbol-function 'lsp-deferred) (lambda (&rest _) (setq started t))) ((symbol-function 'executable-find) (lambda (_) nil))) |
