首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Emacs:在派生模式下更改python.el缩进

Emacs:在派生模式下更改python.el缩进
EN

Stack Overflow用户
提问于 2014-02-16 01:08:03
回答 2查看 198关注 0票数 0

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

例如,由于这是针对Boo的,因此try/ensure语法使用"ensure“而不是"finally”。我可以在python.el中通过更改python-rx-constituents的块起始定义来轻松地更改这一点。然而,我似乎不能在派生模式下覆盖它,因为python-rx-constituents正被一个宏python-rx使用,我猜一旦在python.el加载时定义了这两个东西(因为我是从它派生的),我就不能再在加载后或在钩子中覆盖它了?因为我确实在内存中、在python.el加载后的钩子中和在后加载语句中更改了它,但它们都不起作用。而直接修改python.el则可以正常工作。

以下是python.el中有问题的代码:

代码语言:javascript
复制
(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的组成部分,以便block-start包含"ensure“而不是finally。

EN

回答 2

Stack Overflow用户

发布于 2014-02-16 16:47:58

正如前面提到的,使用派生模式在这里是不合适的:你不能回溯一个宏。同样,重新定义它也是不可取的:加载/评估的顺序将决定哪一个是有效的-在更大的范围内,这意味着会遇到混乱。

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

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

票数 1
EN

Stack Overflow用户

发布于 2014-02-17 21:36:30

实际上,复制文件不是一个好主意,因为它会让跟踪python.el的演变变得很痛苦。派生也不是一个很好的想法,因为Boo实际上不是Python的扩展或变体,所以您可能希望重用它的一些缩进机制和代码来理解重要的缩进,但仅此而已。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21800828

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档