From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Rodrigo Morales Newsgroups: gmane.emacs.help Subject: How to get the current column regardless of the content of the current line? Date: Thu, 15 Dec 2022 14:22:49 -0500 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7716"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 15 21:41:32 2022 Return-path: Envelope-to: geh-help-gnu-emacs@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 1p5v2p-0001oL-8k for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 15 Dec 2022 21:41:31 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5v1p-0004PO-0g; Thu, 15 Dec 2022 15:40:29 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5toz-00069J-3W for help-gnu-emacs@gnu.org; Thu, 15 Dec 2022 14:23:10 -0500 Original-Received: from mail-vk1-xa31.google.com ([2607:f8b0:4864:20::a31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p5tox-0005l5-2R for help-gnu-emacs@gnu.org; Thu, 15 Dec 2022 14:23:08 -0500 Original-Received: by mail-vk1-xa31.google.com with SMTP id x65so37042vkg.11 for ; Thu, 15 Dec 2022 11:23:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=HWR19X7iWWGvzo+eCtGJ+KemgQtxngHZ1IPGNc+dOqg=; b=Czw6l5ywrBUnz/BzDRIkYxdiACiJwUn7FQaGSymaLT6qr0Fx512NgTaPsjqjpiFjFM UcpcKuim5mKBfMNsGvkY2sCaJE3GAlprjS8yFYtqFXezIeIEGwz8sJ6mF2jotfHyM3p2 oCdMbmBr6aNe972g9P73pspxF9gxDgpXWDB6+r2yZmSgLA2HhkFKcIJlLcEk20qEnl+/ OKDF1lM1x4pdRF9ubZhpWYNOUGnX0keEy/NHBvOvzYd9YrH1YqvOtjuDRCa2iYCF+x0E SQyIFg8iJ/sf4QktBGISQk8SdBAw19RTE/9iFBkkw5fovqi0hSxicJV0u1fHS4OUg/lL q+QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=HWR19X7iWWGvzo+eCtGJ+KemgQtxngHZ1IPGNc+dOqg=; b=2KXBK2TlSFk3G1hF9lNnYxpRI4gIoXMRtdunnC6FjblGSB88TA8vVGi+yPV8u7Btwa 6q1haVUu7IaudNnXnHtFTeRKBfhjV4u6QaxWfY9n8xqn9GKTu+f4urtARZ5F6Jvf6yim EP5ejeXptWRTgowLfPQSEuasZ+oUzbAbycWwAQWXUwiE13u7ah86mxD+Kvc0UXUngiAr cwrJU6YK6tn43FdtsX68NBH3fBN6jU5FnQnFIdSN50FB7ouisbC3cQtcafEh3bHY35Vh w+Iq/RXnpq3blw8ee4mH8hxKAx8rYyR9VsqTluDNzIF/nVcrRkosVCdXedPiHep5xLs3 l7IA== X-Gm-Message-State: ANoB5pmXeUp/UL+By38DU9Sxv08j/Dwc9WHAyv0VHP+C2UuKSgrtGsla oBpaIg+eUuTX28USqEPdHj9WJPq5ZiONvdS3A6ftEkM+eis= X-Google-Smtp-Source: AA0mqf6bb9qWTjTN0rCI3DHG6b0Fa18wP8/uW5WQqSgv4qfZBthsdJJ7HjtwFuFVZiYBa2wZywpZzl7x6oskzDZc3sY= X-Received: by 2002:a1f:5e06:0:b0:3bd:3aeb:3006 with SMTP id s6-20020a1f5e06000000b003bd3aeb3006mr22010014vkb.26.1671132185622; Thu, 15 Dec 2022 11:23:05 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::a31; envelope-from=moralesrodrigo1100@gmail.com; helo=mail-vk1-xa31.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 15 Dec 2022 15:40:27 -0500 X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:141781 Archived-At: Table of Contents _________________ 1. The context 2. The question 3. The current workaround 4. Additional information 1 The context =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D I'm aware that `current-column' returns the column of the cursor position. See two minimal working examples below. ,---- | (with-temp-buffer | (insert "foo") | (end-of-line) | (princ (current-column))) `---- ,---- | 1 `---- ,---- | (with-temp-buffer | (insert "foofoo") | (end-of-line) | (princ (current-column))) `---- ,---- | 6 `---- Sometimes, `current-column' considers one character as if it were two. In the minimal working example below, you can see that the line contains `=E4=BD=A0' (U+4F60) 3 times and `current-column' returns 6 when= it is at the end of the line. ,---- | (with-temp-buffer | (insert "=E4=BD=A0=E4=BD=A0=E4=BD=A0") | (end-of-line) | (princ (current-column))) `---- ,---- | 6 `---- In the minimal working example below, you can see that even though the line contains two characters, `current-column' returns `3'. This happens because, as shown in the previous example, `=E4=BD=A0' is counted= as two characters by `current-column'. ,---- | (with-temp-buffer | (insert "a=E4=BD=A0") | (end-of-line) | (princ (current-column))) `---- ,---- | 3 `---- 2 The question =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Which function could I use to obtain the column of the current position that would work for any line regardless of its content? 3 The current workaround =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D I have written the following function to get the results that I expect. However, I decided to open this thread just in case there's another (preferably, shorter or built-in) function that any of you might know. ,---- | (defun my/current-column () | (save-excursion | ;; Save the current point | (let ((orig (point)) | (counter 0)) | (beginning-of-line) | ;; Count the number of characters from the beginning of the line | ;; to the previously stored point | (while (and (<=3D (point) orig) | (not (eobp))) | (setq counter (1+ counter)) | (forward-char)) | counter))) `---- The following code blocks contains minimal working examples that show the results of this function. ,---- | (with-temp-buffer | (insert "=E4=BD=A0=E4=BD=A0=E4=BD=A0") | (my/current-column)) `---- ,---- | 3 `---- ,---- | (with-temp-buffer | (insert "a=E4=BD=A0") | (my/current-column)) `---- ,---- | 2 `---- 4 Additional information =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D I opened a thread in the bug-gnu-emacs mailing list, because I thought that there was a bug in `current-column', and Eli Zaretskii explained some details of this function. You can find the thread in this link at the archives: