|
From: | arthur miller |
Subject: | Sv: Suggestion: two new commands: beginning-of-list and end-of-list |
Date: | Wed, 11 Sep 2024 05:39:00 +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?
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. |
[Prev in Thread] | Current Thread | [Next in Thread] |