0

我正在尝试从 python.el (当前的官方 gnu 模式)为 Boo 派生一个新的 emacs 模式,但我在更改缩进时遇到了麻烦。有人对如何最好地处理这个问题有任何建议吗?我不需要彻底改变任何东西,只需添加一些新的块形式和东西。

例如,因为这是 Boo,try/except 语法使用“ensure”而不是“finally”。我可以通过更改 python-rx-constituents 的 block-start def 在 python.el 中轻松更改这一点。但是,我似乎无法在派生模式下覆盖它,因为 python-rx-constituents 正在被一个宏 python-rx 使用,我猜一旦这两个东西在 python.el 加载时被定义(因为它必须,因为我是从它派生的),我不能再在加载后或在钩子中覆盖它?因为我确实在 python.el 加载后的内存和钩子中以及在加载后的语句中更改了它,但它们都不起作用。虽然直接改变 python.el 工作正常。

以下是来自 python.el 的代码:

(eval-when-compile
  (defconst python-rx-constituents
    `((block-start          . ,(rx symbol-start
                                   (or "def" "class" "if" "elif" "else" "try"
                                       "except" "finally" "for" "while" "with"
                                       )
                                   symbol-end))
      (decorator            . ,(rx line-start (* space) ?@ (any letter ?_)
                                   (* (any word ?_))))
      (defun                . ,(rx symbol-start (or "def" "class") symbol-end))
      (if-name-main         . ,(rx line-start "if" (+ space) "__name__"
                                   (+ space) "==" (+ space)
                                   (any ?' ?\") "__main__" (any ?' ?\")
                                   (* space) ?:))
      (symbol-name          . ,(rx (any letter ?_) (* (any word ?_))))
      (open-paren           . ,(rx (or "{" "[" "(")))
      (close-paren          . ,(rx (or "}" "]" ")")))
      (simple-operator      . ,(rx (any ?+ ?- ?/ ?& ?^ ?~ ?| ?* ?< ?> ?= ?%)))
      ;; FIXME: rx should support (not simple-operator).
      (not-simple-operator  . ,(rx
                                (not
                                 (any ?+ ?- ?/ ?& ?^ ?~ ?| ?* ?< ?> ?= ?%))))
      ;; FIXME: Use regexp-opt.
      (operator             . ,(rx (or "+" "-" "/" "&" "^" "~" "|" "*" "<" ">"
                                       "=" "%" "**" "//" "<<" ">>" "<=" "!="
                                       "==" ">=" "is" "not")))
      ;; FIXME: Use regexp-opt.
      (assignment-operator  . ,(rx (or "=" "+=" "-=" "*=" "/=" "//=" "%=" "**="
                                       ">>=" "<<=" "&=" "^=" "|=")))
      (string-delimiter . ,(rx (and
                                ;; Match even number of backslashes.
                                (or (not (any ?\\ ?\' ?\")) point
                                    ;; Quotes might be preceded by a escaped quote.
                                    (and (or (not (any ?\\)) point) ?\\
                                         (* ?\\ ?\\) (any ?\' ?\")))
                                (* ?\\ ?\\)
                                ;; Match single or triple quotes of any kind.
                                (group (or  "\"" "\"\"\"" "'" "'''"))))))
    "Additional Python specific sexps for `python-rx'")

  (defmacro python-rx (&rest regexps)
    "Python mode specialized rx macro.
This variant of `rx' supports common python named REGEXPS."
    (let ((rx-constituents (append python-rx-constituents rx-constituents)))
      (cond ((null regexps)
             (error "No regexp"))
            ((cdr regexps)
             (rx-to-string `(and ,@regexps) t))
            (t
             (rx-to-string (car regexps) t))))))

我想更改 python-rx-constituents 以便 block-start 包含“确保”而不是最终。

4

2 回答 2

1

正如已经评论过的,在这里使用派生模式不适合:您不能回退更改宏。也不推荐重新定义它:加载/评估的顺序将决定哪个有效 - 在更大的范围内,这意味着陷入混乱。

复制文件,存储为 boo.el,将前缀替换为“boo-”,重新加载并编辑需要更改的内容。

您表达的 IMO 的担忧是不合理的,因为允许复制、更改和重新发布更改后的代码是 GPL 的核心。

于 2014-02-16T08:47:58.463 回答
0

复制文件确实是个坏主意,因为跟踪 python.el 的演变会很痛苦。推导也不是一个好主意,因为 Boo 并不是 Python 的真正扩展或变体,因此您可能希望重用它的一些缩进机制和它的一些代码来理解显着缩进,但仅此而已比起那个来说。

您可能想联系 python.el 的作者(抄送至 emacs-devel),看看是否可以调整 python.el 以使您的生活更轻松。例如,可以将公共代码提取到可以在两者之间共享的辅助文件中。理想情况下,此文件可能可用于 cofferscript 模式,也可能适用于 Haskell 模式。

于 2014-02-17T13:36:30.187 回答