unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Suggestion: two new commands: beginning-of-list and end-of-list
@ 2024-09-09 18:32 arthur miller
  2024-09-09 19:11 ` Eli Zaretskii
  2024-09-10 12:05 ` Yuri Khan
  0 siblings, 2 replies; 13+ messages in thread
From: arthur miller @ 2024-09-09 18:32 UTC (permalink / raw)
  To: emacs-devel@gnu.org


[-- Attachment #1.1: Type: text/plain, Size: 3165 bytes --]

In elisp-mode.el, there is a function, IMO somewhat unfortunately named
"elisp--beginning-of-sexp".  What this function does is to place cursor at the
beginning of the innermost list, which we can perhaps call more conveniently,
"current list".

The function does so always, and is relatively well written, minor the case when
the cursor is placed in a literal string or outside a symbolic expression, say
between two top-level forms. In those cases, it jumps into the first string
before the current string, which might be anywhere in the file prior to the
current string, or to the beginning of the file.

I took me a liberty to rename this function and update the doc to a more
appropriate wording, and turn it into a command. I have also patched the
above mentioned cases when it is invoked in a literal string or outside of
 an expression.

As another consideration, I have moved this function into lisp.el (in
lisp/emacs-lisp/) in the sources.  It does not look like it has nothing
particularly specific to EmacsLisp per se, seems like it should work on any
"parenthesis"-language. I have tested it successfully in both CommonLisp and
EmacsLisp files.

I found only one user of elisp--beginning-of-sexp in the entire Emacs, and that
is the function directly above: elisp--fnsym-in-current-sexp.

Emacs already has few functions for motion over lists and symbolic expressions,
but actually not the one that places the cursor at the beginning of a list. I
think people use "lispy" to move several sexps at a time or cook their own via
paredit to move to the end of a list or beginning of a list. At least what I
have seen in some SX posts when looking around after I made the patch. I don't
 even have one myself, I use either C-f/b to move by words or paredit-forward to
move one expression at a time.

IMO it is a pitty to leave "elisp--beginning-of-sexp" underused, when it can
 perhaps be more useful to someone, so I suggest this little "re-furntituring" as a
 small quality-of-life improvement for Lisp programmers.

Of course, if there is a beginning-of-list, there should be end-of-list too? I
have prototyped one hastly, which just inverts the condition (works), but the
 proper  way would be to refactor out the common code and do the argument
 handling similar as in forward-sexp, or something like that.

TBH I am not sure how generally useful this is (it is to me), but if it is an
acceptable change, I can refactor out the common code, and format the patch
according to Emacs style, with NEWS entry and perhaps some tests (I tested
interactively only).

As extra chatter: a symbolic expression is either atom (non consp such as
literals or symbols) or a list:

> 1. Atomic symbols are S-expressions.
> 2. If e1 and e2 are S-expressions, so is (e1 . e2).

From the "Recursive Functions of Symbolic Expressions" by J. McCarthy (the paper
freely available online).

Thus elisp--beginning-of-sexp, is really a misnomer considering what it
does. Also, Emacs already has a function that actually does move cursor to the
beginning of a sexp, (forward-sexp -1) does it, and it does it correctly.

[-- Attachment #1.2: Type: text/html, Size: 10122 bytes --]

[-- Attachment #2: 0001-beginning-end-of-list.patch --]
[-- Type: application/octet-stream, Size: 4065 bytes --]

From 920174b47f19a3604e4978a8232d0703d4c53b79 Mon Sep 17 00:00:00 2001
From: arthur <arthur.miller@live.com>
Date: Mon, 9 Sep 2024 20:17:47 +0200
Subject: [PATCH] beginning/end-of-list

---
 lisp/emacs-lisp/lisp.el      | 60 ++++++++++++++++++++++++++++++++++++
 lisp/progmodes/elisp-mode.el | 26 +---------------
 2 files changed, 61 insertions(+), 25 deletions(-)

diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index e65eec508d9..89c4cdde494 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -296,6 +296,66 @@ up-list
               (signal (car err) (cdr err)))))))
       (setq arg (- arg inc)))))
 
