收集缓冲区的行

时间:2013-01-02 21:56:12

标签: elisp

需要将每行的进程输出解析为结构。

sug skProc  strutils.capitalize proc (string): string{.noSideEffect.}
sug skProc  strutils.quoteIfContainsWhite   proc (string): string
sug skProc  system.gorge    proc (string, string): string
sug skProc  system.of   proc (T, S): bool{.noSideEffect.}
sug skProc  system.definedInScope   proc (expr): bool{.noSideEffect.}
sug skIterator  system.items    iterator (cstring): char{.inline.}
sug skProc  system.ord  proc (T): int{.noSideEffect.}

此数据位于缓冲区内。那么我该如何阅读每一行并传递它 到一个函数,它返回一个解析的表示并收集所有 线到底?

编辑:解析行的代码(未调试):

(defstruct nimrod-sug type namespace name signature)

(defun nimrod-parse-suggestion-line (line)
  (let ((split (split-string line "[\t\n]")))
    (make-nimrod-sug
     :type (nth 1 split)
     :namespace (first (split-string (nth 2 split) "\\."))
     :name (second (split-string (nth 2 split) "\\."))
     :signature (nth 3 split))

1 个答案:

答案 0 :(得分:1)

对解析器进行一些小的更改:

(defun nimrod-parse-suggestion-line (line)
  (destructuring-bind (_ type fn &rest sig) (split-string line "[[:space:]]+" t)
    (make-nimrod-sug :type      type 
                     :namespace (first  (split-string fn "\\."))
                     :name      (second (split-string fn "\\."))
                     :signature (apply 'concat sig))))    

假设缓冲区的名称是*output*,您可以像这样解析它:

(with-current-buffer "*output*" 
  (mapcar 'nimrod-parse-suggestion-line
          (split-string (buffer-string) "[\r\n]" t)))

; => ([cl-struct-nimrod-sug "skProc" "strutils" "capitalize" "proc(string):string{.noSideEffect.}"] ...)

如果您当前正在访问输出缓冲区,则不需要with-current-buffer包装器。