title: How to highlight the current line number in `nlinum-mode`
body: <p>I am writing a minor mode to highlight the current line number when using <code>nlinum-mode</code> (written by @Stefan), and I got everything working <em>except</em> <strong>when the cursor is on the first line at the top of the window</strong>.</p>
  
  <p>The code for <code>nlinum-mode</code> can be found here:  <a href="http://elpa.gnu.org/packages/nlinum.html" rel="nofollow">http://elpa.gnu.org/packages/nlinum.html</a></p>
  
  <p>Any assistance in figuring out why this doesn't work (i.e., <strong>when the cursor is on the first line at the top of the window</strong>) would be greatly appreciated.</p>
  
    <pre class="lang-lisp prettyprint-override"><code>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;; M-x hl-nlinum-mode
  
  (defvar nlinum-highlight-current-line-number-string nil
    "An overlay string used to highlight the current line number.")
  (make-variable-buffer-local 'nlinum-highlight-current-line-number-string)
  
  (defvar nlinum-highlight-p nil
    "Set to non-`nil` when overlay is present, and `nil` when not present.")
  (make-variable-buffer-local 'nlinum-highlight-p)
  
  (defface ln-active-face
    '((t (:foreground "black" :background "#eab700" :bold nil :italic nil
        :underline nil :box nil :overline nil)))
    "Face for `ln-active-face`."
    :group 'linum)
  
  (defface ln-inactive-face
    '((t (:foreground "SteelBlue" :background "black" :bold t :italic nil
        :underline nil :box nil :overline nil)))
    "Face for `ln-active-face`."
    :group 'linum)
  
  (defun hl-nlinum-remove-overlay ()
    (when nlinum-highlight-p
      (remove-overlays (point-min) (point-max)
        'before-string nlinum-highlight-current-line-number-string)
      (setq nlinum-highlight-p nil)))
  
  (defun nlinum-highlight-current-line-number ()
    (when nlinum-mode
      (hl-nlinum-remove-overlay)
      (let* (
          (pbol (point-at-bol))
          (line (nlinum--line-number-at-pos))
          (line-mod
            (cond
              ((eq nlinum--width 2)
                (cond
                  ((&lt; line 10)
                    (concat " " (format "%s" line)))
                  (t (format "%s" line))))
              ((eq nlinum--width 3)
                (cond
                  ((&lt; line 10)
                    (concat "  " (format "%s" line)))
                  ((and
                      (&gt; line 9)
                      (&lt; line 100))
                    (concat " " (format "%s" line)))
                  (t (format "%s" line))))
              ((eq nlinum--width 4)
                (cond
                  ((&lt; line 10)
                    (concat "   " (format "%s" line)))
                  ((and
                      (&gt; line 9)
                      (&lt; line 100))
                    (concat "  " (format "%s" line)))
                  ((and
                      (&gt; line 99)
                      (&lt; line 1000))
                    (concat " " (format "%s" line)))
                  (t (format "%s" line))))
              (t (format "%s" line))))
          (str (propertize line-mod 'face 'ln-active-face) )
          (final-line-number (propertize " " 'display `((margin left-margin) ,str))))
        (setq nlinum-highlight-current-line-number-string final-line-number)
        (overlay-put (make-overlay pbol pbol)
          'before-string nlinum-highlight-current-line-number-string)
        (setq nlinum-highlight-p t))))
  
  (define-minor-mode hl-nlinum-mode
  "A minor-mode for highlighting the current line number when nlinum-mode is active."
    :init-value nil
    :lighter " HL#"
    :keymap nil
    :global nil
    :group 'linum
    (cond
      (hl-nlinum-mode
        (when (not nlinum-mode)
           (nlinum-mode 1))
        (add-hook 'post-command-hook #'nlinum-highlight-current-line-number nil t))
      (t
        (remove-hook 'post-command-hook #'nlinum-highlight-current-line-number t)
        (remove-overlays (point-min) (point-max)
          'before-string nlinum-highlight-current-line-number-string))))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  </code></pre>