From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joost Newsgroups: gmane.emacs.devel Subject: csv-mode: header does not align when line numbers are displayed Date: Fri, 29 Apr 2022 09:47:08 +0200 Message-ID: <64bbe68b-f2b9-4cb5-93b8-07e5720e74fa@www.fastmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29772"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.7.0-alpha0-591-gfe6c3a2700-fm-20220427.001-gfe6c3a27 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Apr 29 09:49:29 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nkLNY-0007VZ-Ey for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Apr 2022 09:49:29 +0200 Original-Received: from localhost ([::1]:45560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkLNV-0007ap-FG for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Apr 2022 03:49:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nkLLh-0005xq-Es for emacs-devel@gnu.org; Fri, 29 Apr 2022 03:47:33 -0400 Original-Received: from out5-smtp.messagingengine.com ([66.111.4.29]:60689) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nkLLf-0006Cu-4Z for emacs-devel@gnu.org; Fri, 29 Apr 2022 03:47:33 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 49B2F5C004B for ; Fri, 29 Apr 2022 03:47:29 -0400 (EDT) Original-Received: from imap52 ([10.202.2.102]) by compute2.internal (MEProxy); Fri, 29 Apr 2022 03:47:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:content-type:date:date:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to; s=fm1; t= 1651218449; x=1651304849; bh=tv4BBndbd3Li12enGh9+8cTqEEIwLjYiKrT 6739i4J4=; b=qF7mdCgsdLffW8mzYjSsumcLZEGgE8IJ+GJEyhxX9MsRtAmI/cb ictoXCPOuqwbSyH8YvBEB8P+t79c7inyGZ3E9jQcEra71B55V4s2bhX7rCc2+4BD pdK9GNtKYzGz3nrhBFNrh8ZIYSNAYvwMs6bQbTZwS++olFgG46/1dTMUiLAweS+R 8X+PtcRcDvGJ9ln7aye7Dx4tDdGhmdNcVf8TOYDmcSRQbzwmW6Vsm1bLSplf7iOA 9S4jzPHrzhtg3JL7kkPYDSY9IxoL55/QN/L+mHe8kAf86DOs4LWtxm92wwbx2mIw ycRHAVDxSWKkDhelp8Qt6FeL46vK2n4Rakw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1651218449; x=1651304849; bh=tv4BBndbd3Li1 2enGh9+8cTqEEIwLjYiKrT6739i4J4=; b=MBHFSoJMfhQmIoZ2PVJ+jnPwu0RBq cw/bG06PBKt/47VQNtpuGrcGEcIb+NvXZgJmtitvM41RS1aHo2QJmgEbw2C6Ttum 6aOoBQeH2A+qe6gVY/m7nXB2zLfMAIKMapclJIOAAJIKfK5CLRFMt/TqdlyQMQ+z 1L17smqOWjgtFQxNEYiplYiRD//HOFU+5b0v1QoJzPO/MftEfphHt+jI0+LVQONY oik1qUGL2scORpes0cYCuK+pKjyJM46BQ0tA4Xpx3PDjw3lL9JZx341jsJo3i2Dk c7Yv8X/yMkro6rKb5zVdYfYE6WmpouBuu3Bs1XSbs8otv/cppKVGW+w4Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudekgdduvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfffhffvufgtsehttdertd erredtnecuhfhrohhmpeflohhoshhtuceojhhoohhsthhkrhgvmhgvrhhssehfrghsthhm rghilhdrfhhmqeenucggtffrrghtthgvrhhnpeeihffgkeejjedufeevtdetteehveffie ehjedtvdehveffgfeggfejffekieekjeenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehjohhoshhtkhhrvghmvghrshesfhgrshhtmhgrihhlrd hfmh X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 0B051C60078; Fri, 29 Apr 2022 03:47:28 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Received-SPF: pass client-ip=66.111.4.29; envelope-from=joostkremers@fastmail.fm; helo=out5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:288963 Archived-At: 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