java - 在java中使用emacs解析器?

标签 java swing emacs rtrt

我在互联网上找到了一个用于 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

最佳答案

这样的事情应该有效:

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

关于java - 在java中使用emacs解析器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30918096/

相关文章:

emacs - 在迷你缓冲区中显示匹配括号的行

Java HashMap - 从 HashMap 获取值,用户输入

java - Glassfish 无法在 Linux 服务器上启动

Java:使用 ActionListener,我需要从文本字段获取用户输入并使用它,我遇到了问题

emacs - 在 emacs 中锁定键,例如 ctrl 或 alt

emacs 前进 n 逗号

java - Spring XML 等效于 @EnableAsync

java - 如何检测右键单击->关闭窗口关闭窗口?

java - JTabbedPane 中禁用的选项卡上的单击事件

java - 在 JPanel 与 JComponent 中绘图