0

[Edit/Clarification: This only happens in sql-mode. I just realized that.]

I used to type ' and get ', now I get ''.

I used to type " and get ", now I get "".

I used to type ( and get (, now I get ().

I realize someone is trying to help me close things I open, but this is really wreaking havoc with my keyboard macros. I type one thing when I define a keyboard macro, but when I execute it, my text gets really messed up. That's because when defining the keyboard macro, the auto-closing of quotes/parens doesn't happen, but when I execute a keyboard macro, it does. SURPRISE! How do I turn off this "assistant?"

8
  • 2
    If you don't see the problem when you start Emacs with emacs -Q (no init file) then bisect your init file to find the culprit. You're doing this to yourself, somehow. Commented Aug 25 at 17:23
  • @Drew I don't see anything obvious, but I'll keep looking. Commented Aug 25 at 19:45
  • 1
    You can use `comment-region' to comment out 1/2, then 3/4, 7/8, 15/16, etc. of your init file to find the problem - bisecting is a binary search, so it's pretty quick (though it doesn't seem it at first. Commented Aug 25 at 21:52
  • 1
    You should check the major mode and all the minor modes that are enabled on the buffer where you observe this behavior. You can do that with C-h m. Add the output to your question. Commented Aug 26 at 0:37
  • 2
    Most likely in my opinion is that you have electric-pair-mode enabled somehow. Commented Aug 26 at 3:51

1 Answer 1

1

You should really go through your init file as @Drew suggests in a comment: you should be able to easily find out any customizations you make to sql-mode and undo them. What you are looking for is probably (just guessing here that electric-pair-mode is the culprit: if you had posted the list of minor modes as I asked in a comment, it would be possible to guess more accurately - but you didn't):

(add-hook 'sql-mode-hook (lambda () (electric-pair-mode 1))) 

If you find something like this, delete it, restart emacs and check again.

As a last resort, if you still cannot find anything, you can try adding the following to the very end of your init file so that it takes effect last:

(add-hook 'sql-mode-hook (lambda () (electric-pair-mode -1)) 99) 

N.B. That 99 argument to add-hook will (with some caveats) place this function at the end of the hook, so it will be executed last.

That will disable electric-pair-mode when the hook is run, i.e. whenever you create a buffer whose major mode is sql-mode, so (one hopes) it will undo what you did before. But that's just a band-aid: obviously, it would be much better to find the place where you turn electric-pair-mode (or whatever other mode is causing the behavior you observe) and eliminate it from there.


EDIT: The OP mentions in a comment that he saw this in an init file:

(use-package emacs ... :hook ((prog-mode . electric-pair-mode))) 

That of course is the culprit: prog-mode is the parent of sql-mode (see the doc string of sql-mode with C-h f sql-mode), so when the mode function is called, not only sql-mode-hook, but also prog-mode-hook is run: that's why electric-pair-mode is enabled in a sql-mode buffer. Note that the mode hook is run after the hook(s) of its ancestor(s), so you can disable anything that the parent (or more generally, ancestor) enabled by doing it in the specific mode hook:

(add-hook 'sql-mode-hook (lambda () (electric-pair-mode -1))) 

There is no need for the 99 paranoia above.

But prog-mode-hook is the parent of many modes (basically any mode that implements facilities for some programming language: python-mode, c-mode, perl-mode, emacs-lisp-mode, as well as sql-mode, and many others) all have prog-mode as an ancestor, so they would all have electric-pair-mode enabled with the setting above.

If you really want electric-pair-mode in most prog-mode buffers, then disabling it for sql-mode makes sense. But if you only want it e.g. for c-mode but not for others, then getting rid of the prog-mode hook setting in the use-package call and enabling it in the c-mode-hook instead is preferable.

5
  • I didn't make any changes to sql-mode. As to minor modes, I see local minor modes: auto-save-mode corfu-mode display-line-numbers-mode font-lock-mode, and global minor modes: auto-encryption-mode column-number-mode context-menu-mode corfu-popupinfo-mode csv-field-index-mode display-time-mode eat-eshell-mode eat-eshell-visual-command-mode electric-indent-mode electric-pair-mode file-name-shadow-mode global-auto-revert-mode global-corfu-mode global-eldoc-mode global-font-lock-mode line-number-mode marginalia-mode menu-bar-mode minibuffer-regexp-mode pixel-scroll-precision-mode savehist-mode ... Commented Aug 28 at 3:25
  • ... show-paren-mode tab-bar-mode tooltip-mode transient-mark-mode vertico-mode which-key-mode . I see electric-pair-mode in there so I'm guessing the code you provided in this answer would take care of the paren issue. I'll try that. Commented Aug 28 at 3:27
  • 1
    I did see in an init file (use-package emacs ... :hook ((prog-mode . electric-pair-mode))) Commented Aug 28 at 3:33
  • (add-hook 'sql-mode-hook (lambda () (electric-pair-mode -1)) 99) seems to have done the trick, thanks Commented Aug 28 at 3:37
  • 1
    See the edited answer: the (use-package emacs ... :hook ((prog-mode . electric-pair-mode))) is the culprit. Commented Aug 28 at 5:18

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.