+(defun beginning-of-list ()
+  "Move cursor to the beginning of current list.
+
+Return the number of nested expressions the point was over or after."
+  (interactive)
+  (let ((parse-sexp-ignore-comments t)
+	(num-skipped-sexps 0)
+        (syntax (syntax-ppss)))
+    (unless (= 0 (nth 0 syntax)) ;; not in a list
+      (when (nth 3 syntax) ;; in a string
+        (goto-char (nth 8 syntax)))
+      (condition-case _
+	  (progn
+	    ;; First account for the case the point is directly over a
+	    ;; beginning of a nested sexp.
+	    (condition-case _
+	        (let ((p (point)))
+		  (forward-sexp -1)
+		  (forward-sexp 1)
+		  (when (< (point) p)
+		    (setq num-skipped-sexps 1)))
+	      (error))
+	    (while
+	        (let ((p (point)))
+		  (forward-sexp -1)
+		  (when (< (point) p)
+		    (setq num-skipped-sexps (1+ num-skipped-sexps))))))
+        (error)))
+    num-skipped-sexps))
+
+(defun end-of-list ()
+  "Move cursor to the end of current list.
+
+Return the number of nested expressions the point was over or after."
+  (interactive)
+  (let ((parse-sexp-ignore-comments t)
+	(num-skipped-sexps 0)
+        (syntax (syntax-ppss)))
+    (unless (= 0 (nth 0 syntax)) ;; not in a list
+      (when (nth 3 syntax) ;; in a string
+        (goto-char (nth 8 syntax)))
+      (condition-case _
+	  (progn
+	    ;; First account for the case the point is directly over a
+	    ;; beginning of a nested sexp.
+	    (condition-case _
+	        (let ((p (point)))
+		  (forward-sexp 1)
+		  (forward-sexp -1)
+		  (when (> (point) p)
+		    (setq num-skipped-sexps 1)))
+	      (error))
+	    (while
+	        (let ((p (point)))
+		  (forward-sexp 1)
+		  (when (> (point) p)
+		    (setq num-skipped-sexps (1+ num-skipped-sexps))))))
+        (error)))
+    num-skipped-sexps))
+
 (defun kill-sexp (&optional arg interactive)
   "Kill the sexp (balanced expression) following point.
 With ARG, kill that many sexps after point.
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 9bf6f9217c8..7345301d2e5 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -2042,36 +2042,12 @@ elisp--docstring-first-line
 (defun elisp--fnsym-in-current-sexp ()
   (save-excursion
     (unless (nth 8 (syntax-ppss))
-      (let ((argument-index (1- (elisp--beginning-of-sexp))))
+      (let ((argument-index (1- (beginning-of-list))))
         ;; If we are at the beginning of function name, this will be -1.
         (when (< argument-index 0)
           (setq argument-index 0))
         (list (elisp--current-symbol) argument-index)))))
 
-;; Move to the beginning of current sexp.  Return the number of nested
-;; sexp the point was over or after.
-(defun elisp--beginning-of-sexp ()
-  (let ((parse-sexp-ignore-comments t)
-	(num-skipped-sexps 0))
-    (condition-case _
-	(progn
-	  ;; First account for the case the point is directly over a
-	  ;; beginning of a nested sexp.
-	  (condition-case _
-	      (let ((p (point)))
-		(forward-sexp -1)
-		(forward-sexp 1)
-		(when (< (point) p)
-		  (setq num-skipped-sexps 1)))
-	    (error))
-	  (while
-	      (let ((p (point)))
-		(forward-sexp -1)
-		(when (< (point) p)
-		  (setq num-skipped-sexps (1+ num-skipped-sexps))))))
-      (error))
-    num-skipped-sexps))
-
 ;; returns nil unless current word is an interned symbol.
 (defun elisp--current-symbol ()
   (let ((c (char-after (point))))
-- 
2.46.0


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

* Re: Suggestion: two new commands: beginning-of-list and end-of-list
  2024-09-09 18:32 Suggestion: two new commands: beginning-of-list and end-of-list arthur miller
@ 2024-09-09 19:11 ` Eli Zaretskii
  2024-09-09 19:41   ` Sv: " arthur miller
  2024-09-10 12:05 ` Yuri Khan
  1 sibling, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2024-09-09 19:11 UTC (permalink / raw)
  To: arthur miller; +Cc: emacs-devel

> From: arthur miller <arthur.miller@live.com>
> Date: Mon, 9 Sep 2024 18:32:33 +0000
> 
> In elisp-mode.el, there is a function, IMO somewhat unfortunately named
> "elisp--beginning-of-sexp".  What this function does is to place cursor at the
> beginning of the innermost list, which we can perhaps call more conveniently,
> "current list".
> 
> The function does so always, and is relatively well written, minor the case when
> the cursor is placed in a literal string or outside a symbolic expression, say
> between two top-level forms. In those cases, it jumps into the first string
> before the current string, which might be anywhere in the file prior to the
> current string, or to the beginning of the file.
> 
> I took me a liberty to rename this function and update the doc to a more
> appropriate wording, and turn it into a command. I have also patched the 
> above mentioned cases when it is invoked in a literal string or outside of
>  an expression.
> 
> As another consideration, I have moved this function into lisp.el (in
> lisp/emacs-lisp/) in the sources.  It does not look like it has nothing
> particularly specific to EmacsLisp per se, seems like it should work on any
> "parenthesis"-language. I have tested it successfully in both CommonLisp and
> EmacsLisp files.
> 
> I found only one user of elisp--beginning-of-sexp in the entire Emacs, and that
> is the function directly above: elisp--fnsym-in-current-sexp.
> 
> Emacs already has few functions for motion over lists and symbolic expressions,
> but actually not the one that places the cursor at the beginning of a list.

I think we do have it: C-M-u, backward-up-list.  What's more, it works
not only in Lisp.  I use it all the time.

So I wonder why we need another function that does basically the same.

Thanks.



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

* Sv: Suggestion: two new commands: beginning-of-list and end-of-list
  2024-09-09 19:11 ` Eli Zaretskii
@ 2024-09-09 19:41   ` arthur miller
  2024-09-09 19:41     ` arthur miller
                       ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: arthur miller @ 2024-09-09 19:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel@gnu.org

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

>> but actually not the one that places the cursor at the beginning of a list.
>
>I think we do have it: C-M-u, backward-up-list.  What's more, it works
>not only in Lisp.  I use it all the time.

Yes you have. It works slightly differently when you are in a string, and it
places cursor before the opening parenthesis, not after.

>So I wonder why we need another function that does basically the same.

I think it makes sense to keep backward-up-list as it is, since it handles
literal strings as it does. But the behaviour is controlled via special vars
esape-strings and no-syntax-crossing. If we want similar command as
beginning-of-string, we have to wrap it and let-bind those variables to
change how it works.

I am not sure, what is a symmetric function to move cursor to the end of list?

But as said in the previous mail: this function is *already* in Emacs, so it is
already taking the memory in the process.  It is just not used more than
once, and have *potential* to be used more. In other words, I suggest these
two functions as a convenience, not because it is impossible to do something
similar via some combination of other commands and variables.

By the way, why did all occasions of the word "expression" ended up surroneded
with underscores in the online archive?
________________________________
Från: Eli Zaretskii <eliz@gnu.org>
Skickat: den 9 september 2024 21:11
Till: arthur miller <arthur.miller@live.com>
Kopia: emacs-devel@gnu.org <emacs-devel@gnu.org>
Ämne: Re: Suggestion: two new commands: beginning-of-list and end-of-list

> From: arthur miller <arthur.miller@live.com>
> Date: Mon, 9 Sep 2024 18:32:33 +0000
>
> In elisp-mode.el, there is a function, IMO somewhat unfortunately named
> "elisp--beginning-of-sexp".  What this function does is to place cursor at the
> beginning of the innermost list, which we can perhaps call more conveniently,
> "current list".
>
> The function does so always, and is relatively well written, minor the case when
> the cursor is placed in a literal string or outside a symbolic expression, say
> between two top-level forms. In those cases, it jumps into the first string
> before the current string, which might be anywhere in the file prior to the
> current string, or to the beginning of the file.
>
> I took me a liberty to rename this function and update the doc to a more
> appropriate wording, and turn it into a command. I have also patched the
> above mentioned cases when it is invoked in a literal string or outside of
>  an expression.
>
> As another consideration, I have moved this function into lisp.el (in
> lisp/emacs-lisp/) in the sources.  It does not look like it has nothing
> particularly specific to EmacsLisp per se, seems like it should work on any
> "parenthesis"-language. I have tested it successfully in both CommonLisp and
> EmacsLisp files.
>
> I found only one user of elisp--beginning-of-sexp in the entire Emacs, and that
> is the function directly above: elisp--fnsym-in-current-sexp.
>
> Emacs already has few functions for motion over lists and symbolic expressions,
> but actually not the one that places the cursor at the beginning of a list.

I think we do have it: C-M-u, backward-up-list.  What's more, it works
not only in Lisp.  I use it all the time.

So I wonder why we need another function that does basically the same.

Thanks.

[-- Attachment #2: Type: text/html, Size: 7445 bytes --]

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

* Sv: Suggestion: two new commands: beginning-of-list and end-of-list
  2024-09-09 19:41   ` Sv: " arthur miller
@ 2024-09-09 19:41     ` arthur miller
  2024-09-10 11:30     ` Eli Zaretskii
  2024-09-11  3:17     ` Sv: " Karthik Chikmagalur
  2 siblings, 0 replies; 13+ messages in thread
From: arthur miller @ 2024-09-09 19:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel@gnu.org

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

I meant beginning-of-list, not beginning-of-string, was a lapsus.
________________________________
Från: arthur miller <arthur.miller@live.com>
Skickat: den 9 september 2024 21:41
Till: Eli Zaretskii <eliz@gnu.org>
Kopia: emacs-devel@gnu.org <emacs-devel@gnu.org>
Ämne: Sv: Suggestion: two new commands: beginning-of-list and end-of-list

>> but actually not the one that places the cursor at the beginning of a list.
>
>I think we do have it: C-M-u, backward-up-list.  What's more, it works
>not only in Lisp.  I use it all the time.

Yes you have. It works slightly differently when you are in a string, and it
places cursor before the opening parenthesis, not after.

>So I wonder why we need another function that does basically the same.

I think it makes sense to keep backward-up-list as it is, since it handles
literal strings as it does. But the behaviour is controlled via special vars
esape-strings and no-syntax-crossing. If we want similar command as
beginning-of-string, we have to wrap it and let-bind those variables to
change how it works.

I am not sure, what is a symmetric function to move cursor to the end of list?

But as said in the previous mail: this function is *already* in Emacs, so it is
already taking the memory in the process.  It is just not used more than
once, and have *potential* to be used more. In other words, I suggest these
two functions as a convenience, not because it is impossible to do something
similar via some combination of other commands and variables.

By the way, why did all occasions of the word "expression" ended up surroneded
with underscores in the online archive?
________________________________
Från: Eli Zaretskii <eliz@gnu.org>
Skickat: den 9 september 2024 21:11
Till: arthur miller <arthur.miller@live.com>
Kopia: emacs-devel@gnu.org <emacs-devel@gnu.org>
Ämne: Re: Suggestion: two new commands: beginning-of-list and end-of-list

> From: arthur miller <arthur.miller@live.com>
> Date: Mon, 9 Sep 2024 18:32:33 +0000
>
> In elisp-mode.el, there is a function, IMO somewhat unfortunately named
> "elisp--beginning-of-sexp".  What this function does is to place cursor at the
> beginning of the innermost list, which we can perhaps call more conveniently,
> "current list".
>
> The function does so always, and is relatively well written, minor the case when
> the cursor is placed in a literal string or outside a symbolic expression, say
> between two top-level forms. In those cases, it jumps into the first string
> before the current string, which might be anywhere in the file prior to the
> current string, or to the beginning of the file.
>
> I took me a liberty to rename this function and update the doc to a more
> appropriate wording, and turn it into a command. I have also patched the
> above mentioned cases when it is invoked in a literal string or outside of
>  an expression.
>
> As another consideration, I have moved this function into lisp.el (in
> lisp/emacs-lisp/) in the sources.  It does not look like it has nothing
> particularly specific to EmacsLisp per se, seems like it should work on any
> "parenthesis"-language. I have tested it successfully in both CommonLisp and
> EmacsLisp files.
>
> I found only one user of elisp--beginning-of-sexp in the entire Emacs, and that
> is the function directly above: elisp--fnsym-in-current-sexp.
>
> Emacs already has few functions for motion over lists and symbolic expressions,
> but actually not the one that places the cursor at the beginning of a list.

I think we do have it: C-M-u, backward-up-list.  What's more, it works
not only in Lisp.  I use it all the time.

So I wonder why we need another function that does basically the same.

Thanks.

[-- Attachment #2: Type: text/html, Size: 8141 bytes --]

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

* Re: Suggestion: two new commands: beginning-of-list and end-of-list
  2024-09-09 19:41   ` Sv: " arthur miller
  2024-09-09 19:41     ` arthur miller
@ 2024-09-10 11:30     ` Eli Zaretskii
  2024-09-10 15:10       ` Sv: " arthur miller
  2024-09-11  3:17     ` Sv: " Karthik Chikmagalur
  2 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2024-09-10 11:30 UTC (permalink / raw)
  To: arthur miller; +Cc: emacs-devel

> From: arthur miller <arthur.miller@live.com>
> CC: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
> Date: Mon, 9 Sep 2024 19:41:12 +0000
> msip_labels:
> 
> >I think we do have it: C-M-u, backward-up-list.  What's more, it works
> >not only in Lisp.  I use it all the time.
> 
> Yes you have. It works slightly differently when you are in a string, and it
> places cursor before the opening parenthesis, not after.

Right.  But I think what it does is very useful, since it can be
invoked repeatedly, each time moving up one level.

> >So I wonder why we need another function that does basically the same.
> 
> I think it makes sense to keep backward-up-list as it is, since it handles
> literal strings as it does. But the behaviour is controlled via special vars
> esape-strings and no-syntax-crossing. If we want similar command as
> beginning-of-string, we have to wrap it and let-bind those variables to
> change how it works.

Yes, but is that a problem?

> I am not sure, what is a symmetric function to move cursor to the end of list?

The converse of C-M-u is C-M-d, but it doesn't move to the end of a
list, it moves _inside_ one level.

> But as said in the previous mail: this function is *already* in Emacs, so it is
> already taking the memory in the process.  It is just not used more than
> once, and have *potential* to be used more. In other words, I suggest these
> two functions as a convenience, not because it is impossible to do something
> similar via some combination of other commands and variables.

It is IME confusing to have two similar functions that do _almost_ the
same job.

What do others think about this?

> By the way, why did all occasions of the word "expression" ended up surroneded
> with underscores in the online archive?

No idea.



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

* Re: Suggestion: two new commands: beginning-of-list and end-of-list
  2024-09-09 18:32 Suggestion: two new commands: beginning-of-list and end-of-list arthur miller
  2024-09-09 19:11 ` Eli Zaretskii
@ 2024-09-10 12:05 ` Yuri Khan
  1 sibling, 0 replies; 13+ messages in thread
From: Yuri Khan @ 2024-09-10 12:05 UTC (permalink / raw)
  To: arthur miller; +Cc: emacs-devel@gnu.org

On Tue, 10 Sept 2024 at 02:00, arthur miller <arthur.miller@live.com> wrote:

> Of course, if there is a beginning-of-list, there should be end-of-list too? I
> have prototyped one hastly, which just inverts the condition (works), but the
>  proper  way would be to refactor out the common code and do the argument
>  handling similar as in forward-sexp, or something like that.

You might be interested in sp-beginning-of-sexp, sp-end-of-sexp and
other navigation commands defined in smartparens.



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

* Sv: Suggestion: two new commands: beginning-of-list and end-of-list
  2024-09-10 11:30     ` Eli Zaretskii
@ 2024-09-10 15:10       ` arthur miller
  2024-09-10 15:48         ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: arthur miller @ 2024-09-10 15:10 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel@gnu.org

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

>> >I think we do have it: C-M-u, backward-up-list.  What's more, it works
>> >not only in Lisp.  I use it all the time.
>>
>> Yes you have. It works slightly differently when you are in a string, and it
>> places cursor before the opening parenthesis, not after.
>
>Right.  But I think what it does is very useful, since it can be
>invoked repeatedly, each time moving up one level.

We are in agreement about backward-up-list being useful, that was never
in question.

>> >So I wonder why we need another function that does basically the same.
>>
>> I think it makes sense to keep backward-up-list as it is, since it handles
>> literal strings as it does. But the behaviour is controlled via special vars
>> esape-strings and no-syntax-crossing. If we want similar command as
>> beginning-of-string, we have to wrap it and let-bind those variables to
>> change how it works.
>
>Yes, but is that a problem?

Everyone who would like to customize it has to write their own. That is
why I say it is convenience. I didn't say it is revolutionary, or that it
replaces something else. But you skip to press C-f after
backward-up-list. As a note, it will work about the same in C code as
backward-up-list. I haven't tested extensively, just a bit. It uses same
primitives as backward-up-list, so it is not surprising.

There are less useful things, even easier to wrap up than this, but ship
with Emacs for user convenience.

>> I am not sure, what is a symmetric function to move cursor to the end of list?
>
>The converse of C-M-u is C-M-d, but it doesn't move to the end of a
>list, it moves _inside_ one level.

Down-list? I don't think it is close to the end-of-list. In some
situations you would clearly prefer down-list in others end-of-list. I
don't think they compete.

>> But as said in the previous mail: this function is *already* in Emacs, so it is
>> already taking the memory in the process.  It is just not used more than
>> once, and have *potential* to be used more. In other words, I suggest these
>> two functions as a convenience, not because it is impossible to do something
>> similar via some combination of other commands and variables.
>
>It is IME confusing to have two similar functions that do _almost_ the
>same job.

I understand your point, but I am not sure it is confusing. I think the
name is quite different. There is also a symmetri with other functions,
there are several beginning-of-* and end-of-* functions in lisp.el. If
someone is new, it might be easier to discover beginning-of-list and
understand what it doew, than backward-up-list and realize they can use
it for the same purpose if they just click a bit more. The most
important argument is that the function is included, I have basically
just renamed it.

As mentioned, people are speaking about Lispy and Yuri mentions
Smartparens by the same author. Obviously other people do find something
similar to this convenient. Paredit does not have something directly
same (or I have missed it).
________________________________
Från: Eli Zaretskii <eliz@gnu.org>
Skickat: den 10 september 2024 13:30
Till: arthur miller <arthur.miller@live.com>
Kopia: emacs-devel@gnu.org <emacs-devel@gnu.org>
Ämne: Re: Suggestion: two new commands: beginning-of-list and end-of-list

> From: arthur miller <arthur.miller@live.com>
> CC: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
> Date: Mon, 9 Sep 2024 19:41:12 +0000
> msip_labels:
>
> >I think we do have it: C-M-u, backward-up-list.  What's more, it works
> >not only in Lisp.  I use it all the time.
>
> Yes you have. It works slightly differently when you are in a string, and it
> places cursor before the opening parenthesis, not after.

Right.  But I think what it does is very useful, since it can be
invoked repeatedly, each time moving up one level.

> >So I wonder why we need another function that does basically the same.
>
> I think it makes sense to keep backward-up-list as it is, since it handles
> literal strings as it does. But the behaviour is controlled via special vars
> esape-strings and no-syntax-crossing. If we want similar command as
> beginning-of-string, we have to wrap it and let-bind those variables to
> change how it works.

Yes, but is that a problem?

> I am not sure, what is a symmetric function to move cursor to the end of list?

The converse of C-M-u is C-M-d, but it doesn't move to the end of a
list, it moves _inside_ one level.

> But as said in the previous mail: this function is *already* in Emacs, so it is
> already taking the memory in the process.  It is just not used more than
> once, and have *potential* to be used more. In other words, I suggest these
> two functions as a convenience, not because it is impossible to do something
> similar via some combination of other commands and variables.

It is IME confusing to have two similar functions that do _almost_ the
same job.

What do others think about this?

> By the way, why did all occasions of the word "expression" ended up surroneded
> with underscores in the online archive?

No idea.

[-- Attachment #2: Type: text/html, Size: 12896 bytes --]

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

* Re: Suggestion: two new commands: beginning-of-list and end-of-list
  2024-09-10 15:10       ` Sv: " arthur miller
@ 2024-09-10 15:48         ` Eli Zaretskii
  2024-09-11  5:39           ` Sv: " arthur miller
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2024-09-10 15:48 UTC (permalink / raw)
  To: arthur miller; +Cc: emacs-devel

> From: arthur miller <arthur.miller@live.com>
> CC: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
> Date: Tue, 10 Sep 2024 15:10:26 +0000
> 
> >> I think it makes sense to keep backward-up-list as it is, since it handles
> >> literal strings as it does. But the behaviour is controlled via special vars
> >> esape-strings and no-syntax-crossing. If we want similar command as
> >> beginning-of-string, we have to wrap it and let-bind those variables to
> >> change how it works.
> >
> >Yes, but is that a problem?
> 
> Everyone who would like to customize it has to write their own.

Why would someone want to customize a command that does its job well?

> >The converse of C-M-u is C-M-d, but it doesn't move to the end of a
> >list, it moves _inside_ one level.
> 
> Down-list? I don't think it is close to the end-of-list.

Try it on a deeply-nested list, and you will see the difference.



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

* Re: Sv: Suggestion: two new commands: beginning-of-list and end-of-list
  2024-09-09 19:41   ` Sv: " arthur miller
  2024-09-09 19:41     ` arthur miller
  2024-09-10 11:30     ` Eli Zaretskii
@ 2024-09-11  3:17     ` Karthik Chikmagalur
  2024-09-11  5:48       ` Sv: " arthur miller
  2 siblings, 1 reply; 13+ messages in thread
From: Karthik Chikmagalur @ 2024-09-11  3:17 UTC (permalink / raw)
  To: arthur miller, Eli Zaretskii; +Cc: emacs-devel@gnu.org

> I think it makes sense to keep backward-up-list as it is, since it handles
> literal strings as it does. But the behaviour is controlled via special vars
> esape-strings and no-syntax-crossing. If we want similar command as
> beginning-of-string, we have to wrap it and let-bind those variables to
> change how it works.
>
> I am not sure, what is a symmetric function to move cursor to the end of list?

If I'm understanding your question correctly: `up-list'  moves the
cursor to the end of the list and out of it, the same way
`backward-up-list' moves it to the beginning and up.



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

* Sv: Suggestion: two new commands: beginning-of-list and end-of-list
  2024-09-10 15:48         ` Eli Zaretskii
@ 2024-09-11  5:39           ` arthur miller
  2024-09-12  4:24             ` Emanuel Berg
  0 siblings, 1 reply; 13+ messages in thread
From: arthur miller @ 2024-09-11  5:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel@gnu.org

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

>> >> I think it makes sense to keep backward-up-list as it is, since it handles
>> >> literal strings as it does. But the behaviour is controlled via special vars
>> >> esape-strings and no-syntax-crossing. If we want similar command as
>> >> beginning-of-string, we have to wrap it and let-bind those variables to
>> >> change how it works.
>> >
>> >Yes, but is that a problem?
>>
>> Everyone who would like to customize it has to write their own.
>
>Why would someone want to customize a command that does its job well?

What kind of question is that? You are asking why would someone want to
customize Emacs? :-)

Obviously people have written packages to do something similar. Small
conventience might matter to people. With backward-up-list you have to
press at least one more time, or if you are in a doc string you have to
invoke it again.

>> Down-list? I don't think it is close to the end-of-list.
>
>Try it on a deeply-nested list, and you will see the difference.

Down list vill move you to the beginning of next list, not the end of a
list, it is a drastic difference, not comparable by any means:

(defun end-of-list ()
  "Move cursor to the beginning of current list.

Return the number of nested expressions the point was over or after."
  (interactive)
  (let ((parse-sexp-ignore-comments t)
      (num-skipped-sexps 0)
        (syntax (syntax-ppss)))| <- cursor before
    (unless (= 0 (nth 0 syntax)) ;; not in a list
      (when (nth 3 syntax) ;; in string
        (goto-char (nth 8 syntax)))
      (ignore-errors
        (progn
          ;; First account for the case the point is directly over a
          ;; beginning of a nested sexp.
          (ignore-errors
              (let ((p (point)))
              (forward-sexp 1)
              (forward-sexp -1)
              (when (> (point) p)
                (setq num-skipped-sexps 1))))
          (while
              (let ((p (point)))
              (forward-sexp 1)
              (when (> (point) p)
                (setq num-skipped-sexps (1+ num-skipped-sexps))))))))
    num-skipped-sexps))

Down-list puts cursor after the next open parenthesis: (|unless (= 0 ...
End-of-list puts cursor before the closing parenthesis of the let:

                   ( ... )
                (setq num-skipped-sexps (1+ num-skipped-sexps))))))))
    num-skipped-sexps|)) <-- cursor after the end-of-list

