emacs - 仅当我编辑 .c 或 .cpp 时,如何加载 .abbrev_defs 文件?

标签 emacs autocomplete elisp

下面是我的 emacs 新手 .abbrev_defs 文件。我不知道这是否是约定俗成的方式。如果有更好的方法,我也想知道。

(define-abbrev-table 'global-abbrev-table '(
    ("if" "if()\n  {\n\n  }" nil 1)
    ("else" "else\n  {\n\n  }" nil 1)
    ("while" "while()\n  {\n\n  }" nil 1)
    ("for" "for(;;)\n  {\n\n  }" nil 1)
    ))

最佳答案

您可以使用特定于模式的缩写表。对于 c 模式和 c++ 模式,您需要添加:

(define-abbrev-table 'c-mode-abbrev-table '(
    ("if" "if()\n  {\n\n  }" nil 1)
    ("else" "else\n  {\n\n  }" nil 1)
    ("while" "while()\n  {\n\n  }" nil 1)
    ("for" "for(;;)\n  {\n\n  }" nil 1)
    ))

(define-abbrev-table 'c++-mode-abbrev-table '(
    ("if" "if()\n  {\n\n  }" nil 1)
    ("else" "else\n  {\n\n  }" nil 1)
    ("while" "while()\n  {\n\n  }" nil 1)
    ("for" "for(;;)\n  {\n\n  }" nil 1)
    ))

起初,我担心重复,但从理论上讲,您可能希望在 c++-mode-abbrev-table 中使用 C++ 特定结构的缩写。

或者,您可以选择 yasnippet [http://code.google.com/p/yasnippet/] 了解更多功能。

关于emacs - 仅当我编辑 .c 或 .cpp 时,如何加载 .abbrev_defs 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5130346/

相关文章:

types - emacs 中的 most-positive-fixnum

emacs - 列出所有必需的功能

jquery - 使用 jQuery Autocomplete 返回多个值

c# - 自动完成从存储在标签中的 JSON 数组中读取的源代码不起作用

emacs - 在 Emacs 中,如何在多个帧中打开相同的缓冲区(使用 ido/iswitch 时)?

emacs - 在 emacs org-mode 中获取表外的值

python - 为 python 开发设置 Emacs24

java - 向 FacesContext 添加消息会禁用自动完成功能

emacs - 如何在 Windows 上启动时最大化 Emacs?

emacs - 对 "wrong-type-argument"使用react