質問

I have (global-linum-mode 1) and (global-whitespace-mode t) defined in my init.el with Aquamacs 2.4. Line numbering is intermittent, and skips displaying a line number following an empty line. Disabling whitespaces fixes the problem. Is there any way to display a line number for every line and also have whitespace enabled?

Perhaps there is an alternative to linum.el that does something very similar?

In the following example, the dollar sign is an empty line with no text.

1  First line.
2  Second line.
3  $
   Fourth line.
5  $
   Sixth Line.
7  Seventh line.
8  $
   Ninth line.
役に立ちましたか?

解決

Solution # 1 -- from http://www.emacswiki.org/LineNumbers (citing Michael Hoffman) - posted there for a different reason, but resolves my problem also:

(eval-after-load 'linum
  '(progn
     (defface linum-leading-zero
       `((t :inherit 'linum
            :foreground ,(face-attribute 'linum :background nil t)))
       "Face for displaying leading zeroes for line numbers in display margin."
       :group 'linum)

     (defun linum-format-func (line)
       (let ((w (length
                 (number-to-string (count-lines (point-min) (point-max))))))
         (concat
          (propertize (make-string (- w (length (number-to-string line))) ?0)
                      'face 'linum-leading-zero)
          (propertize (number-to-string line) 'face 'linum))))

     (setq linum-format 'linum-format-func)))

Solution # 2:

(setq linum-format "%d")

F.Y.I. # A:

For anyone who is wondering how to resolve a related issue where various whitespace colorations (and/or highlight the current line) invade the left-hand margin that is reserved for line numbering, setting the background coloration of that area fixes the issue. The foreground and/or background of the line numbers can be user-defined. Solution number one above can be modified also by adding a color definitation after the word foreground at line 5 -- e.g., :foreground "red", ... The following snippet is a separate line that would either precede or follow the entire workaround mentioned in solution number one, and modified with whatever colors the user desires:

(custom-set-faces '(linum ((t (:foreground "red" :background "white" :height 120 :family "Courier")))) )

F.Y.I. # B: I modified line 13 of solution number one to eliminate the 0 and replace it with a plain old space because I'm not accustomed to seeing the leading zeroes and was just looking for a solution to the initial issue described in this thread. Solution number 2 appears to be flush-left and solution number 1 is flush-right. Just a matter of personal preference. There are undoubtedly several other possibilities for changing the linum-format to something other than the dynamic default defined within linum.el.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top