GNU bug report logs - #52092
28.0.60; hs-toggle-hiding does not toggle once folded

Previous Next

Package: emacs;

Reported by: Mohammed Sadiq <sadiq <at> sadiqpk.org>

Date: Thu, 25 Nov 2021 07:42:01 UTC

Severity: normal

Tags: help

Found in version 28.0.60

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 52092 in the body.
You can then email your comments to 52092 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#52092; Package emacs. (Thu, 25 Nov 2021 07:42:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Mohammed Sadiq <sadiq <at> sadiqpk.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 25 Nov 2021 07:42:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Mohammed Sadiq <sadiq <at> sadiqpk.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.0.60; hs-toggle-hiding does not toggle once folded
Date: Thu, 25 Nov 2021 13:10:51 +0530
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.

Tested with c-mode and css-mode.

In GNU Emacs 28.0.60 (build 2, x86_64-pc-linux-gnu, GTK+ Version 
3.24.30, cairo version 1.16.0)
 of 2021-11-25 built on purism
Repository revision: 0854453ec2343cbfac3ac8e233cdc7bd2c8554a9
Repository branch: emacs-28
Windowing system distributor 'The X.Org Foundation', version 
11.0.12011000
System Description: Debian GNU/Linux bookworm/sid

Configured using:
 'configure --with-native-compilation'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES
NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_IN
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: iso-latin-1-unix

