不是python程序员,我不确定这涵盖了所有的情况,但在一个简单的情况下适合我.如果数组存在,__all__
它将向数组添加符号,如果不存在则创建. 注意:它不解析数组以避免双重插入.
(defun python-add-to-all () "take the symbol under the point and add to the __all__ routine" (interactive) (save-excursion (let ((thing (thing-at-point 'word)) p) (if (progn (goto-char (point-min)) (re-search-forward "^__all__ = \\[" nil t)) (insert (format "\"%s\", " thing)) (goto-char (point-min)) (insert (format "__all__ = [\"%s\"]\n" thing))))))