reddit / emacs

electric-pair-mode does not work as intended with $, * and `

cidra_ · 2022-04-25 18:25
Hi all. I'm trying **really** hard to make *elec-pair* work for me without any success. This is a minimal config (Emacs 26.3): (electric-pair-mode t) (setq electric-pair--skip-whitespace nil) (setq electric-pair-skip-self nil) ;;it's hard to indent in reddit (setq electric-pair-pairs '((?\( . ?\)) (?\[ . ?\]) (?{ . ?}) (?* . ?*) (?` . ?`) (?$ . ?$))) (setq electric-pair-text-pairs '((?\( . ?\)) (?\[ . ?\]) (?{ . ?}) (?* . ?*) (?` . ?`) (?$ . ?$))) Basically the paired character are the brackets, the dollar sign, the backtick and the asterisk. The intended behaviour is that none of these should "skip". (Meaning that typing `}` near another `}` should result in `}}`). The brackes do not skip, but the other chars **do** skip! For example, if the point is at `$|$` and i type another `$` what i get is `$$|`. The dollar sign gets skipped! Also, something i notices is that the double quote char (`"`) gets paired even if it is not in my config file. Why is that? How should I configure electric-pair?
kunht · 2022-04-26 16:04
`elec-pair` depends on the syntax table (see info node (elisp) Syntax Tables) and that is why the double quote char is paired automatically. The two variables, as stated in their documentation, are used as a fallback. As for the first issue that `$` gets skipped, I skimmed the elec-pair.el and thought it should also be due to the syntax table. There is no syntax entry for `$` in the current table so it is skipped unconditionally (check the source of `electric-pair-post-self-insert-function` and `electric-pair-syntax-info`). By the way, the `(setq electric-pair--skip-whitespace nil)` may have no effect? There is only a function called `electric-pair--skip-whitespace` in `elec-pair`.
cidra_ · 2022-04-26 16:21
Thank you, this did the trick (it's for markdown mode): ``` (eval-after-load "markdown-mode" '(modify-syntax-entry ?$ "$" markdown-mode-syntax-table)) (eval-after-load "markdown-mode" '(modify-syntax-entry ?* "$" markdown-mode-syntax-table)) (eval-after-load "markdown-mode" '(modify-syntax-entry ?` "$" markdown-mode-syntax-table)) ``` I must say that this behaviour is rather inconsistent: even if that's just a fallback list, why wouldn't they behave like the other pairs? Is there something I'm missing? Anyway, thank you a lot for your help. For the ``electric-pair--skip-whitespace``, there's a custom variable [defined here](https://github.com/emacs-mirror/emacs/blob/bffc4cb39dc7b83fc4a1bffd23eeed2774b79444/lisp/elec-pair.el#L130). I accidentally set the function instead of the custom variable :p
kunht · 2022-04-26 16:45
Glad it helps! I am not very familiar with `elec-pair` so I am not sure if such a behavior is to tackle some other issues, but indeed it feels inconsistent to me.