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

2019-09-02 09:46发布

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.

2条回答
叼着烟拽天下
2楼-- · 2019-09-02 09:52

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.

查看更多
成全新的幸福
3楼-- · 2019-09-02 09:58

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.

查看更多
登录 后发表回答