0

我在互联网上找到了一个用于 emacs 的解析器:http : //www.emacswiki.org/emacs/rtrt-script.el 用于 testRT 脚本(一个 IBM 测试工具)。

我想知道是否可以在 Java Swing 应用程序中使用这个 Emacs Lips 解析器文件。我只需要缩进代码的部分。例如,使用如下命令行:我给需要缩进的文件 rtrt-script.el 作为回报,我有一个带有缩进的文件。有什么办法吗?谢谢你的帮助。

编辑:我认为我需要的部分是:

代码缩进。

(defun rtrt-script-indent-line ()
  "Indent current line as RTRT-SCRIPT code"
  (interactive)
  (save-excursion                ; si la ligne précedente est test ou 

    (beginning-of-line)
    (if (bobp)                          ; Check for rule 1
        (indent-line-to 0)
      (let ((not-indented t)      cur-indent)
        (if (looking-at "^[ \t]*--[ -=]*\n") ; indentation des commentaires
            (progn             
              (save-excursion    ; si la ligne précedente est test ou 
                (forward-line -1)       ; on indente au même niveau.
                (if (looking-at "^[ \t]*\\<\\(TEST\|SERVICE\\)\\>")
                    (setq cur-indent (current-indentation))
                  (while not-indented
                    (forward-line -1)

                    ;; on ignore les lignes blanches et les commentaires.
                    (while (looking-at "^[ \t]*\n")
                      (forward-line -1))
                    (if (looking-at "^[ \t]*\\<END\\>") ; Check for rule 3
                        (progn

                          (setq cur-indent (current-indentation))
                          (setq not-indented nil))
                    ; Check for rule 4
                      (if (looking-at 
                           "^[ \t]*\\<\\(ENVIRONMENT\\|ELEMENT\\|INITIALIZATION\\|DEFINE[ \t]+STUB\\|TERMINATION\\|TEST\\|SERVICE\\|NEXT_TEST\\)\\>")
                          (progn
                            (setq cur-indent (+ (current-indentation) rtrt-script-indent))
                            (setq not-indented nil))
                        (if (bobp)      ; Check for rule 5
                            (setq not-indented nil))    
                        ))))
                )
              )
          (if (looking-at "^[ \t]*\\<\\(END\\|NEXT_TEST\\)\\>") ; Check for rule 2
              (progn
                (save-excursion
                  (forward-line -1)

                  ;; on ignore les lignes blanches.
                  (while (looking-at "^[ \t]*\\(\n\\|--.*\n\\)")
                    (forward-line -1))

                  (setq cur-indent (- (current-indentation) rtrt-script-indent)))
                (if (< cur-indent 0)
                    (setq cur-indent 0)))
            (save-excursion 
              (while not-indented
                (forward-line -1)

                ;; on ignore les lignes blanches et les commentaires.
                (while (looking-at "^[ \t]*\\(\n\\|--.*\n\\)")
                  (forward-line -1))

                (if (looking-at "^[ \t]*\\<END\\>") ; Check for rule 3
                    (progn

                      (setq cur-indent (current-indentation))
                      (setq not-indented nil))
                    ; Check for rule 4
                  (if (looking-at 
                       "^[ \t]*\\<\\(ENVIRONMENT\\|ELEMENT\\|INITIALIZATION\\|DEFINE[ \t]+STUB\\|TERMINATION\\|TEST\\|SERVICE\\|NEXT_TEST\\)\\>")
                      (progn
                        (setq cur-indent (+ (current-indentation) rtrt-script-indent))
                        (setq not-indented nil))
                    (if (bobp)          ; Check for rule 5
                        (setq not-indented nil))    
                    ))))
            )
          )
        (if cur-indent
            (progn
              (save-excursion    ; si la ligne précedente est test ou 

                (message "cur_indent =>%d" cur-indent)
                (if (looking-at "^[ \t]*\n")
                    (indent-line-to 0)
                  (indent-line-to cur-indent)
                  ;; tant qu'a faire on retire aussi les tabulations.
                  (untabify (point-at-bol) (point-at-eol)))
                )
              )
          (indent-line-to 0)))
      )
    )
  ) ;; If we didn't see an indentation hint, then allow no indentation
4

2 回答 2

2

像这样的东西应该工作:

emacs --batch -l /path/to/rtrt-script.el my-file.rtrt \
      -f rtrt-script-mode --eval '(indent-region (point-min) (point-max))' \
      -f save-buffer

请注意,这将my-file.rtrt用缩进的版本覆盖。

于 2015-06-18T15:01:06.327 回答
1

您可以告诉 emacs 在启动时运行代码。参见 options-f和(也许还有-l)in 。--eval--batchman emacs

于 2015-06-18T14:51:00.697 回答