bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#19267: 25.0.50; Enhance cycle-spacing with a state where only whites


From: Tassilo Horn
Subject: bug#19267: 25.0.50; Enhance cycle-spacing with a state where only whitespace after point is deleted
Date: Fri, 13 May 2022 10:50:22 +0200
User-agent: mu4e 1.7.20; emacs 29.0.50

Tassilo Horn <tsdh@gnu.org> writes:

Hi all,

> Perfect.  If you are not already implementing that, I'd give it a shot
> when I find some spare time.

Ok, attached is a first version of the patch for discussion.  The
supported actions are:

(setq cycle-spacing-actions
      '( just-one-space        ; you name it
         ;; delete-space-after ; delete spaces after point
         delete-space-before   ; delete spaces before point
         delete-all-space      ; delete all spaces around point
         restore))             ; restore the original spacing

In addition, you can add functions (symbols) into that list which are
simply funcall-ed.

Here are some thoughts I'd like to discuss:

1. Currently as previously, changing the prefix arg will start a new
   sequence, e.g., M-4 M-SPC M-8 M-SPC will call just-one-space twice
   with 4 and then 8.  I think that made sense when just-one-space was
   guaranteed to be the first action ("Oh, I mistyped my prefix arg so
   let's just correct that!").

   However, with the new version, I think it would make more sense when
   the prefix arg given to the initial invocation is passed on to
   following invocations of this cycle.  The reason is that only
   just-one-space actually cares about the exact numerical value whereas
   all actions (except 'restore) care about the prefix arg being
   positive or negative.  A negative arg always indicates that newlines
   are treated as a deletable space whereas arg => 0 only considers tabs
   and spaces.  So right now, if you want to delete all space including
   newlines, you have to type M-- M-SPC M-- M-SPC M-- M-SPC which is
   inconvenient.  If the initial arg was passed on, it would just be M--
   M-SPC M-SPC M-SPC which is much easier to type.

   Of course, that comes with the (IMHO little) downside that you need
   to do something else to break a cycle, e.g., C-g.  That could be
   fixed by starting a new cycle only if the prefix arg is not 1 (the
   default).

2. With my configured emacs (but not with emacs -Q) it may take a
   substantial amount of time (up to a second) until the action's effect
   is displayed, most notably when cycling with negative prefix arg
   where also newlines may be deleted.  Profiling revealed that this
   comes mostly through stuff sitting in post-command-hook or
   after-change-functions.  To name a few: aggressive-indent, show-paren
   (which I use with the costly show-paren-context-when-offscreen
   value 'child-frame), eldoc,...

   Ok, aggressive-indent is countering manual spacing adjustments
   fundamentally but can be tamed with:

       (add-to-list 'aggressive-indent-dont-indent-if
                    '(eq last-command 'cycle-spacing))

   But is there some good way to tame the others?  It's hard to decide
   which known performance hogs to inhibit and there might be much worse
   unknown ones.  (Well, I also don't know how to inhibit.  I guess
   let-binding post-command-hook in a command has no effect since it's
   run after the command, right?)

Bye,
Tassilo

Attachment: 0001-Improve-cycle-spacing.patch
Description: Text Data


reply via email to

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