2

Some document said emacs-lisp is more powerful than perl/Python to parser text file, but I still didn't see good example for reference.

For example, if input below text block:

12-22 07:43:14.699  1640  2722 E JavaBinder:    at android.util.ArrayMap.allocArrays(ArrayMap.java:175)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at android.util.ArrayMap.put(ArrayMap.java:463)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at android.os.BaseBundle.putInt(BaseBundle.java:455)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at android.content.Intent.putExtra(Intent.java:7174)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at com.android.server.audio.AudioService$VolumeStreamState.setIndex(AudioService.java:4289)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at com.android.server.audio.AudioService.setStreamVolumeInt(AudioService.java:1929)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at com.android.server.audio.AudioService.onSetStreamVolume(AudioService.java:1670)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at com.android.server.audio.AudioService.setStreamVolume(AudioService.java:1769)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at com.android.server.audio.AudioService.setStreamVolume(AudioService.java:1683)

I wish to produce below output: (extract the file name, function name and line number, then reformat as plantuml input text)

-> AudioService:setStreamVolume():1683
AudioService -> AudioService:setStreamVolume():1769
AudioService -> AudioService:onSetStreamVolume():1670
AudioService -> AudioService:setStreamVolumeInt():1929
AudioService -> AudioService:setStreamVolumeInt():4289
AudioService -> Intent:putExtra():7174
Intent -> BaseBundle:putInt():455
BaseBundle -> ArrayMap:put():463
ArrayMap -> ArrayMap:allocArrays():175

Then we can use plantuml to covert it to a UML diagram (org mode).

How can we do that with emacs-lisp (maybe in org mode)?

My idea is put the input text in a code block, then run the emacs-lisp code in another code block. The result will be the output as expected above

#+NAME: myinput
#+BEGIN_EXAMPLE :session 
input text here
#+END_EXAMPLE

#+BEGIN_SRC emacs-lisp :exports both
(message 'process myinput here')
#+END_SRC

#+RESULTS:
: output reformat result here
  • 3
    This question is rather puzzling. More powerful than what? Why is the example output incorrect? What does doing it in org-mode even mean? And why don't you just use regex replace, then fix up the mistakes? The Emacs way is about solving stuff, not being particularly elegant, powerful or otherwise exceptional about it. – wasamasa Feb 15 '17 at 20:39
  • 1
    This is a please-do-my-coding-for-me question. Too broad. – Drew Feb 15 '17 at 22:42
2

Try below org sample:

#+NAME: input-log
#+BEGIN_EXAMPLE
12-22 07:43:14.699  1640  2722 E JavaBinder:    at android.util.ArrayMap.allocArrays(ArrayMap.java:175)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at android.util.ArrayMap.put(ArrayMap.java:463)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at android.os.BaseBundle.putInt(BaseBundle.java:455)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at android.content.Intent.putExtra(Intent.java:7174)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at com.android.server.audio.AudioService$VolumeStreamState.setIndex(AudioService.java:4289)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at com.android.server.audio.AudioService.setStreamVolumeInt(AudioService.java:1929)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at com.android.server.audio.AudioService.onSetStreamVolume(AudioService.java:1670)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at com.android.server.audio.AudioService.setStreamVolume(AudioService.java:1769)
12-22 07:43:14.699  1640  2722 E JavaBinder:    at com.android.server.audio.AudioService.setStreamVolume(AudioService.java:1683)
#+END_EXAMPLE

#+HEADER: :var inputlog=input-log
#+BEGIN_SRC emacs-lisp :file test.png :exports results
(defun logme(instr)
  (let ((matches)(prevObj "")
    (regexstr "\\.\\([a-zA-Z]+\\)(\\([a-zA-Z]+\\).java:\\([0-9]+\\)"))
    (with-temp-buffer
      (insert instr)
      (goto-char (point-min))
      (while (re-search-forward regexstr nil t)
    (push (list (match-string 1) (match-string 2) (match-string 3)) matches))
      (concat "
scale 800*400
hide footbox
skinparam shadowing false
skinparam monochrome true
"
       (mapconcat (lambda(x)
      (format "%s -> %s:%s():%s" prevObj
      (setq prevObj (nth 1 x))
      (car x)
      (nth 2 x))) matches "\n")))))
(org-babel-execute:plantuml (logme inputlog) params)
#+END_SRC

It works but need more work to make it better!

The output graph is:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.