However, as Karthink pointed out up-list places cursor to the closing let
parenthesis so it is close, similar to backward-up-list, one C-b press
away from the end of a list, and it also handles the literal strings the
same way as backward-up-list (puts cursor after the closing string
quote). Btw, I wasn't using myself up-list, I was manipulating my cursor
by other means :).

Anyway, I still think it is an improvement to rename at least
elisp--beginning-of-sexp, to beginning-of-list.

Personally I also think beginning-of-list and end-of-list are slightly
more convenient and the connection between the name and what they do is
much more clear than backward-up-list and up-list. It might be just me,
I admit that one, at least I wasn't using those myself even though I
knew about them by the name. Obviously people who are using smartparens
are thinking similar (paredit does not have this either). Do a web
search and you will see questions on SX asking "how do I move cursor to
the end of list", and you will see Drew teaching them "you wish to move
out of list, up-list does that".

I don't understand why this response if I wish to add a small
convenience for users (and myself admittedly). There are so many other
small wrappers included in Emacs that does much less.
________________________________
Från: Eli Zaretskii <eliz@gnu.org>
Skickat: den 10 september 2024 17:48
Till: arthur miller <arthur.miller@live.com>
Kopia: emacs-devel@gnu.org <emacs-devel@gnu.org>
Ämne: Re: Suggestion: two new commands: beginning-of-list and end-of-list

