-->

emacs: abbrev-mode can't work in python-mode

2019-09-02 09:39发布

问题:

I have defined some abbreviations for python mode by using code like this

(define-abbrev-table 'python-mode-abbrev-table
  '(
    ("i_settings" "from django.conf import settings")
    ("i_requestcontext" "from django.template import RequestContext")
    ("i_model" "from django.db import models")
    ("i_form" "from django import forms")
    ))

but it can't work correctly. for example, I input "i_settings" then input a space, emacs doesn't expand to "from django.conf import settings". I have tried it with all configuration disabled, but no help.

回答1:

It seems the underscore _ is preventing the expansion. Try the same table without underscores

(define-abbrev-table 'python-mode-abbrev-table
  '(
    ("isettings" "from django.conf import settings")
    ("irequestcontext" "from django.template import RequestContext")
    ("imodel" "from django.db import models")
    ("iform" "from django import forms")
    ))

and it will work as expected.



回答2:

The internal proceeding expanding an abbrev --abbrev--before-point-- relies on word-syntax - can't see a reason for this BTW, Emacs could take any printable instead.

In result, with any mode where underscore-character has word syntax, your definitions should work - for example with python-mode.el.