[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
csv-mode: header does not align when line numbers are displayed
From: |
Joost |
Subject: |
csv-mode: header does not align when line numbers are displayed |
Date: |
Fri, 29 Apr 2022 09:47:08 +0200 |
User-agent: |
Cyrus-JMAP/3.7.0-alpha0-591-gfe6c3a2700-fm-20220427.001-gfe6c3a27 |
Hi list,
Not sure if this should be reported as a bug or not; let me know if it should.
`csv-mode` has the option to display a header line so you can make column names
permanently visible, which is a very nice option. However, when
`display-line-numbers-mode` is active, the column names do not line up with the
actual columns, because the header line does not take into account the space
taken up by the line numbers.
The following patch seems to be a quick fix:
```
diff --git a/csv-mode.el b/csv-mode.el
index 10ce166052..33118aa2e8 100644
--- a/csv-mode.el
+++ b/csv-mode.el
@@ -1382,6 +1382,10 @@ If there is already a header line, then unset the header
line."
(move-to-column (or csv--header-hscroll 0))
(let ((str (replace-regexp-in-string
"%" "%%" (buffer-substring (point) (line-end-position))))
+ (line-number-width (if (and (bound-and-true-p
display-line-numbers-mode)
+ display-line-numbers-width)
+ (+ 2 display-line-numbers-width)
+ 0))
(i 0))
(while (and i (< i (length str)))
(let ((prop (get-text-property i 'display str)))
@@ -1392,13 +1396,13 @@ If there is already a header line, then unset the
header line."
(newprop
`(space :align-to
,(if (numberp x)
- (- x (or csv--header-hscroll 0))
- `(- ,x csv--header-hscroll)))))
+ (+ line-number-width (- x (or
csv--header-hscroll 0)))
+ `(+ line-number-width (- ,x
csv--header-hscroll))))))
(put-text-property i (or nexti (length str))
'display newprop str)
(setq i nexti))))
(setq i (next-single-property-change i 'display str)))
- (concat (propertize " " 'display '((space :align-to 0))) str)))))
+ (concat (propertize " " 'display `((space :align-to
,line-number-width))) str)))))
;;; Auto-alignment
```
Though it doesn't automatically adjust the header line when
`display-line-numbers-mode` is toggled or if `display-line-number-width`
changes, so it's probably not the ideal solution.
Thanks,
--
Joost Kremers
Life has its moments
- csv-mode: header does not align when line numbers are displayed,
Joost <=