* csv-mode: header does not align when line numbers are displayed
@ 2022-04-29 7:47 Joost
2022-04-29 10:40 ` Eli Zaretskii
0 siblings, 1 reply; 3+ messages in thread
From: Joost @ 2022-04-29 7:47 UTC (permalink / raw)
To: emacs-devel
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: csv-mode: header does not align when line numbers are displayed
2022-04-29 7:47 csv-mode: header does not align when line numbers are displayed Joost
@ 2022-04-29 10:40 ` Eli Zaretskii
2022-05-12 15:40 ` Joost Kremers
0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2022-04-29 10:40 UTC (permalink / raw)
To: Joost; +Cc: emacs-devel
> Date: Fri, 29 Apr 2022 09:47:08 +0200
> From: Joost <joostkremers@fastmail.fm>
>
> Not sure if this should be reported as a bug or not; let me know if it should.
The bug tracker is not just for bugs, it is also for features. So
yes, please post such suggestions via "M-x report-emacs-bug".
> `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:
Thanks.
> 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.
Indeed. I think tabulated-list.el shows how to cause the adjustment
when the variable is toggled. Can you use those ideas to submit a
better solution?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: csv-mode: header does not align when line numbers are displayed
2022-04-29 10:40 ` Eli Zaretskii
@ 2022-05-12 15:40 ` Joost Kremers
0 siblings, 0 replies; 3+ messages in thread
From: Joost Kremers @ 2022-05-12 15:40 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
On Fri, Apr 29 2022, Eli Zaretskii wrote:
>> Date: Fri, 29 Apr 2022 09:47:08 +0200
>> From: Joost <joostkremers@fastmail.fm>
>> 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.
>
> Indeed. I think tabulated-list.el shows how to cause the adjustment
> when the variable is toggled. Can you use those ideas to submit a
> better solution?
Not sure. It's difficult to estimate how much time I'd need (not being familiar
with the code for tabulated-list-mode) and when I'd have that time. I sent a bug
report to make sure it's not forgotten. If I don't come up with a solution,
perhaps someone else with a little time on their hands will.
--
Joost Kremers
Life has its moments
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-05-12 15:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-29 7:47 csv-mode: header does not align when line numbers are displayed Joost
2022-04-29 10:40 ` Eli Zaretskii
2022-05-12 15:40 ` Joost Kremers
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.