From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.devel Subject: Fix for `use-region-p' problem [was: Elisp test for whether `mouse-1' is pressed?] Date: Sun, 7 Nov 2021 23:26:45 +0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28089"; mail-complaints-to="usenet@ciao.gmane.io" To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Nov 08 00:28:09 2021 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 1mjra5-00078K-B7 for ged-emacs-devel@m.gmane-mx.org; Mon, 08 Nov 2021 00:28:09 +0100 Original-Received: from [::1] (port=60672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjra3-0006IS-Lv for ged-emacs-devel@m.gmane-mx.org; Sun, 07 Nov 2021 18:28:07 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:46268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjrYs-0005bf-GO for emacs-devel@gnu.org; Sun, 07 Nov 2021 18:26:54 -0500 Original-Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:31304) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjrYp-0002T3-Lf for emacs-devel@gnu.org; Sun, 07 Nov 2021 18:26:54 -0500 Original-Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1A7KOxEi010170 for ; Sun, 7 Nov 2021 23:26:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=92QI7zdesh9XmJd7bmnhbzyA5KCXfdpPJE1bCf4KKgM=; b=eLmLLpez1VJcO3EPZ4Xw9SwUSUv5Mrs3amR99BpyzQS49E9zr8P2WDw4rBTa7w93Avyj XrjaUAo1OW5L9Bjd2O06ljllghmy/Djptl5h/IQ8wjZGi4ErFQKYLGmZLraT1zyOcbAn EGvsXuBTlLnEABvgywcgNEp2LWjmuIm7L/CMrf4b6PxcrkJYo9MsLLXraIhHaEqfyhzb +XmM+Gj5hLSNIICXyTqq6CwfWhf3BftmDno4tzoXmoOIb5Xh8aJKewBW9lI04jZrAPMD J6MAsqjEJJ8ccMwQVwzID7+C8WGhgT6ETD67APlHfoLE7GWDYzkB2Oc/kOzlC2Bte1G8 gA== Original-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3c5gg3m25u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sun, 07 Nov 2021 23:26:49 +0000 Original-Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1A7NGha1193668 for ; Sun, 7 Nov 2021 23:26:48 GMT Original-Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2171.outbound.protection.outlook.com [104.47.59.171]) by userp3020.oracle.com with ESMTP id 3c63fqfcuc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sun, 07 Nov 2021 23:26:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cyDV1U9yvGgpa5/wCUh5Y+OPSm2wFVuBUdTibnopUaoNSpVHQMiDrUsLACHRUoBIDOA8/GnwAJlkYfP+qkcaGm+V8QXt+un6t0MS4CGCKCVuis9iymBB/4NOFaoq+QtS1VeXAfyFrPuw4Np/2mITy9eSSNaGDJlbnh3dqCmFxZykHaKRkz/1/rX+g2ALBsvjt6pUCZrG/LM8Fxkqi/VC/BqII2j5IxnTC7OrX3QNZyJ+HWqo1xKcpxoMtBvqeMLS3YL+pXfzeT5nyflkd2gIeBTUtsevfGB9hKzdt7wdN9Zp138L09ZWdvKqtwIUvabUDn/VsEtNqY1zXJ/T58lqFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=92QI7zdesh9XmJd7bmnhbzyA5KCXfdpPJE1bCf4KKgM=; b=XQsz8rgzl/8EqrfFCQnX5faZqP5WJEQFdNbeYpraQPKNwA8+remuV2zRnyuzR0NE3xQrInAVivhigKRlpsBOweTLs02mTUdk2Ktt9H/5F9ODqnYslmcAHTvOdO3WqMHyHdRuF54ybAN/ZM/Qw/bZ5f2MSQ/Z7DVbmKXUOw/pwMm9MgFxU84is8zPAhtsIcqthu6DEU8eiGGyn4UCMI44J5MDVnoevKu5wCWFOAzkD32/irRRBV/L6eVUP2MRn9HjJgRbpWEtp2p5BKyvurzjgFxWn6g7gf7XT9+oxeucIvr4wpAumTubPR5vlMHDmAQIdTD6eBEezCK0JI7kXOuGmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=92QI7zdesh9XmJd7bmnhbzyA5KCXfdpPJE1bCf4KKgM=; b=vBXYHkinkVdbCwmsw8B0V9srJqU5Mi1svHAxvFNBHmH5hUMaLfLGyhoBQVfyz2Ih6tojnbtP3Ce0tw8wJH51HaRz2pTiCdDn7aJepKIksmKYl6ihrTLss+WZsK7veIF5bQLAhbuZTyPOHkMzEZg49hGJFUYtWvXaofxKP1xEnmg= Original-Received: from CO6PR10MB5473.namprd10.prod.outlook.com (2603:10b6:5:355::21) by CO1PR10MB4451.namprd10.prod.outlook.com (2603:10b6:303:96::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.10; Sun, 7 Nov 2021 23:26:46 +0000 Original-Received: from CO6PR10MB5473.namprd10.prod.outlook.com ([fe80::d0fa:fa4b:7c65:ddd6]) by CO6PR10MB5473.namprd10.prod.outlook.com ([fe80::d0fa:fa4b:7c65:ddd6%5]) with mapi id 15.20.4669.016; Sun, 7 Nov 2021 23:26:45 +0000 Thread-Topic: Fix for `use-region-p' problem [was: Elisp test for whether `mouse-1' is pressed?] Thread-Index: AdfULWzJsx8TOaOsSn2pj14arbCbdA== Accept-Language: en-US Content-Language: en-US authentication-results: gnu.org; dkim=none (message not signed) header.d=none;gnu.org; dmarc=none action=none header.from=oracle.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1da8a38f-a933-4fd6-5a4b-08d9a2461029 x-ms-traffictypediagnostic: CO1PR10MB4451: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: xlKv1NuRuE0NKPXAtJitMkqbATf0ToaNfrwBHuA0BjhDSyimTVFoZMWMAwVuY8Cdt2/o2XXQrQd8zUgNCSZ0u2Z6T9c2ZI0yk9N96DKOyS62SomGqQUWY7MEEAM86uJIN/bPd0RSQQMdNzxI8N932dMAVkHy5AFudvQZzsOrj5szDVtM+eAfWSxB7BnObx7o3i34CuhGV6JepGFj0ouD4Xytc1K6uy4brvALd8hEpj9Y3t7gsEcm06gcq0N+XjyJGHcOFz8YcYvAaL2FvtbRgFItij278Si33fsQfMh+wo6KtNWksfD4ixuFn6eri6fTrtEliBPrwE7qxmw3VCQ/e5uzAK3K+qytywFI9LA9Mkh5hutWsWS6TyNfMuuTaUvagIOnMx/68voGPAckp0ZSQ50otQqxkSes3t/qauQvnB1gjmI7j6NeduB2xYkR0Tm7YAkzVtnNEJI1fNJMkdsWzw5bNKT79BlUqaznybcIrjveXuzwLSRROrRKweYbg6VpI9b7K7AXJSMS3Vsg1tV21pmOfuCMuEk1F4xIb1109BHrKE5QmWwcEvuxmUcsDn/sb5LUTKs5linm+5lwbIFhU42IcGDIUK7c9J7lc7GA0VAT6JyuJgDXseqZ/BArYnOnNTZ8GJ+os+gYa4usRMlpuiOWt3UpR4SLo4G84KS2/5Hr4UOAoP7R6osBMEY2qrv4OAeM5dGANS7IHGs22o98WFiUqO2OOU8oF3H6MXrCV2Y= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR10MB5473.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(5660300002)(6916009)(64756008)(52536014)(44832011)(83380400001)(66556008)(186003)(6506007)(26005)(8676002)(66946007)(8936002)(76116006)(66446008)(66476007)(38100700002)(7696005)(33656002)(38070700005)(71200400001)(316002)(9686003)(86362001)(122000001)(508600001)(55016002)(2906002)(81973001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?rFDgnJOhS+/benVcI+1azS7EdfE4KfHwZ+IymFBgNrFMT62/YB6mGyEEwzKh?= =?us-ascii?Q?AgbgNuLdelEKTsWGg7QTDz5K8FiIC6l5Pj6MyGxPlQ+lPhQm0a1Nf76vVaCu?= =?us-ascii?Q?7hapzP/Nkq0CO8QWYstUsQi5gONL7v4tVRknP41SKbwRJ/cVw98aHCS74v2e?= =?us-ascii?Q?eGEqqV6r/QYWv0mFajEamTG7ZMB7NHD1N2Ih8c0fzJIhQxyqABnuAwRzCSV8?= =?us-ascii?Q?thMzTZcm5aRht0W98IG1oJx7YvEzXZVuGT4FAYBH+b+ZDlD71Dqca8uLp0yh?= =?us-ascii?Q?MnH5l3FsIRpqhJUErP4C9RCs/EpaA1s9m7QVBcSHvBORGvvAe/LiOwLkhAWq?= =?us-ascii?Q?JjHuej6krkloRSZEPyivxRn/tC5YuwfK+ke3eDFKZ+OpEpSalILyfjWo1K1g?= =?us-ascii?Q?Fq2fJiEaw0Yy7djvHXwwNxw/Hd9TEHpcBxF6xvBH2f8yFhYvEeXsa4F//3+f?= =?us-ascii?Q?EeS5fhA86qiyfrK9gnv/szGTHZavO7Dkh8jEiTtjcMV/8BL/v4IppEWnJgvj?= =?us-ascii?Q?W7S5npXXVsqCwAVX5cZtjuV3UCN5LOCzGOaoRGpMBAYfLt1llL7Ri8x9x5vo?= =?us-ascii?Q?3Ry3MnvQLEHeKtWaulUiyuKF6sYBAE4Qy5IEeDMXCngUWQNhovNTgs/PjuVt?= =?us-ascii?Q?FO X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO6PR10MB5473.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1da8a38f-a933-4fd6-5a4b-08d9a2461029 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Nov 2021 23:26:45.0489 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: u7RL3NwyLeoXaNz+z6au9psQbc9NNlXx8l1mISaKmkg1Iy/Dccj/WSlCiNZ4e3DOoT06NkQUBN2OZjybCg9PJA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4451 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10161 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=763 spamscore=0 mlxscore=0 bulkscore=0 phishscore=0 suspectscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111070155 X-Proofpoint-ORIG-GUID: XsYEevgwbg0ZGmA-M5GbZ1Pb6G47Cltx X-Proofpoint-GUID: XsYEevgwbg0ZGmA-M5GbZ1Pb6G47Cltx Received-SPF: pass client-ip=205.220.177.32; envelope-from=drew.adams@oracle.com; helo=mx0b-00069f02.pphosted.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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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:278994 Archived-At: I got no response to my question of how to tell whether `mouse-1' is still pressed during a click. But I found an answer that seems to work across Emacs releases (24 through 27, the latest I have). Now let me pose a different question/suggestion. I think `use-region-p' does the wrong thing in a particular case, and I suggest a fix for that. Here's the problem I see. Admittedly, most code hasn't, and won't, run into it. `use-region-p' is designed to let code know that either (1) the active region is nonempty or (2) the user has OK'd the use of an empty region (non-nil option `use-empty-active-region'). It should return non-nil in those cases _only_. The problem I've run into comes in #2: empty active region that's declared to be OK to use. I think the real motivation for "use" must be for the user (or some code) to act on the region with the _next_ action - in particular, a user input action - a command. If the region is active and usable then you can act on it - that's the idea. In simple user terms, in this context (being able to act on the active region) a click of `mouse-1' can be considered a single user action. There's no intention, and little ability, for a user to act _between_ the down & up events of a click (as opposed to a drag). (About the only thing a user can do between the down & up events is hit a keyboard key.) I think a user who's OK'd acting on (aka "using") the empty active region really expects that action ("use") to come after the down-&-up click, not between the down & up events. But `use-region-p' is a general test, and it can be used anytime - including between down & up. The current implementation doesn't effectively check whether the region is active and useful for an upcoming user action. If some code tests between down & up, and if the result of that test is shown to a user, then a false impression of "usable" is given - if only momentarily (till the up event). This problem just hasn't been noticed, most likely, because `use-region-p' hasn't been invoked in between those events. My use case is to have the active region - as something that can be acted on by users - be indicated in the mode-line. When active, you see that it's active (you see the region size indicated also, but that's irrelevant here). In particular, OK'ing the use of an empty active region is helpful in this context because you see, in the mode-line, that you're about to act on the empty region - something you typically don't want to do. IOW, this is a way to _see_ ahead of time that you're trying to use an empty region. I use a different user option for this from `use-empty-active-region', and its default value is non-nil. So this feature doesn't interfere with whatever value you prefer for that standard option. But I think the solution I've found (after I posed the question looking for one) should be considered as a fix for the problem in `use-region-p' itself. Why not fix this corner case, even though people aren't very likely to run into it? Here's the code I'd propose: --- (defun use-region-p () "Return non-nil if it is appropriate to act on the region. This is used by commands that act specially on the region when Transient Mark mode is enabled. The return value is non-nil if the region is active and either of the following conditions is true; otherwise, the return value is nil. * The region is nonempty. * Option `use-empty-active-region' is non-nil, and the last input did not use `mouse-1' to set or adjust the region. For some commands, it might be appropriate to ignore the value of `use-empty-active-region'; in that case, use `region-active-p'." (ignore-errors (and (region-active-p) (or (> (region-end) (region-beginning)) (and use-empty-active-region (not (eq 'down-mouse-1 (car-safe last-input-event))) (not (mouse-movement-p last-input-event))))))) --- (The fix ANDs those two mouse conditions to `use-empty-active-region'.) I'm no expert on events, mouse or otherwise, so if someone sees a better implementation, great. (I'm not sure the `ignore-errors' is needed, for example.) The question is really whether preventing `use-region-p' from returning true between the down-&-up events of a click makes sense, and if so, how best to do that.