Edgewall Software
Modify

Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#1828 closed defect (fixed)

mimeviewer:tab_width in config is not work for browser

Reported by: Shun-ichi Goto <gotoh@…> Owned by: Matthew Good
Priority: normal Milestone: 0.9
Component: version control/browser Version: devel
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Christopher Lenz)

On browsing source file, tab-width 8 is always used although specifying [mimeviewer] tab_width. I made a patch, but it may not correct fix.

  • api.py

     
    216216                candidates.append((qr, renderer))
    217217        candidates.sort(lambda x,y: cmp(y[0], x[0]))
    218218
     219        tab_width = int(self.config.get('mimeviewer', 'tab_width'))
     220       
     221        if mimetype.lower().startswith('text/'):
     222            content = content.expandtabs(tab_width)
     223
    219224        for qr, renderer in candidates:
    220225            try:
    221226                self.log.debug('Trying to render HTML preview using %s'
     
    226231                elif isinstance(result, (str, unicode)):
    227232                    return result
    228233                elif annotations:
    229                     return self._annotate(result, annotations)
     234                    return self._annotate(result, annotations, tab_width)
    230235                else:
    231236                    buf = StringIO()
    232237                    buf.write('<div class="code-block"><pre>')
    233                     tab_width = int(self.config.get('mimeviewer', 'tab_width'))
    234238                    for line in result:
    235239                        buf.write(line.expandtabs(tab_width) + '\n')
    236240                    buf.write('</pre></div>')
     
    239243                self.log.warning('HTML preview using %s failed (%s)'
    240244                                 % (renderer, e), exc_info=True)
    241245
    242     def _annotate(self, lines, annotations):
     246    def _annotate(self, lines, annotations, tab_width):
    243247        buf = StringIO()
    244248        buf.write('<table class="code-block listing"><thead><tr>')
    245249        annotators = []
     
    259263                div, mod = divmod(len(m), 2)
    260264                return div * '&nbsp; ' + mod * '&nbsp;'
    261265            return (match.group('tag') or '') + '&nbsp;'
    262         tab_width = int(self.config.get('mimeviewer', 'tab_width'))
    263266
    264267        for num, line in enum(_html_splitlines(lines)):
    265268            cells = []

I'm using r2017. There's relating ticket:1655.

Attachments (0)

Change History (5)

comment:1 by Christopher Lenz, 19 years ago

Milestone: 0.9
Owner: changed from Jonas Borgström to Christopher Lenz
Status: newassigned

comment:2 by Christopher Lenz, 19 years ago

Description: modified (diff)

The patch looks okay.

comment:3 by Christopher Lenz, 19 years ago

Actually, no. The patch expands tabs before and after letting the renderer doing its job. Currently, the expansion is only done after the processing.

Is the pre-processing needed because the mimeviewer in question (which one is it?) expands tabs itself? If that's the case, we'll run into similar problems as those raised in #1920 about binary vs textual content. Simply checking for subtypes of text/ is not enough.

comment:4 by Matthew Good, 19 years ago

Owner: changed from Christopher Lenz to Matthew Good
Status: assignednew

cmlenz I'm gonna highjack this one.

comment:5 by Matthew Good, 19 years ago

Resolution: fixed
Status: newclosed

Fixed in [2156]

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Matthew Good.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Matthew Good to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.