> From: arthur miller <arthur.miller@live.com>
> CC: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
> Date: Tue, 10 Sep 2024 15:10:26 +0000
>
> >> I think it makes sense to keep backward-up-list as it is, since it handles
> >> literal strings as it does. But the behaviour is controlled via special vars
> >> esape-strings and no-syntax-crossing. If we want similar command as
> >> beginning-of-string, we have to wrap it and let-bind those variables to
> >> change how it works.
> >
> >Yes, but is that a problem?
>
> Everyone who would like to customize it has to write their own.

Why would someone want to customize a command that does its job well?

> >The converse of C-M-u is C-M-d, but it doesn't move to the end of a
> >list, it moves _inside_ one level.
>
> Down-list? I don't think it is close to the end-of-list.

Try it on a deeply-nested list, and you will see the difference.

[-- Attachment #2: Type: text/html, Size: 15440 bytes --]

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

* Sv: Sv: Suggestion: two new commands: beginning-of-list and end-of-list
  2024-09-11  3:17     ` Sv: " Karthik Chikmagalur
@ 2024-09-11  5:48       ` arthur miller
  0 siblings, 0 replies; 13+ messages in thread
From: arthur miller @ 2024-09-11  5:48 UTC (permalink / raw)
  To: Karthik Chikmagalur, Eli Zaretskii; +Cc: emacs-devel@gnu.org

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

>> I think it makes sense to keep backward-up-list as it is, since it handles
>> literal strings as it does. But the behaviour is controlled via special vars
>> esape-strings and no-syntax-crossing. If we want similar command as
>> beginning-of-string, we have to wrap it and let-bind those variables to
>> change how it works.
>>
>> I am not sure, what is a symmetric function to move cursor to the end of list?
>
>If I'm understanding your question correctly: `up-list'  moves the
>cursor to the end of the list and out of it, the same way
>`backward-up-list' moves it to the beginning and up.

Indeed, I don't know where my brain was :). I don't use myself
functions, I am typically moving my cursor by other means.

up-list also treats literal strings the same as backward-up-list, places
cursor after the closing parenthesis, so both up-list/end-of-list are
useful in different contexts.
________________________________
Från: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Skickat: den 11 september 2024 05:17
Till: arthur miller <arthur.miller@live.com>; Eli Zaretskii <eliz@gnu.org>
Kopia: emacs-devel@gnu.org <emacs-devel@gnu.org>
Ämne: Re: Sv: Suggestion: two new commands: beginning-of-list and end-of-list

> I think it makes sense to keep backward-up-list as it is, since it handles
> literal strings as it does. But the behaviour is controlled via special vars
> esape-strings and no-syntax-crossing. If we want similar command as
> beginning-of-string, we have to wrap it and let-bind those variables to
> change how it works.
>
> I am not sure, what is a symmetric function to move cursor to the end of list?

If I'm understanding your question correctly: `up-list'  moves the
cursor to the end of the list and out of it, the same way
`backward-up-list' moves it to the beginning and up.

[-- Attachment #2: Type: text/html, Size: 4523 bytes --]

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

* Re: Suggestion: two new commands: beginning-of-list and end-of-list
  2024-09-11  5:39           ` Sv: " arthur miller
@ 2024-09-12  4:24             ` Emanuel Berg
  0 siblings, 0 replies; 13+ messages in thread
From: Emanuel Berg @ 2024-09-12  4:24 UTC (permalink / raw)
  To: emacs-devel

arthur miller wrote:

> Small conventience might matter to people.
> With backward-up-list you have to press at least one more
> time, or if you are in a doc string you have to invoke
> it again.

`1+'

Small or big, that's up to anyone to decide. We take it.

Emacs including Emacs Lisp has had a huge problem and has it
still, and that is to neglect simple, small things.

If one is falling behind the most advanced because of reasons
that are legit - we have no resources, no developers,
incompatible license etc etc - then that's okay, if it can't
happen it can't happen.

What one does in a such a situation tho is, because one cannot
focus on what one cannot do, instead focus is what can be
done, cover all the basics, polish, let it shine, enjoy.
But that also don't happen :( We have had far to little
respect for that, I don't know why.

For example, I have 193 lines of config for Dired. Cool, you
think, what fancy extensions are those, you think? Answer:
stuff that dired should have had ages ago. E.g.

(defun dired-first-file ()
  (interactive)
  (goto-char (point-min))
  (dired-next-line 1)
  (recenter))

(defun dired-last-file ()
  (interactive)
  (goto-char (point-max))
  (dired-next-line -1)
  (recenter -2))

or

(defun dired-kill-path-dwim ()
  (interactive)
  (kill-new
    (or (dired-get-filename nil t)  ; kill file path
        (dired-current-directory))) ; or dir path
  (echo-kill))

or

(defun dired-toggle-mark ()
  (interactive)
  (if (= dired-marker-char (char-after (pos-bol)))
      (dired-unmark 1)
    (dired-mark 1)))

[ Maybe nowadays dired has support for some of that,
  I don't know. Full source with 16 `defun': 

  https://dataswamp.org/~incal/emacs-init/dired-incal.el ]

(Note: I like dired but am absolutely no fan of it, not
a single line of Elisp has been added because of love for
dired or the desire to spend time with it any more
than necessary.)

So while it is okay to fall behind, like it is okay to loose
a game of hockey, it isn't okay to just put the skates on the
ice and play without heart.

The developers should maybe rethink their attitude. To have
10 000+ commits, yet basic functions are not included? I don't
understand how that is even possible?

Speed, ergonomics and convenience in _everything_.
Youngers don't read manual (most of them), they expect
everything to be great day 1. And why not? In a way I agree.
and 2) senior citizens cannot or have no time, mental
discipline to acquire vast new skills. And as for professional
IT people - what they need is actually the same, speed,
ergonomics, convenience, because they need to be productive
(and also enjoy/being able to work with the software all day
every day).

For GNU Emacs to stay relevant, we must be (almost) as
intuitive, well-integrated and problem-free as smartphone apps
_but also_ (almost) as productive as other software, including
solutions that are expensive/specialized in nature, so
therefor has a head start with backing from the
corporate world.

1) Cut all the corners wherever possible, one-keystroke
interface when typing doesn't happen, as short-and-clos as
possible all other keystrokes. Has a new window (pane) opened?
Not only go their with point, go there with point _and_ move
it to the first button, so they user immediately can do RET.

