emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Suggestion: two new commands: beginning-of-list and end-of-list


From: arthur miller
Subject: Suggestion: two new commands: beginning-of-list and end-of-list
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 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: 0001-beginning-end-of-list.patch
Description: 0001-beginning-end-of-list.patch


reply via email to

[Prev in Thread] Current Thread [Next in Thread]