unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#71170: 30.0.50; hs-hide-all in python mode not works as expected
@ 2024-05-24  8:40 lorniu
  2024-05-25 10:28 ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: lorniu @ 2024-05-24  8:40 UTC (permalink / raw)
  To: 71170


When I run `hs-hide-all` in python mode for some python files,
It cannot work properly.

For example, the `class` in following code can not be hide:

  ```
   if TYPE_CHECKING:
       Base64FileInput = Union[IO[bytes], PathLike[str]]
       FileContent = Union[IO[bytes], bytes, PathLike[str]]
   else:
       Base64FileInput = Union[IO[bytes], PathLike]
       FileContent = Union[IO[bytes], bytes, PathLike]  # PathLike is not subscriptable in Python 3.8.
   
   class aaa:
       ...
  ```

Maybe the issue caused by function in `python-hideshow-find-next-block`
of python.el, that the comment regexp should be "^#" instead of "#"?

*** /tmp/ediffpq2CbT	2024-05-24 16:32:36.561363335 +0800
--- /tmp/ediff7ExE1i	2024-05-24 16:32:36.561363335 +0800
***************
*** 17,23 ****
           (next-comment
            (or (when comments
                  (save-excursion
!                   (cl-loop while (re-search-forward "#" maxp t)
                             if (python-syntax-context 'comment)
                             return (point))))
                (1+ maxp)))
--- 17,23 ----
           (next-comment
            (or (when comments
                  (save-excursion
!                   (cl-loop while (re-search-forward "^#" maxp t)
                             if (python-syntax-context 'comment)
                             return (point))))
                (1+ maxp)))



In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.41, cairo version 1.18.0) of 2024-05-17 built on svarch
Repository revision: 6ca3a60db3427bc6aef08144c1524920ff3d9c4d
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101013
System Description: Arch Linux

Configured using:
 'configure --with-modules --with-xwidgets --with-xinput2
 --with-mailutils --with-imagemagick --with-json --with-tree-sitter
 --with-native-compilation=no'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ
IMAGEMAGICK JPEG LCMS2 LIBSELINUX LIBSYSTEMD LIBXML2 MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM XWIDGETS
GTK3 ZLIB

Important settings:
  value of $LC_ALL: en_US.UTF-8
  value of $LC_COLLATE: C
  value of $LC_CTYPE: zh_CN.UTF-8
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=fcitx
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  treemacs-filewatch-mode: t
  treemacs-follow-mode: t
  treemacs-git-mode: t
  treemacs-fringe-indicator-mode: only-when-focused
  eat-eshell-visual-command-mode: t
  eat-eshell-mode: t
  magit-wip-initial-backup-mode: t
  magit-wip-before-change-mode: t
  magit-wip-after-apply-mode: t
  magit-wip-after-save-mode: t
  magit-wip-mode: t
  global-git-commit-mode: t
  which-function-mode: t
  which-key-mode: t
  engine-mode: t
  jdecomp-mode: t
  yas-global-mode: t
  yas-minor-mode: t
  auto-insert-mode: t
  vertico-mode: t
  global-corfu-mode: t
  corfu-mode: t
  marginalia-mode: t
  im/smart-completion-styles-mode: t
  editorconfig-mode: t
  mpvi-emms-integrated-mode: t
  emms-mode-line-mode: t
  emms-playing-time-display-mode: t
  emms-playing-time-mode: t
  global-ahs-mode: t
  winner-mode: t
  recentf-mode: t
  savehist-mode: t
  global-so-long-mode: t
  global-page-break-lines-mode: t
  repeat-mode: t
  global-auto-revert-mode: t
  pixel-scroll-precision-mode: t
  override-global-mode: t
  imfine-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  column-number-mode: 1
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/home/vip/.emacs.d/repo/go-translate/gt-engine-youdao hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/gt-engine-youdao
/home/vip/.emacs.d/repo/go-translate/gt-faces hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/gt-faces
/home/vip/.emacs.d/repo/go-translate/gt-engine-echo hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/gt-engine-echo
/home/vip/.emacs.d/repo/go-translate/gt-extension hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/gt-extension
/home/vip/.emacs.d/repo/go-translate/gt-engine-bing hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/gt-engine-bing
/home/vip/.emacs.d/repo/go-translate/gt-engine-google-rpc hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/gt-engine-google-rpc
/home/vip/.emacs.d/repo/go-translate/gt-text-utility hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/gt-text-utility
/home/vip/.emacs.d/repo/go-translate/gt-engine-google hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/gt-engine-google
/home/vip/.emacs.d/repo/go-translate/go-translate hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/go-translate
/home/vip/.emacs.d/repo/go-translate/gt-core hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/gt-core
/home/vip/.emacs.d/repo/go-translate/gt-engine-deepl hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/gt-engine-deepl
/home/vip/.emacs.d/repo/go-translate/gt-engine-chatgpt hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/gt-engine-chatgpt
/home/vip/.emacs.d/repo/go-translate/gt-engine-stardict hides /home/vip/.emacs.d/elpa/go-translate-20240512.1153/gt-engine-stardict
/home/vip/.emacs.d/extra/ox-freemind/ox-freemind hides /home/vip/.emacs.d/elpa/org-contrib-0.4.2/ox-freemind
/home/vip/.emacs.d/elpa/transient-20240509.1849/transient hides /usr/local/share/emacs/30.0.50/lisp/transient

Features:
(follow treemacs treemacs-header-line treemacs-compatibility
treemacs-mode treemacs-bookmarks treemacs-tags treemacs-interface
treemacs-persistence treemacs-filewatch-mode treemacs-follow-mode
treemacs-rendering treemacs-annotations treemacs-async
treemacs-workspaces treemacs-dom treemacs-visuals
treemacs-fringe-indicator treemacs-faces treemacs-icons treemacs-scope
treemacs-themes treemacs-core-utils pfuture inline hl-line ht
treemacs-logging treemacs-customization treemacs-macros reporter ediff
ediff-merg ediff-mult ediff-wind ediff-diff ediff-help ediff-init
ediff-util shadow mail-extr emacsbug consult-compile consult-imenu
consult-register iy-go-to-char edebug skeleton jka-compr shortdoc
comp-common cl-print cape help-fns radix-tree tramp-cmds
web-mode-expansions eglot-volar web-mode sql eshell esh-mode esh-var eat
term ehelp esh-cmd esh-ext esh-opt esh-proc esh-io esh-arg esh-module
esh-groups esh-util expand-region text-mode-expansions
cc-mode-expansions the-org-mode-expansions python-el-fgallina-expansions
er-basic-expansions expand-region-core expand-region-custom
magit-bookmark magit-submodule magit-blame magit-stash magit-reflog
magit-bisect magit-push magit-pull magit-fetch magit-clone magit-remote
magit-commit magit-sequence magit-notes magit-worktree magit-tag
magit-merge magit-branch magit-reset magit-files magit-refs magit-status
magit magit-repos magit-apply magit-wip magit-log magit-diff smerge-mode
magit-core magit-autorevert magit-margin magit-transient magit-process
magit-mode git-commit magit-git magit-base magit-section cursor-sensor
crm dash with-editor log-edit message sendmail rfc822 mml mml-sec epa
epg rfc6068 epg-config gnus-util mm-decode mm-bodies mm-encode
mailabbrev mail-utils gmm-utils mailheader pcvs-util emacsql
emacsql-compiler org-capture ob-awk ob-latex ob-restclient restclient
ob-calc calc-store calc-trail calc-ext calc calc-loaddefs rect calc-macs
ob-plantuml ob-dot ob-ditaa ob-gnuplot ob-sqlite ob-sql ob-fsharp
ob-ocaml ob-csharp ob-csx csharp-mode c-ts-common cc-langs citre-lang-c
cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine
cc-vars cc-defs ob-js ob-java ob-haskell ob-ruby ob-python ob-lisp
ob-typescript ob-powershell ob-shell ox-spectacle org-timer org-clock
org-special-block-extras ox-odt rng-loc rng-uri rng-parse rng-match
rng-dt rng-util rng-pttrn nxml-parse nxml-ns nxml-enc xmltok nxml-util
ox-latex ox-icalendar org-agenda ox-html table ox-ascii ox-publish ox
org-tempo tempo org-img org-attach async embark-org edraw-org edraw-util
edraw-msg org-element org-persist org-id org-refile avl-tree generator
bilibili org org-version ob-emacs-lisp org-table org-loaddefs ob
ob-tangle ol ob-ref ob-lob ob-table ob-exp org-macro org-src org-keys oc
ob-comint ob-core org-cycle org-fold ob-eval org-pcomplete org-list
org-footnote org-fold-core org-entities org-faces org-compat org-macs
cal-china-x cal-china lunar solar cal-dst holidays holiday-loaddefs
cal-menu calendar cal-loaddefs yank-media markdown-mode edit-indirect
find-dired grep eglot-jdt s eglot-fsac fsharp-mode inf-fsharp-mode
fsharp-mode-util tramp trampver tramp-integration files-x tramp-message
tramp-compat xdg shell pcomplete parse-time iso8601 tramp-loaddefs
fsharp-mode-structure smie eglot-cls eglot external-completion jsonrpc
flymake diff ert ewoc debug backtrace find-func compile view python
treesit comint ansi-osc ansi-color mule-util vc-git diff-mode
track-changes vc-dispatcher citre citre-xref-adapter citre-global
citre-ui-peek citre-ui-jump pulse go-translate go-translate-v2
gts-engine-youdao gts-engine-stardict gts-engine-deepl
gts-engine-google-rpc gts-engine-google gts-engine-bing gts-implements
alert posframe gts-faces gts-core gt-chat-openai gt-text-utility
gt-engine-echo gt-engine-chatgpt gt-engine-youdao gt-engine-stardict
gt-engine-deepl gt-engine-google-rpc gt-engine-google gt-engine-bing
gt-extension plz gt-faces gt-core let-alist dom add-log disp-table
noutline outline which-func imenu rainbow-delimiters over imsketch
implay living vps imsilly ikmd-kmacro ikmd-keys-and-commands which-key
iorg+TeX iorg-notes iorg iwww-gnus iwww-irc iwww engine-mode
simple-httpd idev-markdown idev-web idev-sql pg idev-php idev-golang
idev-haskell idev-elixir idev-erlang idev-ruby idev-python idev-lisp
lisp-mnt sly-autoloads idev-dotnet idev-jvm jdecomp arc-mode
archive-mode idev-rust idev-cc idev-lsp idev-hexl idevelop citre-config
citre-lang-fileref citre-tags citre-ctags citre-readtags
citre-readtags-tables citre-backend-interface citre-common-tag
citre-common-util imod-gpt imod-eaf imod-ime imod-shell imod-vcs
imod-tui-actions embark-consult embark imod-folding fold-this hideshow
imod-snippet yasnippet autoinsert imod-completing consult bookmark
text-property-search pp vertico kind-all-the-icons all-the-icons
all-the-icons-faces data-material data-weathericons data-octicons
data-fileicons data-faicons data-alltheicons corfu-kind-grouping corfu
marginalia compat orderless imod-search imod-evil warnings imod-project
editorconfig editorconfig-core editorconfig-core-handle
editorconfig-fnmatch imod-dired dired-collapse ls-lisp wdired imod-mmm
polymode derived poly-lock polymode-base polymode-weave polymode-export
polymode-compat polymode-methods polymode-core polymode-classes
eieio-custom eieio-base imod-tramp imod-print imod-tools dropbox dupan
dired-aux url-http url-auth mail-parse rfc2231 rfc2047 rfc2045 mm-util
ietf-drums mail-prsvr url-gw nsm puny imod-colorful-media mpvi mpvi-ps
emms-mpris dbus emms-librefm-stream xml emms-librefm-scrobbler
emms-playlist-limit emms-i18n emms-history emms-score emms-stream-info
emms-metaplaylist-mode emms-bookmarks emms-cue emms-mode-line-icon
emms-browser sort emms-volume emms-volume-sndioctl emms-volume-mixerctl
emms-volume-pulse emms-volume-amixer emms-playlist-sort emms-last-played
emms-player-xine emms-player-mpd tq emms-lyrics emms-url time-date
emms-streams emms-show-all emms-tag-editor emms-tag-tracktag emms-mark
emms-mode-line emms-cache emms-info-native emms-info-native-spc
emms-info-native-mp3 emms-info-native-ogg emms-info-native-opus
emms-info-native-flac emms-info-native-vorbis bindat emms-info-exiftool
emms-info-tinytag emms-info-metaflac emms-info-opusinfo
emms-info-ogginfo emms-info-mp3info emms-playlist-mode emms-player-vlc
emms-player-mpv emms-playing-time emms-info emms-later-do
emms-player-mplayer emms-player-simple emms-source-playlist
emms-source-file locate dired dired-loaddefs emms-setup emms emms-compat
ffap thingatpt imod-edit+ vlf-setup advice ahs cl color imod-display
imod-session winner recentf tree-widget wid-edit savehist imod-scratch
imod-transient imod-safety aes imods so-long page-break-lines repeat
xref project ibuffer ibuffer-loaddefs autorevert filenotify face
pixel-scroll cua-base ring face-modeline face-font dist delight
use-package use-package-ensure use-package-delight use-package-diminish
use-package-bind-key bind-key use-package-core finder-inf aes-autoloads
alchemist-autoloads all-the-icons-autoloads android-mode-autoloads
attrap-autoloads auctex-autoloads tex-site bbdb-autoloads
blackout-autoloads c-eldoc-autoloads cape-autoloads citre-autoloads
clojure-mode-autoloads cmake-mode-autoloads company-autoloads
consult-eglot-autoloads corfu-autoloads cowsay-autoloads
csproj-mode-autoloads csv-mode-autoloads delight-autoloads
dired-dups-autoloads docker-autoloads aio-autoloads
dockerfile-mode-autoloads eat-autoloads edit-indirect-autoloads
editorconfig-autoloads elixir-mode-autoloads embark-consult-autoloads
consult-autoloads embark-autoloads emmet-mode-autoloads emms-autoloads
engine-mode-autoloads erc-hl-nicks-autoloads erlang-autoloads
evil-autoloads forge-autoloads closql-autoloads fuzzy-finder-autoloads
ghub-autoloads git-modes-autoloads git-timemachine-autoloads
gitignore-templates-autoloads gnuplot-autoloads go-mode-autoloads
go-translate-autoloads goto-chg-autoloads gptel-autoloads
graphviz-dot-mode-autoloads groovy-mode-autoloads
gruvbox-theme-autoloads autothemer-autoloads haskell-mode-autoloads
hide-lines-autoloads hindent-autoloads htmlize-autoloads
httprepl-autoloads hyperbole-autoloads kotl-autoloads hact set hhist
jdecomp-autoloads keycast-autoloads know-your-http-well-autoloads
kotlin-mode-autoloads kubernetes-autoloads license-templates-autoloads
lsp-java-autoloads dap-mode-autoloads lsp-docker-autoloads bui-autoloads
lsp-treemacs-autoloads lsp-ui-autoloads lsp-mode-autoloads f-autoloads
lua-mode-autoloads macrostep-autoloads magit-autoloads
git-commit-autoloads magit-popup-autoloads marginalia-autoloads
markdown-toc-autoloads memory-usage-autoloads nano-theme-autoloads
nhexl-mode-autoloads nov-autoloads esxml-autoloads kv-autoloads
ob-fsharp-autoloads fsharp-mode-autoloads ob-powershell-autoloads
ob-restclient-autoloads ob-typescript-autoloads orderless-autoloads
org-contrib-autoloads org-make-toc-autoloads
org-noter-pdftools-autoloads org-pdftools-autoloads org-noter-autoloads
org-present-autoloads org-reverse-datetree-autoloads
org-roam-ui-autoloads org-roam-autoloads magit-section-autoloads
emacsql-autoloads ox-pandoc-autoloads package-lint-autoloads
page-break-lines-autoloads pcre2el-autoloads pdf-tools-autoloads
php-mode-autoloads pkg-info-autoloads epl-autoloads
plantuml-mode-autoloads plz-autoloads poly-markdown-autoloads
poly-org-autoloads polymode-autoloads powershell-autoloads
pyim-autoloads async-autoloads pyim-basedict-autoloads
qrencode-autoloads rainbow-delimiters-autoloads rainbow-mode-autoloads
request-autoloads restclient-autoloads rg-autoloads rime-autoloads
popup-autoloads robe-autoloads inf-ruby-autoloads rust-mode-autoloads
sass-mode-autoloads haml-mode-autoloads scala-mode-autoloads
session-autoloads sharper-autoloads simple-httpd-autoloads sis-autoloads
spinner-autoloads sql-indent-autoloads srcery-theme-autoloads
ssh-agency-autoloads sx-autoloads markdown-mode-autoloads
syntax-subword-autoloads systemd-autoloads rx tablist-autoloads
transient-autoloads trashed-autoloads treemacs-autoloads cfrs-autoloads
posframe-autoloads ht-autoloads hydra-autoloads lv-autoloads
pfuture-autoloads ace-window-autoloads avy-autoloads s-autoloads
dash-autoloads treepy-autoloads typescript-mode-autoloads
udev-mode-autoloads uuidgen-autoloads vertico-autoloads vlf-autoloads
vundo-autoloads web-beautify-autoloads web-mode-autoloads
websocket-autoloads wgrep-autoloads which-key-autoloads info
with-editor-autoloads xr-autoloads xterm-color-autoloads yaml-autoloads
yaml-mode-autoloads yasnippet-autoloads ztree-autoloads package
browse-url url url-proxy url-privacy url-expand url-methods url-history
url-cookie generate-lisp-file url-domsuf url-util mailcap url-handlers
url-parse auth-source icons password-cache json map url-vars cust server
easy-mmode fast transient cl-extra help-mode format-spec edmacro kmacro
eieio byte-opt bytecomp byte-compile eieio-core pcase cl-seq util
cl-macs bm gv subr-x cl-loaddefs cl-lib rmc iso-transl tooltip cconv
eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd touch-screen
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 nadvice seq
simple cl-generic indonesian philippine 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 abbrev obarray oclosure cl-preloaded button
loaddefs theme-loaddefs faces cus-face macroexp files window
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget keymap hashtable-print-readable backquote threads
xwidget-internal dbusbind inotify lcms2 dynamic-setting
system-font-setting font-render-setting cairo gtk x-toolkit xinput2 x
multi-tty move-toolbar make-network-process emacs)

Memory information:
((conses 16 1036604 2115619) (symbols 48 66867 127)
 (strings 32 276483 136003) (string-bytes 1 7344809)
 (vectors 16 118029) (vector-slots 8 1826730 895932)
 (floats 8 2798 12651) (intervals 56 9192 2718) (buffers 992 41))





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#71170: 30.0.50; hs-hide-all in python mode not works as expected
  2024-05-24  8:40 bug#71170: 30.0.50; hs-hide-all in python mode not works as expected lorniu
@ 2024-05-25 10:28 ` Eli Zaretskii
  2024-05-25 14:36   ` kobarity
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2024-05-25 10:28 UTC (permalink / raw)
  To: lorniu, kobarity; +Cc: 71170

> From: lorniu <lorniu@gmail.com>
> Date: Fri, 24 May 2024 16:40:39 +0800
> 
> 
> When I run `hs-hide-all` in python mode for some python files,
> It cannot work properly.
> 
> For example, the `class` in following code can not be hide:
> 
>   ```
>    if TYPE_CHECKING:
>        Base64FileInput = Union[IO[bytes], PathLike[str]]
>        FileContent = Union[IO[bytes], bytes, PathLike[str]]
>    else:
>        Base64FileInput = Union[IO[bytes], PathLike]
>        FileContent = Union[IO[bytes], bytes, PathLike]  # PathLike is not subscriptable in Python 3.8.
>    
>    class aaa:
>        ...
>   ```
> 
> Maybe the issue caused by function in `python-hideshow-find-next-block`
> of python.el, that the comment regexp should be "^#" instead of "#"?

Shouldn't that be something like "^[:space:]*#" instead?





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#71170: 30.0.50; hs-hide-all in python mode not works as expected
  2024-05-25 10:28 ` Eli Zaretskii
@ 2024-05-25 14:36   ` kobarity
  2024-05-26  4:39     ` lorniu
  0 siblings, 1 reply; 11+ messages in thread
From: kobarity @ 2024-05-25 14:36 UTC (permalink / raw)
  To: lorniu, Eli Zaretskii; +Cc: 71170

[-- Attachment #1: Type: text/plain, Size: 1395 bytes --]

Eli Zaretskii wrote:
> 
> > From: lorniu <lorniu@gmail.com>
> > Date: Fri, 24 May 2024 16:40:39 +0800
> > 
> > 
> > When I run `hs-hide-all` in python mode for some python files,
> > It cannot work properly.
> > 
> > For example, the `class` in following code can not be hide:
> > 
> >   ```
> >    if TYPE_CHECKING:
> >        Base64FileInput = Union[IO[bytes], PathLike[str]]
> >        FileContent = Union[IO[bytes], bytes, PathLike[str]]
> >    else:
> >        Base64FileInput = Union[IO[bytes], PathLike]
> >        FileContent = Union[IO[bytes], bytes, PathLike]  # PathLike is not subscriptable in Python 3.8.
> >    
> >    class aaa:
> >        ...
> >   ```
> > 
> > Maybe the issue caused by function in `python-hideshow-find-next-block`
> > of python.el, that the comment regexp should be "^#" instead of "#"?
> 
> Shouldn't that be something like "^[:space:]*#" instead?

Hi lorniu,
Thanks for pointing out this issue.
After running `hs-hide-all', the buffer will be like this:

```
   if TYPE_CHECKING:...
   else:...  # PathLike is not subscriptable in Python 3.8.
   
   class aaa:
       ...
```

As you pointed out, the class aaa is not hidden.  However, it is also
a problem that the comment is not hidden.

I think it is better to fix `python-hideshow-forward-sexp-function' to
move the point to the end of the line to include the comment.
Attached is the patch to do that.

[-- Attachment #2: 0001-Fix-hiding-a-Python-block-ending-with-a-comment.patch --]
[-- Type: application/octet-stream, Size: 1934 bytes --]

From a65b9c2fde88aa5792b20e210b049a26c88c4c2d Mon Sep 17 00:00:00 2001
From: kobarity <kobarity@gmail.com>
Date: Sat, 25 May 2024 23:20:10 +0900
Subject: [PATCH] Fix hiding a Python block ending with a comment

* lisp/progmodes/python.el (python-hideshow-forward-sexp-function): Move
point to the end of the line.
* test/lisp/progmodes/python-tests.el (python-hideshow-hide-block-2):
New test.  (Bug#71170)
---
 lisp/progmodes/python.el            |  3 ++-
 test/lisp/progmodes/python-tests.el | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 360936c9efd..631d077295c 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -5723,7 +5723,8 @@ python-describe-at-point
 (defun python-hideshow-forward-sexp-function (_arg)
   "Python specific `forward-sexp' function for `hs-minor-mode'.
 Argument ARG is ignored."
-  (python-nav-end-of-block))
+  (python-nav-end-of-block)
+  (end-of-line))
 
 (defun python-hideshow-find-next-block (regexp maxp comments)
   "Python specific `hs-find-next-block' function for `hs-minor-mode'.
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index b19c5c31f16..7b95751bb70 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -7400,6 +7400,24 @@ python-hideshow-hide-block-1
 "))))
 
 
+(ert-deftest python-hideshow-hide-block-2 ()
+  "Should hide the comment at the end of the block."
+  (python-tests-with-temp-buffer
+   "
+def f():
+    a = 1  # Comment
+"
+   (hs-minor-mode 1)
+   (python-tests-look-at "def")
+   (hs-hide-block)
+   (should
+    (string=
+     (python-tests-visible-string)
+     "
+def f():
+"))))
+
+
 (ert-deftest python-tests--python-nav-end-of-statement--infloop ()
   "Checks that `python-nav-end-of-statement' doesn't infloop in a
 buffer with overlapping strings."
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#71170: 30.0.50; hs-hide-all in python mode not works as expected
  2024-05-25 14:36   ` kobarity
@ 2024-05-26  4:39     ` lorniu
  2024-05-26  5:10       ` kobarity
  0 siblings, 1 reply; 11+ messages in thread
From: lorniu @ 2024-05-26  4:39 UTC (permalink / raw)
  To: kobarity; +Cc: Eli Zaretskii, 71170


Maybe patch like this can avoid too much newlines between hidden blocks.

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 79e383a1c1a..26546df13c4 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -5734,7 +5734,12 @@ python-describe-at-point
 (defun python-hideshow-forward-sexp-function (_arg)
   "Python specific `forward-sexp' function for `hs-minor-mode'.
 Argument ARG is ignored."
-  (python-nav-end-of-block))
+  (python-nav-end-of-block)
+  (end-of-line)
+  (let ((pt (point)))
+    (skip-chars-forward " \n\t")
+    (re-search-backward "\n\n" nil t)
+    (when (< (point) pt) (goto-char pt))))

-- 
Mess.





^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#71170: 30.0.50; hs-hide-all in python mode not works as expected
  2024-05-26  4:39     ` lorniu
@ 2024-05-26  5:10       ` kobarity
       [not found]         ` <87fru512ne.fsf@gmail.com>
  0 siblings, 1 reply; 11+ messages in thread
From: kobarity @ 2024-05-26  5:10 UTC (permalink / raw)
  To: lorniu; +Cc: Eli Zaretskii, 71170

lorniu wrote:
> 
> 
> Maybe patch like this can avoid too much newlines between hidden blocks.
> 
> diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
> index 79e383a1c1a..26546df13c4 100644
> --- a/lisp/progmodes/python.el
> +++ b/lisp/progmodes/python.el
> @@ -5734,7 +5734,12 @@ python-describe-at-point
>  (defun python-hideshow-forward-sexp-function (_arg)
>    "Python specific `forward-sexp' function for `hs-minor-mode'.
>  Argument ARG is ignored."
> -  (python-nav-end-of-block))
> +  (python-nav-end-of-block)
> +  (end-of-line)
> +  (let ((pt (point)))
> +    (skip-chars-forward " \n\t")
> +    (re-search-backward "\n\n" nil t)
> +    (when (< (point) pt) (goto-char pt))))
> 
> -- 
> Mess.

It seems this patch hides like this:

```
   if TYPE_CHECKING:...else:...

   class aaa:...
```

Is this what you want?  I think it is overkill to put if and else on
one line.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#71170: 30.0.50; hs-hide-all in python mode not works as expected
       [not found]         ` <87fru512ne.fsf@gmail.com>
@ 2024-05-26  8:31           ` kobarity
  2024-05-26  8:51             ` lorniu
  0 siblings, 1 reply; 11+ messages in thread
From: kobarity @ 2024-05-26  8:31 UTC (permalink / raw)
  To: lorniu; +Cc: Eli Zaretskii, 71170

lorniu wrote:
> 
> 
> > Is this what you want?
> 
> What I want is, for example, this python code:
> 
>   ```
>   if TYPE_CHECKING:
>       Base64FileInput = Union[IO[bytes], PathLike[str]]
>       FileContent = Union[IO[bytes], bytes, PathLike[str]]
>   else:
>       Base64FileInput = Union[IO[bytes], PathLike]
>       FileContent = Union[IO[bytes], bytes, PathLike]  # PathLike is not  subscriptable in Python 3.8.
> 
> 
> 
> 
>   class aaa:
>       ...
> 
> 
> 
>   class bbb:
>       ...
>   ```
> 
> will fold as:
> 
>   ```
>   if TYPE_CHECKING:...
>   else:...
> 
>   class aaa:...
> 
>   class bbb:...
>   ```
> 
> instead of:
> 
>   ```
>   if TYPE_CHECKING:...
>   else:...
> 
> 
> 
> 
>   class aaa:...
> 
> 
> 
>   class bbb:...
>   ```
> 
> That is too much newlines between hidden blocks.
> 
> Maybe the patch I suggested is not well enough. Some update like this
> may be better?
> 
> diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
> index 79e383a1c1a..009e0c4fb3a 100644
> --- a/lisp/progmodes/python.el
> +++ b/lisp/progmodes/python.el
> @@ -5734,7 +5734,13 @@ python-describe-at-point
>  (defun python-hideshow-forward-sexp-function (_arg)
>    "Python specific `forward-sexp' function for `hs-minor-mode'.
>  Argument ARG is ignored."
> -  (python-nav-end-of-block))
> +  (python-nav-end-of-block)
> +  (end-of-line)
> +  (let ((pt (point)))
> +    (skip-chars-forward " \n\t")
> +    (re-search-backward "\n\n" pt t)
> +    (unless (eolp) (goto-char (1- (line-beginning-position))))
> +    (when (< (point) pt) (goto-char pt))))
> 
>  (defun python-hideshow-find-next-block (regexp maxp comments)
>    "Python specific `hs-find-next-block' function for `hs-minor-mode'.
> 
> 
> 
> -- 
> Mess.

The patch works as expected.
I guess it depends on the person whether this kind of behavior is
desirable or not.  Wouldn't it be better to make it a customized
setting or something?





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#71170: 30.0.50; hs-hide-all in python mode not works as expected
  2024-05-26  8:31           ` kobarity
@ 2024-05-26  8:51             ` lorniu
  2024-05-26  9:05               ` kobarity
  0 siblings, 1 reply; 11+ messages in thread
From: lorniu @ 2024-05-26  8:51 UTC (permalink / raw)
  To: kobarity; +Cc: Eli Zaretskii, 71170


I came here mainly to report the bug. My patch is just a suggestion. You
can decide what to do with it. Thanks.

-- 
Mess.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#71170: 30.0.50; hs-hide-all in python mode not works as expected
  2024-05-26  8:51             ` lorniu
@ 2024-05-26  9:05               ` kobarity
  2024-06-08 11:54                 ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: kobarity @ 2024-05-26  9:05 UTC (permalink / raw)
  To: lorniu; +Cc: Eli Zaretskii, 71170

lorniu wrote:
> 
> 
> I came here mainly to report the bug. My patch is just a suggestion. You
> can decide what to do with it. Thanks.
> 
> -- 
> Mess.

Understood.  Then I think it would be better to separate the proposed
improvements to combine blank lines from the bug.

Does anyone want the ability to combine blank lines when hiding blocks?





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#71170: 30.0.50; hs-hide-all in python mode not works as expected
  2024-05-26  9:05               ` kobarity
@ 2024-06-08 11:54                 ` Eli Zaretskii
  2024-06-08 15:22                   ` kobarity
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2024-06-08 11:54 UTC (permalink / raw)
  To: kobarity; +Cc: lorniu, 71170

Ping! Can we please make progress with this bug report?

> Date: Sun, 26 May 2024 18:05:48 +0900
> From: kobarity <kobarity@gmail.com>
> Cc: Eli Zaretskii <eliz@gnu.org>,
> 	71170@debbugs.gnu.org
> 
> lorniu wrote:
> > 
> > 
> > I came here mainly to report the bug. My patch is just a suggestion. You
> > can decide what to do with it. Thanks.
> > 
> > -- 
> > Mess.
> 
> Understood.  Then I think it would be better to separate the proposed
> improvements to combine blank lines from the bug.
> 
> Does anyone want the ability to combine blank lines when hiding blocks?
> 





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#71170: 30.0.50; hs-hide-all in python mode not works as expected
  2024-06-08 11:54                 ` Eli Zaretskii
@ 2024-06-08 15:22                   ` kobarity
  2024-06-09 13:50                     ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: kobarity @ 2024-06-08 15:22 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: lorniu, 71170

Eli Zaretskii wrote:
> Ping! Can we please make progress with this bug report?
> 
> > Date: Sun, 26 May 2024 18:05:48 +0900
> > From: kobarity <kobarity@gmail.com>
> > Cc: Eli Zaretskii <eliz@gnu.org>,
> > 	71170@debbugs.gnu.org
> > 
> > lorniu wrote:
> > > 
> > > 
> > > I came here mainly to report the bug. My patch is just a suggestion. You
> > > can decide what to do with it. Thanks.
> > > 
> > > -- 
> > > Mess.
> > 
> > Understood.  Then I think it would be better to separate the proposed
> > improvements to combine blank lines from the bug.
> > 
> > Does anyone want the ability to combine blank lines when hiding blocks?

I propose to apply my bug fix patch of May 25.  So far, no one seems
to want the new feature, but if they do, they can report the bug
separately.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#71170: 30.0.50; hs-hide-all in python mode not works as expected
  2024-06-08 15:22                   ` kobarity
@ 2024-06-09 13:50                     ` Eli Zaretskii
  0 siblings, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2024-06-09 13:50 UTC (permalink / raw)
  To: kobarity; +Cc: 71170-done, lorniu

> Date: Sun, 09 Jun 2024 00:22:19 +0900
> From: kobarity <kobarity@gmail.com>
> Cc: lorniu@gmail.com,
> 	71170@debbugs.gnu.org
> 
> Eli Zaretskii wrote:
> > Ping! Can we please make progress with this bug report?
> > 
> > > Date: Sun, 26 May 2024 18:05:48 +0900
> > > From: kobarity <kobarity@gmail.com>
> > > Cc: Eli Zaretskii <eliz@gnu.org>,
> > > 	71170@debbugs.gnu.org
> > > 
> > > lorniu wrote:
> > > > 
> > > > 
> > > > I came here mainly to report the bug. My patch is just a suggestion. You
> > > > can decide what to do with it. Thanks.
> > > > 
> > > > -- 
> > > > Mess.
> > > 
> > > Understood.  Then I think it would be better to separate the proposed
> > > improvements to combine blank lines from the bug.
> > > 
> > > Does anyone want the ability to combine blank lines when hiding blocks?
> 
> I propose to apply my bug fix patch of May 25.  So far, no one seems
> to want the new feature, but if they do, they can report the bug
> separately.

Thanks, I installed that patch, and I'm closing the bug.





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-06-09 13:50 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-24  8:40 bug#71170: 30.0.50; hs-hide-all in python mode not works as expected lorniu
2024-05-25 10:28 ` Eli Zaretskii
2024-05-25 14:36   ` kobarity
2024-05-26  4:39     ` lorniu
2024-05-26  5:10       ` kobarity
     [not found]         ` <87fru512ne.fsf@gmail.com>
2024-05-26  8:31           ` kobarity
2024-05-26  8:51             ` lorniu
2024-05-26  9:05               ` kobarity
2024-06-08 11:54                 ` Eli Zaretskii
2024-06-08 15:22                   ` kobarity
2024-06-09 13:50                     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).