Streamline everything, cut corners for real with technology -
don't rely on mere humans to implement human-invented
conventions,

;; this is a mail

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Suggestion: two new commands: beginning-of-list and end-of-list
@ 2024-09-13 13:30 arthur miller
  0 siblings, 0 replies; 13+ messages in thread
From: arthur miller @ 2024-09-13 13:30 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: emacs-devel@gnu.org

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

>> Small conventience might matter to people.
>> With backward-up-list you have to press at least one more
>> time, or if you are in a doc string you have to invoke
>> it again.
> ( ... )
>Small or big, that's up to anyone to decide. We take it.
>
>Emacs including Emacs Lisp has had a huge problem and has it
>still, and that is to neglect simple, small things.
>
>  ( ... )
>
>Speed, ergonomics and convenience in _everything_.
>Youngers don't read manual (most of them), they expect
>everything to be great day 1. And why not? In a way I agree.
>and 2) senior citizens cannot or have no time, mental
>discipline to acquire vast new skills. And as for professional
>IT people - what they need is actually the same, speed,
>ergonomics, convenience, because they need to be productive
>(and also enjoy/being able to work with the software all day
>every day).
>
>  ( ... )
>
>Streamline everything, cut corners for real with technology -
>don't rely on mere humans to implement human-invented
>conventions,

