Использовать парсер Emacs в Java?

В интернете я нашел парсер для emacs: http://www.emacswiki.org/emacs/rtrt-script.el для сценария testRT (инструмент IBM для тестирования).

И я хочу знать, возможно ли использовать этот файл парсера Emacs Lips в приложении Java Swing. Мне просто нужна часть, которая делает отступ в коде. Например, с помощью командной строки: я даю файл, который мне нужен для отступа в 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

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 с отступом версии.

Вы можете указать emacs запускать код при запуске. Посмотреть варианты -f, -l а также --eval (и возможно --batchтоже) в man emacs,

Другие вопросы по тегам