From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id QtX/CjvHtF6ZRgAA0tVLHw (envelope-from ) for ; Fri, 08 May 2020 02:43:07 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id QNXUJEfHtF5vXQAAB5/wlQ (envelope-from ) for ; Fri, 08 May 2020 02:43:19 +0000 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 092D4940609 for ; Fri, 8 May 2020 02:43:17 +0000 (UTC) Received: from localhost ([::1]:54274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWsyq-0005oX-79 for larch@yhetil.org; Thu, 07 May 2020 22:43:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWsyS-0005oD-1A for emacs-orgmode@gnu.org; Thu, 07 May 2020 22:42:52 -0400 Received: from pb-smtp20.pobox.com ([173.228.157.52]:50981) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWsyP-0003KV-JM for emacs-orgmode@gnu.org; Thu, 07 May 2020 22:42:51 -0400 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id E4658D3824; Thu, 7 May 2020 22:42:46 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:in-reply-to:references:date:message-id:mime-version :content-type; s=sasl; bh=n1YfmUlZqtA35EOXT7Ka4v/GbEA=; b=nPuIAh vR5SXI/CJNpUorgvJGb4ZcJ4rNNxFtq4nhIT2bc1l/gMfJujQSVaPTV8gsBXaARv ZOdZPtd4ovKo+mR+/08s4UrkXWjVx5ic8niEwf1vvUpr3WwO3lEJWSh+sOJCMdEj cBoS0hBcdi8a3Yd80RIBg3uBv6DtEhiJ8QA+c= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id DBC15D3823; Thu, 7 May 2020 22:42:46 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:subject:in-reply-to:references:date:message-id:mime-version:content-type; s=mesmtp; bh=ssKGb8ReZsxMIsUsshJVgzCCSagwRxF60wZFl4WTS1w=; b=Z+/fRj/GN0EIbkFUjhuSfhO+copSbvd63czgo+Zz+xspXfA/Bo1FMDMEF/nMv/jyKP2K13KGg9BtkYLpO9SNHjHGUHDYL5leIS312QncuffsJwRMeeQfDAYXoTnGwy2aQRnxg7x2zSk+/F26WVeQItaZLnc/tHianuR20Aorpmg= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 3086BD3822; Thu, 7 May 2020 22:42:44 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: Matt Lundin , Org Mode List Subject: Re: [PATCH] Fix moving cursor in org-set-tags-command In-Reply-To: <871rnvi8g6.fsf@fastmail.fm> References: <871rnvi8g6.fsf@fastmail.fm> Date: Fri, 08 May 2020 02:42:42 +0000 Message-ID: <878si3du59.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 98147EDC-90D5-11EA-BD31-B0405B776F7B-24757444!pb-smtp20.pobox.com Received-SPF: pass client-ip=173.228.157.52; envelope-from=kyle@kyleam.com; helo=pb-smtp20.pobox.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/07 22:42:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 X-Spam-Score: -1.21 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=nPuIAh v; dkim=pass header.d=kyleam.com header.s=mesmtp header.b=Z+/fRj/G; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 2001:470:142::17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Scan-Result: default: False [-1.21 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; GENERIC_REPUTATION(0.00)[-0.4989124056224]; DWL_DNSWL_FAIL(0.00)[kyleam.com:server fail,2001:470:142::17:server fail]; R_SPF_ALLOW(-0.20)[+ip6:2001:470:142::/48:c]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.10), country: US(-0.00), ip: 2001:470:142::17(-0.50)]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; RCPT_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[pobox.com:+,kyleam.com:+]; MAILLIST(-0.20)[mailman]; FREEMAIL_TO(0.00)[imapmail.org,gnu.org]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:22989, ipnet:2001:470:142::/48, country:US]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_FROM(0.00)[larch=yhetil.org]; FROM_NEQ_ENVFROM(0.00)[kyle@kyleam.com,emacs-orgmode-bounces@gnu.org]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[pobox.com:s=sasl,kyleam.com:s=mesmtp]; URIBL_BLOCKED(0.00)[kyleam.com:dkim,pobox.com:dkim]; FROM_HAS_DN(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[kyleam.com]; HAS_LIST_UNSUB(-0.01)[]; DNSWL_BLOCKED(0.00)[2001:470:142::17:from]; RCVD_COUNT_SEVEN(0.00)[7]; FORGED_SENDER_MAILLIST(0.00)[] X-TUID: SB8b2qJokdMV Matt Lundin writes: > Commit 44ec473c199262d89b372d8a6cd35bed7672164d from Feb. 23 causes > org-set-tags-command to move the cursor forward 1 char when situated on > headline asterisks. [...] > This commit modified a previous change on Feb. 21 > (450452de4b790706d187291f9f71a286f8f62004). But that commit also had > problems, since it would move the cursor one asterisk forward on > headlines > 1, thus also interfering with org-speed-keys. In my view > org-set-tags-command should not move the cursor except to fix the very > specific thing that commit 450452de4b was meant to fix: namely the > cursor moving when on a blank headline: i.e., from here... Thanks for the nice description of the problem. I wouldn't mind if at least a condensed version made its way into the commit message :) > I've attached a patch that corrects the problem, but it would be ideal > if we figured out why the cursor is moving in the first place. I looked quickly at org-set-tags (and the functions it calls). Based on commenting bits out, I think there are at least a couple of parts that modify the buffer in a way that prevent save-excursion from restoring the intended location. While not ideal, this after-the-fact adjustment is probably the simplest way to deal with the issue. > Subject: [PATCH 1/1] Fix bug that placed cursor incorrectly when setting tags > > * lisp/org.el: (org-set-tags-command) Only fix cursor position in very nitpick: The colon should follow (org-set-tags-command). > diff --git a/lisp/org.el b/lisp/org.el > index dd017e662..0e4fd7be1 100644 > --- a/lisp/org.el > +++ b/lisp/org.el > @@ -11846,8 +11846,9 @@ in Lisp code use `org-set-tags' instead." > (org-set-tags tags))))) > ;; `save-excursion' may not replace the point at the right > ;; position. > - (when (save-excursion (skip-chars-backward "*") (bolp)) > - (forward-char)))) > + (and (looking-at " ") > + (string-match "\\*+" (buffer-substring (point-at-bol) (point))) > + (forward-char)))) Looks fine to me, with the minor nit that I think looking-at-p and string-match-p would be preferable here. Would you mind adding a regression test?