help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to disable abbrev-mode in all major modes?


From: Rodrigo Morales
Subject: How to disable abbrev-mode in all major modes?
Date: Fri, 18 Oct 2024 18:34:38 -0500

Let me explain my use case: I want abbrev-mode to be disabled in all buffers 
because I want to expand abbreviations by explicitly calling the function 
=expand-abbrev=, but the default behavior is that abbreviations are expanded 
when pressing SPC, punctuations (e.g. PERIOD and COMMA) or C-i. After some 
investigation, I found out that abbrev-mode is enabled in message-mode (see 
next section for details on how I found that out).

I know that I can define a function that disables abbrev-mode and add it as a 
hook of those major modes where abbrev-mode is enabled by default, but I wonder 
if there is a cleaner way than doing this, because I don't want to be editing 
my configuration whenever I found out another major mode enables abbrev-mode by 
default.

#+BEGIN_SRC elisp
(defun my-abbrev-mode-disable ()
  (abbrev-mode -1))
(add-hook 'message-mode-hook 'my-abbrev-mode-disable)
#+END_SRC

*** Finding out abbrev-mode is enabled in message-mode

I started Emacs by using the command shown below:

#+BEGIN_SRC sh
emacs -Q
#+END_SRC

In the buffer =*scratch*=, the value of the variable =abbrev-mode= was nil, so 
I conclude that =abbrev-mode= was not enabled. The major mode of the buffer 
=*scratch*= was =lisp-interaction-mode=.

I called compose-mail (by default bound to =C-x m= in GNU Emacs 29.4). In the 
buffer =*unsent mail*=, the value of the variable =abbrev-mode= was t, so I 
conclude that =abbrev-mode= was enabled. The major mode of the buffer =*unsent 
mail*= was =message-mode=.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]