From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#60654: 30.0.50; tree-sitter: `transpose-sexps-function' uses a lambda in a defvar Date: Mon, 09 Jan 2023 07:57:11 +0100 Message-ID: <87lemctcu0.fsf@thornhill.no> References: <111EEEA5-B5FC-4C45-99A9-06B4C63713A8@thornhill.no> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7624"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 60654@debbugs.gnu.org To: Yuan Fu , Mickey Petersen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 09 07:58:23 2023 Return-path: Envelope-to: geb-bug-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 1pEm6v-0001mO-WA for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 09 Jan 2023 07:58:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pEm6e-0001j1-TH; Mon, 09 Jan 2023 01:58:04 -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 1pEm6c-0001it-Ph for bug-gnu-emacs@gnu.org; Mon, 09 Jan 2023 01:58:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pEm6c-0004dU-Hk for bug-gnu-emacs@gnu.org; Mon, 09 Jan 2023 01:58:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pEm6c-0002x2-DY for bug-gnu-emacs@gnu.org; Mon, 09 Jan 2023 01:58:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Jan 2023 06:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60654 X-GNU-PR-Package: emacs Original-Received: via spool by 60654-submit@debbugs.gnu.org id=B60654.167324743811275 (code B ref 60654); Mon, 09 Jan 2023 06:58:02 +0000 Original-Received: (at 60654) by debbugs.gnu.org; 9 Jan 2023 06:57:18 +0000 Original-Received: from localhost ([127.0.0.1]:35639 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pEm5t-0002vn-UL for submit@debbugs.gnu.org; Mon, 09 Jan 2023 01:57:18 -0500 Original-Received: from out2.migadu.com ([188.165.223.204]:57978) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pEm5r-0002vd-CA for 60654@debbugs.gnu.org; Mon, 09 Jan 2023 01:57:17 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1673247434; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GSpL6E/WjMHDv+VLIE/9Qaxy0S+EbuVQzSZ4N9YnlGk=; b=yy9XGwajq5S6X34oNA9a+taMWQHZJdHtUlSQy0tyWU3xfKzpzQBWtRwWExL0aGagZNkjl7 IymT3YmOEAHYGqJF00Unh7ao2R8XjQpyG14px9F4OPTywZHwBT+Wy+hsfOkmgTPixD9HPm T3vPGjN+M3p0Vl+66lL4K+qvQtEIirtQkTLdhNl09YGXGgAg7A9J+UA0H1LfItbrm/6z78 yugDVW8A8F7ub6YCySHyCAE1mUcLdyeIyAMrJRH0UULxkdPiiETtZCZVTuJu6Vv2I5MzFK gZ+XdlMUMrnPwXm/2iwtjHhSQ+IxxhW8l32wS3sJFvpFieoSbIWR2svlPfxP8Q== In-Reply-To: <111EEEA5-B5FC-4C45-99A9-06B4C63713A8@thornhill.no> X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:252992 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Theodor Thornhill writes: > On 9 January 2023 04:39:34 CET, Yuan Fu wrote: >> >>Mickey Petersen writes: >> >>> The defvar `transpose-sexps-function' holds on to a lambda function. >>> Would it be possible to make it an actual function? Its purpose is >>> rather important as it is the default transposition function that was >>> moved out of `transpose-sexps'. Being able to reliably access it when >>> `transpose-sexps-function' is overriden is useful. >> >>CC=E2=80=99d Theo. >> >>Yuan > > Thanks yuan. > > Yeah I'll make this change and call the new function transpose-sexps-defa= ult-function. > > Apologies for any inconvenience :) > > Theo=20 How about this, Mickey. Is this something you can work with? Theo --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-named-defun-for-transpose-sexps-default-function.patch >From 442cb4676d359faf23abb15799338f2025c797cb Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Mon, 9 Jan 2023 07:52:38 +0100 Subject: [PATCH] Add named defun for transpose-sexps-default-function (bug#60654) * lisp/simple.el (transpose-sexps-default-function): Move the lambda into its own function. (transpose-sexps-function): Refer to it by name. * etc/NEWS: Mention the change. --- etc/NEWS | 4 ++++ lisp/simple.el | 64 ++++++++++++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 60dab575da6..3aa8f2abb77 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -57,6 +57,10 @@ trash when deleting. Default is nil. Emacs now can set this variable to customize the behavior of the 'transpose-sexps' function. +** New function 'transpose-sexps-default-function'. +The previous implementation is moved into its own function, to be +bound by transpose-sexps-function'. + ** New function 'treesit-transpose-sexps'. treesit.el now unconditionally sets 'transpose-sexps-function' for all Tree-sitter modes. This functionality utilizes the new diff --git a/lisp/simple.el b/lisp/simple.el index 690968ca938..c8c5542caee 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -8436,37 +8436,39 @@ transpose-words (interactive "*p") (transpose-subr 'forward-word arg)) -(defvar transpose-sexps-function - (lambda (arg) - ;; Here we should try to simulate the behavior of - ;; (cons (progn (forward-sexp x) (point)) - ;; (progn (forward-sexp (- x)) (point))) - ;; Except that we don't want to rely on the second forward-sexp - ;; putting us back to where we want to be, since forward-sexp-function - ;; might do funny things like infix-precedence. - (if (if (> arg 0) - (looking-at "\\sw\\|\\s_") - (and (not (bobp)) - (save-excursion - (forward-char -1) - (looking-at "\\sw\\|\\s_")))) - ;; Jumping over a symbol. We might be inside it, mind you. - (progn (funcall (if (> arg 0) - #'skip-syntax-backward #'skip-syntax-forward) - "w_") - (cons (save-excursion (forward-sexp arg) (point)) (point))) - ;; Otherwise, we're between sexps. Take a step back before jumping - ;; to make sure we'll obey the same precedence no matter which - ;; direction we're going. - (funcall (if (> arg 0) #'skip-syntax-backward #'skip-syntax-forward) - " .") - (cons (save-excursion (forward-sexp arg) (point)) - (progn (while (or (forward-comment (if (> arg 0) 1 -1)) - (not (zerop (funcall (if (> arg 0) - #'skip-syntax-forward - #'skip-syntax-backward) - "."))))) - (point))))) +(defun transpose-sexps-default-function (arg) + "Default method to locate a pair of points for transpose-sexps." + ;; Here we should try to simulate the behavior of + ;; (cons (progn (forward-sexp x) (point)) + ;; (progn (forward-sexp (- x)) (point))) + ;; Except that we don't want to rely on the second forward-sexp + ;; putting us back to where we want to be, since forward-sexp-function + ;; might do funny things like infix-precedence. + (if (if (> arg 0) + (looking-at "\\sw\\|\\s_") + (and (not (bobp)) + (save-excursion + (forward-char -1) + (looking-at "\\sw\\|\\s_")))) + ;; Jumping over a symbol. We might be inside it, mind you. + (progn (funcall (if (> arg 0) + #'skip-syntax-backward #'skip-syntax-forward) + "w_") + (cons (save-excursion (forward-sexp arg) (point)) (point))) + ;; Otherwise, we're between sexps. Take a step back before jumping + ;; to make sure we'll obey the same precedence no matter which + ;; direction we're going. + (funcall (if (> arg 0) #'skip-syntax-backward #'skip-syntax-forward) + " .") + (cons (save-excursion (forward-sexp arg) (point)) + (progn (while (or (forward-comment (if (> arg 0) 1 -1)) + (not (zerop (funcall (if (> arg 0) + #'skip-syntax-forward + #'skip-syntax-backward) + "."))))) + (point))))) + +(defvar transpose-sexps-function #'transpose-sexps-default-function "If non-nil, `transpose-sexps' delegates to this function. This function takes one argument ARG, a number. Its expected -- 2.34.1 --=-=-=--