unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#12428: 23.4; Add padding for rendering of the line numbers by linum-mode
@ 2012-09-12 19:57 Sean Perry
  2012-10-26 16:47 ` Stefan Monnier
  2016-05-26 19:56 ` Alan Third
  0 siblings, 2 replies; 7+ messages in thread
From: Sean Perry @ 2012-09-12 19:57 UTC (permalink / raw)
  To: 12428

[-- Attachment #1: Type: text/plain, Size: 1505 bytes --]

I was experiencing the issue discussed here at StackOverflow
http://stackoverflow.com/questions/4920210/what-causes-this-graphical-error-in-emacs-with-linum-mode-on-os-x. The
suggestions boil down to a few choices

* stop using dynamic format and explicitly set a format like "%7d ".
  Note the trailing space.
* specify a function to return the format which will include the
  trailing space
* edit the source to ensure a space is added when the line number is
  finally rendered.

I dislike all three choices. Choice 1 will usually eat too much room
on the left. That is why dynamic was created in the first place. The
format handler routine option in Choice 2 is inefficient to implement
since the user will need to basically reimplement the dynamic logic and
this is called for every line in the file. If you follow some of the links on
StackOverflow there are several solutions to this and similar problems
that all reproduce the dynamic logic.

I finally chose to implement a variation of option 3 which is attached as a
patch. Basically it lets the user specify a padding value to added when
the line is rendered. The patch is small, easy for a user to implement
and efficient in execution. It certainly seems easier than the solutions
involving defadvice and the dynamic format logic.

For now I have a fork of linum in my .emacs.d/site-lisp. My patch to
linum is attached. Feel free to change the name of the customization
variable or improve the help text.

Sean


[-- Attachment #2: linum.patch --]
[-- Type: application/octet-stream, Size: 1032 bytes --]

--- linum.el	2012-09-12 12:16:20.000000000 -0700
+++ linum.sperry.el	2012-09-12 12:17:58.000000000 -0700
@@ -53,6 +53,12 @@ See also `linum-before-numbering-hook'."
   :group 'linum
   :type 'sexp)
 
+(defcustom linum-margin-padding 0
+  "Padding added to the left margin when displaying the line numbers.
+Should be a positive integer. A value between 1 and 5 is probably sufficient."
+  :group 'linum
+  :type 'integer)
+
 (defface linum
   '((t :inherit (shadow default)))
   "Face for displaying line numbers in the display margin."
@@ -157,7 +163,7 @@ and you have to scroll or press \\[recen
                               (push o linum-overlays))
                             (setq linum-available (delq o linum-available))
                             (throw 'visited t))))))
-        (setq width (max width (length str)))
+        (setq width (max width (+ (length str) linum-margin-padding)))
         (unless visited
           (let ((ov (if (null linum-available)
                         (make-overlay (point) (point))

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-09-25 13:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-12 19:57 bug#12428: 23.4; Add padding for rendering of the line numbers by linum-mode Sean Perry
2012-10-26 16:47 ` Stefan Monnier
2012-10-26 18:34   ` Sean Perry
2012-10-28 15:27     ` Stefan Monnier
2016-05-26 19:56 ` Alan Third
2016-05-26 20:19   ` shaleh
2017-09-25 13:53     ` Alan Third

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).