This file is indexed.

/usr/lib/python2.7/dist-packages/bikeemacs.py is in bicyclerepair 0.9-6.2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# Bicycle Repair Man integration with (X)Emacs
# By Phil Dawes (2002)
# Uses the fabulous Pymacs package by François Pinard

from Pymacs import lisp, Let
import bike
reload(bike)
from bike import bikefacade
import StringIO, traceback
import sys

class EmacsLogger:
    def __init__(self):
        self.msg = ""
    
    def write(self,output):
        self.msg +=output
        if output.endswith("\n"):
            lisp.message(self.msg)
            self.msg = ""

class NullLogger:
    def write(self,output):
        pass
        
logger = EmacsLogger()


class ExceptionCatcherWrapper:

    def __init__(self,myobj):
        self.myobj = myobj
    
    def __getattr__(self,name):
        return ExceptionInterceptor(self.myobj,name)
        

class ExceptionInterceptor:
    def __init__(self,targetobj,name):
        self.targetobj = targetobj
        self.name = name
    
    def __call__(self,  *params, **kwparams ):
        try:
            return self.makeCall(params)
        except:
            traceback.print_exc()
            lisp.error(str(sys.exc_info()[1]))

    def makeCall(self,params):
        argsstr="(self.targetobj"
        for i in range(len(params)):
            argsstr += ",params["+`i`+"]"
        argsstr+=")"
        return eval("self.targetobj.__class__."+self.name+argsstr)


class BRMEmacs(object):
    
    def __init__(self,brmctx):
        self.ctx = brmctx

        lisp.require(lisp["python-mode"])
        lisp("""
        (defvar brm-menu nil "Menu for Bicycle Repair Man")
         (easy-menu-define
          brm-menu python-mode-map "Bicycle Repair Man"
          '("BicycleRepairMan"
                   "Queries"
                   ["Find-References" brm-find-references]
                   ["Find-Definition" brm-find-definition]
                   "---"
                   "Refactoring"
                   ["Rename" brm-rename t]
                   ["Extract-Method" brm-extract-method t]
                   ["Extract-Local-Variable" brm-extract-local-variable t]
                   ["Inline-Local-Variable" brm-inline-local-variable t]
                   ["Undo Last Refactoring" brm-undo t]

        ))
        (add-hook 'python-mode-hook (lambda () (easy-menu-add brm-menu)))
        """)
        #           ["Move-Class-To-New-Module" brm-move-class t]
        #           ["Move-Function-To-New-Module" brm-move-class t]

        self.ctx.setProgressLogger(logger)


    def rename(self,newname):
        lisp.save_some_buffers()
        filename = lisp.buffer_file_name()
        line,col = _getCoords()
        brmctx.setRenameMethodPromptCallback(promptCallback)
        try:
            self.ctx.renameByCoordinates(filename,line,col,newname)
            savedFiles = brmctx.save()
            _revertSavedFiles(savedFiles)
            lisp.set_marker(lisp.mark_marker(),None)
        except bikefacade.CouldntLocateASTNodeFromCoordinatesException:
            print >>logger,"Couldn't find AST Node. Are you renaming the declaration?"

    def kill(self):        
        self.ctx = None
        self.ctx = bike.init()
        self.ctx.setProgressLogger(logger)

    def undo(self):
        brmctx.undo()
        savedFiles = brmctx.save()
        _revertSavedFiles(savedFiles)

    def find_references(self):
        lisp.save_some_buffers()
        filename = lisp.buffer_file_name()
        line,col = _getCoords()
        refs = brmctx.findReferencesByCoordinates(filename,line,col)
        _switchToConsole()
        numRefs = 0
        for ref in refs:
            _insertRefLineIntoConsole(ref)
            numRefs +=1
        lisp.insert("Done - %d refs found\n"%numRefs)


    def find_definition(self):
        lisp.save_some_buffers()
        filename = lisp.buffer_file_name()
        line,col = _getCoords()
        defns = brmctx.findDefinitionByCoordinates(filename,line,col)

        try:
            firstdefn = defns.next()
            lisp.find_file_other_window(firstdefn.filename)
            lisp.goto_line(firstdefn.lineno)
            lisp.forward_char(firstdefn.colno)
        except StopIteration:
            pass
        else:
            numRefs = 1
            for defn in defns:
                if numRefs == 1:
                    _switchToConsole()
                    _insertRefLineIntoConsole(firstdefn)
                _insertRefLineIntoConsole(defn)
                numRefs += 1


    def inline_local_variable(self):
        lisp.save_some_buffers()
        filename = lisp.buffer_file_name()
        line,col = _getCoords()
        brmctx.inlineLocalVariable(filename,line,col)
        lisp.set_marker(lisp.mark_marker(),None)
        _revertSavedFiles(brmctx.save())

    def extract_local_variable(self,name):
        lisp.save_some_buffers()
        filename = lisp.buffer_file_name()

        bline,bcol = _getPointCoords()
        lisp.exchange_point_and_mark()
        eline,ecol = _getPointCoords()
        lisp.exchange_point_and_mark()

        brmctx.extractLocalVariable(filename,bline,bcol,eline,ecol,name)
        lisp.set_marker(lisp.mark_marker(),None)
        _revertSavedFiles(brmctx.save())
        
    def extract_method(self,name):
        lisp.save_some_buffers()
        filename = lisp.buffer_file_name()

        bline,bcol = _getPointCoords()
        lisp.exchange_point_and_mark()
        eline,ecol = _getPointCoords()
        lisp.exchange_point_and_mark()

        brmctx.extract(filename,bline,bcol,eline,ecol,name)
        lisp.set_marker(lisp.mark_marker(),None)
        _revertSavedFiles(brmctx.save())

        
    def move_class(self,newfilename):
        lisp.save_some_buffers()
        filename = lisp.buffer_file_name()
        line,col = _getCoords()
        brmctx.moveClassToNewModule(filename,line,newfilename)
        _revertSavedFiles(brmctx.save())
        