Sorry for cutting up a bit, I think it was well-formulated by you.
You are on the point most of the time. I just shortened a bit to
underline the most important points you made (in my opinions).

At least looking from the online questions, I think you are correct
about people either just looking at completion options, and probably
not reading the manual. I think for many users even something as
simple as this would be an improvement in Emacs:

(defun beginning-of-list ()
  "Move cursor to the beginning of current list."
  (interactive)
  (call-interactively #'backward-up-list)
  (forward-char))

(defun end-of-list ()
  "Move cursor to the end of current list"
  (interactive)
  (call-interactively #'up-list)
  (backward-char))

The naming is more descriptive of what commands do, and they automate
something. Automation is good, computers should do the work for humans
not the other way around. I would though argue that the other definition
of beginning/end-of-list are more convenient since they properly jump
out of the literal strings .

[-- Attachment #2: Type: text/html, Size: 8504 bytes --]

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

end of thread, other threads:[~2024-09-13 13:30 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-09 18:32 Suggestion: two new commands: beginning-of-list and end-of-list arthur miller
2024-09-09 19:11 ` Eli Zaretskii
2024-09-09 19:41   ` Sv: " arthur miller
2024-09-09 19:41     ` arthur miller
2024-09-10 11:30     ` Eli Zaretskii
2024-09-10 15:10       ` Sv: " arthur miller
2024-09-10 15:48         ` Eli Zaretskii
2024-09-11  5:39           ` Sv: " arthur miller
2024-09-12  4:24             ` Emanuel Berg
2024-09-11  3:17     ` Sv: " Karthik Chikmagalur
2024-09-11  5:48       ` Sv: " arthur miller
2024-09-10 12:05 ` Yuri Khan
  -- strict thread matches above, loose matches on Subject: below --
2024-09-13 13:30 arthur miller

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).