Major mode: C/*l

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t
  abbrev-mode: t
  hs-minor-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg rfc6068 epg-config gnus-util rmail
rmail-loaddefs auth-source eieio eieio-core eieio-loaddefs
password-cache json map text-property-search time-date mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail comp comp-cstr warnings subr-x rx cl-seq cl-macs cl-extra
help-mode rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
hideshow vc-git diff-mode easy-mmode vc-dispatcher seq byte-opt gv
bytecomp byte-compile cconv cc-mode cc-fonts cc-guess cc-menus cc-cmds
cc-styles cc-align cc-engine cc-vars cc-defs cl-loaddefs cl-lib
iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit x multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 125023 9196)
 (symbols 48 10111 1)
 (strings 32 30461 3484)
 (string-bytes 1 1135663)
 (vectors 16 20448)
 (vector-slots 8 388478 20146)
 (floats 8 31 60)
 (intervals 56 377 0)
 (buffers 992 13))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52092; Package emacs. (Thu, 25 Nov 2021 10:30:02 GMT) Full text and rfc822 format available.

Message #8 received at 52092 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Mohammed Sadiq <sadiq <at> sadiqpk.org>
Cc: 52092 <at> debbugs.gnu.org
Subject: Re: bug#52092: 28.0.60; hs-toggle-hiding does not toggle once folded
Date: Thu, 25 Nov 2021 12:29:54 +0200
> Date: Thu, 25 Nov 2021 13:10:51 +0530
> From: Mohammed Sadiq <sadiq <at> sadiqpk.org>
> 
> 
> 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.
> 
> Tested with c-mode and css-mode.

It seems that unhiding works only if you are at the beginning of the
hidden block.  In C Mode, that means cursor is on the opening brace of
the block.

The problem seems to be inside hs-already-hidden-p:

  (defun hs-already-hidden-p ()
    "Return non-nil if point is in an already-hidden block, otherwise nil."
    (save-excursion
      (let ((c-reg (hs-inside-comment-p)))
	(if (and c-reg (nth 0 c-reg))
	    ;; point is inside a comment, and that comment is hideable
	    (goto-char (nth 0 c-reg))
	  (end-of-line)

That call to end-of-line moves point outside of the braces _unless_
point is on the left brace that starts the hidden block.  That
movement then makes it appear as if we are in the outer block, not in
the one that you've just hidden.

I don't know enough about hideshow.el and don't use it enough to
propose a robust enough solution for this which won't break some use
case out there.




Added tag(s) help. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Fri, 03 Dec 2021 01:13:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52092; Package emacs. (Mon, 19 Sep 2022 06:33:01 GMT) Full text and rfc822 format available.

Message #13 received at 52092 <at> debbugs.gnu.org (full text, mbox):

From: kobarity <kobarity <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>, Mohammed Sadiq <sadiq <at> sadiqpk.org>,
 52092 <at> debbugs.gnu.org
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#52092: 28.0.60; hs-toggle-hiding does not toggle once folded
Date: Mon, 19 Sep 2022 15:31:56 +0900
[Message part 1 (text/plain, inline)]
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 <monnier <at> iro.umontreal.ca>
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,
[0001-Fix-hs-toggle-hiding-behaviors.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52092; Package emacs. (Fri, 23 Sep 2022 22:02:02 GMT) Full text and rfc822 format available.

Message #16 received at 52092 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: kobarity <kobarity <at> gmail.com>
Cc: 52092 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 Mohammed Sadiq <sadiq <at> sadiqpk.org>
Subject: Re: bug#52092: 28.0.60; hs-toggle-hiding does not toggle once folded
Date: Fri, 23 Sep 2022 18:01:05 -0400
> 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.

Hmm... indeed it's a trivial oversight in my patch, sorry.
The patch below should fix it.

> (posn-set-point (event-end e)) was added to `hs-toggle-hiding' by this
> commit.  This is the main cause of bug#52092.

Indeed, thanks.

I had no idea that (posn-point (posn-at-point POS)) doesn't return POS
if POS is within an invisible chunk of text and instead returns the next
visible position.

I'll have to think about how best to fix the consequence.


        Stefan


diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el
index c0796fc2eeb..8dd8c7e182c 100644
--- a/lisp/progmodes/hideshow.el
+++ b/lisp/progmodes/hideshow.el
@@ -948,7 +948,7 @@ hs-toggle-hiding
   "Toggle hiding/showing of a block.
 See `hs-hide-block' and `hs-show-block'.
 Argument E should be the event that triggered this action."
-  (interactive)
+  (interactive (list last-nonmenu-event))
   (hs-life-goes-on
    (posn-set-point (event-end e))
    (if (hs-already-hidden-p)





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52092; Package emacs. (Sat, 24 Sep 2022 06:01:02 GMT) Full text and rfc822 format available.

Message #19 received at 52092 <at> debbugs.gnu.org (full text, mbox):

From: kobarity <kobarity <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 52092 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 Mohammed Sadiq <sadiq <at> sadiqpk.org>
Subject: Re: bug#52092: 28.0.60; hs-toggle-hiding does not toggle once folded
Date: Sat, 24 Sep 2022 14:59:56 +0900
Stefan Monnier wrote:
> The patch below should fix it.

Thanks, I didn't know `last-nonmenu-event'.  I confirmed that the
patch enables the mouse to hide the clicked block.

> I had no idea that (posn-point (posn-at-point POS)) doesn't return POS
> if POS is within an invisible chunk of text and instead returns the next
> visible position.
> 
> I'll have to think about how best to fix the consequence.

Thank you for consideration.

Regards,




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52092; Package emacs. (Sat, 24 Sep 2022 06:19:02 GMT) Full text and rfc822 format available.

Message #22 received at 52092 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 52092 <at> debbugs.gnu.org, kobarity <at> gmail.com, sadiq <at> sadiqpk.org
Subject: Re: bug#52092: 28.0.60; hs-toggle-hiding does not toggle once folded
Date: Sat, 24 Sep 2022 09:17:53 +0300
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: Eli Zaretskii <eliz <at> gnu.org>,  Mohammed Sadiq <sadiq <at> sadiqpk.org>,
>   52092 <at> debbugs.gnu.org
> Date: Fri, 23 Sep 2022 18:01:05 -0400
> 
> I had no idea that (posn-point (posn-at-point POS)) doesn't return POS
> if POS is within an invisible chunk of text and instead returns the next
> visible position.

posn-at-point uses display routines, so it cannot report on invisible
POS, because the display code skips invisible text.  The doc string
kinda hints on that:

  Return nil if POS is not visible in WINDOW.  Otherwise,
  the return value is similar to that returned by ‘event-start’ for
  a mouse click at the upper left corner of the glyph corresponding
  to POS:

You cannot click a mouse on a glyph corresponding to invisible text,
can you?

We could make this more clear in the documentation.  I think this
usually isn't a problem because this function is not called for POS
calculated in some way, as opposed to positions actually displayed, or
nil.




Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Sat, 24 Sep 2022 15:11:02 GMT) Full text and rfc822 format available.

Notification sent to Mohammed Sadiq <sadiq <at> sadiqpk.org>:
bug acknowledged by developer. (Sat, 24 Sep 2022 15:11:02 GMT) Full text and rfc822 format available.

Message #27 received at 52092-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: kobarity <kobarity <at> gmail.com>
Cc: Dan Nicolaescu <dann <at> ics.uci.edu>, Thien-Thi Nguyen <ttn <at> gnu.org>,
 Eli Zaretskii <eliz <at> gnu.org>, 52092-done <at> debbugs.gnu.org,
 Mohammed Sadiq <sadiq <at> sadiqpk.org>
Subject: Re: bug#52092: 28.0.60; hs-toggle-hiding does not toggle once folded
Date: Sat, 24 Sep 2022 11:10:26 -0400
[ Added Thien-Thi and Dan to the Cc since they're listed as maintainers
  of `hideshow.el`.  ]

kobarity [2022-09-24 14:59:56] wrote:
> Stefan Monnier wrote:
>> The patch below should fix it.
> Thanks, I didn't know `last-nonmenu-event'.  I confirmed that the
> patch enables the mouse to hide the clicked block.

I pushed it to the `emacs-28` branch, because it's fixing a stupid regression.

>> I had no idea that (posn-point (posn-at-point POS)) doesn't return POS
>> if POS is within an invisible chunk of text and instead returns the next
>> visible position.
>> 
>> I'll have to think about how best to fix the consequence.
>
> Thank you for consideration.

I pushed to `master` a patch which makes `event-end` return a position
that's always at `point` for keyboard events, even if `point` is hidden.
That should bring back the previous behavior (it's not safe enough for
the `emacs-28` branch, sadly).

But I think your patch is still an improvement since it makes
`hs-toggle-hiding` work even when point is right after the hidden block.
I also like the additional tests you provide.
So I adjusted it to the new code and pushed it to `master`.

Thank you,


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52092; Package emacs. (Sat, 24 Sep 2022 15:12:01 GMT) Full text and rfc822 format available.

Message #30 received at 52092 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 52092 <at> debbugs.gnu.org, kobarity <at> gmail.com, sadiq <at> sadiqpk.org
Subject: Re: bug#52092: 28.0.60; hs-toggle-hiding does not toggle once folded
Date: Sat, 24 Sep 2022 11:11:29 -0400
> posn-at-point uses display routines, so it cannot report on invisible
> POS, because the display code skips invisible text.  The doc string
> kinda hints on that:

Yes, it makes a lot of sense.  In the case of `event-end` and
`event-start` that's not what we want, tho, so I tweaked those
functions accordingly.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52092; Package emacs. (Sun, 25 Sep 2022 02:28:01 GMT) Full text and rfc822 format available.

Message #33 received at 52092 <at> debbugs.gnu.org (full text, mbox):

From: kobarity <kobarity <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 52092 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 Dan Nicolaescu <dann <at> ics.uci.edu>, Mohammed Sadiq <sadiq <at> sadiqpk.org>,
 Thien-Thi Nguyen <ttn <at> gnu.org>
Subject: Re: bug#52092: 28.0.60; hs-toggle-hiding does not toggle once folded
Date: Sun, 25 Sep 2022 11:26:35 +0900
Stefan Monnier wrote:
> I pushed to `master` a patch which makes `event-end` return a position
> that's always at `point` for keyboard events, even if `point` is hidden.
> That should bring back the previous behavior (it's not safe enough for
> the `emacs-28` branch, sadly).
> 
> But I think your patch is still an improvement since it makes
> `hs-toggle-hiding` work even when point is right after the hidden block.
> I also like the additional tests you provide.
> So I adjusted it to the new code and pushed it to `master`.

I confirmed that everything works as expected.  Thank you for fixing
the issue and improving my patch.

Regards,




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 23 Oct 2022 11:24:14 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 184 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.