Вопрос

What's the reason by concatenate is not working in my abbreviations file? I would like 'env' to expand to this little chunk of code, and for readability reasons I prefer to separate the string into multiple lines. However, the abbreviation seems to be ignored by Emacs.

(define-abbrev-table 'python-mode-abbrev-table
  '(
    ("env" (concatenate 'string
             "#! /usr/bin/env python\n"
             "\n"
             "from __future__ import division\n"
             "from __future__ import print_function\n"
             "from __future__ import absolute_import\n"
             "from __future__ import unicode_literals\n\n")
       nil 3)
   ))
Это было полезно?

Решение

Expressions are not evaluated inside a quoted list. You can use backquote to selectively evaluate parts of a list structure:

(define-abbrev-table 'python-mode-abbrev-table
  `(
    ("env" ,(concatenate 'string
             "#! /usr/bin/env python\n"
             "\n"
             "from __future__ import division\n"
             "from __future__ import print_function\n"
             "from __future__ import absolute_import\n"
             "from __future__ import unicode_literals\n\n")
       nil 3)
))

Within a backquoted expression, comma indicates the parts that should be evaluated.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top