Commits

Anonymous committed 4ab4c10

Added `line_number_start` option to image formatter (#456).

Comments (0)

Files changed (3)

 build/*
 dist/*
 Pygments.egg-info/*
+.ropeproject
 
 - Updated the Logtalk lexer.
 
+- Added `line_number_start` option to image formatter (#456).
+
 - Fixed the HtmlFormatter's handling of noclasses=True to not output any
   classes (#427).
 

pygments/formatters/img.py

 
         Default: True
 
+    `line_number_start`
+        The line number of the first line.
+
+        Default: 1
+
     `line_number_step`
         The step used when printing line numbers.
 
         self.line_number_separator = get_bool_opt(options,
                                         'line_number_separator', True)
         self.line_number_step = get_int_opt(options, 'line_number_step', 1)
+        self.line_number_start = get_int_opt(options, 'line_number_start', 1)
         if self.line_numbers:
             self.line_number_width = (self.fontw * self.line_number_chars +
                                    self.line_number_pad * 2)
         return (self._get_char_x(maxcharno) + self.image_pad,
                 self._get_line_y(maxlineno + 0) + self.image_pad)
 
-    def _draw_linenumber(self, lineno):
+    def _draw_linenumber(self, posno, lineno):
         """
         Remember a line number drawable to paint later.
         """
         self._draw_text(
-            self._get_linenumber_pos(lineno),
-            str(lineno + 1).rjust(self.line_number_chars),
+            self._get_linenumber_pos(posno),
+            str(lineno).rjust(self.line_number_chars),
             font=self.fonts.get_font(self.line_number_bold,
                                      self.line_number_italic),
             fill=self.line_number_fg,
         """
         if not self.line_numbers:
             return
-        for i in xrange(self.maxlineno):
-            if ((i + 1) % self.line_number_step) == 0:
-                self._draw_linenumber(i)
+        for p in xrange(self.maxlineno):
+            n = p + self.line_number_start
+            if (n % self.line_number_step) == 0:
+                self._draw_linenumber(p, n)
 
     def _paint_line_number_bg(self, im):
         """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.