Boo の python.el (現在の公式の gnu モード) から新しい emacs モードを派生させようとしていますが、インデントの変更に問題があります。これを最もよく処理する方法について何か提案はありますか? 大幅に変更する必要はありません。新しいブロック フォームなどを追加するだけです。
たとえば、これは Boo 用であるため、try/except 構文は「finally」ではなく「ensure」を使用します。これは、python-rx-constituents のブロック開始定義を変更することで、python.el で簡単に変更できます。ただし、python-rx-constituents がマクロ python-rx によって使用されているため、派生モードでこれをオーバーライドできないようです。python.el の読み込み時にこれら 2 つのものが定義されると思います (必要に応じて、私はそれから派生しているので)、ロード後またはフックでオーバーライドできなくなりましたか? 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))))))
block-start に finally ではなく「ensure」が含まれるように python-rx-constituents を変更したいと思います。