Skip to content

Commit

Permalink
Use environment variables EDITOR_CLIENT_COMMAND and EMACSCLIENT if set
Browse files Browse the repository at this point in the history
  • Loading branch information
gvol committed Jun 5, 2010
1 parent 6956d8f commit 0f12212
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions EditorClientWorker.py
Expand Up @@ -21,7 +21,14 @@
from Carbon import AppleEvents
import Carbon.File

EDITOR_COMMAND = "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -a '' +%(linenum)s '%(filename)s'"
if os.getenv('EDITOR_CLIENT_COMMAND'):
EDITOR_COMMAND = os.getenv('EDITOR_CLIENT_COMMAND')
elif os.getenv('EMACSCLIENT'):
EDITOR_COMMAND = "%s -c -a '%s' +%%(linenum)s '%%(filename)s'" % (os.getenv('EMACSCLIENT'), os.getenv('EMACS'))
else:
EDITOR_COMMAND = "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -a '' +%(linenum)s '%(filename)s'"

NSLog('EDITOR_COMMAND: %s', EDITOR_COMMAND )

class EditorClientWorker(NSThread):
def initWithODB(self, path, linenum=0, odb_app=None, odb_token=None):
Expand All @@ -42,22 +49,22 @@ def main(self):
subprocess.call(EDITOR_COMMAND % {'linenum': self.linenum, 'filename': self.path},
shell=True, stdin=stdin, stdout=stdout, stderr=stdout)
#os.system(EDITOR_COMMAND % {'linenum':self.linenum, 'filename':self.path})

# Send the "file closed" ODB event.
if self.odb_app:
NSLog("sending file closed event to %s, %s" % (self.odb_app, type(self.odb_app)))

target = AE.AECreateDesc(AppleEvents.typeApplSignature, self.odb_app[::-1]) # For strange endianness reasons, have to reverse this
event = AE.AECreateAppleEvent(kODBEditorSuite, kAEClosedFile, target, AppleEvents.kAutoGenerateReturnID, AppleEvents.kAnyTransactionID)

if self.odb_token:
event.AEPutParamDesc(keySenderToken, pack(self.odb_token, typeWildcard))

fsr = Carbon.File.FSPathMakeRef(self.path)[0]
event.AEPutParamDesc(AppleEvents.keyDirectObject, pack(fsr))

event.AESend(AppleEvents.kAENoReply, AppleEvents.kAENormalPriority, AppleEvents.kAEDefaultTimeout)

#evt_app = NSAppleEventDescriptor.descriptorWithTypeCode_(fourcc(self.odb_app))
#evt = NSAppleEventDescriptor.appleEventWithEventClass_eventID_targetDescriptor_returnID_transactionID_(fourcc(kODBEditorSuite),
# fourcc(kAEClosedFile),
Expand All @@ -74,4 +81,4 @@ def main(self):

NSLog("editing thread finished for %s" % self.path)
del pool

0 comments on commit 0f12212

Please sign in to comment.