brmctx = bike.init()

brmemacs = None

is_xemacs = (lisp.emacs_version().find("GNU") == -1)
currently_saving=0

# fix pop_excursion to work with xemacs
class Let(Let):
    def pop_excursion(self):
        method, (buffer, point_marker, mark_marker) = self.stack[-1]
        assert method == 'excursion', self.stack[-1]
        del self.stack[-1]
        lisp.set_buffer(buffer)
        lisp.goto_char(point_marker)
        lisp.set_mark(mark_marker)
        lisp.set_marker(point_marker, None)
        if mark_marker is not None:   # needed for xemacs
            lisp.set_marker(mark_marker, None)



def init():
    global brmemacs
    brmemacs = ExceptionCatcherWrapper(BRMEmacs(brmctx))

    
def kill():
    """
    Removes the bicyclerepairman context (freeing the state),
    and reinitialises it.
    """
    brmemacs.kill()
kill.interaction=""


def promptCallback(filename,line,colbegin,colend):
    let = Let().push_excursion()   # gets popped when let goes out of scope
    buffer = lisp.current_buffer()
    if let:
        ans = 0
        lisp.find_file(filename)
        lisp.goto_line(line)
        lisp.move_to_column(colbegin)
        lisp.set_mark(lisp.point() + (colend - colbegin))
        if is_xemacs:
            lisp.activate_region()
        ans = lisp.y_or_n_p("Couldn't deduce object type - rename this method reference? ")
    del let
    lisp.switch_to_buffer(buffer)
    return ans

def rename(newname):
    return brmemacs.rename(newname)
rename.interaction="sNew name: "


def undo():
    return brmemacs.undo()
undo.interaction=""


def _revertSavedFiles(savedFiles):
    global currently_saving
    currently_saving = 1
    for file in savedFiles:
        buf = lisp.find_buffer_visiting(file)
        if buf:
            lisp.set_buffer(buf)
            lisp.revert_buffer(None,1)
    currently_saving = 0

def find_references():
    brmemacs.find_references()    
find_references.interaction=""

def _getCoords():
    line = lisp.count_lines(1,lisp.point())
    col = lisp.current_column()
    if col == 0:            
        line += 1  # get round 'if col == 0, then line is 1 out' problem

    if mark_exists() and lisp.point() > lisp.mark():
        lisp.exchange_point_and_mark()
        col = lisp.current_column()
        lisp.exchange_point_and_mark()
    return line,col

def mark_exists():
    if is_xemacs:
        return lisp.mark()
    else:
        return lisp("mark-active") and lisp.mark()



def _switchToConsole():
    consolebuf = lisp.get_buffer_create("BicycleRepairManConsole")
    lisp.switch_to_buffer_other_window(consolebuf)
    lisp.compilation_mode("BicycleRepairMan")
    lisp.erase_buffer()
    lisp.insert("Bicycle Repair Man\n")
    lisp.insert("(Hint: Press Return a Link)\n")
    
def find_definition():
    brmemacs.find_definition()
find_definition.interaction=""

def _insertRefLineIntoConsole(ref):
    lisp.insert(ref.filename+":"+str(ref.lineno)+":    "+str(ref.confidence)+"% confidence\n")
    _redisplayFrame()

def _redisplayFrame():
    lisp.sit_for(0)

def inline_local_variable():
    brmemacs.inline_local_variable()
inline_local_variable.interaction=""

def extract_local_variable(name):
    brmemacs.extract_local_variable(name)
extract_local_variable.interaction="sVariable name: "


def extract_method(name):
    brmemacs.extract_method(name)
extract_method.interaction="sName of function: "


def move_class(newfilename):
    return brmemacs.move_class(newfilename)
move_class.interaction="fTarget file: "



def _getPointCoords():
    bline = lisp.count_lines(1,lisp.point())
    bcol = lisp.current_column()
    if bcol == 0:  # get round line is one less if col is 0 problem
        bline += 1
    return bline,bcol