Disable Parenthese and quote autocompletion when the cursor is just before a word or characters
neozhaoliang opened this issue · 8 comments
Dear Purcell:
I'm new to your emacs config. In my experience, it's very fast and more comfortable than prelude emacs.
I'm having a problem with the parentheses and quote autocompletion mode: How can I disable the autocompletion if the cursor is just before a word? For example, if I have the word John
, and I want to quote it like "John"
, when I move my cursor to the position just before the letter J
and type"
, it autocompletes it to ""John
and I have to delete the extra quote. I believe this problem is solved in your config, but I don't know how. Thank you for any help.
It sounds like you're using your own config and wondering why the behaviour is different from mine?
If so, this behaviour could be affected by a number of things, and it's hard for me to speculate. Probably the code that's inserting the extra quote is electric-pair-mode
. If that mode is disabled, then this could be a behaviour of the auto-completion framework, which may or may not be the same one I'm using.
It might also depend on the language major mode for the buffer where you're seeing this.
So perhaps provide a bit more info and I'll give you some pointers if I can.
Hi, I just cloned your repo, replace it with my old .emacs.d folder, kept all your code untouched, and created my own init-local.el file as follows:
;;; package --- my personal config
(setq-default cursor-type '(bar . 6))
(set-cursor-color "#FFFF00")
(global-set-key (kbd "C-<tab>") 'set-mark-command)
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
(load-theme 'hardhacker t)
(setq flymake-start-on-flymake-mode nil)
(elpy-enable)
(require 'use-package)
(require 'quelpa-use-package)
(use-package copilot
:quelpa (copilot :fetcher github
:repo "zerolfx/copilot.el"
:branch "main"
:files ("dist" "*.el")))
;; you can utilize :map :hook and :config to customize copilot
(add-hook 'prog-mode-hook 'copilot-mode)
(define-key copilot-completion-map (kbd "<tab>") 'copilot-accept-completion)
(define-key copilot-completion-map (kbd "TAB") 'copilot-accept-completion)
(provide 'init-local)
I also installed some packages like elpy
and user-package
(because I can't enable the autocompletion for python mode and I want to use copilot). Does that make a difference?
I also installed some packages like elpy and user-package (because I can't enable the autocompletion for python mode and I want to use copilot). Does that make a difference?
Probably nothing there makes a difference. You can try disabling electric-pair-mode
and see if that helps. You can also use C-h k "
to check that there's no special override for that character (it should normally be bound to self-insert-command
).
You could use paredit-mode and use C-)
to slurp after the quotes.
"|"John
becomes
"|John"
Usually used for lisp languages though.
@psyconorlogy Yeah, and I'm in the process of adding puni
to my config, to provide some Paredit-style structural editing support in non-Lisp buffers. But what I actually do in the above case is select the John
, then hit "
, which has the result of quoting the word to "John"
. You can also use C-q
to disable any magic when inserting a char, so if there are certain occasional misbehaviours you can recognise those situations and work around them with C-q "
or C-q (
etc.
@purcell I just deleted my .emacs.d folder, cloned your repo again and kept everything untouched, and it still autocompletes the quotes as before. I'm using ubuntu 22.04 and installed the snap version emacs (28.2).
In that case you should either just disable electric-pair-mode
(see init-editing-utils.el
) or get in the habit of using one of the tricks I described above.
Thank you for the help, I will use the tricks!