unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#60654: 30.0.50; tree-sitter: `transpose-sexps-function' uses a lambda in a defvar
@ 2023-01-08 10:46 Mickey Petersen
  2023-01-09  3:39 ` Yuan Fu
  2023-01-09 20:35 ` Yuan Fu
  0 siblings, 2 replies; 7+ messages in thread
From: Mickey Petersen @ 2023-01-08 10:46 UTC (permalink / raw)
  To: 60654


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.


In GNU Emacs 30.0.50 (build 6, x86_64-pc-linux-gnu, GTK+ Version
 3.24.20, cairo version 1.16.0) of 2023-01-02 built on mickey-work
Repository revision: c209802f7b3721a1b95113290934a23fee88f678
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12013000
System Description: Ubuntu 20.04.3 LTS

Configured using:
 'configure --with-native-compilation --with-json --with-mailutils
 --without-compress-install --with-imagemagick CC=gcc-10'






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#60654: 30.0.50; tree-sitter: `transpose-sexps-function'  uses a lambda in a defvar
  2023-01-08 10:46 bug#60654: 30.0.50; tree-sitter: `transpose-sexps-function' uses a lambda in a defvar Mickey Petersen
@ 2023-01-09  3:39 ` Yuan Fu
  2023-01-09  6:23   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-01-09 20:35 ` Yuan Fu
  1 sibling, 1 reply; 7+ messages in thread
From: Yuan Fu @ 2023-01-09  3:39 UTC (permalink / raw)
  To: Mickey Petersen; +Cc: Theodor Thornhill, 60654


Mickey Petersen <mickey@masteringemacs.org> 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’d Theo.

