all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Sean Perry <shaleh@speakeasy.net>
To: 12428@debbugs.gnu.org
Subject: bug#12428: 23.4; Add padding for rendering of the line numbers by linum-mode
Date: Wed, 12 Sep 2012 12:57:08 PDT	[thread overview]
Message-ID: <62162.1347479828@speakeasy.net> (raw)

[-- 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))

             reply	other threads:[~2012-09-12 19:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-12 19:57 Sean Perry [this message]
2012-10-26 16:47 ` bug#12428: 23.4; Add padding for rendering of the line numbers by linum-mode 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=62162.1347479828@speakeasy.net \
    --to=shaleh@speakeasy.net \
    --cc=12428@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.