Emacs:更改Python.el派生mod中的缩进

2024-10-02 12:29:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从Python.el(当前官方GNUOne)对于Boo和我来说,改变缩进有困难。有人对如何最好地处理这个问题有什么建议吗?我不需要彻底改变任何东西,只是添加一些新的块形式和东西。在

例如,由于这是用于Boo的,try/except语法使用“确保”而不是“finally”。我可以很容易地在Python.el通过更改pythonrx组件的块启动def。但是,我似乎无法在派生模式中覆盖它,因为pythonrx组件随后被宏pythonrx使用,我想一旦这两个东西被定义,当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))))))

我想更改pythonrx的组成部分,以便块start包含“确保”而不是finally。在


Tags: orifdefnotanyspacesymbolrx
2条回答

如前所述,在这里使用派生模式是不合适的:不能反向更改宏。另外,重新定义它是不推荐的:加载/评估的顺序将决定哪一个是有效的-在更大的规模意味着陷入混乱。在

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

你的担心在IMO看来是没有道理的,因为允许复制、更改和重新发布更改后的代码是GPL的核心。在

实际上,复制文件是个坏主意,因为跟踪Python.el. 派生也不是什么好主意,因为Boo并不是Python的一个扩展或变体,所以您可能希望重用它的一些缩进机制和一些代码来理解重要的缩进,但仅此而已。在

你可以联系Python.el的作者(使用Cc to emacs devel)查看Python.el可以调整以使你的生活更轻松。e、 g.可能将通用代码提取到一个辅助文件中,该文件可以在两者之间共享。理想情况下,这个文件可以用于cafferscript模式,也可以用于Haskell模式。在

相关问题 更多 >

    热门问题