Yuan





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#60654: 30.0.50; tree-sitter: `transpose-sexps-function'  uses a lambda in a defvar
  2023-01-09  3:39 ` Yuan Fu
@ 2023-01-09  6:23   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-01-09  6:57     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 7+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-01-09  6:23 UTC (permalink / raw)
  To: Yuan Fu, Mickey Petersen; +Cc: 60654



On 9 January 2023 04:39:34 CET, Yuan Fu <casouri@gmail.com> wrote:
>
>Mickey Petersen <mickey@masteringemacs.org> 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’d Theo.
>
>Yuan

Thanks yuan.

Yeah I'll make this change and call the new function transpose-sexps-default-function.

Apologies for any inconvenience :)

Theo





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#60654: 30.0.50; tree-sitter: `transpose-sexps-function' uses a lambda in a defvar
  2023-01-09  6:23   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-01-09  6:57     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-01-09  8:47       ` Mickey Petersen
  0 siblings, 1 reply; 7+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-01-09  6:57 UTC (permalink / raw)
  To: Yuan Fu, Mickey Petersen; +Cc: 60654

[-- Attachment #1: Type: text/plain, Size: 808 bytes --]

Theodor Thornhill <theo@thornhill.no> writes:

> On 9 January 2023 04:39:34 CET, Yuan Fu <casouri@gmail.com> wrote:
>>
>>Mickey Petersen <mickey@masteringemacs.org> 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’d Theo.
>>
>>Yuan
>
> Thanks yuan.
>
> Yeah I'll make this change and call the new function transpose-sexps-default-function.
>
> Apologies for any inconvenience :)
>
> Theo 


How about this, Mickey.  Is this something you can work with?

Theo


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-named-defun-for-transpose-sexps-default-function.patch --]
[-- Type: text/x-patch, Size: 4355 bytes --]

From 442cb4676d359faf23abb15799338f2025c797cb Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#60654: 30.0.50; tree-sitter: `transpose-sexps-function' uses a lambda in a defvar
  2023-01-09  6:57     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-01-09  8:47       ` Mickey Petersen
  2023-01-09 12:20         ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 7+ messages in thread
From: Mickey Petersen @ 2023-01-09  8:47 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: Yuan Fu, 60654


Theodor Thornhill <theo@thornhill.no> writes:

> Theodor Thornhill <theo@thornhill.no> writes:
>
>> On 9 January 2023 04:39:34 CET, Yuan Fu <casouri@gmail.com> wrote:
>>>
>>>Mickey Petersen <mickey@masteringemacs.org> 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’d Theo.
>>>
>>>Yuan
>>
>> Thanks yuan.
>>
>> Yeah I'll make this change and call the new function transpose-sexps-default-function.
>>
>> Apologies for any inconvenience :)
>>
>> Theo
>
>
> How about this, Mickey.  Is this something you can work with?
>

Looks perfect. Nice one, Theo.

Kind regards,

Mickey.

> Theo
>
> [2. text/x-patch; 0001-Add-named-defun-for-transpose-sexps-default-function.patch]...






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#60654: 30.0.50; tree-sitter: `transpose-sexps-function' uses a lambda in a defvar
  2023-01-09  8:47       ` Mickey Petersen
@ 2023-01-09 12:20         ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 7+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-01-09 12:20 UTC (permalink / raw)
  To: Mickey Petersen; +Cc: Yuan Fu, 60654

Mickey Petersen <mickey@masteringemacs.org> writes:

> Theodor Thornhill <theo@thornhill.no> writes:
>
>> Theodor Thornhill <theo@thornhill.no> writes:
>>
>>> On 9 January 2023 04:39:34 CET, Yuan Fu <casouri@gmail.com> wrote:
>>>>
>>>>Mickey Petersen <mickey@masteringemacs.org> 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’d Theo.
>>>>
>>>>Yuan
>>>
>>> Thanks yuan.
>>>
>>> Yeah I'll make this change and call the new function transpose-sexps-default-function.
>>>
>>> Apologies for any inconvenience :)
>>>
>>> Theo
>>
>>
>> How about this, Mickey.  Is this something you can work with?
>>
>
> Looks perfect. Nice one, Theo.
>
> Kind regards,
>
> Mickey.
>

Great! Yuan, can you install for me?

Theo





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#60654: 30.0.50; tree-sitter: `transpose-sexps-function'  uses a lambda in a defvar
  2023-01-08 10:46 bug#60654: 30.0.50; tree-sitter: `transpose-sexps-function' uses a lambda in a defvar Mickey Petersen
  2023-01-09  3:39 ` Yuan Fu
@ 2023-01-09 20:35 ` Yuan Fu
  1 sibling, 0 replies; 7+ messages in thread
From: Yuan Fu @ 2023-01-09 20:35 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: 60654-done, Mickey Petersen


Theodor Thornhill <theo@thornhill.no> writes:

> Mickey Petersen <mickey@masteringemacs.org> writes:
>
>> Theodor Thornhill <theo@thornhill.no> writes:
>>
>>> Theodor Thornhill <theo@thornhill.no> writes:
>>>
>>>> On 9 January 2023 04:39:34 CET, Yuan Fu <casouri@gmail.com> wrote:
>>>>>
>>>>>Mickey Petersen <mickey@masteringemacs.org> 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’d Theo.
>>>>>
>>>>>Yuan
>>>>
>>>> Thanks yuan.
>>>>
>>>> Yeah I'll make this change and call the new function transpose-sexps-default-function.
>>>>
>>>> Apologies for any inconvenience :)
>>>>
>>>> Theo
>>>
>>>
>>> How about this, Mickey.  Is this something you can work with?
>>>
>>
>> Looks perfect. Nice one, Theo.
>>
>> Kind regards,
>>
>> Mickey.
>>
>
> Great! Yuan, can you install for me?
>
> Theo

Sure, I applied it to trunk.

Yuan





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-01-09 20:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-08 10:46 bug#60654: 30.0.50; tree-sitter: `transpose-sexps-function' uses a lambda in a defvar Mickey Petersen
2023-01-09  3:39 ` Yuan Fu
2023-01-09  6:23   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-09  6:57     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-09  8:47       ` Mickey Petersen
2023-01-09 12:20         ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-09 20:35 ` Yuan Fu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).