PageRenderTime 28ms CodeModel.GetById 17ms app.highlight 9ms RepoModel.GetById 1ms 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
 9from Pymacs import lisp
10import time
11
12# Utility support functions
13class EmacsLog:
14    def __init__(self,category):
15        self.logBuffer="*LogBuffer*" # "*Pymacs Log Buffer*"
16        self.category=category
17        self.startTime=time.time()
18
19    def show(self,level,msg):
20        start=int(time.time()-self.startTime)
21        mx=str(start)+" <"+level+"> PY "+self.category+" "+msg
22        lisp.message(mx)
23        #mx = mx + "\n"
24        #lisp.set_buffer(self.logBuffer)
25        #lisp.insert(mx)
26
27    def info(self, msg):
28        self.show("I",msg)
29
30    def debug(self,msg):
31        self.show("DEBUG",msg)
32
33
34    # Finest debugging
35    def debugf(self,msg):
36        self.show("DEBUG FINER",msg)
37
38
39class BufferMan:
40    def __init__(self):
41        self.bufferName=lisp.buffer_name()
42        self.fname=lisp.buffer_file_name()
43
44    def getBufferAsText(self):
45        f=open(self.fname,"r")
46        text=f.read()
47        f.close()
48        return text
49
50    def writeBuffer(self,text):
51        f=open(self.fname,"w")
52        f.write(text)
53        f.close()
54        self.reloadBuffer()
55
56    def reloadBuffer(self):
57        # ;; (switch-to-buffer bname)
58        # ;; (revert-buffer 'IGNORE-AUTO 'NOCONFIRM)
59        lisp.switch_to_buffer(self.bufferName)
60        lisp.revert_buffer(lisp.IGNORE_AUTO, lisp.NOCONFIRM)
61
62
63
64
65
66log=EmacsLog("main")
67log.debugf("Pymacs.utility Loaded and happy to serve you")
68