Subject: Re: bug#52092: 28.0.60; hs-toggle-hiding does not toggle once folded

From: kobarity <[email-masked]>
Date: Mon, 19 Sep 2022 15:31:56 +0900

Mohammed Sadiq wrote:
> With hs-minor-mode enabled, I could hide the visibility of a block with
> hs-toggle-hiding, but using it again doesn't unfold the region.

There is another problem related to this issue.  `hs-toggle-hiding' is
also bound to shift mouse-2, but it toggles the block where the
current point is located instead of the block where mouse is clicked.
The problem is described below:

1. emacs -Q
2. Open the following C mode file.

#+begin_src C
int
main() {
  sub();
}

int
sub() {
  printf("sub\n");
}
#+end_src

3. M-x hs-minor-mode
4. Move the point to the "printf" line in the "sub" function.
5. Shift mouse-2 in the function "main".
   The function body of "sub" is hidden instead of "main".  This is
   not I expected.

This behavior was introduced by the following commit.  Is this
intended behavior?

commit d0e9113de9783094b4da7f6aeee131194653c325
Author: Stefan Monnier <[email-masked]>
Date:   Sun May 19 09:36:22 2019 -0400

    * lisp/progmodes/hideshow.el: Simplify mouse binding; Use lexical-binding

    (hs-set-up-overlay, hs-adjust-block-beginning): Use non-nil default for
    function variables, so `add-function` can be used on them.
    (hs-toggle-hiding): Make it work for mouse bindings as well.
    (hs-minor-mode-map): Use it for the mouse binding.
    (hs-grok-mode-type): Use bound-and-true-p.
    (hs-life-goes-on): Use `declare` for the debug spec.
    (hs-mouse-toggle-hiding): Make it an obsolete alias.

(posn-set-point (event-end e)) was added to `hs-toggle-hiding' by this
commit.  This is the main cause of bug#52092.  When the point is
inside the hidden block, (posn-set-point (event-end e)) moves the
point to the first shown character (e.g. closing "}"), resulting in
the failure to show the block.  This is not needed for keyboard
operations.  Although this is necessary for mouse operations, current
code does not handle mouse events because "e" is not specified in
`interactive'.  So I think `hs-mouse-toggle-hiding' should be revived
to separate `posn-set-point' from `hs-toggle-hiding' if the above
behavior is not intentional.

As for the `hs-already-hidden-p', the current implementation returns
nil when the point is at closing "}".  Although this is not a big
problem for keyboard operations, this is harmful for mouse to show the
hidden block because `posn-set-point' sets the point at closing "}" as
described above.  Current implementation only checks if the end of the
line is inside a block.  I suggest to add a check if the beginning of
the line is inside a block to be able detect a hidden block when the
point is at the line of closing "}".

Attached is a patch to fix bug#52092 and the above behavior.  I'm not
sure if it is okay to cancel `define-obsolete-function-alias'.

Regards,