From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pierre Rouleau Newsgroups: gmane.emacs.help Subject: Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode? Date: Sat, 13 Jul 2024 09:45:54 -0400 Message-ID: References: <87msmmi39t.fsf@dataswamp.org> 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="19633"; 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 Sat Jul 13 15:46:51 2024 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 1sSd5P-0004xO-93 for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 13 Jul 2024 15:46:51 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSd4m-0006We-9l; Sat, 13 Jul 2024 09:46:12 -0400 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 1sSd4j-0006WP-G8 for help-gnu-emacs@gnu.org; Sat, 13 Jul 2024 09:46:09 -0400 Original-Received: from mail-vk1-xa36.google.com ([2607:f8b0:4864:20::a36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sSd4h-0001nl-C3 for help-gnu-emacs@gnu.org; Sat, 13 Jul 2024 09:46:09 -0400 Original-Received: by mail-vk1-xa36.google.com with SMTP id 71dfb90a1353d-4f2e13622e4so1052859e0c.3 for ; Sat, 13 Jul 2024 06:46:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720878366; x=1721483166; darn=gnu.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=ze7Z8A6hAekSX7uuikhT9OJp13N+lnmLBFlHe+JfvWM=; b=XEVIf9faiSnD9yNzrVpEI7TFTo8gKlj0azHePmsZw8uw6HnPf/Z8VJwZ7+L/0rXp10 WpRhGMlfF4vyUXfi8ccnvVLd2Av3B32j6oTRaIJUqt5JarQIvMy9EpTWMNm1j+Sc9690 7eQBreLCS19OvIqWXpNGXFzoxyorH1JOTyfJkI0JY/4Sxvvvezm/TOBMiO3QTVvQK1rO 7WIKVAihjZhDSg+n2gtBmxPLvOXh43zP6G9g+E3Hc+fx7qOJAXUOjcAm2JV7asEwd2E5 AomHbBZLZXMTUctT3NTTbbb0nZxyVSA5pLZ6erkptNA6gYfkD3Fh0rswM8mYcuITfW0d zAtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720878366; x=1721483166; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ze7Z8A6hAekSX7uuikhT9OJp13N+lnmLBFlHe+JfvWM=; b=mMukQQjL9w8UTW9ftrPDtig/k7BnffVZff6tc0brP70XK3IMDyvI3Mb6a4fGtBdPmE 9nSfs8826T3boA9vZJKgbsT1OY0b23NhhNu/lv0eHoBT5K3wBmpZ/Q9mg6+6uMllXZeY P9jjcYOzS6wz/D5R5lgV79k1MreC39Krem0n7d/c0TEff26WUTMZsq2/iwx9BHcmRoXj o63it9LT4Nf0OX8hqIXWvHVdqPmxRi+xH55Hjn6ypeIPyl7weMPfsyk/eY2xpozdNiF0 DnbOszkyYVfmSGRjTaRwONrNzdYkONZh4Bhku8J6+u4oediCL0y51qcODzXXZeDp/1dh 1VoA== X-Gm-Message-State: AOJu0YyxmXMb2SvKRvWHz0LpoAtMnmkxubB82BQlFhWCRUgmYGc6vtP9 vlyqGt48AHuGvmdWyzxWLuPALfXqqdBiRoWfYqfncPBYk3ldcPTz2z2z+CL8aWW39VDIpfWoA0P muCXTE96uoxMAHBuLQiYorVS+nGvByo2F X-Google-Smtp-Source: AGHT+IFIZbzabMqaZKpxlB9ItmmPyT8KbfXQcBgTRwZjy+u6/32HyRSuKSsQw2n3AgDkUJ6aeoL0AgiP5D5OchHe68U= X-Received: by 2002:a05:6122:8c5:b0:4ec:f8e4:e0bf with SMTP id 71dfb90a1353d-4f33f1799damr18544624e0c.2.1720878365572; Sat, 13 Jul 2024 06:46:05 -0700 (PDT) In-Reply-To: <87msmmi39t.fsf@dataswamp.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::a36; envelope-from=prouleau001@gmail.com; helo=mail-vk1-xa36.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-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:147195 Archived-At: On Fri, Jul 12, 2024 at 11:23=E2=80=AFPM Emanuel Berg = wrote: > Pierre Rouleau wrote: > > > The real reason I want to do that is to prevent reporting > > key binding clashes in code that tries to use the same key > > binding for 2 different global key bindings when that key > > binding is not even possible because Emacs will not be able > > to react to it. > > Can't you just branch on `display-graphic-p'? It is nil here > but t in a GUI Emacs instance so should work. > > Another way is to just set some variable when you start it: > > $ HERE=3D"some-system" emacs > > then branch on (getenv "HERE"). > > Sounds easier? > Well, perhaps I did not explain the problem properly. Code is probably easier to provide the context. Here's the code, published here: https://github.com/pierre-rouleau/pel/blob/master/pel-spell-iedit.el#L63 (defun pel-spell-iedit-check-conflict () "Check for key binding conflict between flyspell and iedit. Warn user if necessary." (when (and (boundp 'iedit-toggle-key-default) (boundp 'flyspell-auto-correct-binding) (string=3D (key-description iedit-toggle-key-default) (key-description flyspell-auto-correct-binding))) (display-warning 'pel-keys (format "Both iedit and flyspell bind functions to \"%s\"!\n\ To use this key, change the key selected in one of the following \n\ user options:\n\ - `iedit-toggle-key-default' - `flyspell-auto-correct-binding' Then save your changes." (key-description flyspell-auto-correct-binding))))) The above code checks if the user that has configured the system to use both iedit and flyspell and use their default key binding that clashes. Their code has the following: (defcustom iedit-toggle-key-default (kbd "C-;") "If no-nil, the key is inserted into global-map, isearch-mode-map, esc-map and help-map." :type 'vector :group 'iedit) (defcustom flyspell-auto-correct-binding [(control ?\;)] "The key binding for flyspell auto correction." :type 'key-sequence) The warning is printed on Emacs running in terminal mode even though when running under a macOS Terminal.app the C-; cannot be used. So, I would like to be able to *check* if the key bindings reported as clashing can be used in the environment (and yes I use the functions you mentioned) and if they can't, I would change the message. This code is part of my PEL project at: https://github.com/pierre-rouleau/pel#readme I wrote this Emacs Lisp project as a way to control my Emacs startup, help me learn Emacs and help some friends transition to Emacs. I use it on a relatively large number of computers, OSes and Emacs versions depending on what's available in the environment provided by my customers. Sorry for the long description, but I hope it provides a better overview of the context. --=20 /Pierre