def onPostSave(tag=None, keywords=None): """After saving a nosentinels file, replace all tabs with spaces.""" global nosentNodes c = keywords.get('c') if c: at = c.atFileCommands for p in nosentNodes: g.red("node %s found" % p.h) at.scanAllDirectives(p) name = p.atNoSentinelsFileNodeName() fname = g.os_path_join(at.default_directory,name) f = open(fname,"r") lines = f.readlines() f.close() #@+<< add a newline before def or class >> #@+node:ekr.20040331151007.3: *3* << add a newline before def or class >> for i in range(len(lines)): ls = lines[i].lstrip() if ls.startswith("def ") or ls.startswith("class "): try: if lines[i-1].strip() != "": lines[i] = "\n" + lines[i] except IndexError: pass #@-<< add a newline before def or class >> #@+<< replace tabs with spaces >> #@+node:ekr.20040331151007.4: *3* << replace tabs with spaces >> s = ''.join(lines) fh = open(fname,"w") fh.write(s.replace("\t",NSPACES)) fh.close() #@-<< replace tabs with spaces >> nosentNodes = []
def onPostSave(tag=None, keywords=None): """After saving an @nosent file, replace all tabs with spaces.""" global nosentNodes c = keywords.get('c') if c: for p in nosentNodes: g.red("node %s found" % p.h) # Use os.path.normpath to give system separators. fname = os.path.normpath(g.fullPath(c, p)) # #1914. f = open(fname,"r") lines = f.readlines() f.close() #@+<< add a newline before def or class >> #@+node:ekr.20040331151007.3: *3* << add a newline before def or class >> for i, s in enumerate(lines): ls = s.lstrip() if ls.startswith("def ") or ls.startswith("class "): try: if lines[i-1].strip() != "": lines[i] = "\n" + lines[i] except IndexError: pass #@-<< add a newline before def or class >> #@+<< replace tabs with spaces >> #@+node:ekr.20040331151007.4: *3* << replace tabs with spaces >> s = ''.join(lines) fh = open(fname,"w") fh.write(s.replace("\t",NSPACES)) fh.close() #@-<< replace tabs with spaces >> nosentNodes = []
def onPostSave(tag=None, keywords=None): """After saving a nosentinels file, replace all tabs with spaces.""" global nosentNodes c = keywords.get('c') if c: at = c.atFileCommands for p in nosentNodes: g.red("node %s found" % p.h) at.scanAllDirectives(p) name = p.atNoSentinelsFileNodeName() fname = g.os_path_join(at.default_directory, name) f = open(fname, "r") lines = f.readlines() f.close() #@+<< add a newline before def or class >> #@+node:ekr.20040331151007.3: *3* << add a newline before def or class >> for i in range(len(lines)): ls = lines[i].lstrip() if ls.startswith("def ") or ls.startswith("class "): try: if lines[i - 1].strip() != "": lines[i] = "\n" + lines[i] except IndexError: pass #@-<< add a newline before def or class >> #@+<< replace tabs with spaces >> #@+node:ekr.20040331151007.4: *3* << replace tabs with spaces >> s = ''.join(lines) fh = open(fname, "w") fh.write(s.replace("\t", NSPACES)) fh.close() #@-<< replace tabs with spaces >> nosentNodes = []
def clear(self, verbose=False): # Deletes all files in the fcache subdirectory. # It would be more thorough to delete everything # below the root directory, but it's not necessary. if verbose: g.red('clearing cache at directory...\n') g.es_print(self.root) self.conn.execute('delete from cachevalues;')
def finishCreate(self): '''AbbrevCommandsClass.finishCreate.''' self.reload_settings() if 0: # Annoying. c = self.c if (not g.app.initing and not g.unitTesting and not g.app.batchMode and not c.gui.isNullGui): g.red('Abbreviations %s' % ('on' if c.k.abbrevOn else 'off'))
def clear(self, verbose=False): # Deletes all files in the fcache subdirectory. # It would be more thorough to delete everything # below the root directory, but it's not necessary. if verbose: g.red('clearing cache at directory...\n') g.es_print(self.root) for z in self.keys(): self.__delitem__(z)
def finishCreate(self): '''AbbrevCommandsClass.finishCreate.''' self.reload_settings() if 0: # Annoying. c = self.c if (not g.app.initing and not g.unitTesting and not g.app.batchMode and not c.gui.isNullGui ): g.red('Abbreviations %s' % ('on' if c.k.abbrevOn else 'off'))
def finishCreate(self): '''AbbrevCommandsClass.finishCreate.''' c, k = self.c, self.c.k self.init_settings() self.init_abbrev() self.init_tree_abbrev() self.init_env() if 0: # Annoying. if (not g.app.initing and not g.unitTesting and not g.app.batchMode and not c.gui.isNullGui): g.red('Abbreviations %s' % ('on' if c.k.abbrevOn else 'off'))
def getIDFromEnv(self): '''Set leoID from environment vars.''' import os g = self.g trace = False and not g.app.silentMode try: id_ = os.getenv('USER') if id_: if trace: g.red("using os.getenv('USER'):", repr(id_)) g.app.leoID = id_ except Exception: pass
def finishCreate(self): '''AbbrevCommandsClass.finishCreate.''' c, k = self.c, self.c.k self.init_settings() self.init_abbrev() self.init_tree_abbrev() self.init_env() if 0: # Annoying. if (not g.app.initing and not g.unitTesting and not g.app.batchMode and not c.gui.isNullGui ): g.red('Abbreviations %s' % ('on' if c.k.abbrevOn else 'off'))
def getIDFromSys(self): ''' Attempt to set g.app.leoID from sys.leoID. This might be set by in Python's sitecustomize.py file. ''' import sys g = self.g trace = False and not g.app.silentMode id_ = getattr(sys, "leoID", None) if id_: g.app.leoID = id_ if trace: g.red("leoID=", id_, spaces=False)
def quit(self): '''Terminate the slide show.''' m = self; c = m.c; k = c.k if m.quit_flag: return if not m.p1: return g.red('end slide show: %s' % (m.p1.h)) m.delete_widgets() k.keyboardQuit() m.clear_state() m.quit_flag = True c.bodyWantsFocus()
def quit(self): '''Terminate the slide show.''' m = self c = m.c k = c.k if m.quit_flag: return if not m.p1: return g.red('end slide show: %s' % (m.p1.h)) m.delete_widgets() k.keyboardQuit() m.clear_state() m.quit_flag = True c.bodyWantsFocus()
def getLeoID(self): import os import sys g = self.g; tag = ".leoID.txt" homeDir = g.app.homeLeoDir globalConfigDir = g.app.globalConfigDir loadDir = g.app.loadDir verbose = False and not g.app.unitTesting #@+<< try to get leoID from sys.leoID >> #@+node:ekr.20070227094232.1: *5* << try to get leoID from sys.leoID>> # This would be set by in Python's sitecustomize.py file. # Use hasattr & getattr to suppress pylint warning. # We also have to use a "non-constant" attribute to suppress another warning! nonConstantAttr = "leoID" if hasattr(sys, nonConstantAttr): g.app.leoID = getattr(sys, nonConstantAttr) if verbose and not g.app.silentMode: g.red("leoID=", g.app.leoID, spaces=False) #@-<< try to get leoID from sys.leoID >> if not g.app.leoID: #@+<< try to get leoID from "leoID.txt" >> #@+node:ekr.20070227094232.2: *5* << try to get leoID from "leoID.txt" >> for theDir in (homeDir, globalConfigDir, loadDir): # N.B. We would use the _working_ directory if theDir is None! if theDir: try: fn = g.os_path_join(theDir, tag) f = open(fn, 'r') s = f.readline() f.close() if s and len(s) > 0: g.app.leoID = s.strip() if verbose and not g.app.silentMode: g.red('leoID=', g.app.leoID, ' (in ', theDir, ')', spaces=False) break elif verbose: g.red('empty ', tag, ' (in ', theDir, ')', spaces=False) except IOError: g.app.leoID = None except Exception: g.app.leoID = None g.error('unexpected exception in app.setLeoID') g.es_exception() #@-<< try to get leoID from "leoID.txt" >> if not g.app.leoID: #@+<< try to get leoID from os.getenv('USER') >> #@+node:ekr.20070227094232.3: *5* << try to get leoID from os.getenv('USER') >> try: theId = os.getenv('USER') if theId: if verbose: g.red("using os.getenv('USER'):", repr(theId)) g.app.leoID = theId except Exception: pass #@-<< try to get leoID from os.getenv('USER') >> return g.app.leoID
def on_open(tag, keywords): c = keywords.get("c") if not c: return p = c.rootPosition() g.blue("scanning for @read-only nodes...") while p: h = p.h if g.match_word(h, 0, "@read-only"): changed = insert_read_only_node(c, p, h[11:]) g.red("changing %s" % p.h) if changed: if not p.isDirty(): p.setDirty() if not c.isChanged(): c.setChanged() p.moveToThreadNext() c.redraw()
def on_open (tag,keywords): c = keywords.get("c") if not c: return p = c.rootPosition() g.blue("scanning for @read-only nodes...") while p: h = p.h if g.match_word(h,0,"@read-only"): changed = insert_read_only_node(c,p,h[11:]) g.red("changing %s" % p.h) if changed: if not p.isDirty(): p.setDirty() if not c.isChanged(): c.setChanged(changed) p.moveToThreadNext() c.redraw()
def print_cp(self, event=None): c = self.c; p = c.p g.red('c: %s' % (c.fileName())) g.red('p: %s' % (p.h))