PageRenderTime 36ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/emacs-pymacs-0.25/contrib/Giorgi/Pymacs/utility.py

#
Python | 68 lines | 36 code | 18 blank | 14 comment | 0 complexity | 02849617628423feab265a188b599052 MD5 | raw file
Possible License(s): GPL-2.0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright 2007 Giovanni Giorgi <jj@objectsroot.com>
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. from Pymacs import lisp
  9. import time
  10. # Utility support functions
  11. class EmacsLog:
  12. def __init__(self,category):
  13. self.logBuffer="*LogBuffer*" # "*Pymacs Log Buffer*"
  14. self.category=category
  15. self.startTime=time.time()
  16. def show(self,level,msg):
  17. start=int(time.time()-self.startTime)
  18. mx=str(start)+" <"+level+"> PY "+self.category+" "+msg
  19. lisp.message(mx)
  20. #mx = mx + "\n"
  21. #lisp.set_buffer(self.logBuffer)
  22. #lisp.insert(mx)
  23. def info(self, msg):
  24. self.show("I",msg)
  25. def debug(self,msg):
  26. self.show("DEBUG",msg)
  27. # Finest debugging
  28. def debugf(self,msg):
  29. self.show("DEBUG FINER",msg)
  30. class BufferMan:
  31. def __init__(self):
  32. self.bufferName=lisp.buffer_name()
  33. self.fname=lisp.buffer_file_name()
  34. def getBufferAsText(self):
  35. f=open(self.fname,"r")
  36. text=f.read()
  37. f.close()
  38. return text
  39. def writeBuffer(self,text):
  40. f=open(self.fname,"w")
  41. f.write(text)
  42. f.close()
  43. self.reloadBuffer()
  44. def reloadBuffer(self):
  45. # ;; (switch-to-buffer bname)
  46. # ;; (revert-buffer 'IGNORE-AUTO 'NOCONFIRM)
  47. lisp.switch_to_buffer(self.bufferName)
  48. lisp.revert_buffer(lisp.IGNORE_AUTO, lisp.NOCONFIRM)
  49. log=EmacsLog("main")
  50. log.debugf("Pymacs.utility Loaded and happy to serve you")